Monday, August 17, 2015

Apple Pay - The next generation mobile payment Service


                         So its time to look more about the new initiative of apple i.e Apple Pay.
I believe there is no need to have a brief explanation about what an Apple Pay is, because the name itself clearly mentions what it is.

Someone might have a doubt while hearing about this ..Is it the same InaApp purchase available from the initial version of iOS.Is it the new name of InApp purchase ?
The Answer is NO ... Both are entirely different payment methods in iOS

InApp purchase Vs Apple Pay

InApp purchases are normally using to buy electronic or InApp contents.i.e If you are a magazine developer and you want some editions of the magazines to be paid,then InApp payment method can be used.So to buy electronic contents only we are using InApp purchases.

Apple pay provides an easy,secure and private way to pay for physical goods and services like clothes,groceries,tickets,reservations etc.

Apple pay provides two ways to purchase items -
    • At the point of sale using NFC .This needs additional hardware to communicate with the device.
    • Within iOS app to purchase online groceries and services

Apple Pay APIs are provided by PassKit framework ,whereas the StoreKit framework provides APIs for InApp purchases.

Since the InApp purchase system is quite familiar for all I am trying to give a brief introduction Apple pay here.

At the time of writing this blog this Apple Pay feature is available only in US and UK

Prerequisites for Apple Pay integration into an application

    • Apple Developer Account membership
    • Payment gateway Account .Apple recommends certain payment gateways which supports Apple Pay .
    • Merchant Server to handle the product purchased and trigger payment in payment gateway

Setting up app in developer portal

To setup apple pay in an application it is necessary to create a merchant ID through developer portal.Following are the steps for this

    • Login to apple developer portal and create an app ID for your application(Wild card appID are not able to make payments with Apple Pay)
    • Create a new merchant ID by selecting the “Merchant Ids” option under Identifiers .
It is recommended to create merchant identifiers in the reverse domain style that starts with merchant ,similar to bundle Ids


Setting up App for Apple Pay

Following are the steps to enable apple pay in application
    • Enable Apple pay under “Capabilities” tab in Xcode Project
    • Enabling this will list the merchant Ids created in developer portal.Select the appropriate merchant ID .This will add apple pay entitlement file to the project

Designing App for Apple Pay

So now our app is ready to support apple pay.Now one more recommendation is there from Apple in integrating Apple Pay i.e button images or icons using for Apple Pay.
Apple Pay guidelines provides set of design rules for images to be used for apple pay button.In the latest iOS release (iOS 8.3 at the time of writing this blog),a new button control is introduced named “PKPaymentButton”.We can choose type and style for this button.

The Apple Pay Guidelines provide explanations of the allowable modifications you can make to the provided buttons, as well as guidelines on what colors you may choose to provide the best amount of contrast between the button and your view’s background. In general, you are not allowed to create your own button artwork, but can “stretch” the provided artwork to be wider if necessary


Apple Pay Technique

Following are the basic steps involved in Apple pay payment method ;

Step 1

Create a payment Request and present payment sheet
This is a “PKPaymentRequest” object which holds all the informations about the payment like the merchant ID created on apple developer portal,currency ,country code ,details of items ,price details including the shipping cost and tax etc.The payment sheet will be displayed based on the request object passed to it .So all the price details including tax,Shipping costs,any additional costs etc should be specified in the request object.

Step 2

Implement delegate methods


"PaymentAuthorizationViewcontroller(ControllerLdidAuthorizePayment:Completion:)"

 This handles the users authorization to complete purchase

PaymentAuthorizationViewcontrolleDidFinish(Controller)

This is called when the payment request completes

Step 3

Now setup the app in the payment gateway selected(recommended by Apple).For this create a Certificate Signing Request (CSR) in the gateway.Then upload this CSR under Merchant ID option in Apple Developer Account and then download the certificate and upload it to the payment gateway website.Now the gateway will generate an “Authentication Token”(This will be in encrypted format).For some gateways it will provide test tokens for demo/testing purpose before going live.

Step 4

Now send the authorisation token via “PKPayment” (coming as parameter in delegate method

func paymentAuthorizationViewController(controller: PKPaymentAuthorizationViewController!, didAuthorizePayment payment: PKPayment!, completion: ((PKPaymentAuthorizationStatus) -> Void)!){

})

object to payment gateway server (using the APIs provided by the gateway SDK) for decryption.If successful the server will return another Token.(The CSR generation on the gateway server will create a private key on the server .Later this will create a public key on the apple account that is the certificate generated.So the app will be signed using the merchant ID associated with this public key certificate.So when the app sends the authorization token in encrypted format to payment server,it will try to decrypt it with its own private key.If it succeeds then the server will respond with Token).

Step 5

Send this Token from payment server to Merchants own server .The request for this will contain all the details of the product purchased to let the Merchant server know about the product purchased and the cost details along with the token received from payment server
This will be implemented in the delegate method.Now the Merchant server will trigger the payment by calling the API provided by the Payment gateway server.The Merchant server will then respond to the app by sending a success or failure message based on the status from gateway server.

Step 1 and Step 5 will be implemented on the delegate method


func paymentAuthorizationViewController(controller: PKPaymentAuthorizationViewController!, didAuthorizePayment payment: PKPayment!, completion: ((PKPaymentAuthorizationStatus) -> Void)!){

}

If the above process returns success from merchant server then this delegate will call the completion block by passing the “PKPaymentAuthorizationStatus” as success or failure


Apple Pay Technical Flow





















No comments:

Post a Comment