use of com.ingenico.connect.gateway.sdk.java.Client in project connect-sdk-java by Ingenico-ePayments.
the class PaymentsClientTest method testCreateNotFound.
/**
* Tests that a 404 response with a non-JSON response will throw a {@link NotFoundException}.
*/
@Test
@SuppressWarnings("resource")
public void testCreateNotFound() {
Client client = Factory.createClient(session);
String responseBody = getResource("not_found.html");
whenPost().thenReturn(new Response(404, responseBody, Arrays.asList(new ResponseHeader("content-type", "text/html"))));
CreatePaymentRequest body = createRequest();
try {
client.merchant("merchantId").payments().create(body);
Assert.fail("Expected NotFoundException");
} catch (NotFoundException e) {
Assert.assertNotNull(e.getCause());
Assert.assertEquals(ResponseException.class, e.getCause().getClass());
Assert.assertTrue(e.getCause().toString().contains(responseBody));
}
}
use of com.ingenico.connect.gateway.sdk.java.Client in project connect-sdk-java by Ingenico-ePayments.
the class PaymentsClientTest method testCreateMethodNotAllowed.
/**
* Tests that a 405 response with a non-JSON response will throw a {@link CommunicationException}.
*/
@Test
@SuppressWarnings("resource")
public void testCreateMethodNotAllowed() {
Client client = Factory.createClient(session);
String responseBody = getResource("method_not_allowed.html");
whenPost().thenReturn(new Response(405, responseBody, Arrays.asList(new ResponseHeader("content-type", "text/html"))));
CreatePaymentRequest body = createRequest();
try {
client.merchant("merchantId").payments().create(body);
Assert.fail("Expected CommunicationException");
} catch (CommunicationException e) {
Assert.assertNotNull(e.getCause());
Assert.assertEquals(ResponseException.class, e.getCause().getClass());
Assert.assertTrue(e.getCause().toString().contains(responseBody));
}
}
use of com.ingenico.connect.gateway.sdk.java.Client in project connect-sdk-java by Ingenico-ePayments.
the class PaymentsClientTest method testCreateRejected.
/**
* Tests that a failure response with a payment result will throw a {@link DeclinedPaymentException}.
*/
@Test
@SuppressWarnings("resource")
public void testCreateRejected() {
Client client = Factory.createClient(session);
String responseBody = getResource("rejected.json");
whenPost().thenReturn(new Response(400, responseBody, null));
CreatePaymentRequest body = createRequest();
try {
client.merchant("merchantId").payments().create(body);
Assert.fail("Expected DeclinedPaymentException");
} catch (DeclinedPaymentException e) {
Assert.assertTrue(e.toString().contains("payment '000002000020142544360000100001'"));
Assert.assertTrue(e.toString().contains("status 'REJECTED'"));
Assert.assertTrue(e.toString().contains(responseBody));
Assert.assertNotNull(e.getCreatePaymentResult());
Assert.assertEquals("000002000020142544360000100001", e.getCreatePaymentResult().getPayment().getId());
Assert.assertEquals("REJECTED", e.getCreatePaymentResult().getPayment().getStatus());
}
}
use of com.ingenico.connect.gateway.sdk.java.Client in project connect-sdk-java by Ingenico-ePayments.
the class GetPaymentProductExample method example.
@SuppressWarnings("unused")
public void example() throws URISyntaxException, IOException {
Client client = getClient();
try {
GetProductParams query = new GetProductParams();
query.setCountryCode("US");
query.setCurrencyCode("USD");
query.setLocale("en_US");
query.setAmount(1000L);
query.setIsRecurring(true);
query.setForceBasicFlow(false);
query.addHide("fields");
PaymentProductResponse response = client.merchant("merchantId").products().get(1, query);
} finally {
client.close();
}
}
use of com.ingenico.connect.gateway.sdk.java.Client in project connect-sdk-java by Ingenico-ePayments.
the class GetPaymentProductsExample method example.
@SuppressWarnings("unused")
public void example() throws URISyntaxException, IOException {
Client client = getClient();
try {
FindProductsParams query = new FindProductsParams();
query.setCountryCode("US");
query.setCurrencyCode("USD");
query.setLocale("en_US");
query.setAmount(1000L);
query.setIsRecurring(true);
query.addHide("fields");
PaymentProducts response = client.merchant("merchantId").products().find(query);
} finally {
client.close();
}
}
Aggregations