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 Afterpay 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.

The Merchant defines the redirectConfirmUrl and redirectCancelUrl for each order in their Create Order call.

To implement the Redirect Method, the following two JavaScript functions must be called, in order:

  1. AfterPay.initialize - This prepares the Afterpay JavaScript to initiate the Afterpay 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 Afterpay. This function accepts one required argument: an object with a required token property. This property must contain the order token returned by Create Order.

AU

1<html>
2<head>
3 <script onload="initAfterPay()" src="https://portal.sandbox.afterpay.com/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: "AU"});
10 AfterPay.redirect({token: "YOUR_TOKEN"});
11 }
12 </script>
13</body>
14</html>

NZ

1<html>
2<head>
3 <script onload="initAfterPay()" src="https://portal.sandbox.afterpay.com/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: "NZ"});
10 AfterPay.redirect({token: "YOUR_TOKEN"});
11 }
12 </script>
13</body>
14</html>

US

1<html>
2<head>
3 <script onload="initAfterPay()" src="https://portal.sandbox.afterpay.com/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: "US"});
10 AfterPay.redirect({token: "YOUR_TOKEN"});
11 }
12 </script>
13</body>
14</html>

CA

1<html>
2<head>
3 <script onload="initAfterPay()" src="https://portal.sandbox.afterpay.com/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: "CA"});
10 AfterPay.redirect({token: "YOUR_TOKEN"});
11 }
12 </script>
13</body>
14</html>

Try using your Sandbox Merchant credentials to obtain a token from Create Order, then use the token to test the Afterpay screenflow on JSFiddle: https://jsfiddle.net/afterpay/cyd3pxfj/

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