How to Set Up Apple Pay Using Stripe For Your Shopping App April 28, 2021April 6, 2017 5431 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 with 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!What is Apple Pay?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.How Does Apple Pay Work?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.How Does Apple Pay Store My Credit Card Details?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.When Should I Use Apple Pay?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.Quick overview of how it worksYou create a Merchant ID and matching certificate in Developer Portal.Your ID and certificate are used to encrypt the payment data.Display Payment sheet to user.User uses Touch ID to authorize transaction.Your app receives the payment token.This token is encrypted using your Merchant ID and certificate so only your application can decrypt it.Send token for processing using one of payment gateways like Stripe.How to Set Up Apple Pay Using StripeLogin/Signup Stripe AccountFirst, 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 certificateAfter 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 PortalGo 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 : StripeApplePayEnter Bundle ID : com.example.StripeApplePayCheck 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 PortalGo 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 : StripeApplePayEnter Merchant ID : merchant.com.example.StripeApplePayContinue > Register > Done.Here, the merchant ID is created.Upload Downloaded stripe.certSigningRequrest File to Merchant IDSelect 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.certSigningRequestChoose downloaded stripe.certSigningRequest file.Download (Download Merchant certificate apple_pay.cer ) > DoneYour strip private certificate successfully bind with your application merchant ID.Upload Downloaded Merchant Certificated to stripe.comGo to the screen where we left on https://dashboard.stripe.com/account/apple_paySelect 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 KeysSelect API option as shown in the image.Copy these keys, we will need these keys in the application code.Create a new XCode ProjectOpen 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 podOpen terminal and write – cd path/to/project/StripApplePayIn your pod file, add the below pod.pod 'Stripe'Save pod file and close it.In terminal > $ pod installThis will generate the StripeApplePay.xcworkspaceOpen StripeApplePay.xcworkspaceEnable Apple Pay CapabilitiesSelect StripeApplePay project from navigation bar.Go to Capabilities.Enable Apple Pay.Our merchant ID will be automatically loaded i.e. merchant.com.example.StripeApplePaySelect the merchant ID.Configure Project for Stripe Payment GatewayGoto AppDelegate.swiftImport StripIn applicationDidFinishLaunchingWithOptions: add below line as first lineSTPPaymentConfiguration.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 + CodeGoto Main.storyboardIn 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:”CodeAdd 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.Useful resourcesA Complete Guide to Integrate Apple Payment Method in iOS App – 1A Complete Guide to Integrate Apple Payment Method in iOS App – 26Author BioHitesh TrivediDesignation: iOS Team Lead Hitesh Trivedi is an iOS Team Lead at Space-O Technologies. He has over 10 years of experience in iOS app development. He has guided to develop over 100 iPhone apps with unique features and functionalities. He has special expertise in Swift and Objective-C.