- Get Started
- Guides
- Integrations
- References
- API Reference
- Basic Payment
- Forex
- Authentication
- Card Account
- Apple Pay
- Virtual Account
- Bank Account
- Token Account
- Customer
- Billing Address
- Merchant Billing Address
- Shipping Address
- Merchant Shipping Address
- Merchant
- Corporate
- Recipient
- Marketplace & Cart
- Airline
- Lodging
- Passenger
- Tokenization
- Recurring Migration
- 3D Secure
- Custom Parameters
- Async Payments
- Webhook notifications
- Job
- Risk
- Point of Sale
- Response Parameters
- Card On File
- Chargeback
- Result Codes
- Payment Methods
- Transaction Flows
- Regression Testing
- Data Retention Policy
- API Reference
- Support
- Impressum
Amazon Pay
Follow this guide to add Amazon Pay to your checkout.
Brand constants to be used:
- AMAZONPAY - Amazon Pay
Payment methods availability:
- Amazon Pay since mSDK version 6.16.0
iOS
Android
Register AmazonPay custom URL scheme
Add this custom url scheme in your app's Info.plist
:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>com.amazon.mobile.shopping</string>
</array>
SDK & Your Own UI
In this guide we assume that you have already implemented all steps for performing standard mSDK transaction.
There are several steps that you have to perform to integrate Amazon Pay, which are as follows:
1. Create AmazonPay brand configuration
Create AmazonPay brand configuration with AmazonPayConfig.AmazonPayRegion.
OPPAmazonPayConfig *brandConfig = [[OPPAmazonPayConfig alloc] initWithRegion:OPPAmazonPayRegionUS];
let config = OPPAmazonPayConfig(region: .US)
2. Create AmazonPay payment param
Use checkoutId and brandConfiguration object created earlier to create AmazonPay Payment params.
NSError *error;
OPPAmazonPayPaymentParams *params = [OPPAmazonPayPaymentParams amazonPayPaymentParamsWithCheckoutID:checkoutID
configuration:brandConfig
error:error];
params.shopperResultURL = @"com.companyname.appname.payments://result";
var params: OPPAmazonPayPaymentParams
do {
params = try OPPAmazonPayPaymentParams.amazonPayPaymentParamsWith(checkoutID: checkoutID, configuration: config)
params.shopperResultURL = "com.companyname.appname.payments://result"
} catch let error as NSError {
// Handle the error.
}
3. Submit transaction
Create a payment provider object and call submit transaction.
OPPTransaction *transaction = [OPPTransaction transactionWithPaymentParams:params];
OPPPaymentProvider *provider = [OPPPaymentProvider paymentProviderWithMode:providerMode];
[self.provider submitTransaction:transaction completionHandler:^(OPPTransaction * _Nonnull transaction, NSError * _Nullable error) {
// Use transaction.redirectURL to get universal link to present AmazonPay.
}];
let transaction = OPPTransaction(paymentParams: params)
let provider = OPPPaymentProvider(mode: providerMode)
let transaction = OPPTransaction(paymentParams: params)
provider.submitTransaction(transaction) { (transaction, error) in
// Use transaction.redirectURL to get universal link to present AmazonPay.
}
4. Redirect to AmazonPay
Use transaction.redirectURL to present AmazonPay in Amazon shopping app or Safari browser to complete the transaction.
NSURL *redirectURL = transaction.redirectURL;
NSString *amazonAppName = @"com.amazon.mobile.shopping://";
NSURL *amazonAppUrl = [NSURL URLWithString:amazonAppName];
if ([[UIApplication sharedApplication] canOpenURL:amazonAppUrl]) {
[[UIApplication sharedApplication] openURL:URL];
} else {
SFSafariViewController *safariVc = [[SFSafariViewController alloc] initWithURL:URL];
safariVc.delegate = delegate;
[self presentViewController:vc animated:YES completion:nil];
}
let amazonAppName = "com.amazon.mobile.shopping://"
if let amazonAppUrl = URL(string: amazonAppName),
UIApplication.shared.canOpenURL(amazonAppUrl) {
UIApplication.shared.open(url)
} else {
self.safariVC = SFSafariViewController(url: url)
self.safariVC?.delegate = self
self.present(safariVC!, animated: true, completion: nil)
}
NOTE: A server-to-server FI call needs to be initiated which is further sent to Amazon Pay. This returns an Amazon Pay URL to which the shopper is expected to be redirected. Once redirected, Amazon Pay processes the transaction and redirects the shopper back to the merchant application.
5. Get the payment status
Finally your app should request the payment status from your server.
For more details you can refer to this document.
1. Create AmazonPay brand configuration
Create AmazonPay brand configuration with AmazonPayConfig.AmazonPayRegion.
AmazonPayConfig amazonPayConfig = new AmazonPayConfig(AmazonPayConfig.AmazonPayRegion.US);
val amazonPayConfig = AmazonPayConfig(AmazonPayConfig.AmazonPayRegion.US)
2. Create AmazonPay payment param and submit transaction
Use checkoutId and amazonPayConfig(AmazonPayConfig) object created earlier in step -> 1 to create AmazonPay Payment params.
AmazonPayPaymentParams paymentParams = new AmazonPayPaymentParams(checkoutId, amazonPayConfig);
paymentParams.setShopperResultUrl("com.companyname.appname.payments://result");
//Create Transaction object by passing AmazonPayPaymentParams, then create payment provider object and call submit transaction
Transaction transaction = new Transaction(paymentParams);
OppPaymentProvider paymentProvider = new OppPaymentProvider(this, Connect.ProviderMode.TEST);
paymentProvider.submitTransaction(transaction, this);
val paymentParams = AmazonPayPaymentParams(checkoutId, amazonPayConfig)
paymentParams.shopperResultUrl = "com.companyname.appname.payments://result"
//Create Transaction object by passing AmazonPayPaymentParams, then create payment provider object and call submit transaction.
val transaction = Transaction(paymentParams)
val paymentProvider = OppPaymentProvider(this, Connect.ProviderMode.TEST)
paymentProvider.submitTransaction(transaction, this)
3. Implement ITransactionListener
Now, let the class implement the ITransactionListener
interface. Implement the following ITransactionListener
methods:
@Override
public void transactionCompleted(Transaction transaction) {
// method which has been created in step 4 would be called here
if ("AMAZONPAY".equals(transaction.getPaymentParams().getPaymentBrand())){
redirectUsingUniversalLink(transaction.getRedirectUrl());
} else {
// code for other brands
}
}
@Override
public void transactionFailed(@NonNull Transaction transaction, @NonNull PaymentError error) {
// show error message
}
override fun transactionCompleted(transaction: Transaction) {
// method which has been created in step 4 would be called here
if ("AMAZONPAY" == transaction.paymentParams.paymentBrand) {
redirectUsingUniversalLink(transaction.redirectUrl)
} else {
// code for other brands
}
}
override fun transactionFailed(transaction: Transaction, error: PaymentError) {
// show error message
}
4. Redirect to AmazonPay
In transactionCompleted() method that you have overriden in step -> 3, call this below method inside it.
public void redirectUsingUniversalLink(String url) {
String amazonPackageName = "com.amazon.mShop.android.shopping";
boolean isAmazonAppInstalled;
try {
getPackageManager().getPackageInfo(amazonPackageName, PackageManager.GET_ACTIVITIES);
isAmazonAppInstalled = true;
} catch (PackageManager.NameNotFoundException e) {
isAmazonAppInstalled = false;
}
if (isAmazonAppInstalled) {
// if amazon shopping app is available on user device, it will open the app
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
} else {
// else you have to open the url in chrome custom tab
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setShareState(CustomTabsIntent.SHARE_STATE_OFF);
CustomTabsIntent tabIntent = builder.build();
tabIntent.launchUrl(context, url);
}
}
fun redirectUsingUniversalLink(url: String) {
val amazonPackageName = "com.amazon.mShop.android.shopping"
val isAmazonAppInstalled: Boolean = try {
packageManager.getPackageInfo(amazonPackageName, PackageManager.GET_ACTIVITIES)
true
} catch (e: PackageManager.NameNotFoundException) {
false
}
if (isAmazonAppInstalled) {
// if amazon shopping app is available on user device, it will open the app
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
} else {
//else you have to open the url in chrome custom tab
val builder = CustomTabsIntent.Builder()
builder.setShareState(CustomTabsIntent.SHARE_STATE_OFF)
val tabIntent = builder.build()
tabIntent.launchUrl(context, url)
}
}
NOTE: A server-to-server FI call needs to be initiated which is further sent to Amazon Pay. This returns an Amazon Pay URL to which the shopper is expected to be redirected. Once redirected, Amazon Pay processes the transaction and redirects the shopper back to the merchant application.
5. Get the payment status
Finally your app should request the payment status from your server.
For more details you can refer to this document.