Integrating MPSDK on iOS

Apple Pay®

Apple Pay is fully PSD2 compliant.
Wirecard ensures that our merchants will stay PSD2 compliant without any additional change in the implementation process.
Before you start you should have access to your testing environment at this point.

Since Apple Pay® is a proprietary service, the setup process requires a different approach.

To set it up, you need to:

  1. Contact our merchant support to create a test Wirecard Payment Gateway Apple Pay merchant account and set up its Apple Merchant ID.

  2. Depending on whether you have an existing Apple Merchant ID, you will need to:

    1. upload the CSR file you’ve received in the previous step,

      or

    2. register with the Apple Merchant ID provided by Wirecard and upload the CSR file.

      Additional information can be found in Apple’s documentation.

After you’ve set up your accounts:

  1. You can add a test card to the Wallet app.

  2. Integrate paymentSDK into your application

  3. Conduct testing

  4. Add a live card to the Wallet app and switch the Wirecard Payment Gateway to production mode (do not forget to use production credentials - MAID/SK/AppleMerchantID/csr)

Executing ApplePay Transactions

There are two approaches, depending on your requirements:

  1. You need full control over PKPaymentRequest (dynamic shipping methods and pricing); use WDApplePayPayment

  2. If you only execute simple transactions with a fixed shipping price, use WDApplePayManagedPayment, and paymentSDK will handle the PKPaymentRequest by itself.

You will find a detailed approach to using both of these in their respective subsections.

Integrating with WDApplePayPayment
  1. Initialize WDClient:

    - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
                           didAuthorizePayment:(PKPayment *)payment
                                    completion:(void (^)(PKPaymentAuthorizationStatus status))completion
    {
        // it is better to keep client as property to keep reference
        WDClient *client = [[WDClient alloc] initWithEnvironment:WDEnvironmentTEST];
  2. Initialize WDApplePayPayment

    WDApplePayPayment *applePayPayment = [[WDApplePayPayment alloc] initWithPayment:payment
                                                                        summaryItems:self.sumaryItems
                                                                            currency:currency];
  3. Generate requestID, requestTimestamp, and requestSignature on your server and assign them to WDApplePayPayment:

     applePayPayment.merchantAccountID = merchantAccountID;   // provided by support
     applePayPayment.requestID = [[NSUUID UUID] UUIDString];  // generated on server, unique to merchant
     applePayPayment.requestTimestamp = [NSDate date];        // generated on server
     applePayPayment.requestSignature = signature;            // generated on server
  4. Create a completionBlock to handle the response, then call PKPaymentAuthorizationViewController completion block to handle response:

    WDCompletionBlock completionBlock = ^(WDPaymentResponse *_Nullable response, NSError *_Nullable error) {
         if (error) {
             IPLogError(@"error: %@", error);
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                 message:error.localizedDescription
                                                                delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [alertView show];
             completion(PKPaymentAuthorizationStatusFailure);
             return;
         }
         completion(PKPaymentAuthorizationStatusSuccess);
     };
  5. Execute the transaction:

    [client makePayment:applePayPayment withCompletion:completionBlock];
    }
Integrating with WDApplePayManagedPayment
  1. Initialize WDClient:

    - (void)makeApplePayManaged
     {
         // it is better to keep client as property to keep reference
         WDClient *client = [[WDClient alloc] initWithEnvironment:WDEnvironmentTEST];
  2. Initialize WDApplePayPayment:

    WDApplePayManagedPayment *applePayPayment = [[WDApplePayManagedPayment alloc] initWithMerchant:kAppleMerchantID
                                                                                         andCountry:WDCountryGB];
    applePayPayment.amount = [NSDecimalNumber decimalNumberWithMantissa:1275 exponent:-2 isNegative:NO];
    applePayPayment.amountCurrency = WDCurrencyGBP;
  3. Generate requestID, requestTimestamp, and requestSignature on your server and assign them to WDApplePayManagedPayment:

    applePayPayment.merchantAccountID = merchantAccountID;   // provided by support
    applePayPayment.requestID = [[NSUUID UUID] UUIDString];  // generated on server, unique to merchant
    applePayPayment.requestTimestamp = [NSDate date];        // generated on server; UTC
    applePayPayment.requestSignature = signature;            // generated on server
  4. Create a WDCompletionBlock to handle the response:

    WDCompletionBlock completionBlock = ^(WDPaymentResponse *_Nullable response, NSError *_Nullable error) {
         if (error) {
             IPLogError(@"error: %@", error);
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                 message:error.localizedDescription
                                                                delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [alertView show];
             return;
         }
         // handle successful response
     };
  5. Execute the transaction:

    [client makePayment:applePayPayment withCompletion:completionBlock];
    }

