Guides • Accept Payments
iOS
doc

Accept payments via Apple Pay - iOS

Welcome to the Revolut Apple Pay SDK for iOS, a powerful tool designed to simplify the integration of Apple Pay into your iOS applications. Our main goal is to help merchants incorporate Revolut's secure and convenient payment solutions via Apple Pay into their apps, offering customers a fast, secure, and seamless payment method.

In this tutorial, we'll walk you through the implementation process of integrating the Apple Pay into your iOS app using the Revolut Apple Pay SDK. By following this guide, you can provide your customers with a seamless and secure checkout experience directly within your app.

Apple Pay - iOS

note

Apple Pay is not available in the sandbox environment. Real transactions must be made to test your implementation in the production environment.

How it works

From an implementation perspective, integrating Apple Pay into your iOS app with the Revolut Apple Pay SDK involves the following components:

  1. Server-side: You need to set up an endpoint on your server that creates an order using the Merchant API: Create an order endpoint.
  2. Client-side: Your iOS app uses the Revolut Apple Pay SDK to collect payment details and communicates with your server to create the order and process the payment.
  3. Endpoint for webhooks: Optionally, you can set up an endpoint to receive webhook events from the Merchant API to track the payment lifecycle. For more information, see: Use webhooks to keep track of the payment lifecycle.

The order and payment flow is similar to all payment solutions:

  1. The customer goes to the checkout screen in your app.
  2. Your app checks if Apple Pay is supported and displays the Apple Pay button.
  3. The customer taps the Apple Pay button.
  4. The Revolut Apple Pay SDK presents the Apple Pay sheet to the customer, who reviews and authorises the payment.
  5. Your app uses your server endpoint to create an order and obtains the order token.
  6. The SDK processes the payment and presents the payment result to the customer.
  7. Optionally, your server receives webhook notifications about each event you're subscribed to.
info

For more information about the order and payment lifecycle, see: Order and payment lifecycle.

Implementation overview

Check the following high-level overview on how to implement the Apple Pay button in your iOS app:

  1. Create a Merchant Identifier
  2. Create an Apple Pay Certificate
  3. Add the Apple Pay capability to your project
  4. Install the SDK
  5. Configure the SDK
  6. Add the Apple Pay button
  7. Create the payment request
  8. Display the Apple Pay sheet
  9. Verify your implementation

Before you begin

Before you start this tutorial, ensure you have completed the following steps:

Implement the Apple Pay button in your iOS app

1. Create a Merchant Identifier

To enable Apple Pay in your app, you need to register a Merchant Identifier on the Apple Developer portal.

  1. Log in to your Apple Developer account.
  2. Navigate to Certificates, Identifiers & Profiles.
  3. Under Identifiers, select Merchant IDs.
  4. Click the + button to create a new Merchant ID.
  5. Follow the prompts to create your Merchant Identifier (e.g., merchant.com.yourappname).

2. Create an Apple Pay Certificate

To process payments with Apple Pay, you need an Apple Pay Payment Processing Certificate associated with your Merchant Identifier.

  1. Request a Certificate Signing Request (CSR) file from Revolut by emailing merchant-integration@revolut.com.
  2. Use the CSR file provided by Revolut to create an Apple Pay Payment Processing Certificate in the Apple Developer portal for the Merchant ID you created earlier.
    • In your Apple Developer account, go to Certificates, Identifiers & Profiles.
    • Select your Merchant ID and click Create Certificate under the Apple Pay Payment Processing Certificate section.
    • Follow the instructions to upload the CSR file and download the generated certificate (.cer file).
  3. Provide the certificate (.cer file) to Revolut by emailing it back to merchant-integration@revolut.com.
caution

Currently, this step is not automated. You must only use one certificate per Merchant ID.

If you want to change the Merchant ID or if the certificate is about to expire, you must repeat this process.

3. Add the Apple Pay capability to your project

To enable Apple Pay in your Xcode project:

  1. Open your project in Xcode.
  2. Select your project in the Project Navigator.
  3. Go to the Signing & Capabilities tab.
  4. Click the + Capability button.
  5. Add the Apple Pay capability.
  6. Select the Merchant ID you created earlier.

4. Install the SDK

note

The Revolut Apple Pay SDK requires a minimum iOS version of 13.0.

CocoaPods

To integrate the Revolut Apple Pay SDK into your Xcode project using CocoaPods, add the following pod to your Podfile:

pod 'RevolutPayments/RevolutApplePay'

Then, run:

pod install

5. Configure the SDK

Import the RevolutPayments module, then configure the SDK at the start of your application by calling the RevolutPayKit.configure(with:) method, typically in your AppDelegate or SceneDelegate.

import RevolutPayments

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

RevolutPaymentsSDK.configure(with: "<yourPublicApiKey>") // Merchant API Public key

return true
}
}

note

Currently, only the production environment is supported.

6. Add the Apple Pay button

First, create a RevolutApplePayKit object. It provides all the necessary tools for processing the payment.

