Hi, I’m working with Shopify Functions in the checkout, specifically for payment methods. I want to fully replace Additional Scripts, but I’m encountering a problem.
For example, I was able to change the names for credit card payments, but no matter what, I can’t change the order of payments or modify the name of PayPal (for instance, adding something in parentheses). I assume it’s because PayPal is listed as an Additional Payment Method and maybe that’s why it can’t be modified at all.
But why can’t I set my own order? I’ve tried different things, for example:
for (let i = 0; i < paymentMethods.length; i++) {
const method = paymentMethods[i];
if (method.name === "Other Payments") {
otherPaymentsIndex = i;
otherPaymentsId = method.id;
}
}
if (otherPaymentsIndex > 0 && otherPaymentsId) {
operations.push({
move: {
paymentMethodId: otherPaymentsId,
position: otherPaymentsIndex - 1,
},
});
}
However, I keep getting an error in the logs in the Shopify Partner panel: InvalidOutputError.
It’s a bit strange because, in Additional Scripts, I was able to hide payments by country, change the order, etc.
I used this documentation:
Can anyone help me figure this out? Here’s the part for renaming that works, but it doesn’t catch PayPal:
export function run(input) {
/** @type {FunctionRunResult['operations']} */
const operations = [];
for (const method of input.paymentMethods) {
if (method.name === "Adyen Payments - Credit Cards") {
operations.push({
rename: {
paymentMethodId: method.id,
name: "💳 Credit Card (Recommended)",
},
});
}
if (method.name === "Other Payments") {
operations.push({
rename: {
paymentMethodId: method.id,
name: "Other Payments (Not Recommended)",
},
});
}
if (method.name === "PayPal Express Checkout" || method.name === "PayPal)") {
operations.push({
rename: {
paymentMethodId: method.id,
name: "PayPal (Not Recommended)",
},
});
}
}
if (operations.length === 0) {
return NO_CHANGES;
}
return {
operations,
};
}`
In general, I need three things:
- Modifying names
- Modifying order
- Hiding based on country.