App reviews, troubleshooting, and recommendations
I have the following code which in theory should hide a payment method if the shipping country is Spain or not, but it doesn't work, does anyone know what could be wrong?
Thank you very much in advance.
// @TS-check
// Use JSDoc annotations for type safety
/**
* @typedef {import("../generated/api").RunInput} RunInput
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
*/
/**
* @type {FunctionRunResult}
*/
// The configured entrypoint for the 'purchase.payment-customization.run' extension target
/**
* @Anonymous {RunInput} input
* @returns {FunctionRunResult}
*/
export function run(input) {
// Find the payment method to hide
const moneiPaymentMethod = input.paymentMethods
.find(method => method.name.includes("Pagar con tarjeta u otros métodos de pago"));
const klarnaPaymentMethod = input.paymentMethods
.find(method => method.name.includes('Klarna'));
const sequraPaymentMethod = input.paymentMethods
.find(method => method.name.includes('seQura'));
const isSpain = input.cart.deliveryGroups
.find(code => code.deliveryAddress?.countryCode == 'ES')
const operationsData = []
if (moneiPaymentMethod) {
operationsData.push({
rename: {
name: 'Bizum',
paymentMethodId: moneiPaymentMethod.id
}
})
}
if (klarnaPaymentMethod && isSpain?.deliveryAddress?.countryCode == 'ES') {
operationsData.push({
hide: {
paymentMethodId: klarnaPaymentMethod.id
}
})
}
if(sequraPaymentMethod && isSpain?.deliveryAddress?.countryCode != 'ES'){
operationsData.push({
hide: {
paymentMethodId: sequraPaymentMethod.id
}
})
}
// The @Shopify/shopify_function package applies JSON.stringify() to your function result
// and writes it to STDOUT
return {
operations: operationsData
};
};
Solved! Go to the solution
This is an accepted solution.
Fixed
Hello bro, is this code you are using to hide the payment methods?
I am working on a similar code, but I still have some errors.
I would be very helpful with your solution.
Best Regards
Show me your code and what is failing you to see if I can help you.
sorry what was the solution that fixed it for you?
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024