Skip to content

Purchase Example

exact edited this page May 10, 2011 · 1 revision
// create the request
final Request request = new Request(TransactionType.Purchase);
request.setExactId("your Gateway ID");
request.setPassword("your Gateway password");

request.setAmount(10.0f);
request.setCardholderName("James Brown");
request.setCardNumber("4111111111111111");
request.setCardExpiryDate("0913");  // MMYY format

// set some optional fields
request.setClientEmail("user@example.com");
request.setCustomerRef("XYZ-12345");
request.setReferenceNo("123gythh12221");
request.setLanguage(com.exact.ews.transaction.enums.Language.English);

// construct the Transporter which will encode requests in JSON
final Transporter transporter = new Transporter("https://api.e-xact.com", Encoding.JSON);

Response response = null;
try {
  response = transporter.submit(request);
} catch (Exception e) {
  e.printStackTrace();
  System.out.println("Submitting purchase failed");
}

if(response == null || !response.isApproved()) {
  System.out.println("Purchase transaction failed.");
}
else {
  System.out.println("Success: " + response.getBankMessage());
}
Something went wrong with that request. Please try again.