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 is not available in the sandbox environment. Real transactions must be made to test your implementation in the production environment.
From an implementation perspective, integrating Apple Pay into your iOS app with the Revolut Apple Pay SDK involves the following components:
The order and payment flow is similar to all payment solutions:
token
.For more information about the order and payment lifecycle, see: Order and payment lifecycle.
Check the following high-level overview on how to implement the Apple Pay button in your iOS app:
Before you start this tutorial, ensure you have completed the following steps:
To enable Apple Pay in your app, you need to register a Merchant Identifier on the Apple Developer portal.
+
button to create a new Merchant ID.merchant.com.yourappname
).For more information, see Configure Apple Pay: Create a merchant identifier.
To process payments with Apple Pay, you need an Apple Pay Payment Processing Certificate associated with your Merchant Identifier.
Create Certificate
under the Apple Pay Payment Processing Certificate section..cer
file)..cer
file) to Revolut by emailing it back to merchant-integration@revolut.com.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.
To enable Apple Pay in your Xcode project:
For more information, see Apple's documentation on Adding Apple Pay Capabilities.
The Revolut Apple Pay SDK requires a minimum iOS version of 13.0.
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
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
}
}
Currently, only the production environment is supported.
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)
}
...
}
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)
}
}
}
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.
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
.
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.
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
}
}
)
}
The amount
specified when creating the order on your backend must match the total amount displayed in the Apple Pay sheet.
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.
Currently, only the production environment is supported. This means that real transactions must be made to test your implementation.
Congratulations! You've successfully integrated the Apple Pay SDK with the Revolut Merchant API in your iOS app.
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/
.