This SDK is deprecated as of July 21, 2023 and will no longer be maintained or supported.
You should upgrade to the newest version of our Vault SDK, and release a new version of your application. The new SDK provides the same functionality of card registration flow, with Kotlin language support., better performance, and continued support.
If you have any other questions around this deprecation, please reach out to our team via the Hub
The mangopay card registration library makes it easy to create a card registration object based on your credit card info.
No need to clone the repository or download any files -- just add this line to your app's build.gradle inside the dependencies section:
implementation 'com.mangopay.android.sdk:card-registration-library:1.2.2'
And the final step is to use one of the following lines in your app/build.gradle
dependencies:
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
implementation(name:'card-registration-library-1.2.2', ext:'aar')
implementation 'com.mangopay.android.sdk:card-registration-library:1.2.2@aar'
You should already have a webapp (the service on your server that communicates with your Android app) and you need to add this new card registration functionality - this includes the API call to MANGOPAY (more info). You will then provide the Android kit with the url
to access this functionality (configured here). The url
should return a JSON response (which has the information obtained from the MANGOPAY API) as follows:
{
"accessKey": "1X0m87dmM2LiwFgxPLBJ",
"baseURL": "https://api.sandbox.mangopay.com",
"cardPreregistrationId": "12444838",
"cardRegistrationURL": "https://homologation-webpayment.payline.com/webpayment/getToken",
"cardType": "CB_VISA_MASTERCARD",
"clientId": "sdk-unit-tests",
"preregistrationData": "ObMObfSdwRfyE4QClGtUc6um8zvFYamY_t-LNSwKAxBisfd7z3cTgS83cCwyP9Gp7qGR3aNxrLUiPbx-Z--VxQ"
}
Using the information received from your server, create an instance of MangoPay as follows:
// holds the card registration data
MangoSettings mSettings = new MangoSettings(baseURL, clientId, cardPreregistrationId,cardRegistrationURL, preregistrationData, accessKey);
// using the default constructor where you should pass the android context and the settings object
MangoPay mangopay = new MangoPay(this, mSettings);
// or using the mangopay builder
MangoPay mangopay = new MangoPayBuilder(this).build();
// holds the card information
MangoCard mCard = new MangoCard("3569990000000157", "0920", "123");
// register card method with callback
mangopay.registerCard(mCard, new Callback() {
@Override public void success(CardRegistration cardRegistration) {
Log.d(MainActivity.class.getSimpleName(), cardRegistration.toString());
}
@Override public void failure(MangoError error) {
Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
}
});
MangoPayBuilder builder = new MangoPayBuilder(this); // android context
builder.baseURL(baseURL) // card pre-registration baseUrl
.clientId(clientId) // card pre-registration clientId
.accessKey(accessKey) // card pre-registration accessKey
.cardRegistrationURL(cardRegistrationURL) // card pre-registration url
.preregistrationData(preregistrationData) // card pre-registration data
.cardPreregistrationId(cardPreregistrationId) // card pre-registration id
.cardNumber("3569990000000157") // credit card number accepted inputs: '123412341234' or '1234-1234-1234-1234' or '1234 1234 1234 1234'
.cardExpirationDate("0920") // credit card expiration date e.g '0920' or '11/20' or '02-19'
.cardCvx("123") // credit card expiration cvx
.callback(new Callback() { // callback that returns the sdk success or failure objects
@Override public void success(CardRegistration cardRegistration) {
Log.d(MainActivity.class.getSimpleName(), cardRegistration.toString());
}
@Override public void failure(MangoError error) {
Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
}
}).start();
// you can pass the card expiration date as a java.util.Date object
.cardExpirationDate(new Date())
// you can pass the card expiration month together with the card expiration year as integers
.cardExpirationMonth(9)
.cardExpirationYear(2019)
// you can set the log level of the SDK
.logLevel(LogLevel.NONE|LogLevel.FULL)
Don't forget to add -keep class com.mangopay.android.sdk.* { *; }
to your proguard-rules.pro