Overview
The Android Direct Native SDK integration is an SDK for native mobile apps to perform 3D-Secure-Only validation using the Nuvei authenticate3d() method.
This topic steps you through the process of integrating Nuvei payment solutions into your native mobile apps on the Android platform.
UI Implementation
3D Authentication presents challenge screens to the user. You can customize the UI of these screens by changing the values in the set of customization definition objects. This customization definition is optional and may be skipped; the default customization is used in this case.
Example Android SDK UI Customization
// Customization val customization = NuveiUiCustomization( toolbarCustomization = NuveiToolbarCustomization( "SECURE CHECKOUT", "sans-serif", 22, "#FFFFFF", "#40C1AC" ), labelCustomization = NuveiLabelCustomization( "sans-serif", 14, "#000000", "sans-serif", 14, "#40C1AC" ), textBoxCustomization = NuveiTextBoxCustomization( "sans-serif", 14, "#000000", "#000000", 0, 1 ) ) // Next button customization NuveiButtonCustomization( "sans-serif", "#FFFFFF", 17, "#40C1AC", 5 ).also { customization.setButtonCustomization(it, NuveiButtonCustomization.Type.NEXT) customization.setButtonCustomization(it, NuveiButtonCustomization.Type.CONTINUE) customization.setButtonCustomization(it, NuveiButtonCustomization.Type.RESEND) customization.setButtonCustomization(it, NuveiButtonCustomization.Type.SUBMIT) } // Cancel button customization NuveiButtonCustomization( "sans-serif", "#40C1AC", 17, "#FFFFFF", 5 ).also { customization.setButtonCustomization(it, NuveiButtonCustomization.Type.CANCEL) } MobileSDK.setUiCustomization(customization)
Submit a Payment Request
Initiate a Session
Send the /openOrder API call, which does the following:
- Authenticates you as our merchant using your given credentials.
- Sets up an order on our system that contains your transaction details, which are referenced later in the payment flow.
Example /openOrder
Request
-
{ "merchantId":"<your merchantId goes here>", "merchantSiteId":"<your merchantSiteId goes here>", "clientUniqueId":"<unique transaction ID in merchant system>", "clientRequestId":"<unique request ID in merchant system>", "currency":"USD", "amount":"200", "timeStamp":"<YYYYMMDDHHmmss>", "checksum":"<calculated checksum>" }
<?php $safecharge = new \SafeCharge\Api\RestClient([ 'environment' => \SafeCharge\Api\Environment::INT, 'merchantId' => '<your merchantId>', 'merchantSiteId' => '<your merchantSiteId>', 'merchantSecretKey' => '<your merchantSecretKey>', ]); $openOrderRequest = $SafeCharge->getPaymentService()->openOrder([ 'clientUniqueId' => '<unique transaction ID in merchant system>', 'clientRequestId' => '<unique request ID in merchant system>', 'currency' => 'USD', 'amount' => '200' ]); ?>
public static void main(String[] args) { // for initialization String merchantId = "<your merchantId>"; String merchantSiteId = "<your merchantSiteId>"; String merchantKey = "<your merchantKey>"; safecharge.initialize(merchantId, merchantSiteId, merchantKey, APIConstants.Environment.INTEGRATION_HOST.getUrl(), Constants.HashAlgorithm.SHA256); //for openOrder String clientUniqueId = "<unique transaction ID in merchant system>"; String clientRequestId = "<unique request ID in merchant system>"; String currency = "USD"; String amount = "200"; SafechargeResponse response = safecharge.openOrder(userTokenId, clientRequestId, clientUniqueId, null, null, null, null, currency, amount, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); }
var safecharge = new Safecharge( "<your merchantKey>", "<your merchantId>", "<your merchantSiteId>", "<your server host value", HashAlgorithmType.SHA256 ); var response = safecharge.OpenOrder( "USD", "200", clientUniqueId: "<unique transaction ID in merchant system>", clientRequestId: "<unique request ID in merchant system>" );
const safecharge = require('safecharge'); safecharge.initiate(<merchantId>, <merchantSiteId>, <merchantSecretKey>, <env>); safecharge.paymentService.openOrder({ 'clientUniqueId' : '<unique transaction ID in merchant system>', 'clientRequestId' : '<unique request ID in merchant system>', 'currency' : 'USD', 'amount' : '200' }, function (err, result) { console.log(err, result) });
Example /openOrder
Response
-
{ "sessionToken": "64fe6953-69d1-440f-8e21-878c85701f09", "orderId": "39272", "merchantId": "427583496191624621", "merchantSiteId": "142033", "clientUniqueId": "12345", "clientRequestId": "1484759782197", "internalRequestId": 866, "status": "SUCCESS", "errCode": 0, "reason": "", "version": "1.0" }
3D-Secure Authentication
Once you have collected all the required transaction details, create an instance of Authenticate3dInput
class with all the data and call NuveiMobileSDK.authenticate3d(...)
method as follows:
Example Input
val paymentOption = PaymentOption( userPaymentOptionId, CardDetails( card_number.editText ? .text.toString(), card_holder_name.editText ? .text.toString(), cvv.editText ? .text.toString(), card_month.editText ? .text.toString(), card_year.editText ? .text.toString() ) ) val input = Authenticate3dInput( sessionToken, merchantId, merchantSiteId, currency.editText ? .text.toString(), amount.editText ? .text.toString(), paymentOption, clientUniqueId, // Optional clientRequestId, customData, // Optional billingAddress, // Optional shippingAddress, // Optional userDetails, // Optional merchantDetails // Optional ) MobileSDK.authenticate3d(this, input, object: Callback { override fun onComplete(output: Authenticate3dOutput) { Log.d(TAG, "Output = $output") } })
Example Output
class Authenticate3dOutput( val result: String ? , val userPaymentOptionId : String ? , val cavv : String ? , val eci : String ? , val dsTransID : String ? , val ccCardNumber : String ? , val bin : String ? , val last4Digits : String ? , val ccExpMonth : String ? , val ccExpYear : String ? , val ccTempToken : String ? , val transactionId : String ? , val threeDReasonId : String ? , val threeDReason : String ? , val challengePreferenceReason : String ? , val isLiabilityOnIssuer : Boolean ? , val cancelled : Boolean, val challengeCancelReasonId: String ? , val challengeCancelReason : String ? , val errorCode : Int ? , val errorDescription : String ? , val rawResult : Map < String, Any > ? )
Handling the authenticate3d()
Response
The response from the authenticate3d() call includes the result
parameter, which can have one of these values:
Result | Notes | Next action |
---|---|---|
APPROVED | This result can be due to either of these cases:
| Perform a server-side liability shift payment by sending a /payment API call, and include an externalMpi class containing the 3D-Secure authentication values received from the authenticate3d() call, as shown below. |
DECLINED | The authentication failed.
| The transaction should not proceed to payment. |
ERROR | The authentication failed.
| The 3D-Secure authentication failed; however, subject to risk considerations, you may still want to proceed with a Non-3D-Secure transaction payment, without liability shift, by simply submitting a payment, without the threeD class, as shown below in Example /payment API Request without Liability Shift. |
Perform the Server-Side Payment
Please press here to continue.