Apple Pay Integration into Mobile Apps

Stfalcon.com
codeburst
Published in
6 min readFeb 11, 2019

--

During the presentation on the 9th of September 2014, Apple introduced Apple Pay — its own system of mobile payments.

Apple pay allows iPhone 6 and iPhone 6+ users, as well as those who have new versions of Apple Watch easily shop online now, and benefit from apple pay app integration as well as make payments with the help of NFC (Near Field Communication) Technology. Touch ID or Face ID technologies are used for payment authorization.

Below we will find out how to integrate apple pay into the mobile applications which are developed and require payment options integration.

Apple mobile Pay is compatible with such proximity card readers as Visa PayWave, MasterCard PayPass, American Express ExpressPay.

Apple Pay Countries Coverage Map (as of May 17, 2018). Dark Blue: up and running Light Blue: planned

Let’s start

We will use the latest Apple Pay version (as of 5 November 2018), Swift 4.2 and Xcode 10.1.

For Apple Pay integration into the mobile app, you must have registered and paid developer account (https://developer.apple.com).

We create a project based on Single View Application.

Our next step should be the project name creation. I will use ApplePayExample.

Further on we are faced with the ViewController class. Here we will actually work.

Apple Pay Adjustment in the Application.

For Apple Pay integration we have to use the PassKit library.

PassKit allows:

  1. To add Apple Pay to the mobile application;
  2. To manage cards in the Wallet App.

For Apple Pay adjustment we have to take 3 obligatory steps:

  1. To create merchant ID;
  2. To enable Apple Pay in Xcode;
  3. To create a test user.

Let’s go to https://developer.apple.com, authorize with our account and follow to Certificates, Identifiers & Profiles.

Go to the Identifiers group choose the App IDs tab. Fill in all the necessary fields in accordance with your app and follow further instructions.

After that, you should choose the Merchant IDs in the Identifiers group.

Create a Merchant ID for your application following the instructions given.

Identifier is recommended to be named the following way “merchant” + Bundle ID. For example: merchant.com.myapp

Arm yourself with patience, we have almost finished our preparations for the project.

Next, we have to go to https://appstoreconnect.apple.com Users and Access section, choose Testers in the Sandbox section and create a test user following the instructions.

We need the user to test payments.

Step 1

Step 2

Step 3

Let’s proceed to Xcode adjustment

Step 1

First, we have to enable Apple Pay in Xcode Capabilities and to add the Merchant IDcreated earlier.

Step 2

Now, when Apple Pay is enabled we can proceed further to the most interesting part — to writing code.

First open Main.storyboard and add the button.

Then proceed to the ViewController.swift.

To start we have to import the PassKit library: import PassKit

Next, we have to create an instance of the class PKPaymentRequest

and to create IBAction for the button.

While opening the PKPaymentAuthorizationViewController we have to subscribe for its delegate, so that we can see the transaction status.

After this, we have to implement the delegate’s methods. We will simulate a successful transaction in the following way:

completion(PKPaymentAuthorizationResult(status: .success, errors: nil))

Now we are ready to check the Apple Pay.

Before Apple Pay check it’s necessary to authorize with the help of user Sandbox, which was created earlier and to add a test card to iPhone.

Test cards examples:

MasterCard

  • FPAN: 5204 2477 5000 1471
  • Expiration Date: 11/2022
  • CVC: 111

Visa

  • FPAN: 4761 1200 1000 0492
  • Expiration Date: 11/2022
  • CVV 533

Start the project and press the button «Pay».

The transaction has been successful. Congratulations, now you know how to integrate Apple Pay into the mobile application.

What about the statistics?

Apple does not provide any statistics on Apple Pay, but according to the experts, the users of this payment service constitute about ~ 31% (> 252 mln people) of the total iPhone users.

The head of the company Tim Cook has also mentioned recently, that almost 1 billion transactions were made with the help of this service in the 3rd quarter of 2018.

The number of banks supporting Apple pay also increases. In June 2018 Apple announced that more than 4 900 banks support this payment option worldwide.

Why do you need Apple Pay?

I guess the section above explains why Apple Pay is needed to you.

But how does it actually work? — You can shop online (using Safari browser), as well as by means of the apps. You do not need to keep cards with you, all you need is just touch your iPhone (if you have Touch ID) or simply smile to the necessary special sensors (if you have Face ID). It will be enough to make a purchase.

Is it secure? You may ask. Yes, unequivocally, it’s secure. Your device does not share your financial details during the transaction, instead, it generates a special one-time token and exchanges it during the payment operation.

In case you are:

  1. A user
  2. A businessmen
  3. A developer

It’s a must for you to integrate this technology (into your business, your project or your life). Thanks to this technology you can refuse from using cards physically.

Originally published in Stfalcon.com.

Thanks for reading the end. Before you go:

Follow us on Instagram, YouTube, and TikTok to see the company lifestyle.

Follow us on Bēhance, Dribbble, and Stfalcon to find design case studies.

Please consider clapping and following the blog!

--

--

IT company designing custom web services and mobile apps. Our goal is to create useful and convenient software. We are the founder of the Air Alert app