This SDK allows mobile developers to accept payments on a customer's mobile device from 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 In-App Payments Guide
Add the dependency from jCenter to your app's (not project's) build.gradle
file.
repositories {
jcenter()
}
dependencies {
compile 'net.authorize:accept-sdk-android:1.0.2'
}
Android API 14+ is required as the minSdkVersion
in your build.gradle
All SDK API's will be accessed through AcceptSDKApiClient
Object, which can be created as follows:
// Parameters:
// 1) Context - Activity context
// 2) AcceptSDKApiClient.Environment - AUTHORIZE.NET ENVIRONMENT
apiClient = new AcceptSDKApiClient.Builder (getActivity(),
AcceptSDKApiClient.Environment.SANDBOX)
.connectionTimeout(5000) // optional connection time out in milliseconds
.build();
Fetch token API requires EncryptTransactionObject
, which can be created as follows:
EncryptTransactionObject transactionObject = TransactionObject.
createTransactionObject(TransactionType.SDK_TRANSACTION_ENCRYPTION)// type of transaction object
.cardData(prepareCardDataFromFields()) // card data to be encrypted
.merchantAuthentication(prepareMerchantAuthentication()) //Merchant authentication
.build();
EncryptTransactionObject
requires cardData
object, which can be created as follows:
CardData cardData = new CardData.Builder(CARD_NUMBER,
EXPIRATION_MONTH, // MM
EXPIRATION_YEAR) // YYYY
.cvvCode(CARD_CVV) // Optional
.zipCode(ZIP_CODE)// Optional
.cardHolderName(CARD_HOLDER_NAME)// Optional
.build();
EncryptTransactionObject
requires merchantAuthentication
object, which can be created as follows:
ClientKeyBasedMerchantAuthentication merchantAuthentication = ClientKeyBasedMerchantAuthentication.
createMerchantAuthentication(API_LOGIN_ID, CLIENT_KEY);
Check out the "Obtaining a Public Client Key" section in Accept Mobile for more information on getting CLIENT_KEY.
When transaction information is ready, you can make the following call to fetch token:
// Parameters:
// 1. EncryptTransactionObject - The transaction object for current transaction
// 2. transaction response callback.
apiClient.getTokenWithRequest(transactionObject, callback);
To get a response back, the activity/fragment should implement the EncryptTransactionCallback
interface. It has thefollowing methods:
This method will be called when token is successfully generated.EncryptTransactionResponse
object has Data Descriptor and Data Value details which will be used to perform the payment transaction.
@Override
public void onEncryptionFinished(EncryptTransactionResponse response)
{
Toast.makeText(getActivity(),
response.getDataDescriptor() + " : " + response.getDataValue(),
Toast.LENGTH_LONG)
.show();
}
This method will be called in three scenarios,
> Validation of information is failed.
> Network related errors.
> API error response.
ErrorTransactionResponse
may contain one or more error messages.
@Override
public void onErrorReceived(ErrorTransactionResponse errorResponse)
{
Message error = errorResponse.getFirstErrorMessage();
Toast.makeText(getActivity(),
error.getMessageCode() + " : " + error.getMessageText() ,
Toast.LENGTH_LONG)
.show();
}
We have a sample application which demonstrates the SDK usage:
https://github.com/AuthorizeNet/accept-sample-android
Google’s developer terms require that purchases related to the app, such as premium features or credits, are made via their native Google Play In-app Billing API. See https://play.google.com/about/developer-content-policy.html for more details.