Search in sources :

Example 56 with Client

use of com.ingenico.connect.gateway.sdk.java.Client in project connect-sdk-java by Ingenico-ePayments.

the class ApproveRefundExample method example.

public void example() throws URISyntaxException, IOException {
    Client client = getClient();
    try {
        ApproveRefundRequest body = new ApproveRefundRequest();
        body.setAmount(199L);
        client.merchant("merchantId").refunds().approve("refundId", body);
    } finally {
        client.close();
    }
}
Also used : ApproveRefundRequest(com.ingenico.connect.gateway.sdk.java.domain.refund.ApproveRefundRequest) Client(com.ingenico.connect.gateway.sdk.java.Client)

Example 57 with Client

use of com.ingenico.connect.gateway.sdk.java.Client in project connect-sdk-java by Ingenico-ePayments.

the class CreateHostedCheckoutExample method example.

@SuppressWarnings("unused")
public void example() throws URISyntaxException, IOException {
    Client client = getClient();
    try {
        HostedCheckoutSpecificInput hostedCheckoutSpecificInput = new HostedCheckoutSpecificInput();
        hostedCheckoutSpecificInput.setLocale("en_GB");
        hostedCheckoutSpecificInput.setVariant("testVariant");
        AmountOfMoney amountOfMoney = new AmountOfMoney();
        amountOfMoney.setAmount(2345L);
        amountOfMoney.setCurrencyCode("USD");
        Address billingAddress = new Address();
        billingAddress.setCountryCode("US");
        Customer customer = new Customer();
        customer.setBillingAddress(billingAddress);
        Order order = new Order();
        order.setAmountOfMoney(amountOfMoney);
        order.setCustomer(customer);
        CreateHostedCheckoutRequest body = new CreateHostedCheckoutRequest();
        body.setHostedCheckoutSpecificInput(hostedCheckoutSpecificInput);
        body.setOrder(order);
        CreateHostedCheckoutResponse response = client.merchant("merchantId").hostedcheckouts().create(body);
    } finally {
        client.close();
    }
}
Also used : Order(com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Order) CreateHostedCheckoutRequest(com.ingenico.connect.gateway.sdk.java.domain.hostedcheckout.CreateHostedCheckoutRequest) CreateHostedCheckoutResponse(com.ingenico.connect.gateway.sdk.java.domain.hostedcheckout.CreateHostedCheckoutResponse) Address(com.ingenico.connect.gateway.sdk.java.domain.definitions.Address) Customer(com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Customer) HostedCheckoutSpecificInput(com.ingenico.connect.gateway.sdk.java.domain.hostedcheckout.definitions.HostedCheckoutSpecificInput) Client(com.ingenico.connect.gateway.sdk.java.Client) AmountOfMoney(com.ingenico.connect.gateway.sdk.java.domain.definitions.AmountOfMoney)

Example 58 with Client

use of com.ingenico.connect.gateway.sdk.java.Client in project connect-sdk-java by Ingenico-ePayments.

the class DefaultConnectionLoggerTest method testLogErrorOnly.

@Test
public void testLogErrorOnly() throws Exception {
    // logging is enabled after the request is logged but before the error is logged
    serverBootstrap.registerHandler("/v1/1234/services/testconnection", requestHandler);
    HttpHost host = start();
    Client client = createClient(host, 1000, 10);
    TestLogger logger = new TestLogger();
    setupRequestHandler(enableLogging(delayedAnswer(setHtmlResponse("notFound.html", 404), 100), client, logger));
    try {
        client.merchant("1234").services().testconnection();
        Assert.fail("expected CommunicationException");
    } catch (CommunicationException e) {
    // expected
    } finally {
        client.close();
    }
    Assert.assertEquals(1, logger.entries.size());
    TestLoggerEntry errorEntry = logger.entries.get(0);
    Assert.assertNotNull(errorEntry.message);
    Assert.assertNotNull(errorEntry.thrown);
    assertError(errorEntry.message);
    Assert.assertEquals(SocketTimeoutException.class, errorEntry.thrown.getClass());
}
Also used : CommunicationException(com.ingenico.connect.gateway.sdk.java.CommunicationException) HttpHost(org.apache.http.HttpHost) Client(com.ingenico.connect.gateway.sdk.java.Client) Test(org.junit.Test)

Example 59 with Client

use of com.ingenico.connect.gateway.sdk.java.Client in project connect-sdk-java by Ingenico-ePayments.

the class DefaultConnectionLoggerTest method testLoggingTestConnection.

@Test
public void testLoggingTestConnection() throws Exception {
    // GET with no query params
    serverBootstrap.registerHandler("/v1/1234/services/testconnection", requestHandler);
    HttpHost host = start();
    Client client = createClient(host);
    TestLogger logger = new TestLogger();
    client.enableLogging(logger);
    setupRequestHandler(setOKJsonResponse("testConnection.json"));
    try {
        TestConnection response = client.merchant("1234").services().testconnection();
        Assert.assertNotNull(response);
        Assert.assertEquals("OK", response.getResult());
    } 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, "testConnection");
}
Also used : HttpHost(org.apache.http.HttpHost) Client(com.ingenico.connect.gateway.sdk.java.Client) TestConnection(com.ingenico.connect.gateway.sdk.java.domain.services.TestConnection) Test(org.junit.Test)

Example 60 with Client

use of com.ingenico.connect.gateway.sdk.java.Client 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)

Aggregations

Client (com.ingenico.connect.gateway.sdk.java.Client)70 Test (org.junit.Test)35 CreatePaymentRequest (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest)19 HttpHost (org.apache.http.HttpHost)17 CreatePaymentResponse (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentResponse)14 Address (com.ingenico.connect.gateway.sdk.java.domain.definitions.Address)12 AmountOfMoney (com.ingenico.connect.gateway.sdk.java.domain.definitions.AmountOfMoney)11 Response (com.ingenico.connect.gateway.sdk.java.Response)9 CallContext (com.ingenico.connect.gateway.sdk.java.CallContext)7 Customer (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Customer)6 Order (com.ingenico.connect.gateway.sdk.java.domain.payment.definitions.Order)6 DeclinedPaymentException (com.ingenico.connect.gateway.sdk.java.DeclinedPaymentException)5 ConvertAmount (com.ingenico.connect.gateway.sdk.java.domain.services.ConvertAmount)5 HashMap (java.util.HashMap)5 ApiException (com.ingenico.connect.gateway.sdk.java.ApiException)4 Card (com.ingenico.connect.gateway.sdk.java.domain.definitions.Card)4 CompanyInformation (com.ingenico.connect.gateway.sdk.java.domain.definitions.CompanyInformation)4 TestConnection (com.ingenico.connect.gateway.sdk.java.domain.services.TestConnection)4 ConvertAmountParams (com.ingenico.connect.gateway.sdk.java.merchant.services.ConvertAmountParams)4 ArrayList (java.util.ArrayList)4