Search in sources :

Example 6 with RequestHeader

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

the class MultiLineHeaderTest method test.

/**
 * Smoke test for products service.
 */
@Test
public void test() throws URISyntaxException, IOException {
    CommunicatorConfiguration configuration = getCommunicatorConfiguration();
    String multiLineHeader = " some value  \r\n \n with  some \r\n  spaces ";
    MetaDataProvider metaDataProvider = new MetaDataProviderBuilder("Ingenico").withAdditionalRequestHeader(new RequestHeader("X-GCS-MultiLineHeader", multiLineHeader)).build();
    DirectoryParams params = new DirectoryParams();
    params.setCountryCode("NL");
    params.setCurrencyCode("EUR");
    Session session = Factory.createSessionBuilder(configuration).withMetaDataProvider(metaDataProvider).build();
    Client client = Factory.createClient(session);
    try {
        Directory response = client.merchant("8500").products().directory(809, params);
        Assert.assertTrue(response.getEntries().size() > 0);
    } finally {
        client.close();
    }
}
Also used : MetaDataProvider(com.ingenico.connect.gateway.sdk.java.MetaDataProvider) MetaDataProviderBuilder(com.ingenico.connect.gateway.sdk.java.MetaDataProviderBuilder) DirectoryParams(com.ingenico.connect.gateway.sdk.java.merchant.products.DirectoryParams) RequestHeader(com.ingenico.connect.gateway.sdk.java.RequestHeader) CommunicatorConfiguration(com.ingenico.connect.gateway.sdk.java.CommunicatorConfiguration) Client(com.ingenico.connect.gateway.sdk.java.Client) Session(com.ingenico.connect.gateway.sdk.java.Session) Directory(com.ingenico.connect.gateway.sdk.java.domain.product.Directory) Test(org.junit.Test)

Example 7 with RequestHeader

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

the class WebhooksHelperTest method testUnmarshalStringInvalidSignature.

@Test(expected = SignatureValidationException.class)
public void testUnmarshalStringInvalidSignature() throws IOException {
    WebhooksHelper helper = createHelper();
    InMemorySecretKeyStore.INSTANCE.storeSecretKey(KEY_ID, SECRET_KEY);
    String body = new String(readResource("valid-body"), CHARSET);
    List<RequestHeader> requestHeaders = Arrays.asList(new RequestHeader(SIGNATURE_HEADER, "1" + SIGNATURE), new RequestHeader(KEY_ID_HEADER, KEY_ID));
    helper.unmarshal(body, requestHeaders);
}
Also used : RequestHeader(com.ingenico.connect.gateway.sdk.java.RequestHeader) Test(org.junit.Test)

Example 8 with RequestHeader

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

the class WebhooksHelperTest method testUnmarshalBytesInvalidSignature.