Simple Transactions

  1. Initialize WDClient:

    - (void)makeCardPayment
     {
         // it is better to keep client as property to keep reference
         WDClient *client = [[WDClient alloc] initWithEnvironment:WDEnvironmentTEST];
  2. Initialize WDCardPayment:

    WDCardPayment *payment = [[WDCardPayment alloc] initWithAmount:[NSDecimalNumber decimalNumberWithMantissa:1275 exponent:-2 isNegative:NO]
                                                      amountCurrency:WDCurrencyEUR
                                                     transactionType:WDTransactionTypePurchase];
  3. Generate requestID, requestTimestamp, andrequestSignature on your server and assign them to WDCardPayment:

     payment.merchantAccountID = merchantAccountID;   // provided by support
     payment.requestID = [[NSUUID UUID] UUIDString];  // generated on server, unique to merchant
     payment.requestTimestamp = [NSDate date];        // generated on server
     payment.requestSignature = signature;            // generated on server
  4. Create a WDCompletionBlock to handle the response:

    WDCompletionBlock completionBlock = ^(WDPaymentResponse *_Nullable response, NSError *_Nullable error) {
         if (error) {
             IPLogError(@"error: %@", error);
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                 message:error.localizedDescription
                                                                delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [alertView show];
             return;
         }
         // handle successful response
     };
  5. Execute the transaction:

    [client makePayment:payment withCompletion:completionBlock];
     }

WDCardField Alternative

WDCardField is a specialized field for collecting card data, with properties similar to UITextField. It is designed to fit in a single line and can be used where an UITextField would be appropriate:

  1. Create a WDCardField (programmatically, or in XIB/Storyboard) and keep the instance reference in your UIViewController:

    \@interface PaymentViewController UIViewController<WDCardFieldDelegate>
    
    \@property (nonatomic, weak) IBOutlet WDCardField *cardField;
    \@property (nonatomic, weak) IBOutlet UIButton *paymentButton;
    \@property (nonatomic, strong) WDClient *client;
    
    @end
  2. Initialize it using WDCardPayment:

    Initializing WDCardField
    @implementation PaymentViewController
    
    - (void)viewDidLoad {
         WDCardPayment *payment = [[WDCardPayment alloc] initWithAmount:[NSDecimalNumber decimalNumberWithMantissa:1275 exponent:-2 isNegative:NO]
                                                         amountCurrency:WDCurrencyEUR
                                                        transactionType:WDTransactionTypePurchase];
         WDCard *card = nil;
         WDCardToken *token = nil;
         if (shouldCollectSecurityCodeOnly) {
             token = [WDCardToken new];
             token.tokenID = @"4585779929881111";
             token.maskedAccountNumber = @"444433******1111";
    
             // It is convenient to set the card data if you're only collecting the security code. The respective card brand security code is validated.
             card = [WDCard new];
             card.brand = WDCardBrandVisa;
             card.expiryDate = [NSDate date];
         }
         WDCardField *cardField = self.cardField;
         cardField.cardPayment = [self buildPaymentWithToken:token];
         cardField.card = card;
         cardField.delegate = self; // it can be set via XIB as well
    
         // initalize a WDClient instance
         self.client = [[WDClient alloc] initWithEnvironment:WDEnvironmentTEST];
     }
  3. Implement the WDCardFieldDelegate protocol to handle user actions listed in WDCardFieldState:

    #pragma mark - WDCardFieldDelegate
    
    - (void)cardField:(WDCardField *)cardField didChangeState:(WDCardFieldState)state {
         // simple data validation
         self.paymentButton.enabled = cardField.valid;
    
         // you can improve the UX by handling state and showing hints to user
     }
  4. Execute the transaction:

    Triggering the Payment
    #pragma mark - Payment Button action
    
    - (IBAction)makePayment:(UIButton *)sender {
         WDPayment *payment = self.cardField.cardPayment;
    
         // The data can be created in advance; requestTimestamp expiration is 30 mins.
         payment.merchantAccountID = merchantAccountID;   // provided by support
         payment.requestID = [[NSUUID UUID] UUIDString];  // generated on server unique to merchant
         payment.requestTimestamp = [NSDate date];        // generated on server
         payment.requestSignature = signature;            // generated on server
    
         // Create a block to handle the response
         WDCompletionBlock completionBlock = ^(WDPaymentResponse *_Nullable response, NSError *_Nullable error) {
             if (error) {
                 WDErrorCode errorCode = error.code;
                 // handle error
                 return;
             }
             // handle success
         }];
    
         // Triggering the payment
         [self.client makePayment:payment withCompletion:completionBlock];
     }
    
     @end

