Search in sources :

Example 11 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 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));
    }
}
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) ResponseException(com.ingenico.connect.gateway.sdk.java.ResponseException) CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) NotFoundException(com.ingenico.connect.gateway.sdk.java.NotFoundException) Client(com.ingenico.connect.gateway.sdk.java.Client) Test(org.junit.Test)

Example 12 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 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));
    }
}
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) CommunicationException(com.ingenico.connect.gateway.sdk.java.CommunicationException) ResponseException(com.ingenico.connect.gateway.sdk.java.ResponseException) CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) Client(com.ingenico.connect.gateway.sdk.java.Client) Test(org.junit.Test)

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

Example 14 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 validateValidPreparedPaymentRequestTokenization.

/**
 * Test that the encrypted blob that will be used for the payment has been created successfully
 */
private void validateValidPreparedPaymentRequestTokenization(PreparedPaymentRequest preparedPaymentRequest) {
    assertNotNull(preparedPaymentRequest);
    assertNotNull(preparedPaymentRequest.getEncodedClientMetaInfo());
    assertNotNull(preparedPaymentRequest.getEncryptedFields());
    CreatePaymentRequest createPaymentRequest = constructCreatePaymentRequest(preparedPaymentRequest);
    CreatePaymentResponse response = createPayment(createPaymentRequest);
    assertNotNull(response);
    assertNotNull(response.getCreationOutput());
    assertNotNull(response.getCreationOutput().getToken());
    deleteToken(response.getCreationOutput().getToken());
}
Also used : CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) CreatePaymentResponse(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse)

Example 15 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 constructCreatePaymentRequest.

/**
 * Creates a minimal CreatePaymentRequest object that can still be payed with
 */
private CreatePaymentRequest constructCreatePaymentRequest(PreparedPaymentRequest preparedPaymentRequest) {
    CreatePaymentRequest createPaymentRequest = new CreatePaymentRequest();
    AmountOfMoney amountOfMoney = new AmountOfMoney();
    amountOfMoney.setAmount(minimalValidPaymentContext.getAmountOfMoney().getAmount());
    amountOfMoney.setCurrencyCode(minimalValidPaymentContext.getAmountOfMoney().getCurrencyCode().toString());
    Address billingAddress = new Address();
    billingAddress.setCountryCode(minimalValidPaymentContext.getCountryCode().toString());
    Customer customer = new Customer();
    customer.setBillingAddress(billingAddress);
    Order order = new Order();
    order.setAmountOfMoney(amountOfMoney);
    order.setCustomer(customer);
    createPaymentRequest.setOrder(order);
    // Set the encrypted blob in the request
    createPaymentRequest.setEncryptedCustomerInput(preparedPaymentRequest.getEncryptedFields());
    return createPaymentRequest;
}
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) AmountOfMoney(com.ingenico.connect.gateway.sdk.java.domain.definitions.AmountOfMoney)

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