AfterpayClearpay

Create an Afterpay/Clearpay payment method instance.

Methods

afterpayClearpay.js
JS
JavaScript

const paymentRequest = payments.paymentRequest({

  countryCode: 'US',

  currencyCode: 'USD',

  total: {

    amount: '5.79',

    label: 'Total'

  },

  requestShippingContact: true,

});



paymentRequest.addEventListener('afterpay_shippingaddresschanged', function (contact) {

  return {

    shippingOptions: [

      {

        id: 'FREE',

        amount: '0.00',

        label: 'Free',

        taxLineItems: [

          {

            id: 'taxItem1',

            label: 'Taxes',

            amount: '3.50',

          }

        ],

        total: {

          amount: '9.29',

          label: 'Total'

        }

      }

    ],

  }

});



const afterpayClearpay = await payments.afterpayClearpay(paymentRequest);

await afterpayClearpay.attach('#afterpay');





afterpayClearpayButton.onclick = async () => {

  const tokenResult = await afterpayClearpay.tokenize();



  // Pass the TokenResult to your server to complete the payment

}