Reading Time: 6 minutes

Carrying around cash has become less and less popular these days. After all, why you should worry about losing those precious banknotes from your wallet when you can have all your money safe & sound on your credit card or - on your phone.

 

apple pay integration

 

More and more people appear to agree with that point of view, as Apple Pay users number has tripled over the last year and reached nearly 400 million users! As for payment solution invented in 2014, that’s a pretty impressive score. So if you are thinking about making or upgrading your mobile app - integrating (or not) Apple Pay to it may have a huge impact on its success.

Apple Pay integration advantages - is this payment method safe to use?

 

If you are one of those people who are scared of paying with your phone - just stop. I can assure you, that it is probably much more secure than other solutions, that you are using right now. For example - if you are having a credit card, with a contactless payment option available, all it takes to get you ripped off is losing it. Then, anyone who finds it can pay with it, without even knowing your PIN number to the specific amount on money. With Apple Pay it’s impossible. To access your money you need to positively pass Touch or Face identification process. So even though someone will find your phone laying on the ground it will be extremely difficult for him to steal some money from you.

 

Here are more proofs backing up the “Apple Pay is extremely safe” statement:

  • The information you enter is becoming encrypted so it safely leaves your device when sent to Apple’s servers. Even if someone will intercept them, they will be useless.
  • When you activate Apple Pay on your device, it uses two-factor authentication – they text you a code which must be typed in the app so access to your card is permitted.
  • It has built-in security features to make sure that your transactions are safe.

 

apple pay integration 1

 

  • Even if you will scan your card with your phone camera, it will not be saved on your device or in the iCloud.
  • You can’t use Apple Pay if you don’t have a passcode set up on your device. It also enables you to use biometric authentication methods (Face ID or Touch ID).
  • It doesn’t store or have access to your original card numbers associated with Apple Pay. It also doesn’t save transaction information, that could track back to you.
  • Apple Pay has got many functionalities, that aim is to avoid fraud. Apple may inform your card issuer or other providers associated with your card to the usage of Apple Pay and determine if your card is eligible. If your card is approved, your card issuer creates a Device Account Number, encrypts it, and only afterward the information is sent to Apple.
  • The Device Account Number can’t be decrypted by Apple, but it gets stored in the Secure Element – a chip specifically designed to safely store your information.
  • The Device Account Number in the Secure Element is isolated from Apple’s operating systems (iOS, watchOS, and macOS) and it never gets saved on Apple’s servers or backed up to iCloud.

 

Apple Pay integration tutorial - step by step

 

Below you will find a clear and easy to follow tutorial about how to integrate your app with Apple Pay. In case of any questions and confusion - feel free to ask them in the comment section!

 

  1. First of all, you need to enable Apple Pay Capabilities in Xcode

 

apple pay integration (6)

 

2. Now, you have to create a Merchant ID for your application. You are able to do this automatically using Xcode or Apple Developer service.

  1. Xcode:

 

apple pay integration (9)

 

b) Apple developer service:

Go to developer.apple.com. Open Certificates, Identifiers & Profiles. Next, go to Identifiers. From the left drop-down menu select Merchant IDs.

 

apple pay integration (2)

 

Then, register a new identifier.

 

apple pay integration (5)

 

Provide name and Merchant ID.

 

apple pay integration (1)

 

3. And now - it’s coding time! :)

 

a) Add PassKit library to your project


b) Create PKPaymentRequest


	// 1
        let request = PKPaymentRequest()
        // 2
        request.merchantIdentifier = merchantID
        // 3
        request.countryCode = countryCode // e.g. “US”
        // 4
        request.currencyCode = currency // e.g. “USD”
        // 5
        request.merchantCapabilities = .capability3DS
        // 6
        request.supportedNetworks = supportedNetworks
        // 7
        request.paymentSummaryItems = paymentSummaryItems

Explanation:

  • 1 create the property of PKPaymentRequest
  • 2 Set merchant identifier created earlier
  • 3 Set country code - the two-letter ISO 3166 country code.
  • 4 Set currency - the three-letter ISO 4217 currency code.
  • 5 If the payment should support 3-D Secure or/and EMV protocols we have to set it before payment request.
  • 6 Set supported participating networks. A list of available participating banks is available here.
  • 7 The last step to proper configured PKPaymentRequest object is a list of items, where the last item has to be a summary of all items.

c) Add Apple Pay button

Now it’s time to add Apple Pay button to the view. To do this, we will use PKPaymentButton.

 

apple pay integration (3)

 

d) Present Apple Pay controller

 


let controller = PKPaymentAuthorizationViewController(paymentRequest: request)
self.parentController.present(controller, animated: true)

 

apple pay integration (8)

    1. Implement delegate methods PKPaymentAuthorizationViewControllerDelegate

 


    // 1
    func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
    }
    
    // 2
    func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController,
                                            didAuthorizePayment payment: PKPayment,
                                            handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
    }

 

Explanation:

  • 1 paymentAuthorizationViewControllerDidFinish

Allows handling what should happen after dismissing Apple Pay pop up.

  • 2 paymentAuthorizationViewController(controller: _, didAuthorizePayment: _, completion: _)

Tells us that payment has been authorized and asks for a result. In this method we have to send given payment data to the backend to proceed the payment, e.g. Stripe, Checkout.com or own backend.

 

4. Last but not least, a very important step is testing your Apple Pay integration to make sure it's working fine.

For this purpose, Apple provides us with its Sandbox Testing environment. The first step is to create a sandbox tester account in App Store Connect. For this account, you will need to use the email address that was never used in Apple’s domains. Next step is to log in on devices with newly created account and adding credit cards that you want to test.

 

Conclusion

 

Apple Pay raising popularity is not surprising at all. As we are all living in a constant hurry now, we want to make things as quickly and conveniently as possible. Apple Pay payment method ticks all the boxes in this matter, as it doesn’t require you to add the same credit card over and over to every application that needs it. Just add it to your wallet once and then, all of your apps can use it - of course, if you allow them to do so. That’s why if you are thinking about creating a mobile app offering you to buy some physical goods and services outside of the app - you should definitely give Apple Pay a go!

 

I hope our Apple Pay integration tutorial will serve you well. If you are interested in reading more in the matter of mobile iOS development, check our other article about Storing structs in a persistence storage Protocol-oriented programming.

Protenders banners-1

Recent Posts