PaymentSDK
Mobile payment SDK
Example

Supported transaction type is purchase only and there are 2 flows based on users requirements:

  • If a merchant requires a full control over PKPaymentRequest (dynamic shipping methods and pricing) then use WDApplePayPayment.
  • If the purchase is simple with fix shipping price use WDApplePayManagedPayment to handle PKPaymentRequest by SDK.

WDApplePayPayment example

  1. Initialize WDClient instance
    1 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
    2  didAuthorizePayment:(PKPayment *)payment
    3  completion:(void (^)(PKPaymentAuthorizationStatus status))completion
    4 {
    5  // it is better to keep client as property to keep reference
    6  WDClient *client = [[WDClient alloc] initWithEnvironment:WDEnvironmentTEST];
  2. Initialize WDApplePayPayment instance
    1 WDApplePayPayment *applePayPayment = [[WDApplePayPayment alloc] initWithPayment:payment
    2  summaryItems:self.sumaryItems
    3  currency:currency];
  3. Generate requestID, requestTimestamp and requestSignature on your server and assign them to WDApplePayPayment object
    1 applePayPayment.merchantAccountID = merchantAccountID; // provided by support
    2 applePayPayment.requestID = [[NSUUID UUID] UUIDString]; // generated on server unique to merchant
    3 applePayPayment.requestTimestamp = [NSDate date]; // generated on server
    4 applePayPayment.requestSignature = signature; // generated on server
  4. Create completionBlock to handle response and call PKPaymentAuthorizationViewController completion block provided to delegate
    1 WDCompletionBlock completionBlock = ^(WDPaymentResponse *_Nullable response, NSError *_Nullable error) {
    2  if (error) {
    3  IPLogError(@"error: %@", error);
    4  UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
    5  message:error.localizedDescription
    6  delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    7  [alertView show];
    8  completion(PKPaymentAuthorizationStatusFailure);
    9  return;
    10  }
    11  completion(PKPaymentAuthorizationStatusSuccess);
    12 };
  5. Trigger the payment
    1  [client makePayment:applePayPayment withCompletion:completionBlock];
    2 }

WDApplePayManagedPayment example

  1. Initialize WDClient instance
    1 - (void)makeApplePayManaged
    2 {
    3  // it is better to keep client as property to keep reference
    4  WDClient *client = [[WDClient alloc] initWithEnvironment:WDEnvironmentTEST];
  2. Initialize WDApplePayManagedPayment instance
    1 WDApplePayManagedPayment *applePayPayment = [[WDApplePayManagedPayment alloc] initWithMerchant:kAppleMerchantID
    2  andCountry:WDCountryGB];
    3 applePayPayment.amount = [NSDecimalNumber decimalNumberWithMantissa:1275 exponent:-2 isNegative:NO];
    4 applePayPayment.amountCurrency = WDCurrencyGBP;
  3. Generate requestID, requestTimestamp and requestSignature on your server and assign them to request WDApplePayManagedPayment
    1 applePayPayment.merchantAccountID = merchantAccountID; // provided by support
    2 applePayPayment.requestID = [[NSUUID UUID] UUIDString]; // generated on server unique to merchant
    3 applePayPayment.requestTimestamp = [NSDate date]; // generated on server; UTC
    4 applePayPayment.requestSignature = signature; // generated on server
  4. Create WDCompletionBlock to handle response
    1 WDCompletionBlock completionBlock = ^(WDPaymentResponse *_Nullable response, NSError *_Nullable error) {
    2  if (error) {
    3  IPLogError(@"error: %@", error);
    4  UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
    5  message:error.localizedDescription
    6  delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    7  [alertView show];
    8  return;
    9  }
    10  // handle successful response
    11 };
  5. Trigger the payment
    1  [client makePayment:applePayPayment withCompletion:completionBlock];
    2 }