In this article, I will explain what is apple pay and how we can make use of Javascript APIs to make a payment using Apple Pay. By following this article you should be able to set up a fully working Apple pay payment option for your e-commerce application.

What is Apple Pay?

Apple Pay is a payment method introduced by Apple for Apple users. It’s mandatory to have an Apple device to use this feature. The main advantage is that users will not have to expose their credit card details to third-party applications when paying with Apple pay which enhances the security to a greater extent. Using apple pay is really easy. you just have to add your credit cards to your apple wallet and that's it. Once you visit an apple pay enabled website and click on the apple pay payment option, your device will show the list of cards in your wallet and you will just need to authorize the payment with the password, fingerprint or face detection feature.

How to support Apple Payments in our application?

There are prerequisites that we have to have when setting up Apple pay. I’ll brief them as points so you don’t have to read the whole documentation.

  1. Application servers should support communication in HTTPS with valid SSL certs and the TLS version should be above 1.2.
  2. Apple pay developer account.

There are multiple ways that we can use to implement code. We will be using Apple pay JS API for this example. You can read other options here.

Before jumping into code there are few things that you need to set up in your apple developer account.

  1. Merchant Identifier (This is to uniquely identify your application by apple pay services.)
  2. Merchant Identity Certificate. (used to authenticate your sessions with the Apple Pay servers)
  3. Payment Processing Certificate. (Apple Pay servers use the certificate’s public key to encrypt payment data. You, or your payment service provider, use the private key to decrypt data to process payments)
  4. Domain Verification Files. (File which is used to verify your domain)

Let’s understand the flow

Once you click on the Pay with Apple Pay Button, a session gets created. This operation will only be successful if you have a device that is capable of doing an apple pay payment plus you are in one of the supported regions. If you are using a sandbox account to test this and your device region is not included in the list of the supported regions, make sure to change the device region to one of the supported regions (Ex: Canada).

Once the session gets created, an apple pay server URL will be received to perform the merchant validation. The application should do a POST request to the aforementioned URL. The request body should contain the following information.

  1. Merchant Identifier
  2. Domain
  3. Merchant Identity Certificate

Once the validation is successful, the user will be presented with the payment screen. Once the user authorizes the payment, a payment token or tracke will be received. This tracke should be passed to the payment gateway in order to capture the payment.

Conclusion

Apple pay is a really cool feature that provides more security to customers when it comes to online payments. This is a widely used feature among apple users. If your application supports Apple pay definitely you can attract more customers. Hope this article will provide good support if you are trying to wire things up together. Feel free to comment. Happy coding :)

Computer Science and Engineering, University of Moratuwa. Lives in Srilanka. “Blogging is a conversation, not a code.”

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store