Afterpay/Clearpay

Take an Afterpay/Clearpay payment

Usage

Code playground

index.html

Payments

Returned by Square.payments(appId, locationId).

Use this object to instantiate Payment methods. Learn more on the Payments page.

Methods

payments.js
JS
JavaScript

const payments = Square.payments(appId, locationId);

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

}