Integrating Apple Pay to Your App Using Stripe
How can you increase sales in your shopping app or a web online store? You can surely invest in ads to get more visitors who will possibly turn into customers. But if those visitors can’t conveniently and quickly pay checkouts online, your business will keep losing revenue. But cheer up! Oberlo forecasts that retail purchases from mobile devices worldwide will grow to $432.24 billion in 2022. So if you want more sales from your app, you should implement in-app purchases. In this post, we’ll talk about native development and integrating Apple Pay into your iOS app.
How Apple Pay works
Apple Pay is very similar to PayPal, as you can integrate it to let users pay for goods in your app. The difference is that PayPal allows payments without a debit or credit card, whereas Apple Pay requires users to link a card — even if it’s an Apple Card.
To allow users to pay for products in physical stores, Apple Pay uses NFC technology on iOS devices and NFC contactless card readers at the point of sale terminals. You can discover which organizations and online and physical stores accept Apple Pay by checking out this list.
Apple’s mobile payment solution is compatible with all existing proximity readers that support Visa PayWave, Mastercard Contactless, American Express Contactless, and ExpressPay. But unlike Samsung Pay, Apple Pay doesn’t work at mobile payment terminals that only have magnetic stripe readers.
How convenient Apple Pay is for users
To checkout with Apple Pay for e-commerce (or for any other service), users need to add a credit card through the Wallet app. But they don’t need to enter the card number or expiry date in their ewallets: they can use their iPhone’s camera to read this information automatically.
To make a transaction in an app using Apple Pay and their digital wallets, users simply select Apple Pay for mobile payments in the list of payment methods, choose a credit card, and use Touch ID, Face ID, or a passcode to confirm the transaction. For first-time payments, users also need to provide a billing address, delivery address, phone number, and other details.
How much does Apple Pay charges for its services
Apple Pay charges both app owners and banks for using its services. App owners are charged 0.15 percent per transaction made within an app. The conditions for banks vary and depend on the country. For instance, Australian banks pay 3 cents per $50, while US banks pay 2 cents for the same amount.
How secure Apple Pay is for users
Apple Pay assigns a unique Device Account Number to every iPhone, iPad, and Apple Watch and saves this number (in an encrypted format) on the device’s Secure Element chip. When processing transactions, Apple Pay doesn’t transmit bank card data to the seller. Instead, it transmits a so-called dynamic safety code. This way credit card details can’t be obtained from a user’s Apple device. And in case a device is lost or stolen, the owner can use the Find My app to switch off Apple Pay.
Since Apple Pay stores a secure transaction token on iPhone, iPad, and Apple Watch, your app won’t need a data connection to use Apple Pay. This means users can pay for goods even without using their iPhone and live in a country supported by Apple Pay. Outside the US and Canada, Apple’s payment system is available in quite several countries in the Asia-Pacific region, Europe, Latin America, and the Middle East. Apple provides a regularly updated list of all countries that currently support Apple Pay.
Apple’s payment system is spreading quite fast, so make sure you can reach Apple Pay users. Now let’s dive into the technical details of Apple Pay integration and the functionality this technology provides.
How to integrate Apple Pay in your app
Step 1: Prepare your Apple Developer account
If you want to know how to set up Apple Pay, the first thing you’ll need is a verified Apple Developer account. You can sign up as an individual or as an organization. If you choose to enroll as an organization, you’ll have to provide your D-U-N-S number, legal entity status, legal authority, and website address. You can learn more about enrolling as a developer in Apple’s official guide.
Step 2: Create a Merchant ID
After that, you should create a merchant ID. It’s very simple. All you need to do is click the plus sign, enter your name, and click Continue and Register.
Step 3: Set up a project
To set up your project, you need to open it in your target and change the Bundle Identifier to the one you’ve already created. Then move to the Capabilities tab, choose the Apple Pay section, and turn the switch to ON. After that, you need to click on the checkbox that corresponds to the merchant ID you’ve created. Now Apple Pay is ready for use!
Step 4: Implement the “Pay with Apple Pay” button
The design of the “Pay with Apple Pay” in-app button needs to adhere to Apple’s guidelines. You can download resources for creating the button on the official Apple Developer website. If necessary, you can also add the Apple Pay feature to your website.
Now let’s take a look at the Apple Pay API.
How to use the Apple Pay API
To work with Apple Pay, you need to import the PassKit framework, which has required classes for working with Apple Pay. When a user initiates a purchase, you need to create PKPaymentRequest and PKPaymentAuthorizationViewController objects. PKPaymentRequest is Apple Pay’s object that corresponds to the payment.
PKPaymentRequest encapsulates a request for payment with information about payment processing capabilities, the payment amount, and shipping information.
PKPaymentAuthorizationViewController is an object needed for displaying a payment controller. It’s created based on PKPaymentRequest. Let’s take a look at an example:
Then you need to configure the PKPaymentRequest object:
-
Define supported types of readers: PKPaymentNetworkVisa, PKPaymentNetworkMasterCard, PKPaymentNetworkAme
-
Set up your current merchant ID
-
Define merchant capabilities
-
Enter the country code for the app, consisting of two symbols
-
Enter the country code for the current transaction
For example:
These are the main settings for the client.
How to handle payment requests
Now you need to set up the PKPaymentAuthorizationViewControllerDelegate for processing user actions in PKPaymentAuthorizationViewController. It has two required delegate methods:
The first method authorizes a user when a purchase is initiated, while the second method is called when the payment is completed. The implementation may look like this:
How to Handle Shipping, Billing, and Contact Information
To add delivery info, we can add one or more variables PKPaymentSummaryItem. We can add any information to them.
For example:
This code defines a summary item in a payment request – for example, total, tax, discount, or grand total.
How to set shipping methods and types
We can customize types of delivery and their cost when setting the shipping methods and types. You can find more examples in Apple’s official guide.
You can set up the following shipping methods in your app and ask the user to choose:
-
Ship the purchase to the provided address using a third-party shipping company (this is the default shipping type)
-
Delivery by the seller (for example, for pizza, flowers, or furniture)
-
Store pick-up
-
Send an item from the provided address (for example, for transportation or shipping services that provide home pick-up)
For each shipping method, you need to set the fields with the user name, delivery price in the currency specified in the purchase settings, description, and ID.
How to use Stripe for Apple Pay payments
Apple Pay doesn’t fulfill any payment operations itself. It only authorizes transactions and creates tokens that allow for payment processing. To make a transaction, you need to use services for implementing in-app payments. But since most of our customers prefer the Stripe payment system, we will share how to set up to use Stripe with Apple Pay. It’s really easy to set up, and it allows you to make test payments inside the app.
After you’ve created a Stripe account, you need to generate a certificate using a Certificate Signing Request (CSR). This procedure will set up Stripe to process your payments.
To do this, you need to go to the Apple Pay section and click Add new application to download the .certSigningRequest file.
Next, get your API keys:
Then you need to go to your Stripe developer account and navigate to Member Center –> Certificates, Identifiers & Profiles –> Identifier –> Merchant IDs, choose your merchant ID, and click Edit. Next, move to Create Certificate –> Continue –> Choose File, choose the certSigningRequest file that you got from Stripe, and click Generate. Finally, click Download to get the .cer file.
Ta-da! Now you can download the Stripe framework and continue implementing your payment functionality. We hope that here you can find more about Apple Pay, and it will help you significantly boost your app’s user experience and, what’s more important, help you get more sales!