Search in sources :

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

Example 22 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 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));
    }
}
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) ApiException(com.ingenico.connect.gateway.sdk.java.ApiException) Test(org.junit.Test)

Example 23 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 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());
    }
}
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) CallContext(com.ingenico.connect.gateway.sdk.java.CallContext) IdempotenceException(com.ingenico.connect.gateway.sdk.java.IdempotenceException) Test(org.junit.Test)

Example 24 with CreatePaymentRequest

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;
}
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