Pay by Bank app

  1. Override AppDelegate's method:

    - (void)application:(UIApplication *)app
                openURL:(NSURL *)url
                options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
    {
        [self.client openURL:url];
    }
  2. Implement makePBBAPayment in AppDelegate. You need to initialize WDClient:

    - (void)makePBBAPayment
         // it is better to keep client as property to keep reference
         self.client = [[WDClient alloc] initWithEnvironment:WDEnvironmentTEST];
  3. Initialize WDPBBAPayment:

    WDPBBAPayment *payment = [[WDPBBAPayment alloc] initWithAmount:[NSDecimalNumber decimalNumberWithMantissa:1275 exponent:-2 isNegative:NO]
                                                    amountCurrency:WDCurrencyGBP
                                                   transactionType:WDTransactionTypeDebit];
    payment.IPAddress = @"127.0.0.1";
    payment.pbbaReturnAppScheme = @"app-scheme";      // the scheme is defined by merchant, shall be unique and enabled in App's Info.plist
    payment.pbbaDeliveryType = pbbaDeliveryType;      // possible values zapp.in.DeliveryType
    payment.pbbaTransactionType = pbbaTransactionType;// possible values zapp.in.TxType
    Important notes
    • The only supported transaction type is debit.

    • The only supported currency is GBP.

    • IPAddress is mandatory for this payment method.

    • pbbaTransactionType is one of following options: BILLPT, PAYMT, INVOICE, DONATIONS .

    • pbbaDeliveryType is one of following options: COLLST, DELTAD, DIGDEL, SERVICE, F2F, NONE.

    • pbbaReturnAppScheme is the URL scheme used in the bank application to redirect the consumer back to your application.
      More information for PBBA specific parameters can be found in PBBA REST API.

  4. Generate requestID, requestTimestamp, and requestSignature on your server and assign them to the WDPBBAPayment:

    payment.merchantAccountID = merchantAccountID;   // provided by support
    payment.requestID = [[NSUUID UUID] UUIDString];  // generated on server, unique to merchant
    payment.requestTimestamp = [NSDate date];        // generated on server
    payment.requestSignature = signature;            // generated on server
  5. Create a WDCompletionBlock to handle the response:

    WDCompletionBlock completionBlock = ^(WDPaymentResponse *_Nullable response, NSError *_Nullable error) {
         if (error) {
             IPLogError(@"error: %@", error);
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                 message:error.localizedDescription
                                                                delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [alertView show];
             return;
         }
         // handle successful response
     };
  6. Execute the transaction:

        [self.client makePayment:payment withCompletion:completionBlock];
    }
  7. You need to use the PBBAButton to call the makePBBAPayment method.

  8. Next, either the PBBA dialog is shown or the banking application is opened.

  9. Consumer makes the payment in the banking application and is redirected back to your application. The application returns success or timeout depending on the response.

PayPal

  1. Initialize WDClient:

    - (void)makePayPalPayment
     {
         // it is better to keep client as property to keep reference
         WDClient *client = [[WDClient alloc] initWithEnvironment:WDEnvironmentTEST];
  2. Initialize WDPayPalPayment:

    WDPayPalPayment *payment = [[WDPayPalPayment alloc] initWithAmount:[NSDecimalNumber decimalNumberWithMantissa:1275 exponent:-2 isNegative:NO]
                                                               currency:WDCurrencyEUR];
    payment.transactionType = WDTransactionTypeDebit;
  3. Generate requestID, requestTimestamp, and requestSignature on your server and assign them to the WDPayPalPayment:

    payment.merchantAccountID = merchantAccountID;   // provided by support
    payment.requestID = [[NSUUID UUID] UUIDString];  // generated on server, unique to merchant
    payment.requestTimestamp = [NSDate date];        // generated on server
    payment.requestSignature = signature;            // generated on server
  4. Create a WDCompletionBlock to handle the response:

    WDCompletionBlock completionBlock = ^(WDPaymentResponse *_Nullable response, NSError *_Nullable error) {
         if (error) {
             IPLogError(@"error: %@", error);
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                 message:error.localizedDescription
                                                                delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [alertView show];
             return;
         }
         // handle successful response
     };
  5. Execute the transaction:

    [client makePayment:payment withCompletion:completionBlock];
     }

SEPA Direct Debit

  1. Initialize WDClient:

    - (void)makeSEPAPayment
     {
         // it is better to keep client as property to keep reference
         WDClient *client = [[WDClient alloc] initWithEnvironment:WDEnvironmentTEST];
  2. Initialize WDSEPAPayment:

    WDSEPAPayment *payment = [[WDSEPAPayment alloc] initWithCreditor:creditorID
                                                           andMandate:mandateID];
    payment.transactionType = WDTransactionTypePendingDebit;
    payment.amount          = [NSDecimalNumber decimalNumberWithMantissa:1275 exponent:-2 isNegative:NO];
    payment.amountCurrency  = WDCurrencyEUR;
  3. Generate requestID, requestTimestamp, and requestSignature on your server and assign them to WDSEPAPayment:

    payment.merchantAccountID = merchantAccountID;   // provided by support
    payment.requestID = [[NSUUID UUID] UUIDString];  // generated on server, unique to merchant
    payment.requestTimestamp = [NSDate date];        // generated on server
    payment.requestSignature = signature;            // generated on server
  4. Create a WDCompletionBlock to handle the response:

    WDCompletionBlock completionBlock = ^(WDPaymentResponse *_Nullable response, NSError *_Nullable error) {
         if (error) {
             IPLogError(@"error: %@", error);
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                 message:error.localizedDescription
                                                                delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [alertView show];
             return;
         }
         // handle successful response
     };
  5. Execute the transaction:

    [client makePayment:payment withCompletion:completionBlock];
     }
Custom URL: