This SDK allows mobile developers to provide credit card payment functionality within their Android applications, without having to pass sensitive card data back to their application backend servers. For more information on including payments in your mobile application see our InApp Payments Guide
dependencies {
implementation "com.cybersource:flex-api-android-client:1.0.1"
}
Note: Update your Gradle local.properties with your local machines username
val MERCHANT_ID = "<MerchantID>"
val MERCHANT_SECRET = "<MerchantSecret>"
val MERCHANT_KEY = "<MerchantKey>"
Please refer sample application which demonstrates creation of Capture context
Sample App
val captureContext = createCaptureContext()
val payloadItems = getPayloadData()
val cc = CaptureContext.fromJwt(keyId)
var flexService = FlexService.getInstance()
try {
flexService.createTokenAsyncTask(cc, payloadItems, object :
TransientTokenCreationCallback {
override fun onSuccess(tokenResponse: TransientToken?) {
//handle successful response
}
override fun onFailure(error: FlexException?) {
//handle failed response
}
})
} catch (e: FlexException) {
//handle exception
}
private fun getPayloadData(): Map<String, Any>? {
val sad: MutableMap<String, Any> = HashMap()
sad["paymentInformation.card.number"] = "4111111111111111"
sad["paymentInformation.card.securityCode"] = "123"
sad["paymentInformation.card.expirationMonth"] = "12"
sad["paymentInformation.card.expirationYear"] = "29"
return sad
}
Your server constructs a transaction request using the Cybersource API, placing the encrypted payment information that it received in previous step in the opaqueData element.
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "YOUR_API_LOGIN_ID",
"transactionKey": "YOUR_TRANSACTION_KEY"
},
"refId": "123456",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "5",
"payment": {
"opaqueData": {
"dataDescriptor": "COMMON.ACCEPT.INAPP.PAYMENT",
"dataValue": "PAYMENT_NONCE_GOES_HERE"
}
}
}
}
}
We have a sample application which demonstrates the SDK usage:
Sample App
The generation of the capture context should originate from your payment application server. As this is a fully authenticated REST api it requires your API credentials which are not secured on a mobile application. It has been included in this demonstration for the purpose of convenience and to demonstrate an end-to-end payment flow.