Apple took a big step into the world of mobile payments with the introduction of the iPhone 6 and Apple Pay. There are two ways you can use Apple Pay to purchase items: at the point of sale using Near Field Communication (NFC), or within an iOS app.
In our last article, we talked about how integrating mobile payment gateways can benefit for your shopping app and how Stripe is used by most popular startup apps like Uber, Instacart, Grab, Postmates, and more. However, we somehow missed to talk about how to set up Apple Pay using Stripe in your iOS app.
In this article, we’re going to fix this. Get your Xcode installed and running, and let’s learn how to set up Apple Pay using Stripe!
Apple Pay enables people to easily and securely pay using their iPhone, iPad, and Apple Watch. Apple Pay is available within native iOS applications, and on the web in Safari starting with iOS 10 or macOS Sierra.
Apple Pay is quite similar to Paypal because in that you can integrate it in your app to allows users to pay for their purchased goods and/or services online. But, what makes Apple Pay different is that it uses NFC technology that lets users pay for products in physical stores equipped with NFC readers.
For you reference, here is the list of stores that accept Apple Pay.
Now, the Apple’s payment system is compatible with all existing readers like American Express and ExpressPay, Visa PayWave, but unlike Samsung pay, it does not work at standard payment terminals with magnetic stripe readers.
To pay using Apple Pay, first you’ll need to add your credit cards through Wallet app. Though, you don’t need to write the complete credit card number or expiry date as you can use your iPhone’s camera to read this information automatically.
Now, to make a transaction, all you need to do is select Apple Pay from the payment options list, choose your credit card, and hold your fingerprint on Touch ID to authorize the transaction.
Simple answer is: It Doesn’t!
Instead, it assigns a unique Device Account Number for each device, and saves this number in the Secure Element Chip on the device in an encrypted format.
So, when it is processing any transaction, it doesn’t transmit the data on a bank card to seller. Here, it uses its dynamic safety code. By doing this, it ensures that nobody can reveal your credit card information using Apple device.
Also, since Apple Pay stores a secure transaction on device, you won’t need to have data connection for Apple Pay. What this means is, you can pay for products without your iPhone if you own an Apple Watch.
In fact, you might have also noticed that Apple Pay system is spreading quite fast, so make sure you can grab the users paying through Apple Pay, we’ll see how to set up Apple Pay using Stripe in your iOS app.
Many people keep getting confused as to when we should be using In App purchases and when to use Apple pay. The key difference is that any thing digital which you sell inside the app needs to be using In App purchases. If you are selling any physical products like tickets, uber, event tickets etc can use Apple pay.
Login/Signup Stripe Account
First, go to https://dashboard.stripe.com/login and login to your account. If you don’t have a Stripe account then click on Signup.
Create Private key for the merchant certificate
After login into your account, go to Payments, then click on Apple Pay and add new application.
This will download the Stripe.certSigningRequest file and show a popup window.
Create AppID on Apple Developer Portal
Go to https://developer.apple.com/account, login/signup if required.
Go to Certificates, IDs & Profiles, then select AppIDs under identifier section.
Select (+) to add new App ID.
Enter App ID Description : StripeApplePay
Enter Bundle ID : com.example.StripeApplePay
Check Apple Pay option under App Services.
Now click on continue.
It will show like the below image. Now click on register and done.
Create MerchantID on Apple Developer Portal
Go to https://developer.apple.com/account/ios/identifier/merchant/landing, login/signup if required.
Select Merchant IDs under Identifiers section.
Select (+) to add new Merchant ID.
Now, enter Description : StripeApplePay
Enter Merchant ID : merchant.com.example.StripeApplePay
Continue > Register > Done.
Here, the merchant ID is created.
Upload Downloaded stripe.certSigningRequrest File to Merchant ID
Select newly created merchant ID > Edit.
Select Create Certificate Under the Processing Certificate.
Select “No” for the Will payments associated with this Merchant ID be processed exclusively in China?
You will find step to create certSigningRequest file, skip that already downloaded stripe.certSigningRequest
Choose downloaded stripe.certSigningRequest file.
Download (Download Merchant certificate apple_pay.cer ) > Done
Your strip private certificate successfully bind with your application merchant ID.
Upload Downloaded Merchant Certificated to stripe.com
Go to the screen where we left on https://dashboard.stripe.com/account/apple_pay
Select downloaded Merchant certificate apple_pay (3).cer and click continue.
You will get the merchant.com.example.StripeApplePay under the iOS certificates section.
Here, you have successfully bind the stripe and apple pay certificates.
Get Your Secret|Publisher Keys
Select API option as shown in the image.
Copy these keys, we will need these keys in the application code.
Create a new XCode Project
Open Xcode, click on file then new and select create new project.
Select Single View Application and click on next.
In the next tab, write your project name and details.
Integreat Stripe pod
Open terminal and write – cd path/to/project/StripApplePay
In your pod file, add the below pod.
Save pod file and close it.
In terminal > $ pod install
This will generate the StripeApplePay.xcworkspace
Enable Apple Pay Capabilities
Select StripeApplePay project from navigation bar.
Go to Capabilities.
Enable Apple Pay.
Our merchant ID will be automatically loaded i.e. merchant.com.example.StripeApplePay
Select the merchant ID.
Configure Project for Stripe Gateway
In applicationDidFinishLaunchingWithOptions: add below line as first line
STPPaymentConfiguration.shared().publishableKey = "pk_test_WkjizjxN2MdJ3Mvsjbwpd0E7q"
This will configure app with your stripe+applePay certificate.
STPPaymentConfiguration.shared().appleMerchantIdentifier = "merchant.com.example.StripeApplePay"
This will configure merchant ID we have created on apple developer portal.
UI + Code
In ViewController scene drag/drop one button.
Set button title to “Buy With Apple Pay” or design as per the ApplePayGuidelines
Add its action method named “btnApplePayDidTap:”
Add code for the method “btnApplePayDidTap:” as show in the image.
Implement “PKPaymentAuthorizationViewControllerDelegate” by creating extension of view controller.
Add delegate code as shown in the image.
Now run the app.
As you know Apple Pay is one of the best features of iOS 8 and how it provided multiple benefits, in fact Entrepreneurs and app owners also implement this feature in their mobile apps. Though, if you’re building a startup app from scratch and want to implement Apple Pay using Stripe, you can either contact expert developer or hire iPhone app development company to help you with that.
Have an iOS App Idea in Mind? Let's Discuss!