Simple SDKs

eWAY is the easiest way to accept payments in your app or on your website. Get integrated and start selling more, faster - in a range of languages using the eWAY SDKs, helpful documentation, and 24/7 support from real humans. eWAY - with you every step of the way.

ANDROID SDK – GETTING STARTED

android icon

​Use the eWAY Android SDK to easily accept payments in your Android application!

The eWAY Android SDK supports three styles of implementation, depending on the requirements of your app:

  • Synchronous – the app will wait for eWAY operations to complete (use this if you aren’t sure)
  • Asynchronous – the app can continue while eWAY operations complete
  • RxJava – for apps built using ReactiveX

INSTALLATION

GRADLE

Gradle is the easiest way to install the eWAY Android SDK – adding the package in the gradle file:

    compile 'com.eway.payment:android-sdk:1.2.2'

    Permissions

    To use the eWAY Android SDK, the INTERNET permission is required. Simply add the following line to the AndroidManifest.xml file if it is not already there:

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    Configuration

    The eWAY Android SDK requires two pieces of information to connect to eWAY, your eWAY account’s Public API Key and the endpoint.

    To find your account’s Public API Key:

    1. In MYeWAY (production or sandbox), go to My Account > User Security > Manage Users

    2. Select the “Actions” dropdown for the Rapid API user and select “View Api Keys”

    3. Select the “Pay Now Button Public API Key”, this is your Public API Key.

    The Endpoint should be one of: ”Production” or “Sandbox”

    These values are passed to the eWAY Android SDK using the following static properties:

    RapidAPI.PublicAPIKey = "epk-XXXXX-XXXX-XXXX-XXXX-XXXXXXX1";
    RapidAPI.RapidEndpoint = "Sandbox";
    

    Don’t forget to change these properties to the production API Key & Endpoint when sending your app live!

Encrypt Values

To secure a customer’s card data for transmission to your server for processing, you can use the encryptValues method. Once encrypted, the values can be sent to your server with any other data to be processed using eWAY’s Rapid Direct Connection API.

Once the eWAY Android SDK has been initialised, the encryptValues method can be called with a NVPair ArrayList. There are three ways of calling this, depending on your app’s design:

Synchronous Request

Final ArrayList values = new ArrayList<>();
values.add(new NVPair("Card", cardNumber));
values.add(new NVPair("CVN", cvnNumber));
EncryptItemsResponse response = RapidAPI.encryptValues(values).body();
                           

The response contains the encrypted values in a NVPair ArrayList which can be fetched with getValues:

EncryptItemsResponse response = RapidAPI.encryptValues(values).body();  

If there was a problem with encrypting the values, the error can be fetched with getErrors. If no errors occurred then null will be returned. See Handling Errors for more information.

Advise : Synchronous request must handle this request on a background thread.

Asynchronous Request


The asynchronous request is simpler to implement with just calling the method below

final ArrayList values = new ArrayList<>();
values.add(new NVPair("Card", cardNumber));
values.add(new NVPair("CVN", cvnNumber));
RapidAPI.asyncEncryptValues(values).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response
response) {
}
@Override
public void onFailure(Call call, Throwable t) {
 }
 });



RxJava – RxAndroid request

According to the new RXJAVA 2.0 documentation. It supports backpressure for better handling network request. For further information please chenck this link.

This flowable request return a disposable with the methods described below:

 final ArrayList values = new ArrayList<>();
values.add(new NVPair("Card", cardNumber));
values.add(new NVPair("CVN", cvnNumber));
RapidAPI.rxEncryptValues(values).subscribe(new Subscriber() {
 @Override
 public void onSubscribe(Subscription s) {
 }
 @Override
 public void onNext(EncryptItemsResponse encryptItemsResponse) {
 }
 @Override
 public void onError(Throwable t) {
 }
 @Override
 public void onComplete() {
 }
 })

If you want to work with observables. The flowable can be changed like:

RapidAPI.rxEncryptValues(values).toObservable().subscribe(new
Observer() {
 @Override
 public void onSubscribe(Disposable d) {
 }
 @Override
 public void onNext(EncryptItemsResponse value) {
 }
 @Override
 public void onError(Throwable e) {
 }
 @Override
 public void onComplete() {
 }
 })

Note: Observables do not support backpressure

Make a Payment

A payment can also be made directly from the app using the eWAY Android SDK, instead of sending details to a server. Note that the result of the transaction (succeeded or failed) can still only be requested using Rapid API from a server – see Getting the Result below.

First collect the details for the payment(such as the customer’s name and card details) prepare the data for sending. All the fields available in RapidAPI’s Direct Connection can be used when submitting a transaction. The following is a simple example:

CardDetails cardDetails = new CardDetails();
cardDetails.setCVN("349");	
cardDetails.setName("Kale Argula");	
cardDetails.setNumber("4556761029983886");	
cardDetails.setExpiryMonth("09");	
cardDetails.setExpiryYear("2020");
	
