Standard Checkout
Production
Sandbox
The afterpay.js
is used to launch the Clearpay screen flow, where the consumer logs in (or registers) then confirms their payment schedule.
Note
Before this JavaScript can be used, the merchant must call Create Checkout from their server backend and retrieve a checkout token. The token is then used in conjunction with this JavaScript to launch the Clearpay screen flow.
Note
It is only after the consumer completes the Clearpay screen flow and returns to the merchant’s website that a subsequent Auth or Capture (Without Auth) call can be completed.
Redirect Method
The Redirect Method is the standard method used by most merchants. This method redirects the consumer away from the merchant’s website to Clearpay to complete their payment. At the end of the process, the consumer will be redirected back to the merchant’s website.
- If the Consumer clicks “confirm”, they will be redirected to the
redirectConfirmUrl
, with theorderToken
and astatus
of “SUCCESS” appended as HTTP query parameters. - If the Consumer cancels, they will be redirected to the
redirectCancelUrl
, with theorderToken
and astatus
of “CANCELLED” appended as HTTP query parameters.
The Merchant defines the redirectConfirmUrl and redirectCancelUrl for each order in their Create Checkout call.
To implement the Redirect Method, the following two JavaScript functions must be called, in order:
AfterPay.initialize
- This prepares the Clearpay JavaScript to initiate the Clearpay screen flow in the appropriate geographical region. This function accepts one required argument: an object with a requiredcountryCode
property. This property must contain the two-character ISO 3166-1 country code of the Merchant account.AfterPay.redirect
- This redirects the consumer’s browser from the merchant’s website to Clearpay. This function accepts one required argument: an object with a requiredtoken
property. This property must contain the checkout token returned by Create Checkout.
Tip
Try using your Sandbox Merchant credentials to obtain a token from Create Checkout, then use the token to test the Clearpay screen flow on JSFiddle:
https://jsfiddle.net/afterpay/we9xfqgm/
Note that since JSFiddle loads the Clearpay screen flow inside a frame-set, the login and redirect features will not be operational.
Popup Method
The Popup Method can be used to open the Clearpay screen flow in a new browser window. For windowed applications, the merchant website will be overlaid with a semi-transparent curtain, with the Clearpay window on top. For fullscreen applications (such as mobile), the browser will switch to a new tab for the Clearpay window. In any case, the consumer will complete the Clearpay screen flow in the same manner as they would if the Redirect Method was used.
The main difference is what happens when the payment is complete. Instead of redirecting to a URL on the merchant website with additional query parameters appended, Clearpay will use postMessage
to call a JavaScript method on the merchant’s front end.
- If the Consumer clicks “confirm”, Clearpay will call the
onComplete
method on the Merchant website, passing theorderToken
and astatus
of “SUCCESS” as properties of a data object. The popup will close. - If the Consumer cancels, Clearpay will call the
onComplete
method on the Merchant website, passing theorderToken
and astatus
of “CANCELLED” as properties of a data object. The popup will close.
Although this method does not redirect the Consumer to the redirectConfirmUrl
or redirectCancelUrl
, these fields are still required by Create Checkout, and are used for context on postMessage
.
At the time of screen flow completion, if the protocol, host and port of the opening window do not match those provided in Create Checkout, the consumer’s browser will not dispatch the JavaScript event for security reasons.