Link Account
Users of the merchant application must link their Amazon Pay Later account with the merchant account. To enable this, the SDK facilitates the retrieval of an authCode, exchangeable for a pair of auth tokens. These tokens allow the merchant application to access Amazon Pay’s server-side APIs.
Request Parameters
Parameter | Type | Description |
---|---|---|
CodeChallenge | String | SHA-256 hashed code challenge for authCode gen. |
Response Parameters
Parameter | Type | Description |
---|---|---|
Status | String | GRANTED: User granted consent; DENIED: User denied consent. |
authCode | String | Code exchangeable for auth token |
clientId | String | Merchant application's mobile client ID |
redirectUri | String | Redirect URI of the merchant application |
Using Objective C
Calling the API
APayAuthorizeCallbackHandler *apayCallback = [[APayAuthorizeCallbackHandler alloc] init];
apayCallback.delegate = self;
APayAuthorizeRequest *request = [APayAuthorizeRequest build:^(id<APayAuthorizeRequestBuilder> builder) {
[builder withCodeChallenge:[[AuthProofKey generate] codeChallenge]];
}];
[[AmazonPay sharedInstance] authorize:request apayAuthorizeCallback: apayCallback];
Handling the response
AuthorizeDelegate.h
#import <Foundation/Foundation.h>
#import <AmazonPayHardenediOSSDK/APayAuthorizationResponse.h>
@protocol AuthorizeDelegate
-(void) authorizationSuccess: (APayAuthorizationResponse *)response;
@end
APayAuthorizeCallbackHandler.h
#import <Foundation/Foundation.h>
#import <AmazonPayHardenediOSSDK/APayAuthorizationResponse.h>
@protocol AuthorizeDelegate
-(void) authorizationSuccess: (APayAuthorizationResponse *)response;
@end
APayAuthorizeCallbackHandler.m
#import "APayAuthorizeCallbackHandler.h"
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <SafariServices/SafariServices.h>
#import "SilentPayHelper.h"
@implementation APayAuthorizeCallbackHandler
- (void)onCancel:(NSError *)error {
//this is called when user clicked 'done' button in safari view
//or selected 'cancel' option when asked for consent to link Amazon account
}
- (void)onMobileSDKError:(NSError *)error {
//mobile sdk specific error
}
- (void)onNetworkUnavailable {
// SDK could not connect to the network
}
- (void)onFailure:(NSError *)error {
// link account failed
}
- (void)onSuccess:(APayAuthorizationResponse *)response {
//successfully authorized, calls 'authorizationSuccess' implemented by the Delegate
if (_delegate) {
[_delegate authorizationSuccess:response];
}
}
@end
Using Swift
Calling the API
let apay = APayAuthorizeCallbackHandler()
apay.delegate = self
let request:APayAuthorizeRequest = APayAuthorizeRequest.build({(builder) in builder?.withCodeChallenge(AuthProofKey.sharedInstance.codeChallenge)})
AmazonPay.sharedInstance()?.authorize(request, apayAuthorizeCallback: apay)
Handling the response
The response from above API call can be handled using below code.
APayAuthorizeCallbackHandler.swift
import Foundation
import AmazonPayHardenediOSSDK
protocol AuthorizeSuccessDelegate: class {func authorizationSuccess(response:APayAuthorizationResponse)}
class APayAuthorizeCallbackHandler : APayAuthorizeCallbackDelegate {
var delegate:AuthorizeSuccessDelegate?
func onSuccess(_ response: APayAuthorizationResponse!) {
if ((delegate)!= nil) {
delegate?.authorizationSuccess(response: response);
}
}
func onFailure(_ error: Error!) {
//authorize failure
}
func onMobileSDKError(_ error: Error!) {
//mobile sdk specific error
}
func onNetworkUnavailable() {
//could not connect to network
}
func onCancel() {
//user selected cancle option or closed the SFSafariWebView
}
}