Search in sources :

Example 16 with CreatePaymentRequest

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);
}
Also used : CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest)

Example 17 with 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");
}
Also used : Order(com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Order) DeclinedPaymentException(com.ingenico.connect.gateway.sdk.java.DeclinedPaymentException) Address(com.ingenico.connect.gateway.sdk.java.domain.definitions.Address) Customer(com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Customer) HttpHost(org.apache.http.HttpHost) CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) Client(com.ingenico.connect.gateway.sdk.java.Client) CardPaymentMethodSpecificInput(com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.CardPaymentMethodSpecificInput) AmountOfMoney(com.ingenico.connect.gateway.sdk.java.domain.definitions.AmountOfMoney) Card(com.ingenico.connect.gateway.sdk.java.domain.definitions.Card) Test(org.junit.Test)

Example 18 with CreatePaymentRequest

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());
}
Also used : Response(com.ingenico.connect.gateway.sdk.java.Response) CreatePaymentResponse(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse) CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) Client(com.ingenico.connect.gateway.sdk.java.Client) CreatePaymentResponse(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse) Test(org.junit.Test)

Example 19 with CreatePaymentRequest

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());
    }
}
Also used : Response(com.ingenico.connect.gateway.sdk.java.Response) CreatePaymentResponse(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse) ResponseHeader(com.ingenico.connect.gateway.sdk.java.ResponseHeader) GlobalCollectException(com.ingenico.connect.gateway.sdk.java.GlobalCollectException) CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) Client(com.ingenico.connect.gateway.sdk.java.Client) Test(org.junit.Test)

Example 20 with CreatePaymentRequest

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;
}
Also used : Order(com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Order) Address(com.ingenico.connect.gateway.sdk.java.domain.definitions.Address) Customer(com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Customer) CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) CardPaymentMethodSpecificInput(com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.CardPaymentMethodSpecificInput) AmountOfMoney(com.ingenico.connect.gateway.sdk.java.domain.definitions.AmountOfMoney) Card(com.ingenico.connect.gateway.sdk.java.domain.definitions.Card)

Aggregations

CreatePaymentRequest (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest)24 Client (com.ingenico.connect.gateway.sdk.java.Client)19 Test (org.junit.Test)18 CreatePaymentResponse (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse)15 Response (com.ingenico.connect.gateway.sdk.java.Response)9 Address (com.ingenico.connect.gateway.sdk.java.domain.definitions.Address)8 AmountOfMoney (com.ingenico.connect.gateway.sdk.java.domain.definitions.AmountOfMoney)8 Customer (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Customer)8 Order (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Order)8 HttpHost (org.apache.http.HttpHost)8 CallContext (com.ingenico.connect.gateway.sdk.java.CallContext)7 Card (com.ingenico.connect.gateway.sdk.java.domain.definitions.Card)6 CardPaymentMethodSpecificInput (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.CardPaymentMethodSpecificInput)6 DeclinedPaymentException (com.ingenico.connect.gateway.sdk.java.DeclinedPaymentException)5 HashMap (java.util.HashMap)5 ResponseHeader (com.ingenico.connect.gateway.sdk.java.ResponseHeader)3 ApiException (com.ingenico.connect.gateway.sdk.java.ApiException)2 IdempotenceException (com.ingenico.connect.gateway.sdk.java.IdempotenceException)2 ResponseException (com.ingenico.connect.gateway.sdk.java.ResponseException)2 ValidationException (com.ingenico.connect.gateway.sdk.java.ValidationException)2