Payment Setup

Environment

Currently available there’s only 2 environments.

  1. MITE or TEST
  2. LIVE

You can choose between each environment by completing 2 steps:

  1. Use your Environment specific credentials set (username, password, installationId) to generate your authentication (client) token
  2. Set the Environment enum inside the PaymentConfig to the specific environment

Available Environment enums: Environment.TEST or Environment.LIVE (lowercase for iOS)

Payment Config

To setup a payment and its details, you need to create a data class called PaymentConfig:

Parameter Description
installationId Your installationId received in the setup
countryCode (Nullable) The country code of the transaction. It might enable some payment methods on specific countries. Country Code format: ISO 3166 – ALPHA-3 (e.g: GBR).
currencyCode The currency code of the transaction. Currency Code format: ISO 4217 – ALPHA-3 (e.g: GBP).
transactionType The type of transaction. TransactionType.PAYMENT or TransactionType.AUTHORIZATION. PAYMENT enum should be used for any and all transactions that will result in money deduction; AUTHORIZATION should be used when you only want to verify the Cardholder’s Card Information to make sure it is valid.
clientToken Your client token obtained earlier
transaction.amount The transaction amount, as double, can be set to 0.00 for verification
transaction.currency The same transaction currency code [equal to currencyCode]
transaction.merchantRef The merchant reference of the transaction. (e.g. “Order_123”). Recommended to be unique. This can be used to identify the transaction afterwards.
transaction.recurring Set this field if you want to start a recurring Continuous Authority relationship from this transaction. Possible values: true, false, null. If the value is not null, make sure you define the continuous authority agreement of the transaction.
transaction.deferred Use the “deferred” indicator with the Payment request to indicate that you only want to perform an authorisation. Possible values: true, false, null.
transaction.continuousAuthorityAgreement The continuous authority agreement of the transaction. Check ContinuousAuthorityAgreement for more details
customer.email The customer’s email address
customer.dob Date-of-birth: Formatted as YYYYMMDD
customer.telephone Customer’s telephone number
customer.customerRef Your customer unique reference. This reference can be used to identify the customer and it’s details while also verifying the transactions made under it.
customer.registered Indicates whether the Customer is registered with the Merchant. If set to true, the customerRef field is mandatory. If set to false, the customerRef field is not required, but supported, it can be used to store a reference to the Customer without registering them. Default value: null – setting to null will keep the same behaviour as before this change; meaning that the customerRef field will be available only if the payment is going through a registered customer.
financialServices.dateOfBirth Date of birth of the loan recipient, in YYYYMMDD format. For example, for Jan 2nd, 1980, this would be “19800102”
financialServices.surname Surname of the loan recipient; up to six characters, excluding numbers or special characters. If the name is longer than six characters, then provide the first six.
financialServices.accountNumber Account number used to identify the customer or loan. If this is a PAN, then provide the first six and last four digits of the PAN.
financialServices.postCode First part of the postal code of the loan recipient; up to six characters. For example, if the postal code is “EC2A 1AE”, this would be “EC2A”.
environment Payment Environment, can be [TEST] or [LIVE]
import com.accesspaysuite.mobilesdk.PaymentConfig

val myPaymentConfig = PaymentConfig(
    installationId = installationId,
    countryCode = "GBR",
    currencyCode = "GBP",
    transactionType = TransactionType.PAYMENT,
    clientToken = clientToken,
    transaction = TransactionDetails(
        amount = 10.0,
        currency = "GBP",
        merchantRef = "Test_order",
        recurring = false,
        deferred = false,
        continuousAuthorityAgreement = null
    ),
    customer = CustomerDetails(
        email = "[email protected]",
        dob = "19870818",
        telephone = "0123 456 789",
        customerRef = "your_unique_customer_ref"
        registered = true,
    ),
    financialServices = FinancialDetails(
        dateOfBirth = "19870818",
        surname = "John",
        accountNumber = "1234561234",
        postCode = "EC2A"
    ),
    environment = Environment.TEST
)

