Skip to content

Set Up the Amazon Pay SDK

Follow these steps to set up the Amazon Pay SDK.

  1. Download the specific SDK version available at Amazon Pay SDKs.

    Caution

    If you use a version of the Amazon Pay SDK not downloaded from the above link, your integration may fail.

  2. Add the AmazonPayHardenediOSSDK.framework and LoginWithAmazon.framework files into your project by following the steps here.

  3. Generate and validate your API keys. For more information, see Obtain API Keys.

  4. Update info.plist. Append the following snippet to the info.plist file by accessing it as a source code:

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>amzn-$(PRODUCT_BUNDLE_IDENTIFIER)</string>
            </array>
        <key>CFBundleURLName</key>
        <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
        </dict>
    </array>
    

    This ensures proper handling of URL schemes within your application.

  5. Generate a code challenge based on the iOS environment you are using:

  6. Configure AppDelegate.m (Objective-C) or AppDelegate.swift (Swift):

    #import <LoginWithAmazon/LoginWithAmazon.h>
    #import <AmazonPayHardenediOSSDK/AmazonPay.h>
    
    static NSString *AMZN_REGEX = @"amzn.*";
    
    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
        NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:AMZN_REGEX options:0 error:nil];
    
        if ([regex numberOfMatchesInString:[url absoluteString] options:0 range:NSMakeRange(0, [[url absoluteString] length])] > 0) {
            return [[AmazonPay sharedInstance] handleRedirectURL:url sourceApplication:sourceApplication];
        }
    
        return false;
    }
    
    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
        NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:AMZN_REGEX options:0 error:nil];
    
        if ([regex numberOfMatchesInString:[url absoluteString] options:0 range:NSMakeRange(0, [[url absoluteString] length])] > 0) {
            return [[AmazonPay sharedInstance] handleRedirectURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]];
        }
    
        return false;
    }
    
    import UIKit
    import AmazonPayHardenediOSSDK
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
        var window: UIWindow?
    
        func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
            do {
                let regex = try NSRegularExpression(pattern: "amzn-.*")
                let results = regex.matches(in: url.absoluteString, range: NSRange(url.absoluteString.startIndex..., in: url.absoluteString))
    
                if results.count > 0 {
                    return AmazonPay.sharedInstance().handleRedirectURL(url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as! String)
                } else {
                    return false
                }
            } catch let error {
                print("invalid regex: \\(error.localizedDescription)")
                return false
            }
        }
    }