The Revolut Merchant Card Form SDK for iOS allows merchants to accept card payments within their iOS applications. This guide provides step-by-step instructions for integrating a prebuilt payment form using the SDK.
From an implementation perspective, the SDK works with the following components:
token
, using the Merchant API: Create an order endpoint.RevolutMerchantCardFormKit
object with the order token
. This creates a form for gathering payment details and confirming the payment.The order and payment flow is similar to all card payment solutions:
For more information about the order and payment lifecycle, see: Order and payment lifecycle.
Before you start this tutorial, ensure you have completed the following steps:
The minimum supported iOS version is: 13.0.
Use CocoaPods to integrate the SDK with your Xcode project by adding the following to your Podfile
:
pod 'RevolutPayments/RevolutMerchantCardForm'
Add the following post_install
script at the end of your Podfile
to set the deployment target:
post_install do |installer|
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
end
end
end
end
To use the Revolut Merchant Card Form, it's essential to configure it using the RevolutPaymentsSDK
object at the start of your application. This ensures that the SDK is ready to handle payments as soon as the app launches. Configuring the SDK in AppDelegate
allows for centralised and consistent initialisation, aligning with best practices for managing app lifecycle events.
Import the RevolutPayments
module by adding the following line:
import RevolutPayments
To start using the SDK, configure the SDK by invoking the RevolutPaymentsSDK.configure(with:)
method:
RevolutPaymentsSDK.configure(
with: .init(
merchantPublicKey: "<yourPublicApiKey>",
environment: .production
)
)
When a customer decides to make a purchase on your website, using the Merchant API: Create an order endpoint, you'll need to create an order based on your customer's checkout and obtain a token
.
This token represents the order and is used to invoke the RevolutMerchantCardFormKit
object. The process of creating an order and receiving a token will vary based on your backend setup.
See an example response of an order created with minimal required parameters:
{
"id": "6516e61c-d279-a454-a837-bc52ce55ed49",
"token": "0adc0e3c-ab44-4f33-bcc0-534ded7354ce",
"type": "payment",
"state": "pending",
"created_at": "2023-09-29T14:58:36.079398Z",
"updated_at": "2023-09-29T14:58:36.079398Z",
"amount": 5,
"currency": "GBP",
"outstanding_amount": 5,
"capture_mode": "automatic",
"checkout_url": "https://checkout.revolut.com/payment-link/0adc0e3c-ab44-4f33-bcc0-534ded7354ce",
"enforce_challenge": "automatic"
}
To create a card form and initiate the payment process, use the RevolutMerchantCardFormKit
as follows:
let revolutMerchantCardFormKit = RevolutMerchantCardFormKit()
revolutMerchantCardFormKit.pay(
publicId: "<token>",
billingAddress: nil,
shippingAddress: nil,
email: "customer@example.com",
savePaymentMethodFor: .customer,
completion: { result in
switch result {
case .success:
// Handle successful payment
print("Payment successful")
case .failure(let error):
// Handle payment error
print("Payment failed: \(error.localizedDescription)")
}
}
)
Code Snippet | Explanation |
---|---|
RevolutMerchantCardFormKit | This class provides the tools necessary for creating and managing the card payment form. |
revolutMerchantCardFormKit.pay() | This method is used to display the payment form and process the payment using the provided order token and other optional parameters. |
publicId | The unique token of the order, obtained from your server after creating an order. This identifies the transaction to be processed. |
billingAddress | An optional parameter that accepts an object of type RevolutMerchantCardFormKit.Address , representing the customer's billing address. Providing this can help increase payment acceptance rates. |
shippingAddress | An optional parameter that accepts an object of type RevolutMerchantCardFormKit.Address , representing the customer's shipping address. |
email | An optional parameter that accepts the customer's email address. It can be used for sending receipts or confirming payment details. |
savePaymentMethodFor | Indicates whether the payment method should be saved for the customer or merchant (optional). For more information, see: Save payment methods. |
completion | A closure that handles the result of the payment process. It returns either a .success or .failure result, allowing the app to react accordingly (e.g., displaying a confirmation message or handling errors). For more information, see: Handle payment results. |
For more details about the available parameters see, Revolut Merchant Card Form SDK: Methods and parameters.
The savePaymentMethodFor
parameter allows you to save a customer's payment method used in the current payment session. You have the option to save a payment method either for the .customer
or the .merchant
. To learn more about customer and merchant initiated payments, see: Charge a customer's saved payment method.
If you wish to save a customer's payment details using the Revolut Merchant Card Form SDK, you need to meet one of the following requirements:
email
and assign it to the order by providing customer.id
customer.email
during order creationOnce the payment form has been submitted and processed, the completion
handler provides you with the result of the payment operation. You can use this result to perform various actions within your application, such as:
Here's how you can handle the payment result in your application:
revolutMerchantCardFormKit.pay(
publicId: "your_order_token",
completion: { result in
switch result {
case .success:
// Notify the user of successful payment
print("Payment completed successfully")
// Send order confirmation email
// Start the shipping workflow
// Log payment success
case .failure(let error):
// Inform the user about the payment failure
print("Error processing payment: \(error)")
// Log payment error
// Retry payment or suggest alternatives
}
}
)
In addition to handling payment results directly in your app, you can also set up webhooks to receive notifications about different events. Webhooks provide a reliable way to track the entire order and payment lifecycle, allowing your server to react to changes.
To implement webhooks, refer to the Use webhooks to track order and payment lifecycle tutorial for detailed instructions on setting up and managing webhooks with the Merchant API.
By utilizing both in-app payment result handling and webhooks, you can create a robust and responsive payment processing system that enhances the user experience and streamlines your business operations.
The SDK's public repository contains a fully functional example app designed to demonstrate how to integrate the Revolut Merchant Card Form SDK into your mobile application. This app serves as a practical reference for developers, showcasing a working implementation of the SDK's features.
Follow these steps to set up and run the example app:
git clone https://bitbucket.org/revolut/revolut-payments-ios.git
ExampleApp
directory:cd Releases/<SDK version>/RevolutMerchantCardForm/ExampleApp
make project
RevolutMerchantCardFormApp.xcworkspace
file.Before deploying your implementation to your production environment, complete the checklist below to see if everything works as expected, using Merchant API's Sandbox environment.
To test in Sandbox environment, set the base URL of your API calls to: sandbox-merchant.revolut.com/
and initialise the SDK in sandbox:
RevolutPaymentsSDK.configure(
with: .init(
merchantPublicKey: "<yourPublicApiKey>",
environment: .sandbox
)
)
token
. The order must be created in the same environment where the widget is loaded, in this case the Sandbox environment. If your implementation handles all these cases as you expect in Sandbox, it is advised you also test your implementation in production before going live. Once your implementation passes all the checks in both environments, you can safely go live with your implementation.
These checks only cover the implementation path described in this tutorial, if your application handles more features of the Merchant API, see the Merchant API: Implementation checklists.
Congratulations! You've successfully integrated the card form with the Merchant API in your app.