...
In the demo project, the payment methods are presented in a tableView, including ApplePay. In the following code snippet is demonstrated the population of a cell, providing a title and an image of the respective payment method.
PaymentMethodTableViewCell * cell = [ self . tableView
dequeueReusableCellWithIdentifier :@ "PaymentMethodTableViewCell" forIndexPath : indexPath ];
AxeptaPaymentMethod * paymentMethod = [[ self paymentMethods ]
objectAtIndex : indexPath . row ];
cell . labelTitle . text = paymentMethod . localizedDescription;
[ cell . paymentImageView setImage : paymentMethod . image ]; |
---|
4.3.4.Checkout
After the configuration of the SDK is completed and all necessary payment data are imported, you can proceed with the checkout for a selected payment method.
Start the checkout by instantiating a AxeptaCheckout object. The AxeptaCheckout class is a top-level class that facilitates the payment procedure. It is responsible for validating payment data and instantiating a AxeptaCheckoutViewController object when a new payment is triggered by passing the respective paymentMethod including the paymentData .
AxeptaCheckout * checkout = [[ AxeptaCheckout alloc ] init ]; |
---|
Proceed with the checkout by presenting a AxeptaCheckoutViewController which is a subclass of UIViewController encapsulating all the views’ stack.
AxeptaPaymentMethod * paymentMethod = [[ self paymentMethods ]
objectAtIndex : indexPath . row ];
[ self . checkout instantiateCheckoutViewControllerWithPaymentMethod : paymentMethod
onSuccess :^( AxeptaCheckoutViewController
* checkoutViewController ) {
checkoutViewController . delegate = self;
// show the new chekoutViewController
// maybe push it on navigation stack
} onFailure :^( NSError * error ) {
// handle the error
}]; |
---|
Receive results from checkout by conforming to AxeptaCheckoutViewControllerDelegate and implementing its methods:
- ( void ) checkoutDidAuthorizePaymentForPaymentData :( id < AxeptaPaymentDataProtocol >) paymentData
withResponse :( AxeptaPaymentRespose *) response
-
( void ) checkoutDidFailToAuthorizePaymentForPaymentData :( id < AxeptaPaymentDataProtocol >) paymentData
withError :( NSError *) error withResponse :( AxeptaPaymentRespose *) response
- ( void ) checkoutDidCancelForPaymentData :( AxeptaPaymentData *) paymentData; |
---|
4.4.Apple Pay
4.4.1.Configuration
...
To enable Apple Pay for your app in XCode, open the Capabilities pane. Select the switch in the Apple Pay row, and then select the merchant ID you want the app to use.
Insert “ Merchant ID ” in the AppDelegate.
#import "AppDelegate.h"
#import <Axepta.h>
@implementation AppDelegate
- ( BOOL ) application :( UIApplication *) application
didFinishLaunchingWithOptions :( NSDictionary *) launchOptions
{
AxeptaConfiguration . merchantAppleID = @ "YOUR_MERCHANT_ID";
return YES;
}
@end |
---|
4.4.1.3. Testing Apple Pay transactions
...
Start Apple Pay by instantiating a AxeptaApplePay object. The AxeptaApplePay class is a top-level class that facilitates the Apple Pay payment procedure. It is responsible for validating payment data and instantiating a PKPaymentAuthorizationViewController object when a new payment is triggered by passing the respective paymentData and paymentMethod .
AxeptaApplePay * applePay = [[ AxeptaApplePay alloc ] init ];
applePay . delegate = self; |
---|
Setup PKPaymentSummaryItem objects:
PKPaymentSummaryItem * paymentSummaryItem1 = [[ PKPaymentSummaryItem alloc ] init ];
paymentSummaryItem1 . label = @ "SUMMARY_ITEM_1_LABEL";
paymentSummaryItem1 . amount = 'SUMMARY_ITEM_1_AMOUNT';
PKPaymentSummaryItem * paymentSummaryItem2 = [[ PKPaymentSummaryItem alloc ] init ];
paymentSummaryItem2 . label = @ "SUMMARY_ITEM_2_LABEL";
paymentSummaryItem2 . amount = 'SUMMARY_ITEM_2_AMOUNT';
PKPaymentSummaryItem * paymentSummaryItemTotal = [[ PKPaymentSummaryItem alloc ] init ];
paymentSummaryItemTotal . label = @ "Total";
paymentSummaryItemTotal . amount = 'TOTAL_AMOUNT'; |
---|
Present the PKPaymentAuthorizationViewController :
AxeptaPaymentMethod * applePayPaymentMethod = [[ Axepta sharedInstance ]
paymentMethodForID : @ "pm_applepay" ];
NSArray * supportedNetworks = @[ PKPaymentNetworkVisa , PKPaymentNetworkMasterCard ,
PKPaymentNetworkAmex , PKPaymentNetworkDiscover ];
[ self . applePay
instantiatePKPaymentAuthorizationViewControllerWithPaymentMethod : self . paymentData
withPaymentSummaryItems : /*your array with PaymentSummaryItems*/
withSupportedNetworks : supportedNetworks
withRequiredShippingAddressFields : self . selectedPKShipping
paymentAuthorizationViewController :^( PKPaymentAuthorizationViewController
* applePayViewController ) {
// show apples pay view controller
[ self presentViewController : applePayViewController
animated : true
completion : nil ];
} onFailure :^( NSError * error ) {
// handle the error
}]; |
---|
AxeptaApplePayDelegate
Implement AxeptaApplePayDelegate protocol’s methods in order to get notified of navigation actions and on ApplePay payment’s result:
- ( void ) applePayDidDismiss {
}
-
( void ) applePayDidAuthorizePaymentForPaymentData :( id < AxeptaPaymentDataProtocol >) paymentDa
ta withResponse :( AxeptaPaymentRespose *) response {
}
-
( void ) applePayDidFailToAuthorizePaymentForPaymentData :( id < AxeptaPaymentDataProtocol >) pay
mentData withError :( NSError *) error withResponse :( AxeptaPaymentRespose *) response {
}
- ( void ) applePayPaymentDidSelectPaymentMethod :( PKPaymentMethod *) paymentMethod
completion :( void (^)( NSArray < PKPaymentSummaryItem *> *)) completion {
}
- ( void ) applePayPaymentDidSelectShippingContact :( PKContact *) contact completion :( void
(^)( PKPaymentAuthorizationStatus , NSArray < PKPaymentSummaryItem *> *)) completion {
} |
---|
4.4.3. iOS Human Interface Guidelines
...
For making payments with WeChat developer should use WeChat class with the public method: startPaymentWithPaymentData.
AxeptaWeChat *weChat = [[ AxeptaWeChat alloc ] init ];
[weChat startPaymentWithPaymentData :paymentMethod
success :^( NSData *data) {
} failure :^( NSError *error) {
}]; |
---|
4.6. PayPal
Developer first should declare the scheme that he will use to return to the merchant App.
...
To respond to requests made to the custom URL type, the application openURL method must be implemented in the application delegate. The openURL method should send a notification to Axepta in order to complete or cancel the PayPal checkout. The notification keys must be same as follows:
- ( BOOL )application:( UIApplication *)application openURL:( NSURL *)url
sourceApplication:( NSString *)sourceApplication
annotation:( id )annotation {
if ([url. scheme localizedCaseInsensitiveCompare : @"com.merchant.MerchantApp.PayPalReturn" ]
== NSOrderedSame ) {
if ([url. host localizedCaseInsensitiveCompare : @"return" ] == NSOrderedSame ) {
NSNotificationCenter * nc = [ NSNotificationCenter defaultCenter ];
[nc postNotificationName : @"completePayPalCheckout" object : self userInfo : nil ];
}
else {
NSNotificationCenter * nc = [ NSNotificationCenter defaultCenter ];
[nc postNotificationName : @"cancelPayPalCheckout" object : self userInfo : nil ];
}
NSLog ( @"%@" , url. host );
return YES ;
}
return NO ;
} |
---|
Important note : Developer should add to main project -l"PPRiskComponent" under the Build settings → Other linker flags the Magnes library used by Axepta.
...
To init PayPal and call the payment method developer should use the following code:
AxeptaayPal *payPal = [[ AxeptaayPal alloc ] init ];
[payPal startPaypalPay :paymentMethod
success :^( NSData *data) {
//Handle the succes
} failure :^( NSError *error) {
//Handle the failure
}]; |
---|