Friday, 12 June 2015

IOS:Apple Pay Integration

 Apple Pay (Apple payment gateway integration)

Apple Pay is a mobile payment technology that lets users give you their payment information for real-world goods and services in a way that is both convenient and secure.Here some step (what would be need to Apple Pay integration) are mention above steps to integrate Apple Pay in your app. 

Step 1 - Configuring Your Environment

A merchant ID identifies you to Apple Pay as being able to accept payments. The public key and certificate associated with your merchant ID is used as part of the payment process to encrypt payment information. Before your app can use Apple Pay, you need to register a merchant ID and configure its certificate.

- To register a merchant ID

In Member Center, select Certificates,Identifiers & Profiles. 
Under Identifiers, select Merchant IDs
Click the Add button (+) in the upper-right corner.
Enter a description and identifier, and click Continue.
Review the settings, and click Register.
Click Done.

-To configure a certificate for your merchant ID

In Member Center, select Certificates,Identifiers & Profiles.
Under Identifiers, select Merchant IDs
Select the merchant ID from the list, and click Edit.
Click Create Certificate, follow the instructions to obtain or generate your certificate signing request (CSR), and click Continue.
Click Choose File, select your CSR, and click Generate.
Download the certificate by clicking Download, and click Done.

If you see a warning in Keychain Access that the certificate was signed by an unknown authority or that it has an invalid issuer, make sure you have the WWDR intermediate certificate - G2 and the Apple Root CA - G2 installed in your keychain. 

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 IDs you want the app to use.

Step 2 - Setting Up

Apple Pay uses the PassKit framework, so you’ll need to be sure to include this in your project and import it into the necessary files.

#import <PassKit/PassKit.h>

You’ll also want to receive callbacks when Apple Pay processes information, so be sure to add the delegate to the receiving class:

@interface ViewController : UIViewController <PKPaymentAuthorizationViewControllerDelegate>

Step 3 - Create Payment Request

You’ll want to be sure to check whether or not the device will handle payments, which you can do with the code here:

if([PKPaymentAuthorizationViewController canMakePayments]) { ... }

Within that block, you can create a payment request using the `PKPayment` class. Modify this information as needed (make sure your `merchantIdentifier` matches the one you created in the previous step!).

PKPaymentRequest *request = [[PKPaymentRequest alloc] init];

        request.countryCode = @"US";
        request.currencyCode = @"USD";
        request.supportedNetworks = @[PKPaymentNetworkAmex,           PKPaymentNetworkMasterCard, PKPaymentNetworkVisa];
        request.merchantIdentifier = @"";
        request.merchantCapabilities = PKMerchantCapabilityEMV;

Step 4 - Add Items To Payment

You can create items to display using the `PKPaymentSummaryItem`. This object represents an item and a price. The last object in the array must be the total value.

 PKPaymentSummaryItem *widget1 = [PKPaymentSummaryItem summaryItemWithLabel:@"Widget 1"  amount:[NSDecimalNumber decimalNumberWithString:@"0.99"]];
PKPaymentSummaryItem *widget2 = [PKPaymentSummaryItem summaryItemWithLabel:@"Widget 2"  amount:[NSDecimalNumber decimalNumberWithString:@"1.00"]];
PKPaymentSummaryItem *total = [PKPaymentSummaryItem summaryItemWithLabel:@"Grand Total"amount:[NSDecimalNumber decimalNumberWithString:@"1.99"]];

request.paymentSummaryItems = @[widget1, widget2, total];

Step 5 - Present the Authorisation view controller

Finally, present the view controller that is provided by the PassKit framework. This will take care of the authorisation.

PKPaymentAuthorizationViewController *paymentPane = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
 paymentPane.delegate = self;
 [self presentViewController:paymentPane animated:TRUE completion:nil];

Step 6 - Implement delegate methods

After the framework displays the transaction’s status, the authorisation view controller calls your delegate’s paymentAuthorizationViewControllerDidFinish: method. In your implementation, dismiss the authorisation view controller and then display your own app-specific order-confirmation page.

(void)paymentAuthorizationViewControllerDidFinish: (PKPaymentAuthorizationViewController *)controller

When the user authorises a payment request, the framework creates a payment token by coordinating with Apple’s server and the Secure Element, which is a dedicated chip on the user’s device. You send this payment token to your server in the paymentAuthorizationViewController:didAuthorizePayment:completion: delegate method, along with any other information you need to process the purchase

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
 didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus status))completion

1 comment:

  1. I know your expertise on this. I must say we should have an online discussion on this. Writing only comments will close the discussion straight away! And will restrict the benefits from this information.
    payment gateway integration