JAVA SDK

Accept payments quickly and easily with eWAY using the eWAY Rapid ​Java SDK. Using the ​Java SDK provides convenient access to all the features of eWAY’s Rapid API, so you can create transactions, process refunds, query transactions, create token customers, and more!

GETTING STARTED

INSTALLATION

The easiest way to add the eWAY Java SDK to your project is using Maven – it will add the SDK along with its required dependencies.

To add the eWAY Java SDK, in your project’s pom.xml file add the following in the dependencies section:

1
2
3
com.ewaypayments
eway-rapid-java
1.0.0

Since the eWAY Java SDK is in Maven Central, no extra repositories are required.

To make development and testing with eWAY easy, get a free partner account which provides access to the eWAY Sandbox.

Now you are all set to build your eWAY integration! You can find code samples for integrating various eWAY functions as part of the eWAY Rapid API reference.

Example Integration

To demonstrate adding the eWAY ​Java SDK, this example will show how to accept a payment with the Responsive Shared Page.

This example assumes that Maven is already installed and a new project is being started. To keep things simple, standard lines such as import statements aren’t shown. Only the eWAY specific code is shown so it can be added to your preferred framework.

1. Add the eWAY Java SDK
In the project’s pom.xml, add the eWAY Java SDK dependency in the dependencies section:
1
2
3
com.ewaypayments
eway-rapid-java
1.0.0

Once completed,​ on the command line you can run

1
maven install

to download the eWAY Java SDK and dependencies.

2. Load the eWAY Client
With the eWAY Java SDK installed, the next step is to add the eWAY integration to your project. To start, generate an instance of the eWAY Client which interacts with eWAY’s Rapid API. It needs an eWAY Rapid API key & password, along with the endpoint to connect to (Live or Sandbox):
1
2
3
String apiKey = "60CF3Ce97nRS1Z1Wp5m9kMmzHHEh8Rkuj31QCtVxjPWGYA9FymyqsK0Enm1P6mHJf0THbR";
String password = "API-P4ss";
String rapidEndpoint = "Sandbox";RapidClient client = RapidSDK.newRapidClient(apiKey, password, rapidEndpoint);
3. Create a Shared Payment URL

In order to send a customer to the Responsive Shared Page, a URL must be generated using thecreate function. This accepts a PaymentMethod and a Transaction object.

The PaymentMethod determines how the card data will be accepted (in this case ResponsiveShared) while the Transaction object contains customer and invoice details – more details of the variables that can be passed can be found in the Rapid API reference.

This step would usually take place after collecting the customer’s information in a checkout process. For this example, just some dummy data will be used:
1
2
3
4
5
6
PaymentDetails paymentDetails = new PaymentDetails();
paymentDetails.setTotalAmount(1000);transaction.setPaymentDetails(paymentDetails);
// Set these to URLs on your website
transaction.setRedirectURL("http://www.eway.com.au");
transaction.setCancelURL("http://www.eway.com.au");
transaction.setTransactionType(TransactionType.Purchase);CreateTransactionResponse response = client.create(PaymentMethod.ResponsiveShared, transaction);

To make sure everything went well, check getErrors is empty. If it isn’t, userDisplayMessage can be used to convert any error codes to human readable messages:

1
2
3
4
5
6
if (!response.getErrors().isEmpty()) {
for (String errorcode: response.getErrors()) {
System.out.println("Error Message: "
+ RapidSDK.userDisplayMessage(errorcode, "en"));
}
}
4. ​Redirect the Customer


​Once the shared page URL has been created, the customer can be redirected. How this is done will depend on the Java framework being used. For example, in a Servlet the method would be:

1
httpResponse.sendRedirect(response.getSharedPaymentUrl());

So now a Responsive Shared Page URL has been created and the customer is redirected to complete their payment.

5. ​​Fetch the Result

Once the customer has gone to the Responsive Shared Page and submitted their payment information, they will be redirected back to the RedirectUrl specified in the request. This page should use the AccessCode (passed as a query variable) to fetch the result of the transaction.

1
2
QueryTransactionResponse response =
client.queryTransaction(request.getParameter("AccessCode"));

Key information such as the success of the transaction and the transaction ID can be found in the transactionStatus of the response. If the transaction wasn’t successful, the reason can be found in the ResponsiveMessage. An example of handling this information would be:

1
2
3
4
5
6
7
8
9
10
11
if (response.getTransactionStatus().isStatus()) {
System.out.println("Payment successful! ID: " + response.getTransactionStatus().getTransactionID());
} else {
String[] errorcodes = response.getTransactionStatus().getProcessingDetails().getResponseMessage().split(", ");

for (String errorcode: errorcodes) {
System.out.println("Response Messages: "
+ RapidSDK.userDisplayMessage(errorcode, "en"));
}

}

That’s it – a complete Responsive Shared Page integration!

For more information on the functions available in the eWAY Java SDK, check out the eWAY Rapid API Reference.

Benefits for you & your clients

  • Simple coding and reduction in development time – a payment can be created with only a few lines of code..
  • Native support for Android and iOS.
  • Safe and secure: eWAY’s eCrypt methods are included so that sensitive data can be secured if merchants wish to process payments on their own server.
  • Easy testing: easily switch between production and sandbox when testing.
  • Process payments directly from any mobile device.

The rise of mobile payments

  • Get on board now and experience the mobile payments boom!
  • Business Insider reports that the total worldwide value of transactions using mobile technology is expected to grow to $173 billion in 2017 (from the current $35 million).
  • Forrester predicts that remote mobile payments will be the largest area of growth over the next five years in eCommerce.
  • According to this recent Yahoo report, 2014 saw a 174% increase in mobile usage for online shopping and leisure.
  • Want to learn more? Check out this article by DialogTech about how smartphones are transforming the eCommerce industry.

Become an eWAY merchant today.

With 24/7 support, over 250 integrations and 20+ years experience – the team at eWAY are here to provide you with the leading all-in-one payments solution.