Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Help! Payment Customization Checkout

Solved

Help! Payment Customization Checkout

javieralarcn10
Shopify Partner
9 2 3

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
  };
};

 

Accepted Solution (1)
javieralarcn10
Shopify Partner
9 2 3

This is an accepted solution.

Now fixed, the function was not applied just by changing the country, you had to fill in the zip and the city for it to be applied.

View solution in original post

Replies 2 (2)

sniper2804
Shopify Partner
407 25 68

Can you paste the screenshot of the output?

Automate & bulk assign products to shipping profile: Auto Shipping Profiles: Shipr
Calculate accurate shipping rates: Shipping Calculator: ShipMagic
Hide, rename, reorder payment methods at checkout: Payment Customization: PayMix
javieralarcn10
Shopify Partner
9 2 3

This is an accepted solution.

Now fixed, the function was not applied just by changing the country, you had to fill in the zip and the city for it to be applied.