Search in sources :

Example 21 with Client

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

the class PaymentProductsTest method test.

/**
 * Smoke test for products service.
 */
@Test
public void test() throws URISyntaxException, IOException {
    DirectoryParams params = new DirectoryParams();
    params.setCountryCode("NL");
    params.setCurrencyCode("EUR");
    Client client = getClient();
    try {
        Directory response = client.merchant("8500").products().directory(809, params);
        Assert.assertTrue(response.getEntries().size() > 0);
    } finally {
        client.close();
    }
}
Also used : DirectoryParams(com.ingenico.connect.gateway.sdk.java.merchant.products.DirectoryParams) Client(com.ingenico.connect.gateway.sdk.java.Client) Directory(com.ingenico.connect.gateway.sdk.java.domain.product.Directory) Test(org.junit.Test)

Example 22 with Client

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

the class CreateTokenExample method example.

@SuppressWarnings("unused")
public void example() throws URISyntaxException, IOException {
    Client client = getClient();
    try {
        Address billingAddress = new Address();
        billingAddress.setAdditionalInfo("Suite II");
        billingAddress.setCity("Monument Valley");
        billingAddress.setCountryCode("US");
        billingAddress.setHouseNumber("1");
        billingAddress.setState("Utah");
        billingAddress.setStreet("Desertroad");
        billingAddress.setZip("84536");
        CompanyInformation companyInformation = new CompanyInformation();
        companyInformation.setName("Acme Labs");
        PersonalNameToken name = new PersonalNameToken();
        name.setFirstName("Wile");
        name.setSurname("Coyote");
        name.setSurnamePrefix("E.");
        PersonalInformationToken personalInformation = new PersonalInformationToken();
        personalInformation.setName(name);
        CustomerToken customer = new CustomerToken();
        customer.setBillingAddress(billingAddress);
        customer.setCompanyInformation(companyInformation);
        customer.setMerchantCustomerId("1234");
        customer.setPersonalInformation(personalInformation);
        BankAccountBban bankAccountBban = new BankAccountBban();
        bankAccountBban.setAccountNumber("000000123456");
        bankAccountBban.setBankCode("05428");
        bankAccountBban.setBranchCode("11101");
        bankAccountBban.setCheckDigit("X");
        bankAccountBban.setCountryCode("IT");
        TokenNonSepaDirectDebitPaymentProduct705SpecificData paymentProduct705SpecificData = new TokenNonSepaDirectDebitPaymentProduct705SpecificData();
        paymentProduct705SpecificData.setAuthorisationId("123456");
        paymentProduct705SpecificData.setBankAccountBban(bankAccountBban);
        MandateNonSepaDirectDebit mandate = new MandateNonSepaDirectDebit();
        mandate.setPaymentProduct705SpecificData(paymentProduct705SpecificData);
        TokenNonSepaDirectDebit nonSepaDirectDebit = new TokenNonSepaDirectDebit();
        nonSepaDirectDebit.setCustomer(customer);
        nonSepaDirectDebit.setMandate(mandate);
        CreateTokenRequest body = new CreateTokenRequest();
        body.setNonSepaDirectDebit(nonSepaDirectDebit);
        body.setPaymentProductId(705);
        CreateTokenResponse response = client.merchant("merchantId").tokens().create(body);
    } finally {
        client.close();
    }
}
Also used : CreateTokenRequest(com.ingenico.connect.gateway.sdk.java.domain.token.CreateTokenRequest) TokenNonSepaDirectDebitPaymentProduct705SpecificData(com.ingenico.connect.gateway.sdk.java.domain.token.definitions.TokenNonSepaDirectDebitPaymentProduct705SpecificData) CompanyInformation(com.ingenico.connect.gateway.sdk.java.domain.definitions.CompanyInformation) Address(com.ingenico.connect.gateway.sdk.java.domain.definitions.Address) PersonalInformationToken(com.ingenico.connect.gateway.sdk.java.domain.token.definitions.PersonalInformationToken) CustomerToken(com.ingenico.connect.gateway.sdk.java.domain.token.definitions.CustomerToken) BankAccountBban(com.ingenico.connect.gateway.sdk.java.domain.definitions.BankAccountBban) MandateNonSepaDirectDebit(com.ingenico.connect.gateway.sdk.java.domain.token.definitions.MandateNonSepaDirectDebit) TokenNonSepaDirectDebit(com.ingenico.connect.gateway.sdk.java.domain.token.definitions.TokenNonSepaDirectDebit) Client(com.ingenico.connect.gateway.sdk.java.Client) CreateTokenResponse(com.ingenico.connect.gateway.sdk.java.domain.token.CreateTokenResponse) PersonalNameToken(com.ingenico.connect.gateway.sdk.java.domain.token.definitions.PersonalNameToken)

