use of com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest in project connect-sdk-java by Ingenico-ePayments.
the class PaymentsClientTest method testCreateReferenceError.
/**
* Tests that a 409 failure response with a duplicate request code but without an idempotence key will throw a
* {@link ReferenceException}.
*/
@Test
@SuppressWarnings("resource")
public void testCreateReferenceError() {
Client client = Factory.createClient(session);
String responseBody = getResource("duplicate_request.json");
whenPost().thenReturn(new Response(409, responseBody, null));
CreatePaymentRequest body = createRequest();
try {
client.merchant("merchantId").payments().create(body);
Assert.fail("Expected ApiException");
} catch (ReferenceException e) {
Assert.assertTrue(e.toString().contains(responseBody));
}
}
use of com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest in project connect-sdk-java by Ingenico-ePayments.
the class PaymentsClientTest method testCreateInvalidAuthorization.
/**
* Tests that a 401 failure response without a payment result will throw a {@link ApiException}.
*/
@Test
@SuppressWarnings("resource")
public void testCreateInvalidAuthorization() {
Client client = Factory.createClient(session);
String responseBody = getResource("invalid_authorization.json");
whenPost().thenReturn(new Response(401, responseBody, null));
CreatePaymentRequest body = createRequest();
try {
client.merchant("merchantId").payments().create(body);
Assert.fail("Expected ApiException");
} catch (ApiException e) {
Assert.assertTrue(e.toString().contains(responseBody));
}
}
use of com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest in project connect-sdk-java by Ingenico-ePayments.
the class PaymentsClientTest method testCreateIdempotenceError.
/**
* Tests that a 409 failure response with a duplicate request code and an idempotence key will throw an {@link IdempotenceException}.
*/
@Test
@SuppressWarnings("resource")
public void testCreateIdempotenceError() {
Client client = Factory.createClient(session);
String responseBody = getResource("duplicate_request.json");
whenPost().thenReturn(new Response(409, responseBody, null));
CreatePaymentRequest body = createRequest();
CallContext context = new CallContext().withIdempotenceKey("key");
try {
client.merchant("merchantId").payments().create(body, context);
Assert.fail("Expected ApiException");
} catch (IdempotenceException e) {
Assert.assertTrue(e.toString().contains(responseBody));
Assert.assertEquals(context.getIdempotenceKey(), e.getIdempotenceKey());
}
}
use of com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest in project connect-sdk-java by Ingenico-ePayments.
the class DefaultConnectionIdempotenceTest method createRequest.
private CreatePaymentRequest createRequest() {
CreatePaymentRequest body = new CreatePaymentRequest();
Order order = new Order();
AmountOfMoney amountOfMoney = new AmountOfMoney();
amountOfMoney.setAmount(2345L);
amountOfMoney.setCurrencyCode("CAD");
order.setAmountOfMoney(amountOfMoney);
Customer customer = new Customer();
Address billingAddress = new Address();
billingAddress.setCountryCode("CA");
customer.setBillingAddress(billingAddress);
order.setCustomer(customer);
CardPaymentMethodSpecificInput cardPaymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
cardPaymentMethodSpecificInput.setPaymentProductId(1);
Card card = new Card();
card.setCvv("123");
card.setCardNumber("4567350000427977");
card.setExpiryDate("1220");
cardPaymentMethodSpecificInput.setCard(card);
body.setCardPaymentMethodSpecificInput(cardPaymentMethodSpecificInput);
return body;
}
Aggregations