Afterpay Pacific/Clearpay
Follow this guide to add Afterpay Pacific/Clearpay to your checkout.
- AFTERPAY_PACIFIC - Afterpay Pacific
- CLEARPAY - Clearpay
Payment methods availability:
- Afterpay Pacific since mSDK version 6.8.0
- Clearpay since mSDK version 6.10.0
iOS
Android
Configuration
To integrate Afterpay Pacific/Clearpay you need to add the Afterpay Pacific dependency in your project. Please download the XCFramefork and add the dependency following steps below:
- Download and unzip Afterpay framework from Github.
- Drag and drop
Afterpay.xcframework
to the "Frameworks" folder of your project.
Make sure "Copy items if needed" is checked. - Check "Frameworks, Libraries, and Embedded Content" section under the general settings tab of your application's target. Ensure the Embed dropdown has Embed and Sign selected for the framework.
Open the build.gradle file in the app module and add the following to the dependencies block: build.gradle
:
implementation "com.afterpay:afterpay-android:4.4.0"
Ready-to-Use UI
When you use our ready-to-use UI, everything works out-of-box. Just set AFTERPAY_PACIFIC/CLEARPAY payment brands and shopper result url in the Checkout Settings class and you are done. Proceed with the presenting checkout as for standard transaction.
Please contact Afterpay for configuration details.
OPPCheckoutSettings *checkoutSettings = [[OPPCheckoutSettings alloc] init];
// Set Afterpay Pacific payment methods
checkoutSettings.paymentBrands = @"AFTERPAY_PACIFIC,CLEARPAY";
// Set shopper result URL
checkoutSettings.shopperResultURL = @"com.companyname.appname.payments://result";
// Set Afterpay Pacific configuration
checkoutSettings.afterpayConfig = [[OPPAfterpayConfig alloc] initWithWithMinimumAmount:minimumAmount
maximumAmount:maximumAmount
locale:locale
consumerLocale:consumerLocale];
let checkoutSettings = OPPCheckoutSettings()
// Set Afterpay Pacific payment methods
checkoutSettings.paymentBrands = "AFTERPAY_PACIFIC,CLEARPAY"
// Set shopper result URL
checkoutSettings.shopperResultURL = "com.companyname.appname.payments://result"
// Set Afterpay Pacific configuration
checkoutSettings.afterpayConfig = OPPAfterpayConfig.init(withMinimumAmount: minimumAmount,
maximumAmount: maximumAmount,
locale: locale,
consumerLocale: consumerLocale)
Create the CheckoutSettings
with AFTERPAY_PACIFIC/CLEARPAY payment brand.
Set<String> paymentBrands = new HashSet<>();
paymentBrands.add("AFTERPAY_PACIFIC");
paymentBrands.add("CLEARPAY");
CheckoutSettings checkoutSettings = new CheckoutSettings(
checkoutId,
paymentBrands,
providerMode
);
val paymentBrands = hashSetOf("AFTERPAY_PACIFIC", "CLEARPAY")
val checkoutSettings = CheckoutSettings(
checkoutId,
paymentBrands,
providerMode
)
Set the AfterpayPacificConfig
. Please contact Afterpay for configuration details.
AfterpayPacificConfig config = new AfterpayPacificConfig(
minimumAmount,
maximumAmount,
locale,
consumerLocale
);
checkoutSettings.setAfterpayPacificConfig(config);
val config = AfterpayPacificConfig(
minimumAmount,
maximumAmount,
locale,
consumerLocale
)
checkoutSettings.afterpayPacificConfig = config
SDK & Your Own UI
If you use our mSDK just for backend communication, you will have to go through the Afterpay Pacific SDK integration as well. In this guide we assume you already implemented all steps for performing standard mSDK transaction. There are 3 main steps:
1. Get Afterpay Pacific redirect checkout url
First of all, create OPP
AfterpayPacificPaymentParams/ClearpayPaymentParams
object and submit a transaction and Server will return:
- redirect checkout url to redirect transaction to the Afterpay Pacific.
- callback url to complete the transaction after all.
- failure callback url to handle the failure/cancel transaction.
NSError *error = nil;
OPPAfterPayPaymentParams *paymentParams = [OPPAfterPayPaymentParams afterPayPaymentParamsWithCheckoutID:checkoutID error:&error];
//or
OPPClearPayPaymentParams *paymentParams = [OPPCearPayPaymentParams clearPayPaymentParamsWithCheckoutID:checkoutID error:&error];
// Set shopper result URL
paymentParams.shopperResultURL = @"com.companyname.appname.payments://result";
if (error) {
// See error.code (OPPErrorCode) and error.localizedDescription to identify the reason of failure.
} else {
OPPTransaction *transaction = [OPPTransaction transactionWithPaymentParams:paymentParams];
[self.provider submitTransaction:transaction completionHandler:^(OPPTransaction * _Nonnull transaction, NSError * _Nullable error) {
if (error) {
// Handle the error.
} else {
// Use the following params to complete transaction via AfterPay SDK.
NSString *redirectCheckoutUrl = transaction.brandSpecificInfo[@"redirectCheckoutUrl"];
NSString *callbackUrl = transaction.brandSpecificInfo[@"callbackUrl"];
NSString *failureCallbackUrl = transaction.brandSpecificInfo[@"failureCallbackUrl"];
}
}];
}
do {
let paymentParams = try OPPAfterPayPaymentParams(checkoutID: checkoutID, error: error)
//or
let paymentParams = try OPPClearPayPaymentParams(checkoutID: checkoutID, error: error)
// Set shopper result URL
paymentParams.shopperResultURL = "com.companyname.appname.payments://result"
let transaction = OPPTransaction(paymentParams: paymentParams)
provider.submitTransaction(transaction) { (transaction, error) in
if (error != nil) {
// Handle the error.
} else {
// Use the following params to complete transaction via AfterPay SDK.
let redirectCheckoutUrl = transaction.brandSpecificInfo[@"redirectCheckoutUrl"];
let callbackUrl = transaction.brandSpecificInfo[@"callbackUrl"]
let failureCallbackUrl = transaction.brandSpecificInfo[@"failureCallbackUrl"];
}
}
} catch let error as NSError {
// See error.code (OPPErrorCode) and error.localizedDescription to identify the reason of failure.
}
PaymentParams paymentParams;
paymentParams = new AfterpayPacificPaymentParams(checkoutId);
// or
paymentParams = new ClearpayPaymentParams(checkoutId);
// set shopper result URL
paymentParams.setShopperResultUrl("companyname://result");
Transaction transaction = new Transaction(paymentParams);
paymentProvider.submitTransaction(transaction);
// use the following params to complete the transaction via Afterpay Pacific SDK
String redirectCheckoutUrl = transaction.getBrandSpecificInfo().get(Transaction.AFTERPAY_PACIFIC_REDIRECT_URL);
String callbackUrl = transaction.getBrandSpecificInfo().get(Transaction.AFTERPAY_PACIFIC_CALLBACK_URL_KEY);
String failureCallbackUrl = transaction.getBrandSpecificInfo().get(Transaction.AFTERPAY_PACIFIC_FAILURE_CALLBACK_URL_KEY);
val paymentParams = AfterpayPacificPaymentParams(checkoutId)
// or
val paymentParams = ClearpayPaymentParams(checkoutId)
// set shopper result URL
paymentParams.shopperResultUrl = "companyname://result"
val transaction = Transaction(paymentParams)
paymentProvider.submitTransaction(transaction)
// use the following params to complete the transaction via Afterpay Pacific SDK
val redirectCheckoutUrl = transaction.brandSpecificInfo[Transaction.AFTERPAY_PACIFIC_REDIRECT_URL]
val callbackUrl = transaction.brandSpecificInfo[Transaction.AFTERPAY_PACIFIC_CALLBACK_URL_KEY]
val failureCallbackUrl = transaction.brandSpecificInfo[Transaction.AFTERPAY_PACIFIC_FAILURE_CALLBACK_URL_KEY]
NOTE: To learn more about shopper result url refer to Asynchronous Payments guide.
2. Proceed with the Afterpay Pacific Mobile SDK
As soon as redirect checkout url is received, you can initialize and load Afterpay Pacific SDK. Just follow the steps from Afterpay Pacific integration guideAfterpay Pacific integration guide.
NSString *checkoutUrl = transaction.brandSpecificInfo[@"checkoutUrl"];
[APAfterpay presentCheckoutModallyOverViewController:topViewController
loadingCheckoutURL:checkoutUrl
animated:true
completion:^(APCheckoutResult *result) {
NSString *urlString = nil;
if ([result isKindOfClass:[APCheckoutResultSuccess class]]) {
urlString = transaction.brandSpecificInfo[@"callbackUrl"];
} else {
urlString = transaction.brandSpecificInfo[@"failureCallbackUrl"];
}
//Process callbackUrl as mentioned in the step 3
}];
var checkoutUrl: String! = transaction.brandSpecificInfo["checkoutUrl"]
APAfterpay.presentCheckoutModallyOverViewController(topViewController, loadingCheckoutURL: url, animated: true) { (result: APCheckoutResult!) -> Void in
var urlString: String! = nil
if result.isKind(of: APCheckoutResultSuccess.self) {
urlString = transaction.brandSpecificInfo["callbackUrl"]
} else {
urlString = transaction.brandSpecificInfo["failureCallbackUrl"]
}
//Process callbackUrl as mentioned in the step 3
}
As soon as redirect checkout url is received, you can initialize and load Afterpay Pacific SDK. The configuration must be set first, see Configuring the SDK for details. Once configuration is set, follow the steps from Afterpay Pacific integration guide to launch Afterpay.
Intent intent = Afterpay.createCheckoutIntent(this, redirectCheckoutUrl);
val intent = Afterpay.createCheckoutIntent(this, redirectCheckoutUrl)
3. Notify Server about payment completion
In order to complete the transaction you have to send additional request to backend.
If Afterpay Pacific activity returns result code Activity.RESULT_OK, use callbackUrl
to notify backend about transaction completion by sending a GET request.
String callbackUrl = transaction.getBrandSpecificInfo().get(Transaction.AFTERPAY_PACIFIC_CALLBACK_URL_KEY);
val callbackUrl = transaction.brandSpecificInfo[Transaction.AFTERPAY_PACIFIC_CALLBACK_URL_KEY]
Otherwise use failureCallbackUrl
to notify server about it.
String failureCallbackUrl = transaction.getBrandSpecificInfo().get(Transaction.AFTERPAY_PACIFIC_FAILURE_CALLBACK_URL_KEY);
val failureCallbackUrl = transaction.brandSpecificInfo[Transaction.AFTERPAY_PACIFIC_FAILURE_CALLBACK_URL_KEY]
NOTE: Expected response from callback urls is a redirect to the shopper result url. You might want to check that status and location of redirect url are valid, or it's also an option just to ignore the response. Request payment status as usual to get final result of the transaction.