Applications take Afterpay payments (Clearpay in the UK) using a combination of the Web Payments SDK and the Payments API. This topic explains how to use the Payments API CreatePayment endpoint on your backend to process an Afterpay/Clearpay payment. The client side is explained in Take Afterpay and Clearpay Payments. This topic refers to Afterpay and Clearpay as "Afterpay" because the same API, calling pattern, and values are used with both payment types.
CreatePayment request, use a Web Payments SDK payment token that represents Afterpay in the
source_id field. Creating an Afterpay payment is a two-step process:
Generate a payment token - Your web application uses the Web Payments SDK to get an Afterpay payment token. The SDK provides the UI for the buyer to sign in to Afterpay, provides Afterpay with the cart information and checkout amount, and returns the payment token.
Charge the payment token - The backend of your application makes a
CreatePaymentcall to charge the payment token. The amount you charge must be equal to the checkout amount provided to Afterpay.
The following shows an example
CreatePaymentrequest. The request charges $100 USD to Afterpay. The
source_idfield identifies Afterpay as the payment source.
The response is as follows:
The following are important response details:
source_typeindicates the payment source as
buy_now_pay_later_detailsappears in the resulting
Paymentonly for the Afterpay payments.
email_addressis the email of the Afterpay account holder, which is the buyer making the purchase.
To test Afterpay payments in the Square Sandbox, get a test payment token using one of the following methods:
Use a Square-provided Afterpay payment token - Square provides Afterpay Sandbox payment tokens as
source_idvalues for testing the backend component of your application.
Use the following test payment tokens as
CreatePaymentrequests for testing Afterpay payments in the Sandbox.
When you use these tokens, you can test
CreatePaymentcalls without charging an actual Afterpay account or running the client side of your application. The tokens don't represent a live Afterpay account. However, the
CreatePaymentendpoint returns a payment response as if the account is real.
Run the Web Payments SDK sample application to generate a payment token - The sample provides an end-to-end Afterpay payment experience. For information about building and running the sample, see Take Afterpay and Clearpay Payments.
Create an Afterpay test customer account - Use this test account to log in to Afterpay. For more information about creating an Afterpay test account and test credit card, see Afterpay Sandbox Guide.
Set up a web application - Integrate the Web Payments SDK into your application.
Use the Afterpay-provided credit card to make a card payment to Afterpay - After the buyer confirms the entire installment plan and provides a credit card for the first installment, Afterpay returns the confirmation to the Web Payments SDK. The SDK then generates a payment token.
Create a payment using the Payments API - The application calls
CreatePayment(Payments API) in the Square Sandbox by specifying the payment token.
The payment token that the Web Payments SDK generates in Sandbox mode results in a successful
CreatePaymentSandbox environment call.
Guidelines for charging Afterpay using
CreatePayment include the following:
- Application developers should ensure that Afterpay supports their merchant category code (MCC). Each seller location has an MCC that describes the types of goods or services sold at that location. Certain MCCs aren't supported by Afterpay (see Check for eligibility and limitations). In such cases, the Web Payments SDK doesn't display Afterpay as a payment option.
Limitations for charging Afterpay using
CreatePayment include the following:
The Web Payments SDK shows the Afterpay payment option only if the following are true:
- The seller is eligible for Afterpay.
- The checkout amount is within the min/max limit set by Afterpay. Afterpay sets a min/max payment limit for each seller. This limit applies to each checkout amount. When a buyer is ready to check out, the Web Payments SDK shows the Afterpay payment option only if the checkout amount is within this range.
Only the Web Payments SDK supports Afterpay as a payment source.
Afterpay has specific payment size limits that differ by region and type of payment. For example, Afterpay monthly payments allow higher limits than Afterpay's "Pay in 4" payments. For more information, see Monetary amount limits.
For credit card payments, authorization indicates that the purchase amount is within credit card limits or the buyer has enough funds on the card. An authorization puts a hold on the specific amount.
An Afterpay payment authorization means that the buyer is charged the first installment by Afterpay and the installment plan is started.
Afterpay allows refunds up to 120 days from the date of purchase.
Afterpay is available in countries according to the Afterpay/Clearpay table.