Create and add the button to your view hierarchy only if Apple Pay is supported on the device. You should use the isApplePaySupported method.

import PassKit
import RevolutPayments

final class CheckoutExampleViewController: UIViewController {
private let revolutApplePayKit = RevolutApplePayKit()
private var applePayButton: PKPaymentButton?

override func viewDidLoad() {
super.viewDidLoad()

// The Apple Pay button is added only if Apple Pay is supported.
guard revolutApplePayKit.isApplePaySupported() else { return }
applePayButton = PKPaymentButton(paymentButtonType: .buy, paymentButtonStyle: .black)
applePayButton?.addTarget(self, action: #selector(handleApplePayButtonTap), for: .touchUpInside)

// Add the button into the view hierarchy.
view.addSubview(applePayButton)
}
...
}

7. Create the payment request

When the Apple Pay button is tapped, you need to first create an Apple Pay payment request.

In your button tap handler, call the makePaymentRequest(merchantId:, totalAmount:, currencyCode:, completion:) method of RevolutApplePayKit. This method initialises a PKPaymentRequest object with some required properties pre-populated according to your Revolut merchant account configuration.

Then configure the returned payment request according to your needs (e.g., setting paymentSummaryItems, shippingMethods, etc.).

Here's how you can implement it:

@objc func handleApplePayButtonTap() {
applePayButton?.isUserInteractionEnabled = false
revolutApplePayKit.makePaymentRequest(
merchantId: "merchant.com.yourappname",
totalAmount: 15_00, // In minor units
currencyCode: "GBP"
) { [weak self] result in
self?.applePayButton?.isUserInteractionEnabled = true
switch result {
case .success(let paymentRequest):
// Apple Pay uses the last element for the grand total.
paymentRequest.paymentSummaryItems = [
PKPaymentSummaryItem(label: "Merchant name", amount: 15.00)
]
self?.presentApplePay(for: paymentRequest) // Defined in the next step
case .failure(let error):
// Handle error (e.g., show an alert to the user)
}
}
}
info

For more information about the parameters, see: Apple Pay SDK: Methods and parameters.

  • Disable the Apple Pay button: It's a good practice to disable the button while the payment request is being created to prevent duplicate requests.

  • Call makePaymentRequest: This method initialises a PKPaymentRequest with some properties set based on your merchant configuration.

  • Handle the result: The completion handler provides a Result<PKPaymentRequest, Error>. On success, you receive a PKPaymentRequest object.

  • Configure paymentSummaryItems: You must set the paymentSummaryItems property of the PKPaymentRequest. These items represent the line items and total amount that will be displayed to the user in the Apple Pay sheet.

    caution

    The last item in paymentSummaryItems is considered the grand total and must match the total amount charged.

  • Error handling: In case of failure, handle the error appropriately, such as displaying an alert to the user.

  • Optional configurations: You can configure additional properties on the PKPaymentRequest, for more information, see: Apple's documentation on PKPaymentRequest.

note

The totalAmount and currencyCode represent the expected total amount for the payment. If the actual total is unknown at this point (e.g., due to variable shipping costs), you can provide a base amount.

The actual total displayed to the user in the Apple Pay sheet is determined by the paymentSummaryItems you set afterwards, which should correspond to the order's total amount.

Currently, recurring and deferred payment requests are not supported by the Revolut Apple Pay SDK.

8. Display the Apple Pay sheet

Present the Apple Pay sheet for your payment request. The presentApplePay method supports multiple callbacks in order to interact with the Apple Pay sheet.

func presentApplePay(for paymentRequest: PKPaymentRequest) {
revolutApplePayKit.presentApplePay(
for: paymentRequest,
onAuthorize: { [weak self] handler in
// Get the order token from your backend - the total price must
// correspond to the one displayed by the Apple Pay sheet
self?.createOrderOnBackend { result in
switch result {
case .success(let orderToken):
handler.set(orderToken: orderToken)
case .failure(let error):
handler.set(errors: [error])
}
}
},
completion: { result in
switch result {
case .success:
// Handle successful payment (e.g., redirection to a confirmation page)
case .failure(let error):
// Handle payment error (e.g., display an error message to the user)
case .userAbandonedPayment:
// Handle abandoned payment
}
}
)
}
note

The amount specified when creating the order on your backend must match the total amount displayed in the Apple Pay sheet.

info

The callbacks correspond to PassKit.PKPaymentAuthorizationControllerDelegate methods. You may also consult Apple's documentation for a deeper understanding of how Apple Pay and the callbacks work.

9. Verify your implementation

Currently, only the production environment is supported. This means that real transactions must be made to test your implementation.

success

Congratulations! You've successfully integrated the Apple Pay SDK with the Revolut Merchant API in your iOS app.

Example project

Check out the example project to test the SDK and better understand how to implement it, in the iOS repository. The example is found under Releases/<SDK-version>/RevolutApplePay/ExampleApp/.


What's next

Was this page helpful?