Payment Processor Setup

The Setup is required to set all the necessary callbacks like when the user enters a card successfully or not, if the payment method is canceled by the user, if the payment result was success or if it failed and why.

Android Example

The only difference between the Android and iOS setup would be the existence of the Android Context in the constructor of the Payment Processor

Create the PaymentProcessor

val processor = PaymentProcessor(
    config = myPaymentConfig,
    context = context // The Android Context
)

Payment Result Callback

processor.setPaymentResultCallback(
    object : PaymentResultCallback {
        override fun onPaymentResult(status: Status) {
            when (status) {
                Status.Canceled -> {
                    // User canceled the payment method
                    // This usually happens when the user proceeds the Google/Apple Pay process but cancels before completing.
                }

                is Status.Error -> {
                    // Payment method failed
                    val error = status.message
                    val traceId = status.traceId
                    // Trace id can be sent over for further information about the error.
                }

                Status.SessionExpired -> {
                    // Session expired
                }

                Status.Success -> {
                    // Payment was successful
                }

                else -> {
                    // Handle unknown cases
                }
            }
        }
    }
)
// OR
processor.setPaymentResultCallback(
    onPaymentSuccess = {
        // Payment was successful
    },
    onPaymentFailed = { error, traceId ->
        // Payment method failed
        // If session expires, then the error argument will be "Session expired"
    },
    onPaymentMethodCanceled = {
        // User canceled the payment method
    }
)

Card Submission Callback

// This callback can be used to control your UI to respond
// properly when the Cardholder information is complete or
// contains errors
processor.setCardCallback(
    onCardSubmittedSuccessfully = {
        // Card submitted successfully
    },
    onCardSubmittedWithErrors = { errors ->
        // Card submitted with errors
    
        // All errors mapped to a single string
        val errorsToString = errors.mapToString(separator = "\n")
    }
)

Payment Initiation

Required before attempting any payment methods

processor.initiate {
    if (status == Status.Initiated) {
        // Initiated successfully
    } else {
        // Could not initiate
        // Can be casted as Status.Error for further details
    }
}

Compose Multiplatform Example

// The PaymentProcessor for Compose does not require any extra setup
// The initiate process is called after declaration
val processor = rememberPaymentProcessor(
    paymentConfig = myPaymentConfig,
    onPaymentSuccess = {
        // Payment was successful
    },
    onPaymentFailed = { reason, traceId ->
        // Payment method failed
        // If session expires, then the error argument will be "Session expired"
    },
    onPaymentMethodCanceled = {
        // User canceled the payment method
    },
    onCardSubmittedSuccessfully = {
        // Card submitted successfully
    },
    onCardSubmittedWithErrors = { errors ->
        // Card submitted with errors
    },
    onInitiate = { status ->
        if (status == Status.Initiated) {
            // Initiated successfully
        } else {
            // Could not initiate
        }
    }
)

iOS Example

Similar to the Android Example

Create the PaymentProcessor

var processor = PaymentProcessor(config: paymentConfig)

Payment Result Callback

processor.setPaymentResultCallback {
    // Success
} onPaymentFailed: { reason, traceId in
    // Failed
    // traceId is a nullable String
} onPaymentMethodCanceled: {
    // Method canceled
}
// OR
processor.setPaymentResultCallback(callback: <any PaymentResultCallback>)

Card Submission Callback

// This callback can be used to control your UI to respond
// properly when the Cardholder information is complete or
// contains errors
processor.setCardCallback {
    // Card submitted successfully
} onCardSubmittedWithErrors: { errors in
    // Card has errors
}

Payment Initiation

Required before attempting any payment methods

processor.initiate { status in
    if (status is Status.Initiated) {
        // Initiated successfully
    } else {
        // Could not initiate
        // Can be casted as Status.Error for further details
    }
}