Contents

Initialise the SDK

 

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:


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:


let dropInVC = ViewControllerFactory.shared.dropInViewController(
	jwt: jwt,
	payButtonTappedClosureBeforeTransaction: { (controller: DropInController) in},
	successfulPaymentCompletion: {
		(
			jwt: String,
			responses: [JWTResponseObject],
			successMessage: String,
			cardReference: TPCardReference?
		)
	in},
	transactionFailure: {
		(
			jwt: String?,
			responses: [JWTResponseObject]?,
			errorMessage: String,
			error: NSError?
		)
	in}
)

 

Parameter specification

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).
cardTypeToBypass Specifies card types that bypass 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.
isDeferInit It determines when the connection with SDK Cardinal Commerce is initiated, whether at the beginning or only after accepting the form (true value – should be true when you want to update the JWT token at this point).
jwt The signed JWT. Click here to learn how generate the 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.

successfulPaymentCompletion Closure triggered after a successful payment transaction
transactionFailure Closure triggered after a failed transaction, when a error was returned at some stage
typeDescriptions Request types to be performed (this defaults to threeDQuery, auth).

 

The following is an alternative example of create a Drop-In View Controller containing more optional parameters:


let dropInVC = ViewControllerFactory.shared.dropInViewController(
	jwt: jwt,
	typeDescriptions: [.auth, .subscription],
	isDeferInit: false,
	customDropInView: dropInCustomView,
	visibleFields: [.securityCode3],
	dropInViewStyleManager: dropInViewStyleManager,
	dropInViewDarkModeStyleManager: dropInViewDarkModeStyleManager,
	cardTypeToBypass: [.mastercard],
	cardinalStyleManager: cardinalStyleManager,
	cardinalDarkModeStyleManager: cardinalDarkModeStyleManager,
	payButtonTappedClosureBeforeTransaction: {
		(
			controller: DropInController
		)
	in},
	successfulPaymentCompletion: {
		(
			jwt: String,
			responses: [JWTResponseObject],
			successMessage: String,
			cardReference: TPCardReference?
		)
	in},
	transactionFailure: {
		(
			jwt: String?,
			responses: [JWTResponseObject]?,
			errorMessage: String,
			error: NSError?
		)
	in}
)

 

External
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 cvcInput: CvcInputView = {
    CvcInputView(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) {
        cvcInput.cardType = cardNumberInputView.cardType
        cvcInput.isEnabled = cardNumberInputView.isCVCRequired
    }

    func cardNumberInputViewDidChangeText(_ cardNumberInputView: CardNumberInputView) {
        cvcInput.cardType = cardNumberInputView.cardType
        cvcInput.isEnabled = cardNumberInputView.isCVCRequired
    }
}

 

Payment Transaction Manager

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 transaction manager as outlined below:


let paymentTransactionManager = try PaymentTransactionManager(jwt: .empty, isDeferInit: true, cardTypeToBypass: [.mastercard])
paymentTransactionManager.performTransaction(jwt: jwt, typeDescriptions: [.threeDQuery, .auth], card: card, transactionSuccessClosure: { jwt, responseObjects, cardReference in
}, transactionErrorClosure: { jwt, responseObjects, errorMessage, foundationError in
}, cardinalAuthenticationErrorClosure: {
}, validationErrorClosure: { error, errorCodes in
})

 

Where next?

Customising the UI
The Drop-In Controller includes customisation options, allowing you to tailor the appearance of your checkout to better fit the branding of your app.
Click here to learn how >>>
Testing
Once you have initialised the SDK in your app, you should now be able to process test transactions.
Click here to learn how >>>
Performing additional requests
By following the information above, your app should be configured to process a card payment that is authenticated with 3-D Secure. For more advanced configurations, additional requests can be referenced in the Drop-In View Controller.
Click here to learn how >>>