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 the orderToken and a status of “SUCCESS” appended as HTTP query parameters.
  • If the Consumer cancels, they will be redirected to the redirectCancelUrl, with the orderToken and a status of “CANCELLED” appended as HTTP query parameters.
Note

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:

  1. AfterPay.initialize - This prepares the Clearpay JavaScript to initiate the Clearpay screenflow in the appropriate geographical region. This function accepts one required argument: an object with a required countryCode property. This property must contain the two-character ISO 3166-1 country code of the Merchant account.
  2. 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 required token property. This property must contain the checkout token returned by Create Checkout.
UK
1<html>
2<head>
3 <script onload="initAfterPay()" src="https://portal.sandbox.clearpay.co.uk/afterpay-async.js" async defer></script>
4</head>
5<body>
6 <p>Your HTML here</p>
7 <script>
8 function initAfterPay () {
9 AfterPay.initialize({countryCode: "GB"});
10 AfterPay.redirect({token: "YOUR_TOKEN"});
11 }
12 </script>
13</body>
14</html>
Tip

Try using your Sandbox Merchant credentials to obtain a token from Create Checkout, then use the token to test the Clearpay screenflow on JSFiddle:

https://jsfiddle.net/afterpay/we9xfqgm/

Note that since JSFiddle loads the Clearpay screenflow inside a frameset, the login and redirect features will not be operational.