Before proceeding, please ensure you have met all requirements
Click here to open this information in a new tab
Our GitLab repository includes an example app that demonstrates how to integrate our payment SDK into your application. Click here to view.
Features
The Trust Payments iOS SDK allows you to seamlessly integrate a prebuilt or custom UI in your app to accept card payments & comply with the Strong Customer Authentication (SCA) mandate.
Use this integration if you need a pre-built “Drop-In” UI that supports the following features:
- Card payments
- Tokenization payments
- Customisation of UI components to fit with your business branding
- Locale and custom translations
Otherwise if you have already built your own payment checkout views in your iOS app, but need a method to process payments to the Trust Payments gateway, you can use our payment transaction manager API.
1. Install the SDK in your app
To embed the iOS SDK into your Xcode project, you will need to use Cocoapods:
1. CocoaPods
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate Trust Payments SDK into your Xcode project using CocoaPods, specify it in your Podfile as follows:
Replace '<TOKEN>' with the CARDINAL_TOKEN received from our Technical Support team.
pod 'CardinalMobile', :git => "https://oauth2:<TOKEN>@gitlab.com/securetrading-gl/software-development-kit/cardinal-sdk-ios", :tag =>'2.2.5-7'
At the end of the Podfile add following:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['CODE_SIGNING_ALLOWED'] ='NO'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "12.0"
end
if target.name == "TrustPayments"
all_filerefs = installer.pods_project.files
all_filerefs.each do |fileref|
if fileref.path.end_with?"CardinalMobile.xcframework"
build_phase = target.frameworks_build_phase
unless build_phase.files_references.include?(fileref)
build_phase.add_file_reference(fileref)
end
end
end
end
end
end
In the Terminal, go to your project folder, and run the command:
pod install
2. Initialise the iOS SDK in your app
Configure the instance
Before you can perform any payment request, you will need to set the username, gateway and environment, as shown in the example below:
The username is to be stored in a secure location, where only the user with the appropriate privileges can access it. You may wish to consider a similar approach documented for our sample app, whereby we store the username using the cocoapods-keys plugin <TODO ADD LINK TO READ ME SECTION ONCE PUBLISHED AS PART OF NEXT IOS RELEASE - LINK TO THE GETTTING STARTED OF README>
import TrustPaymentsCore
TrustPayments.instance.configure(
username: username_from_trustpayments,
gateway: .eu,
environment: .staging,
translationsForOverride: nil
)
View controllers
The following is an example of how to create a Drop-In View Controller using only the required fields:
import TrustPaymentsUI
do {
let dropInVC = try ViewControllerFactory.shared.dropInViewController(jwt: signedJWT, payButtonTappedClosureBeforeTransaction: nil, transactionResponseClosure: { jwt, result, error in
// Handle transaction response
}).viewController
// Present drop in view. E.g.
navigationController?.pushViewController(dropInVC, animated: true)
} catch {
// Handle initialization error
}
Parameter | Description | |
cardinalDarkModeStyleManager | Specifies light/dark mode for the ACS view (3-D Secure). | |
cardinalStyleManager | Specifies interface style for the ACS view (3-D Secure). | |
customDropInView | DropInViewProtocol compliant view for additional views, e.g. for adding a tip to a payment. | |
dropInViewDarkModeStyleManager | Specifies light/dark mode for the Drop-In View Controller. | |
dropInViewStyleManager | Used to customise the Drop-In View Controller. | |
jwt |
The signed JWT. |
|
payButtonTappedClosureBeforeTransaction |
Closure triggered by pressing the pay button (just before the transaction – you can use this closure to update the JWT token) You can use this closure to update the JWT token by calling the updateJWT() function on the controller that is passed as an argument. |
|
transactionResponseClosure |
Closure triggered when the transaction is completed, with the following properties:
|
The following is an alternative example of how to create a Drop-In View Controller containing more optional parameters:
import TrustPaymentsUI
do {
let dropInVC = try ViewControllerFactory.shared.dropInViewController(jwt: signedJwt, customDropInView: customView, visibleFields: [.expiryDate], dropInViewStyleManager: dropInViewStyleManager, dropInViewDarkModeStyleManager: dropInViewDarkModeStyleManager, cardinalStyleManager: cardinalStyleManager, cardinalDarkModeStyleManager: cardinalDarkModeStyleManager, payButtonTappedClosureBeforeTransaction: { dropInViewController in
// Perform any action before the transaction is started
// such as updating the JWT
}, transactionResponseClosure: { jwt, result, error in
// Handle transaction result
}).viewController
// Present the Drop-In view
navigationController?.pushViewController(dropInVC, animated: true)
} catch {
// Handle initialization error
}
You can customise UI components in the Drop-In View Controller or ACS interface (3-D Secure).
Click here to open instructions in a new tab.
Plain card input field
The below demonstrates how to create card detail input views without performing any requests on your behalf:
Creating separate UI components:
lazy var cardNumberInput: CardNumberInputView = {
CardNumberInputView(inputViewStyleManager: inputViewStyleManager)
}()
lazy var expiryDateInput: ExpiryDateInputView = {
ExpiryDateInputView(inputViewStyleManager: inputViewStyleManager)
}()
lazy var cvvInput: CVVInputView = {
CVVInputView(inputViewStyleManager: inputViewStyleManager)
}()
Then listen for CardNumberInput delegate method and adjust the security code to reflect required number of digits for given card:
extension SingleInputView: CardNumberInputViewDelegate {
func cardNumberInputViewDidComplete(_ cardNumberInputView: CardNumberInputView) {
cvvInput.cardType = cardNumberInputView.cardType
cvvInput.isEnabled = cardNumberInputView.isCVVRequired
}
func cardNumberInputViewDidChangeText(_ cardNumberInputView: CardNumberInputView) {
cvvInput.cardType = cardNumberInputView.cardType
cvvInput.isEnabled = cardNumberInputView.isCVVRequired
}
}
Payment Transaction Manager
If you already have / intend to build your own payment checkout views in your iOS app, but need a method to process payments to the Trust Payments gateway, you can use our transaction manager API.
You can review our example app for examples on how to configure the Payment Transaction Manager.
import TrustPaymentsCore
do {
let paymentTransactionManager = try PaymentTransactionManager(jwt: .empty)
paymentTransactionManager.performTransaction(jwt: signedJwt, card: card) { jwt, result, error in
// Handle transaction result
}
} catch {
// Handle initialization error
}
As part of this process, the payment card fields, pan, expirydate and securitycode will be captured on your custom payment form and added to the JSON Web Token (JWT) payload. To learn how to construct the JWT, click here to open more info in a new tab.
If you specify the fields pan, expirydate and securitycode inside of the JWT payload created on your merchant server, then the same JWT (including card details) provided during initialisation will be passed back in the response from the gateway inside the field jwt.
Ensure any sensitive payment credentials (pan, expirydate and securitycode) are sanitized prior to logging to your system.
3. Configure webhooks
It is strongly recommended that you configure webhooks on your Mobile SDK solution. When configured, URL notifications are sent to your system when payments are processed on your account.
If you do not configure webhooks as explained below, you may not be notified of payments processed on your account, e.g. in cases of client-side errors that occur prior to the response being returned.
- Sign in to Portal.
- Search for your sitereference using the search box found at the top of the page.
- When viewing your site details, click “Rule manager“.
- Select the action type “URL notification” from the drop-down and your browser will be redirected.
- Create a new URL notification rule:
- (A) Click “Add new condition” and specify the circumstances in which the URL notification is to be triggered following a transaction. In the Requests box displayed, ensure “AUTH” is ticked (meaning the notification is triggered following payment authorisations).
Click here to learn more about configuring conditions. - (B) Click “Add new action” and specify the endpoint for the URL notification.
Click here to learn more about URL notification actions. - (C) Using the drop-down boxes, assign the condition to the action and click “Create rule“.
- (A) Click “Add new condition” and specify the circumstances in which the URL notification is to be triggered following a transaction. In the Requests box displayed, ensure “AUTH” is ticked (meaning the notification is triggered following payment authorisations).
- Ensure the rule is active (this is shown with a tick under the Active column). Once enabled, the rule will be applied to all payment sessions for the given sitereference, and the URL notification will be triggered whenever the condition specified is met.
Note: All new rules should be created on your test sitereference and tested to ensure they work as expected before being added to your live sitereference.
-
You must configure your system to respond to all URL notifications received from Trust Payments with an HTTP 200 OK response.
For example: “HTTP/1.0 200 OK”.
Your system must reply within 8 seconds of receiving a notification.
Once you have completed the steps above, we recommend returning to the Getting started page to learn more about enabling add-ons, testing your solution and going live.