##Integration
- Before integrating Worldpay library make sure you have installed the Android SDK with API Level 16.
- Import Worldpay library to your workspace.
##Initialise the library
-
Link the WorldpayLibrary Project to your project.
-
Declare internet permission in AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
-
Initialise the library
Worldpay worldpay = Worldpay.getInstance(); worldpay.setClientKey(YOUR_CLIENT_KEY); // decide whether you want to charge this card multiple times or only once worldpay.setReusable(true); // set validation type advanced or basic Card.setValidationType(Card.VALIDATION_TYPE_ADVANCED);
Developers can use **SaveCardActivity** of the library.
1. Declare the activity in AndroidManifest.xml
<activity android:name="com.worldpay.SaveCardActivity" android:label="Card Details" />
2. Open the activity :
Intent intent = new Intent(myactivity, SaveCardActivity.class);
//SAVE_CARD_REQUEST_CODE a custom request code for that activity
startActivityForResult(intent, SAVE_CARD_REQUEST_CODE);
3. Handle activity response implementing **Activity.onActivityResult(int, int, android.content.Intent)**.
The developer can use Intent parameter from **Activity.onActivityResult(int, int, android.content.Intent)** to retrieve more information about the result.
1. Create a Card object, pass card details and validate it.
Card card = new Card();
CardValidationError validate = card.setHolderName("John Newman")
.setCardNumber("1234123412341234")
.setCvc("123")
.setExpiryMonth("12")
.setExpiryYear("2018")
.validate();
2. Use the Worldpay library to connect with Worldpay to store card details and create a token. This can be done by creating an AsyncTask and executing it. A callback interface should be implemented to handle the response.
AsyncTask<Void, Void, HttpServerResponse> createTokenAsyncTask = worldpay.createTokenAsyncTask(this, card, new WorldpayResponse() {
@Override
public void onSuccess(ResponseCard responseCard) {
//handle success
}
@Override
public void onResponseError(ResponseError responseError) {
//handle error
}
@Override
public void onError(WorldpayError worldpayError) {
//handle error
}
});
if (createTokenAsyncTask != null) {
createTokenAsyncTask.execute();
}
Developers can use **SaveAlternativePaymentMethodActivity** of the library.
1. Declare the activity in AndroidManifest.xml
<activity android:name="com.worldpay.SaveAlternativePaymentMethodActivity" android:label="APM Details" />
2. Open the activity :
Intent intent = new Intent(myactivity, SaveAlternativePaymentMethodActivity.class);
//SAVE_APM_REQUEST_CODE a custom request code for that activity
startActivityForResult(intent, SAVE_APM_REQUEST_CODE);
3. Handle activity response implementing **Activity.onActivityResult(int, int, android.content.Intent)**.
The developer can use Intent parameter from **Activity.onActivityResult(int, int, android.content.Intent)** to retrieve more information about the result.
1. Create an AlternativePaymentMethod object and validate it.
AlternativePaymentMethod apm = AlternativePaymentMethod.newPayPalApm("First Last", "GB");
AlternativePaymentMethodValidationError validationError = apm.validate();
2. Use the Worldpay library to connect with Worldpay to store the APM and create a token. This can be done by creating an AsyncTask and executing it. A callback interface should be implemented to handle the response.
AsyncTask<Void, Void, HttpServerResponse> createTokenAsyncTask = worldpay.createTokenAsyncTask(this, apm, new WorldPayApmResponse() {
@Override
public void onSuccess(AlternativePaymentMethodToken token) {
//handle success
}
@Override
public void onResponseError(ResponseError responseError) {
//handle error
}
@Override
public void onError(WorldpayError worldpayError) {
//handle error
}
});
if (createTokenAsyncTask != null) {
createTokenAsyncTask.execute();
}