Customer customer = new Customer();	
customer.setFirstName("Kale");	
customer.setLastName("Argula");	
customer.setCardDetails(cardDetails);
	
Payment payment = new Payment();
payment.setCurrencyCode("AUD");	
payment.setTotalAmount(1000);	
payment.setInvoiceNumber(UUID.randomUUID().toString());	
payment.setInvoiceReference(UUID.randomUUID().toString());	
payment.setInvoiceDescription("Demo Transaction");
	
Transaction transaction = new Transaction();	
transaction.setCustomer(customer);	
transaction.setTransactionType(TransactionType.Purchase);	
transaction.setPayment(payment);

Then submit the data to eWAY using the method appropriate for your app’s design:


SYNCHRONOUS REQUEST

We recommend use this request off the main thread.There are some libraries and frameworks that help to handle this. Like asyntask, runnables threads, ..etc

SubmitPayResponse submitPayResponse = RapidAPI.submitPayment(transaction).body();


Asynchronous request

RapidAPI.asyncSubmitPayment(transaction).enqueue(new Callback() {
 @Override
 public void onResponse(Call call,
Response response) {
 }
 @Override
 public void onFailure(Call call, Throwable t) {
 }
 });



RXJAVA – RXANDROID RESPONSE

Flowable request:

RapidAPI.rxSubmitPayment(transaction).subscribeWith(new
Subscriber() {
 @Override
 public void onSubscribe(Subscription s) {
 }
 @Override
 public void onNext(SubmitPayResponse submitPayResponse) {
 }
 @Override
 public void onError(Throwable t) {
 }
 @Override
 public void onComplete() {
 }
 });

Observable request :

RapidAPI.rxSubmitPayment(transaction).toObservable().subscribe(new
Observer() {
 @Override
 public void onSubscribe(Disposable d) {
 }
 @Override
 public void onNext(SubmitPayResponse value) {
 }
 @Override
 public void onError(Throwable e) {
 }
 @Override
 public void onComplete() {
 }
 });

In all cases, the response object also contains status and error properties. The status is set to one of “accepted” or “error”. This does not indicate whether the transaction was successful, it indicates if the SDK received a response.



If an error did occur, the errors property this will contain one or more comma separated error codes. These codes can be translated with userMessage – see Handling Errors below for more details.



HANDLING ERRORS

If a call with the eWAY Android SDK fails for some reason, an error code will be returned in the response object. Note that only SDK errors will be returned – if there was an error with the transaction (such as card declined) no error will be supplied to the SDK.

To check for a transaction or validation failure, use the Access Code to do a server side Transaction Query with eWAY’s Rapid API.



To check if an SDK error occurred, use the method appropriate for your app’s design:



SYNCHRONOUS RESPONSE

Test if the getErrors method returns null:

EncryptItemsResponse response = RapidAPI.encryptValues(values).body();
if(response.getErrors() != null){
 //handle errors
}


ASYNCHRONOUS RESPONSE

@Override
public void onFailure(Call call, Throwable t) {
}


RXJAVA – RXANDROID RESPONSE

@Override
public void onError(Throwable t) {
}

If there is an error, it can be looked up using userMessage to return a user friendly version of the response (only English is available at this time):



SYNCHRONOUS RESPONSE

UserMessageResponse response = RapidAPI.userMessage(Locale.getDefault().getLanguage(),
errorCodeNumber);


ASYNCHRONOUS REQUEST

RapidAPI.asynUserMessage(Locale.getDefault().getLanguage(), errorCodeNumber, new
AbsAsyncUserMessageUseCase.CallbackUserMessage() {
 @Override
 public void onSuccess(UserMessageResponse response) {
 }
 @Override
 public void onError(Throwable throwable) {
 }
 })


RXJAVA – RXANDROID REQUEST

RapidAPI.rxUserMessage(Locale.getDefault().getLanguage(),
errorCodeNumber).subscribeWith(new Subscriber() {
 @Override
 public void onSubscribe(Subscription s) {
 }
 @Override
 public void onNext(UserMessageResponse userMessageResponse) {
 }
 @Override
 public void onError(Throwable t) {
 }
 @Override
 public void onComplete() {
 }
 })


Error Codes

The following error codes are specific to the eWAY Android SDK. They can be translated using the userMessage as described in the Handling Errors section.

  Error Code

  Purpose

  S9990

  Library does not have Endpoint initialised, or not initialise to a URL

  S9991

  Library does not have PublicAPI key initialised, or Key is Invalid.

  S9992

  Communication error with Rapid API.

  S9993

  Authentication error with Rapid API.

  S9994

  Internal system error communicating with Rapid API.

  S9995

  Internal SDK Error, Bad Parameters etc.



eWAY makes it easy for us to process and manage payments. They have an SDK that my developers liked working with and their payment management tools are very easy to use.

Dean Van Es, Managing Director FastCover