- Home
- All APIs
- Worldpay Online Payments Guide
- Worldpay Android Library
Worldpay Android Library
Integration
- Before integrating the Worldpay library, make sure you have installed the Android SDK with API Level 16.
- Import
Worldpay Android Library to your workspace.
Initialise the library
- Link the WorldpayLibrary Project to your project.
- Declare internet permission in AndroidManifest.xmlCopied!
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET" /> - Initialise the libraryCopied!
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);
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);
Choose library-provided or create your custom card submission form
Default Library-provided form
Developers can use SaveCardActivity of the library.
- Declare the activity in AndroidManifest.xmlCopied!
<activity android:name="com.worldpay.SaveCardActivity" android:label="Card Details" />
<activity android:name="com.worldpay.SaveCardActivity" android:label="Card Details" /> - Open the activity:Copied!
Intent intent = new Intent(myactivity, SaveCardActivity.class); //SAVE_CARD_REQUEST_CODE a custom request code for that activity startActivityForResult(intent, SAVE_CARD_REQUEST_CODE);
Intent intent = new Intent(myactivity, SaveCardActivity.class); //SAVE_CARD_REQUEST_CODE a custom request code for that activity startActivityForResult(intent, SAVE_CARD_REQUEST_CODE); - 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.
Custom form
- Create a Card object, pass card details and validate it.Copied!
Card card = new Card(); CardValidationError validate = card.setHolderName("John Newman"). setCardNumber("1234123412341234") .setCvc("123").setExpriryMonth("12").setExpiryYear("2018") .validate();
Card card = new Card(); CardValidationError validate = card.setHolderName("John Newman"). setCardNumber("1234123412341234") .setCvc("123").setExpriryMonth("12").setExpiryYear("2018") .validate(); - 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.Copied!
@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(); }
@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(); }