@Test(expected = SignatureValidationException.class)
public void testUnmarshalBytesInvalidSignature() throws IOException {
    WebhooksHelper helper = createHelper();
    InMemorySecretKeyStore.INSTANCE.storeSecretKey(KEY_ID, SECRET_KEY);
    ByteArrayInputStream bodyStream = new ByteArrayInputStream(readResource("valid-body"));
    List<RequestHeader> requestHeaders = Arrays.asList(new RequestHeader(SIGNATURE_HEADER, "1" + SIGNATURE), new RequestHeader(KEY_ID_HEADER, KEY_ID));
    helper.unmarshal(bodyStream, requestHeaders);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RequestHeader(com.ingenico.connect.gateway.sdk.java.RequestHeader) Test(org.junit.Test)

Example 9 with RequestHeader

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

the class WebhooksHelperTest method testUnmarshalStringSuccess.

@Test
public void testUnmarshalStringSuccess() throws IOException {
    WebhooksHelper helper = createHelper();
    InMemorySecretKeyStore.INSTANCE.storeSecretKey(KEY_ID, SECRET_KEY);
    String body = new String(readResource("valid-body"), CHARSET);
    List<RequestHeader> requestHeaders = Arrays.asList(new RequestHeader(SIGNATURE_HEADER, SIGNATURE), new RequestHeader(KEY_ID_HEADER, KEY_ID));
    WebhooksEvent event = helper.unmarshal(body, requestHeaders);
    Assert.assertEquals("v1", event.getApiVersion());
    Assert.assertEquals("8ee793f6-4553-4749-85dc-f2ef095c5ab0", event.getId());
    Assert.assertEquals("2017-02-02T11:24:14.040+0100", event.getCreated());
    Assert.assertEquals("20000", event.getMerchantId());
    Assert.assertEquals("payment.paid", event.getType());
    Assert.assertNull(event.getRefund());
    Assert.assertNull(event.getPayout());
    Assert.assertNull(event.getToken());
    Assert.assertNotNull(event.getPayment());
    Assert.assertEquals("00000200000143570012", event.getPayment().getId());
    Assert.assertNotNull(event.getPayment().getPaymentOutput());
    Assert.assertNotNull(event.getPayment().getPaymentOutput().getAmountOfMoney());
    Assert.assertEquals((Long) 1000L, event.getPayment().getPaymentOutput().getAmountOfMoney().getAmount());
    Assert.assertEquals("EUR", event.getPayment().getPaymentOutput().getAmountOfMoney().getCurrencyCode());
    Assert.assertNotNull(event.getPayment().getPaymentOutput().getReferences());
    Assert.assertEquals("200001681810", event.getPayment().getPaymentOutput().getReferences().getPaymentReference());
    Assert.assertEquals("bankTransfer", event.getPayment().getPaymentOutput().getPaymentMethod());
    Assert.assertNull(event.getPayment().getPaymentOutput().getCardPaymentMethodSpecificOutput());
    Assert.assertNull(event.getPayment().getPaymentOutput().getCashPaymentMethodSpecificOutput());
    Assert.assertNull(event.getPayment().getPaymentOutput().getDirectDebitPaymentMethodSpecificOutput());
    Assert.assertNull(event.getPayment().getPaymentOutput().getInvoicePaymentMethodSpecificOutput());
    Assert.assertNull(event.getPayment().getPaymentOutput().getRedirectPaymentMethodSpecificOutput());
    Assert.assertNull(event.getPayment().getPaymentOutput().getSepaDirectDebitPaymentMethodSpecificOutput());
    Assert.assertNotNull(event.getPayment().getPaymentOutput().getBankTransferPaymentMethodSpecificOutput());
    Assert.assertEquals((Integer) 11, event.getPayment().getPaymentOutput().getBankTransferPaymentMethodSpecificOutput().getPaymentProductId());
    Assert.assertEquals("PAID", event.getPayment().getStatus());
    Assert.assertNotNull(event.getPayment().getStatusOutput());
    Assert.assertEquals(false, event.getPayment().getStatusOutput().getIsCancellable());
    Assert.assertEquals("COMPLETED", event.getPayment().getStatusOutput().getStatusCategory());
    Assert.assertEquals((Integer) 1000, event.getPayment().getStatusOutput().getStatusCode());
    Assert.assertEquals("20170202112414", event.getPayment().getStatusOutput().getStatusCodeChangeDateTime());
    Assert.assertEquals(true, event.getPayment().getStatusOutput().getIsAuthorized());
}
Also used : WebhooksEvent(com.ingenico.connect.gateway.sdk.java.domain.webhooks.WebhooksEvent) RequestHeader(com.ingenico.connect.gateway.sdk.java.RequestHeader) Test(org.junit.Test)

Example 10 with RequestHeader

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

the class WebhooksHelperTest method testUnmarshalBytesSuccess.

@Test
public void testUnmarshalBytesSuccess() throws IOException {
    WebhooksHelper helper = createHelper();
    InMemorySecretKeyStore.INSTANCE.storeSecretKey(KEY_ID, SECRET_KEY);
    ByteArrayInputStream bodyStream = new ByteArrayInputStream(readResource("valid-body"));
    List<RequestHeader> requestHeaders = Arrays.asList(new RequestHeader(SIGNATURE_HEADER, SIGNATURE), new RequestHeader(KEY_ID_HEADER, KEY_ID));
    WebhooksEvent event = helper.unmarshal(bodyStream, requestHeaders);
    Assert.assertEquals("v1", event.getApiVersion());
    Assert.assertEquals("8ee793f6-4553-4749-85dc-f2ef095c5ab0", event.getId());
    Assert.assertEquals("2017-02-02T11:24:14.040+0100", event.getCreated());
    Assert.assertEquals("20000", event.getMerchantId());
    Assert.assertEquals("payment.paid", event.getType());
    Assert.assertNull(event.getRefund());
    Assert.assertNull(event.getPayout());
    Assert.assertNull(event.getToken());
    Assert.assertNotNull(event.getPayment());
    Assert.assertEquals("00000200000143570012", event.getPayment().getId());
    Assert.assertNotNull(event.getPayment().getPaymentOutput());
    Assert.assertNotNull(event.getPayment().getPaymentOutput().getAmountOfMoney());
    Assert.assertEquals((Long) 1000L, event.getPayment().getPaymentOutput().getAmountOfMoney().getAmount());
    Assert.assertEquals("EUR", event.getPayment().getPaymentOutput().getAmountOfMoney().getCurrencyCode());
    Assert.assertNotNull(event.getPayment().getPaymentOutput().getReferences());
    Assert.assertEquals("200001681810", event.getPayment().getPaymentOutput().getReferences().getPaymentReference());
    Assert.assertEquals("bankTransfer", event.getPayment().getPaymentOutput().getPaymentMethod());
    Assert.assertNull(event.getPayment().getPaymentOutput().getCardPaymentMethodSpecificOutput());
    Assert.assertNull(event.getPayment().getPaymentOutput().getCashPaymentMethodSpecificOutput());
    Assert.assertNull(event.getPayment().getPaymentOutput().getDirectDebitPaymentMethodSpecificOutput());
    Assert.assertNull(event.getPayment().getPaymentOutput().getInvoicePaymentMethodSpecificOutput());
    Assert.assertNull(event.getPayment().getPaymentOutput().getRedirectPaymentMethodSpecificOutput());
    Assert.assertNull(event.getPayment().getPaymentOutput().getSepaDirectDebitPaymentMethodSpecificOutput());
    Assert.assertNotNull(event.getPayment().getPaymentOutput().getBankTransferPaymentMethodSpecificOutput());
    Assert.assertEquals((Integer) 11, event.getPayment().getPaymentOutput().getBankTransferPaymentMethodSpecificOutput().getPaymentProductId());
    Assert.assertEquals("PAID", event.getPayment().getStatus());
    Assert.assertNotNull(event.getPayment().getStatusOutput());
    Assert.assertEquals(false, event.getPayment().getStatusOutput().getIsCancellable());
    Assert.assertEquals("COMPLETED", event.getPayment().getStatusOutput().getStatusCategory());
    Assert.assertEquals((Integer) 1000, event.getPayment().getStatusOutput().getStatusCode());
    Assert.assertEquals("20170202112414", event.getPayment().getStatusOutput().getStatusCodeChangeDateTime());
    Assert.assertEquals(true, event.getPayment().getStatusOutput().getIsAuthorized());
}
Also used : WebhooksEvent(com.ingenico.connect.gateway.sdk.java.domain.webhooks.WebhooksEvent) ByteArrayInputStream(java.io.ByteArrayInputStream) RequestHeader(com.ingenico.connect.gateway.sdk.java.RequestHeader) Test(org.junit.Test)

Aggregations

RequestHeader (com.ingenico.connect.gateway.sdk.java.RequestHeader)14 Test (org.junit.Test)13 ByteArrayInputStream (java.io.ByteArrayInputStream)4 WebhooksEvent (com.ingenico.connect.gateway.sdk.java.domain.webhooks.WebhooksEvent)3 ArrayList (java.util.ArrayList)2 Client (com.ingenico.connect.gateway.sdk.java.Client)1 CommunicatorConfiguration (com.ingenico.connect.gateway.sdk.java.CommunicatorConfiguration)1 Marshaller (com.ingenico.connect.gateway.sdk.java.Marshaller)1 MetaDataProvider (com.ingenico.connect.gateway.sdk.java.MetaDataProvider)1 MetaDataProviderBuilder (com.ingenico.connect.gateway.sdk.java.MetaDataProviderBuilder)1 Session (com.ingenico.connect.gateway.sdk.java.Session)1 DefaultMarshaller (com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultMarshaller)1 Directory (com.ingenico.connect.gateway.sdk.java.domain.product.Directory)1 DirectoryParams (com.ingenico.connect.gateway.sdk.java.merchant.products.DirectoryParams)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1