use of com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest in project connect-sdk-client-android by Ingenico-ePayments.
the class GcSessionPreparePaymentRequestTest method validateValidPreparedPaymentRequest.
/**
* Test that the encrypted blob that will be used for the payment has been created successfully
*/
private void validateValidPreparedPaymentRequest(PreparedPaymentRequest preparedPaymentRequest) {
assertNotNull(preparedPaymentRequest);
assertNotNull(preparedPaymentRequest.getEncodedClientMetaInfo());
assertNotNull(preparedPaymentRequest.getEncryptedFields());
CreatePaymentRequest createPaymentRequest = constructCreatePaymentRequest(preparedPaymentRequest);
createPayment(createPaymentRequest);
}
use of com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest in project connect-sdk-java by Ingenico-ePayments.
the class DefaultConnectionLoggerTest method testCreatePaymentRejected.
@Test
public void testCreatePaymentRejected() throws Exception {
// an exception is thrown after logging the response
serverBootstrap.registerHandler("/v1/1234/payments", requestHandler);
HttpHost host = start();
Client client = createClient(host);
TestLogger logger = new TestLogger();
client.enableLogging(logger);
setupRequestHandler(setJsonResponse("createPayment.failure.rejected.json", 402));
try {
AmountOfMoney amountOfMoney = new AmountOfMoney();
amountOfMoney.setCurrencyCode("CAD");
amountOfMoney.setAmount(2345L);
Address billingAddress = new Address();
billingAddress.setCountryCode("CA");
Customer customer = new Customer();
customer.setBillingAddress(billingAddress);
Order order = new Order();
order.setAmountOfMoney(amountOfMoney);
order.setCustomer(customer);
Card card = new Card();
card.setCvv("123");
card.setCardNumber("1234567890123452");
card.setExpiryDate("1220");
CardPaymentMethodSpecificInput paymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
paymentMethodSpecificInput.setPaymentProductId(1);
paymentMethodSpecificInput.setCard(card);
CreatePaymentRequest request = new CreatePaymentRequest();
request.setOrder(order);
request.setCardPaymentMethodSpecificInput(paymentMethodSpecificInput);
client.merchant("1234").payments().create(request);
Assert.fail("expected DeclinedPaymentException");
} catch (DeclinedPaymentException e) {
// expected
Assert.assertNotNull(e.getCreatePaymentResult());
Assert.assertNotNull(e.getCreatePaymentResult().getPayment());
Assert.assertNotNull(e.getCreatePaymentResult().getPayment().getId());
} finally {
client.close();
}
Assert.assertEquals(2, logger.entries.size());
TestLoggerEntry requestEntry = logger.entries.get(0);
Assert.assertNotNull(requestEntry.message);
Assert.assertNull(requestEntry.thrown);
TestLoggerEntry responseEntry = logger.entries.get(1);
Assert.assertNotNull(responseEntry.message);
Assert.assertNull(responseEntry.thrown);
assertRequestAndResponse(requestEntry.message, responseEntry.message, "createPayment.failure.rejected");
}
use of com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest in project connect-sdk-java by Ingenico-ePayments.
the class PaymentsClientTest method testCreateSuccess.
/**
* Tests that a non-failure response will not throw an exception.
*/
@Test
@SuppressWarnings("resource")
public void testCreateSuccess() {
Client client = Factory.createClient(session);
String responseBody = getResource("pending_approval.json");
whenPost().thenReturn(new Response(201, responseBody, null));
CreatePaymentRequest body = createRequest();
CreatePaymentResponse response = client.merchant("merchantId").payments().create(body);
Assert.assertEquals("000002000020142549460000100001", response.getPayment().getId());
Assert.assertEquals("PENDING_APPROVAL", response.getPayment().getStatus());
}
use of com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest in project connect-sdk-java by Ingenico-ePayments.
the class PaymentsClientTest method testCreateInternalServerErrorWithoutBody.
/**
* Tests that a 500 response with a JSON response with no body will throw a {@link GlobalCollectException} and not a {@link NullPointerException}.
*/
@Test
@SuppressWarnings("resource")
public void testCreateInternalServerErrorWithoutBody() {
Client client = Factory.createClient(session);
String responseBody = null;
whenPost().thenReturn(new Response(500, responseBody, Arrays.asList(new ResponseHeader("content-type", "text/html"))));
CreatePaymentRequest body = createRequest();
try {
client.merchant("merchantId").payments().create(body);
Assert.fail("Expected GlobalCollectException");
} catch (GlobalCollectException e) {
Assert.assertEquals(responseBody, e.getResponseBody());
Assert.assertNull(e.getErrorId());
Assert.assertEquals(0, e.getErrors().size());
}
}
use of com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest in project connect-sdk-java by Ingenico-ePayments.
the class PaymentsClientTest 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