How to Successfully Integrate Apple Pay into Your iOS App?

How to Successfully Integrate Apple Pay into Your iOS App?

Setting up a payment gateway for your mobile app represents the most important thing as long as you’re planning to sell things. If the process is inconvenient and the page takes too long to load customers tend to abandon the purchase. By integrating Apple Pay into your iOS app you can make online shopping fast and easy for your customers.

Reasons for Integrating Apple Pay

More and more people are turning to their phones when it comes to online shopping. Mobile payments represent an ever-increasing trend, a reason for why you should make the process as efficient and as easy as possible. Since the base of mobile payment users is quite high, making the checkout simple will surely help your clients.

Apple made the world of mobile payments extremely easy. Their Apple Pay technology allows you to pay for stuff with a single touch. Its integration in an iOS app will allow customers to process payments directly through Messenger or even Siri.

Apple Pay can be integrated with your business in two major ways. Firstly, you can use it in a land-based store and take advantage of the wonders of NFC technologies. This will allow clients to pay directly with their phone, removing the need for carrying a wallet. However, the owner will have to install at least one NFC terminal to make this process work. The other method is by integrating Apple technology into your mobile app.

Security online is becoming an ever more important topic. Over 50% of mobile online shoppers are concerned about the security of their private information. Happily, Apple Pay is considered to be a highly-secured method as it utilizes a unique code and a device-specific number for each user. As it doesn’t store your card number on the payment terminal your information is fully secure.

Read More: How Better Mobile Onboarding Can Help Banks Target Millennials and Gen Z

Although not all merchants support this technology, Apple Pay experiences constant user growth each year. A total of 43% of all iPhone users have this payment technology activated on their phones. This statistic represents a great opportunity for business owners as not too many merchants are using Apple Pay as of now.

When looking at Apple Pay and the Apple Card we can easily say that the company is determined to change the traditional payment systems. Apple has had a solid streak since the number of Apple Pay users doubled between 2017 and now.

Most problems regarding the adoption of this technology concern the brick-and-mortar stores as they are greatly lagging behind. Using Apple Pay technology online is considerably more popular. iOS users would surely appreciate the ability to purchase goods and services within your mobile app through the Apple secure gateway.

Any successful business should integrate multiple payment methods, Apple Pay being one of them. In this article, we will share a couple of useful tips regarding Apple Pay Integration.

Read More: In-App Versus Open Web: Adopting Strategies for Optimal Customer Engagement

How to Set Up Apple Pay in Your App

Swift 4 represents the go-to language for Apple Pay integration. To set up the right environment for integration, you must follow the below steps:

  • Create a Merchant ID
  • Configure Apple Pay capabilities in Xcode for your project
  • Create a sandbox user in iTunes Connect
  • Add a test card
  • Create a payment request in your project
  • Handle the result

1. Go to https://developer.apple.com and login to your developer account. Navigate to Certificates, Identifiers and Profiles.

Go under the Identifier section and select App ID. Make sure that you select the Explicit App ID as this is very important. Otherwise, the wildcard App IDs will not be able to interact with Apple Pay. Moreover, make sure that the Apple Pay box under Apple Services is checked. Click Continue and Submit, and your Apple ID is ready.

Next, you have to click on Merchant ID and select the “+” icon in the upper right corner. You’ll end up on a window where you have to enter a Merchant ID description. You can enter whatever you want. Next, create a Bundle ID starting with the word “merchant” as in: “merchant.com.yourcompany.yourapp.”

2. Open up your project in XCode and select Capabilities in the .xcproject section.

Toggle on Apple Pay and enter your Merchant ID and make sure that the switch from the right side is on. After this, your ID should be added to the developer portal. You should also make sure that the Team box is pointing to the right team and that all items in Steps are checked.

3. Create a new Gmail account.

Once the above steps have been completed, go to https://itunesconnect.apple.com/ and pick Users and Roles. Then, choose Sandbox Testers and click on the “+” icon. Pick a country where Apple Pay is enabled and you can confirm your new Gmail created by Apple ID.

4. Change the iPhone region to the United States.

You have to log out of your iCloud account so you log in with your sandbox user details. Add a new test card to Apple Pay, such as the following one:

FPAN: 5204 2477 5000 1505

Expiration Date: 11/2022

CVC: 111

5. Create a payment in your app.

Add a button to the ViewController from the storyboard and then connect IBAction with your ViewController.swift. To be able to use Apple Pay you have to insert into ViewController.swift the following line:

Import PassKit

After this you will be able to configure the payment request present in purhcaseItem():

@IBAction func purchaseItem(_ sender: Any) {

let request = PKPaymentRequest()

request.merchantIdentifier = “merchant.net.mobindustry.likeMe”

request.supportedNetworks = [PKPaymentNetwork.visa, PKPaymentNetwork.masterCard, PKPaymentNetwork.amex]

request.merchantCapabilities = PKMerchantCapability.capability3DS

request.countryCode = “US”

request.currencyCode = “USD”

request.paymentSummaryItems = [

PKPaymentSummaryItem(label: “Some Product”, amount: 9.99)

]

let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request)

self.present(applePayController!, animated: true, completion: nil)

}

6. Add the following line to purchaseItem():

applePayController?.delegate = self

Then create this extension:

extension PaymentViewController:

PKPaymentAuthorizationViewControllerDelegate{

func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {

controller.dismiss(animated: true, completion: nil)

}

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

completion(PKPaymentAuthorizationResult(status: PKPaymentAuthorizationStatus.success, errors: []))

}

}

In order to check if the Apple Pay integration with your iOS app has been a success you should continue the payment request with your payment system of choice, such as Stripe, Visa, Mastercard, etc.

To finish the payment you have to include the following line in the didAuthorizePayment method:

completion(PKPaymentAuthorizationResult(status: PKPaymentAuthorizationStatus.success, errors: []))

Now Apple Pay should be successfully integrated into your iOS mobile application.

Read More: 2020 Mobile Tech Prediction: NFC Replaces Barcode Scanners at Events

Picture of Dmitry Harmashev

Dmitry Harmashev

Dmitry is a tech lead in Mobindustry and an Android and cross-platform developer. He is passionate about new technologies, and loves to try them in his pet projects.

You Might Also Like