Search in sources :

Example 1 with RedirectPaymentMethodSpecificInput

use of com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.RedirectPaymentMethodSpecificInput in project connect-sdk-java by Ingenico-ePayments.

the class IdempotenceTest method test.

/**
 * Smoke test for idempotence.
 */
@Test
public void test() throws URISyntaxException, IOException {
    CreatePaymentRequest body = new CreatePaymentRequest();
    Order order = new Order();
    AmountOfMoney amountOfMoney = new AmountOfMoney();
    amountOfMoney.setCurrencyCode("EUR");
    amountOfMoney.setAmount(100L);
    order.setAmountOfMoney(amountOfMoney);
    Customer customer = new Customer();
    customer.setLocale("en");
    Address billingAddress = new Address();
    billingAddress.setCountryCode("NL");
    customer.setBillingAddress(billingAddress);
    order.setCustomer(customer);
    body.setOrder(order);
    RedirectPaymentMethodSpecificInput paymentMethodSpecificInput = new RedirectPaymentMethodSpecificInput();
    paymentMethodSpecificInput.setReturnUrl("http://example.com/");
    paymentMethodSpecificInput.setPaymentProductId(809);
    RedirectPaymentProduct809SpecificInput paymentProductSpecificInput = new RedirectPaymentProduct809SpecificInput();
    paymentProductSpecificInput.setIssuerId("INGBNL2A");
    paymentMethodSpecificInput.setPaymentProduct809SpecificInput(paymentProductSpecificInput);
    body.setRedirectPaymentMethodSpecificInput(paymentMethodSpecificInput);
    String idempotenceKey = UUID.randomUUID().toString();
    CallContext context = new CallContext().withIdempotenceKey(idempotenceKey);
    Client client = getClient();
    try {
        CreatePaymentResponse response = client.merchant("20000").payments().create(body, context);
        String paymentId = response.getPayment().getId();
        Assert.assertEquals(idempotenceKey, context.getIdempotenceKey());
        Assert.assertNull(context.getIdempotenceRequestTimestamp());
        response = client.merchant("20000").payments().create(body, context);
        Assert.assertEquals(paymentId, response.getPayment().getId());
        Assert.assertEquals(idempotenceKey, context.getIdempotenceKey());
        Assert.assertNotNull(context.getIdempotenceRequestTimestamp());
    } finally {
        client.close();
    }
}
Also used : Order(com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Order) RedirectPaymentMethodSpecificInput(com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.RedirectPaymentMethodSpecificInput) 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) RedirectPaymentProduct809SpecificInput(com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.RedirectPaymentProduct809SpecificInput) Client(com.ingenico.connect.gateway.sdk.java.Client) CreatePaymentResponse(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse) CallContext(com.ingenico.connect.gateway.sdk.java.CallContext) AmountOfMoney(com.ingenico.connect.gateway.sdk.java.domain.definitions.AmountOfMoney) Test(org.junit.Test)

Aggregations

CallContext (com.ingenico.connect.gateway.sdk.java.CallContext)1 Client (com.ingenico.connect.gateway.sdk.java.Client)1 Address (com.ingenico.connect.gateway.sdk.java.domain.definitions.Address)1 AmountOfMoney (com.ingenico.connect.gateway.sdk.java.domain.definitions.AmountOfMoney)1 CreatePaymentRequest (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest)1 CreatePaymentResponse (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse)1 Customer (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Customer)1 Order (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Order)1 RedirectPaymentMethodSpecificInput (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.RedirectPaymentMethodSpecificInput)1 RedirectPaymentProduct809SpecificInput (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.RedirectPaymentProduct809SpecificInput)1 Test (org.junit.Test)1