Example 23 with Client

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

the class SystemProxyTest method test.

/**
 * Smoke test for using a proxy configured through system properties.
 */
@Test
public void test() throws URISyntaxException, IOException {
    final boolean[] authenticationCalled = { false };
    final String username = System.getProperty("http.proxyUser");
    final String password = System.getProperty("http.proxyPass");
    Authenticator.setDefault(new Authenticator() {

        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            authenticationCalled[0] = true;
            return new PasswordAuthentication(username, password.toCharArray());
        }
    });
    ConvertAmountParams request = new ConvertAmountParams();
    request.setAmount(123L);
    request.setSource("USD");
    request.setTarget("EUR");
    CommunicatorConfiguration configuration = getCommunicatorConfiguration().withProxyConfiguration(null);
    Client client = Factory.createClient(configuration);
    try {
        ConvertAmount response = client.merchant("9991").services().convertAmount(request);
        Assert.assertNotNull(response.getConvertedAmount());
    } finally {
        client.close();
    }
    // for https, authentication may not be required
    if ("http".equalsIgnoreCase(configuration.getApiEndpoint().getScheme())) {
        Assert.assertTrue("getPasswordAuthentication() should have been called", authenticationCalled[0]);
    }
}
Also used : ConvertAmountParams(com.ingenico.connect.gateway.sdk.java.merchant.services.ConvertAmountParams) ConvertAmount(com.ingenico.connect.gateway.sdk.java.domain.services.ConvertAmount) CommunicatorConfiguration(com.ingenico.connect.gateway.sdk.java.CommunicatorConfiguration) Client(com.ingenico.connect.gateway.sdk.java.Client) Authenticator(java.net.Authenticator) PasswordAuthentication(java.net.PasswordAuthentication) Test(org.junit.Test)

Example 24 with Client

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

the class DefaultConnectionLoggerTest method testLogRequestOnly.

@Test
public void testLogRequestOnly() throws Exception {
    // logging is disabled after the request is logged but before the response is logged
    serverBootstrap.registerHandler("/v1/1234/services/testconnection", requestHandler);
    HttpHost host = start();
    Client client = createClient(host);
    TestLogger logger = new TestLogger();
    client.enableLogging(logger);
    setupRequestHandler(disableLogging(setOKJsonResponse("testConnection.json"), client));
    try {
        TestConnection response = client.merchant("1234").services().testconnection();
        Assert.assertNotNull(response);
        Assert.assertEquals("OK", response.getResult());
    } finally {
        client.close();
    }
    Assert.assertEquals(1, logger.entries.size());
    TestLoggerEntry requestEntry = logger.entries.get(0);
    Assert.assertNotNull(requestEntry.message);
    Assert.assertNull(requestEntry.thrown);
    assertRequest(requestEntry.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 25 with Client

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

the class DefaultConnectionLoggerTest method testLogResponseOnly.

@Test
public void testLogResponseOnly() throws Exception {
    // logging is enabled after the request is logged but before the response is logged
    serverBootstrap.registerHandler("/v1/1234/services/testconnection", requestHandler);
    HttpHost host = start();
    Client client = createClient(host);
    TestLogger logger = new TestLogger();
    setupRequestHandler(enableLogging(setOKJsonResponse("testConnection.json"), client, logger));
    try {
        TestConnection response = client.merchant("1234").services().testconnection();
        Assert.assertNotNull(response);
        Assert.assertEquals("OK", response.getResult());
    } finally {
        client.close();
    }
    Assert.assertEquals(1, logger.entries.size());
    TestLoggerEntry responseEntry = logger.entries.get(0);
    Assert.assertNotNull(responseEntry.message);
    Assert.assertNull(responseEntry.thrown);
    assertResponse(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)

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