From 740d1f32487f3603c5746a0d0a06f7c85c7dc0bb Mon Sep 17 00:00:00 2001 From: Ingenico ePayments Date: Fri, 1 Apr 2016 11:51:08 +0200 Subject: [PATCH] Release 2.0.0 --- pom.xml | 16 +- .../gateway/sdk/it/ConnectionPoolingTest.java | 4 +- .../gateway/sdk/it/ConvertAmountTest.java | 14 +- .../gateway/sdk/it/IdempotenceTest.java | 80 ++++ .../gateway/sdk/it/PaymentProductsTest.java | 15 +- .../gateway/sdk/it/RiskAssessmentsTest.java | 14 +- .../gateway/sdk/it/SDKProxyTest.java | 24 +- .../gateway/sdk/it/SystemProxyTest.java | 18 +- .../gateway/sdk/it/TokenTest.java | 19 +- .../gateway/sdk/java/gc/GcClient.java | 3 +- .../gateway/sdk/java/gc/GcClientImpl.java | 24 +- .../java/gc/errors/definitions/APIError.java | 10 + .../CreateHostedCheckoutRequest.java | 11 - .../sdk/java/gc/merchant/MerchantClient.java | 19 +- .../java/gc/merchant/MerchantClientImpl.java | 59 +-- .../HostedcheckoutsClient.java | 43 ++- .../HostedcheckoutsClientImpl.java | 82 ++-- .../gc/merchant/payments/PaymentsClient.java | 174 ++++++++- .../merchant/payments/PaymentsClientImpl.java | 345 ++++++----------- .../gc/merchant/payouts/PayoutsClient.java | 108 +++++- .../merchant/payouts/PayoutsClientImpl.java | 209 ++++------ .../gc/merchant/products/ProductsClient.java | 46 ++- .../merchant/products/ProductsClientImpl.java | 95 ++--- .../paymentproduct/PaymentProductClient.java | 22 +- .../PaymentProductClientImpl.java | 46 +-- .../gc/merchant/refunds/RefundsClient.java | 86 ++++- .../merchant/refunds/RefundsClientImpl.java | 165 +++----- .../RiskassessmentsClient.java | 43 ++- .../RiskassessmentsClientImpl.java | 76 ++-- .../gc/merchant/services/ServicesClient.java | 84 +++- .../merchant/services/ServicesClientImpl.java | 143 +++---- .../gc/merchant/sessions/SessionsClient.java | 22 +- .../merchant/sessions/SessionsClientImpl.java | 44 +-- .../java/gc/merchant/tokens/TokensClient.java | 109 +++++- .../gc/merchant/tokens/TokensClientImpl.java | 205 ++++------ .../java/gc/payment/CreatePaymentRequest.java | 11 - .../CheckPaymentMethodSpecificInput.java | 6 - .../CheckPaymentMethodSpecificOutput.java | 6 - .../gc/payment/definitions/PaymentOutput.java | 11 - .../gateway/sdk/java/CallContext.java | 46 +++ .../gateway/sdk/java/GcApiException.java | 8 +- .../gateway/sdk/java/GcApiResource.java | 39 +- .../gateway/sdk/java/GcAuthenticator.java | 6 +- .../gateway/sdk/java/GcCommunicator.java | 73 ++-- .../gateway/sdk/java/GcConnection.java | 42 +- .../sdk/java/GcDeclinedPaymentException.java | 2 +- .../sdk/java/GcDeclinedPayoutException.java | 2 +- .../sdk/java/GcDeclinedRefundException.java | 2 +- .../sdk/java/GcDefaultConfiguration.java | 68 +++- .../gateway/sdk/java/GcFactory.java | 9 +- .../sdk/java/GcIdempotenceException.java | 44 +++ .../gateway/sdk/java/GcMarshaller.java | 23 +- .../sdk/java/GcProxyConfiguration.java | 25 +- .../gateway/sdk/java/GcResponse.java | 74 ++++ .../gateway/sdk/java/GcResponseException.java | 56 ++- .../gateway/sdk/java/GcSession.java | 9 +- .../gateway/sdk/java/GcSessionBuilder.java | 3 +- .../gateway/sdk/java/RequestHeader.java | 8 +- .../gateway/sdk/java/RequestParam.java | 6 +- .../gateway/sdk/java/ResponseHeader.java | 34 ++ .../gateway/sdk/java/TypeWrapper.java | 19 - .../defaultimpl/DefaultGcAuthenticator.java | 2 - .../defaultimpl/DefaultGcCommunicator.java | 98 ++++- .../java/defaultimpl/DefaultGcConnection.java | 61 +-- .../java/defaultimpl/DefaultGcMarshaller.java | 14 +- .../DefaultGcMetaDataProvider.java | 27 +- .../DefaultGcConnectionIdempotenceTest.java | 364 ++++++++++++++++++ .../merchant/payments/PaymentsClientTest.java | 246 ++++++------ .../idempotence_duplicate_failure.json | 8 + .../defaultimpl/idempotence_rejected.json | 46 +++ .../java/defaultimpl/idempotence_success.json | 39 ++ .../merchant/payments/duplicate_request.json | 8 + .../merchant/payments/method_not_allowed.html | 1 + .../java/gc/merchant/payments/not_found.html | 1 + 74 files changed, 2572 insertions(+), 1452 deletions(-) create mode 100644 src/it/java/com/globalcollect/gateway/sdk/it/IdempotenceTest.java delete mode 100644 src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/definitions/CheckPaymentMethodSpecificInput.java delete mode 100644 src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/definitions/CheckPaymentMethodSpecificOutput.java create mode 100644 src/main/java/com/globalcollect/gateway/sdk/java/CallContext.java create mode 100644 src/main/java/com/globalcollect/gateway/sdk/java/GcIdempotenceException.java create mode 100644 src/main/java/com/globalcollect/gateway/sdk/java/GcResponse.java create mode 100644 src/main/java/com/globalcollect/gateway/sdk/java/ResponseHeader.java delete mode 100644 src/main/java/com/globalcollect/gateway/sdk/java/TypeWrapper.java create mode 100644 src/test/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcConnectionIdempotenceTest.java create mode 100644 src/test/resources/com/globalcollect/gateway/sdk/java/defaultimpl/idempotence_duplicate_failure.json create mode 100644 src/test/resources/com/globalcollect/gateway/sdk/java/defaultimpl/idempotence_rejected.json create mode 100644 src/test/resources/com/globalcollect/gateway/sdk/java/defaultimpl/idempotence_success.json create mode 100644 src/test/resources/com/globalcollect/gateway/sdk/java/gc/merchant/payments/duplicate_request.json create mode 100644 src/test/resources/com/globalcollect/gateway/sdk/java/gc/merchant/payments/method_not_allowed.html create mode 100644 src/test/resources/com/globalcollect/gateway/sdk/java/gc/merchant/payments/not_found.html diff --git a/pom.xml b/pom.xml index be05632c0..65f9926f2 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.ingenico.connect.gateway connect-sdk-java - 1.0.0 + 2.0.0 jar connect-sdk-java @@ -13,7 +13,7 @@ https://github.com/Ingenico-ePayments/connect-sdk-java - Ingenico ePayments + Ingenico ePayments http://www.globalcollect.com/ @@ -49,6 +49,8 @@ 1.6 1.6 + + 4.5.2 @@ -250,7 +252,15 @@ org.apache.httpcomponents httpclient - 4.5.1 + ${version.httpclient} + + + + org.apache.httpcomponents + httpclient + tests + ${version.httpclient} + test diff --git a/src/it/java/com/globalcollect/gateway/sdk/it/ConnectionPoolingTest.java b/src/it/java/com/globalcollect/gateway/sdk/it/ConnectionPoolingTest.java index 9350e9277..74b564e84 100644 --- a/src/it/java/com/globalcollect/gateway/sdk/it/ConnectionPoolingTest.java +++ b/src/it/java/com/globalcollect/gateway/sdk/it/ConnectionPoolingTest.java @@ -37,8 +37,8 @@ private void testConnectionPooling(int requestCount, int maxConnections) throws ExecutorService executorService = Executors.newFixedThreadPool(requestCount); try { - GcDefaultConfiguration defaultConfiguration = getDefaultConfiguration(); - defaultConfiguration.setMaxConnections(maxConnections); + GcDefaultConfiguration defaultConfiguration = getDefaultConfiguration() + .withMaxConnections(maxConnections); GcCommunicator communicator = GcFactory.createCommunicator(defaultConfiguration); try { diff --git a/src/it/java/com/globalcollect/gateway/sdk/it/ConvertAmountTest.java b/src/it/java/com/globalcollect/gateway/sdk/it/ConvertAmountTest.java index 31f0a1081..e40fe198c 100644 --- a/src/it/java/com/globalcollect/gateway/sdk/it/ConvertAmountTest.java +++ b/src/it/java/com/globalcollect/gateway/sdk/it/ConvertAmountTest.java @@ -1,10 +1,12 @@ package com.globalcollect.gateway.sdk.it; +import java.io.IOException; import java.net.URISyntaxException; import org.junit.Assert; import org.junit.Test; +import com.globalcollect.gateway.sdk.java.gc.GcClient; import com.globalcollect.gateway.sdk.java.gc.merchant.services.ConvertAmountParams; import com.globalcollect.gateway.sdk.java.gc.services.ConvertAmount; @@ -14,15 +16,21 @@ public class ConvertAmountTest extends ItTest { * Smoke test for convert amount service. */ @Test - public void test() throws URISyntaxException { + public void test() throws URISyntaxException, IOException { ConvertAmountParams request = new ConvertAmountParams(); request.setAmount(123L); request.setSource("USD"); request.setTarget("EUR"); - ConvertAmount response = getGcClient().merchant("9991").services().convertAmount(request); + GcClient client = getGcClient(); + try { + ConvertAmount response = client.merchant("9991").services().convertAmount(request); - Assert.assertNotNull(response.getConvertedAmount()); + Assert.assertNotNull(response.getConvertedAmount()); + + } finally { + client.close(); + } } } diff --git a/src/it/java/com/globalcollect/gateway/sdk/it/IdempotenceTest.java b/src/it/java/com/globalcollect/gateway/sdk/it/IdempotenceTest.java new file mode 100644 index 000000000..23578df71 --- /dev/null +++ b/src/it/java/com/globalcollect/gateway/sdk/it/IdempotenceTest.java @@ -0,0 +1,80 @@ +package com.globalcollect.gateway.sdk.it; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.UUID; + +import org.junit.Assert; +import org.junit.Test; + +import com.globalcollect.gateway.sdk.java.CallContext; +import com.globalcollect.gateway.sdk.java.gc.GcClient; +import com.globalcollect.gateway.sdk.java.gc.fei.definitions.Address; +import com.globalcollect.gateway.sdk.java.gc.fei.definitions.AmountOfMoney; +import com.globalcollect.gateway.sdk.java.gc.payment.CreatePaymentRequest; +import com.globalcollect.gateway.sdk.java.gc.payment.CreatePaymentResponse; +import com.globalcollect.gateway.sdk.java.gc.payment.definitions.Customer; +import com.globalcollect.gateway.sdk.java.gc.payment.definitions.Order; +import com.globalcollect.gateway.sdk.java.gc.payment.definitions.RedirectPaymentMethodSpecificInput; +import com.globalcollect.gateway.sdk.java.gc.payment.definitions.RedirectPaymentProduct809SpecificInput; + +public class IdempotenceTest extends ItTest { + + /** + * 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); + + GcClient client = getGcClient(); + 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(); + } + } +} diff --git a/src/it/java/com/globalcollect/gateway/sdk/it/PaymentProductsTest.java b/src/it/java/com/globalcollect/gateway/sdk/it/PaymentProductsTest.java index f04ed301d..1082d5f03 100644 --- a/src/it/java/com/globalcollect/gateway/sdk/it/PaymentProductsTest.java +++ b/src/it/java/com/globalcollect/gateway/sdk/it/PaymentProductsTest.java @@ -1,10 +1,12 @@ package com.globalcollect.gateway.sdk.it; +import java.io.IOException; import java.net.URISyntaxException; import org.junit.Assert; import org.junit.Test; +import com.globalcollect.gateway.sdk.java.gc.GcClient; import com.globalcollect.gateway.sdk.java.gc.merchant.products.paymentproduct.DirectoryParams; import com.globalcollect.gateway.sdk.java.gc.product.Directory; @@ -14,13 +16,20 @@ public class PaymentProductsTest extends ItTest { * Smoke test for products service. */ @Test - public void test() throws URISyntaxException { + public void test() throws URISyntaxException, IOException { DirectoryParams params = new DirectoryParams(); params.setCountryCode("NL"); params.setCurrencyCode("EUR"); - Directory response = getGcClient().merchant("8500").products().paymentProduct(809).directory(params); - Assert.assertTrue(response.getEntries().size() > 0); + GcClient client = getGcClient(); + try { + Directory response = client.merchant("8500").products().paymentProduct(809).directory(params); + + Assert.assertTrue(response.getEntries().size() > 0); + + } finally { + client.close(); + } } } diff --git a/src/it/java/com/globalcollect/gateway/sdk/it/RiskAssessmentsTest.java b/src/it/java/com/globalcollect/gateway/sdk/it/RiskAssessmentsTest.java index 69ed724f0..89755af95 100644 --- a/src/it/java/com/globalcollect/gateway/sdk/it/RiskAssessmentsTest.java +++ b/src/it/java/com/globalcollect/gateway/sdk/it/RiskAssessmentsTest.java @@ -1,10 +1,12 @@ package com.globalcollect.gateway.sdk.it; +import java.io.IOException; import java.net.URISyntaxException; import org.junit.Assert; import org.junit.Test; +import com.globalcollect.gateway.sdk.java.gc.GcClient; import com.globalcollect.gateway.sdk.java.gc.fei.definitions.AmountOfMoney; import com.globalcollect.gateway.sdk.java.gc.fei.definitions.BankAccountBban; import com.globalcollect.gateway.sdk.java.gc.riskassessments.RiskAssessmentBankAccount; @@ -18,7 +20,7 @@ public class RiskAssessmentsTest extends ItTest { * Smoke test for risk assessments service. */ @Test - public void test() throws URISyntaxException { + public void test() throws URISyntaxException, IOException { RiskAssessmentBankAccount body = new RiskAssessmentBankAccount(); @@ -41,7 +43,13 @@ public void test() throws URISyntaxException { body.setOrder(order); - RiskAssessmentResponse riskAssessmentResponse = getGcClient().merchant("8500").riskassessments().bankaccounts(body); - Assert.assertTrue(riskAssessmentResponse.getResults().size() > 0); + GcClient client = getGcClient(); + try { + RiskAssessmentResponse riskAssessmentResponse = client.merchant("8500").riskassessments().bankaccounts(body); + Assert.assertTrue(riskAssessmentResponse.getResults().size() > 0); + + } finally { + client.close(); + } } } diff --git a/src/it/java/com/globalcollect/gateway/sdk/it/SDKProxyTest.java b/src/it/java/com/globalcollect/gateway/sdk/it/SDKProxyTest.java index b6b8ba768..dec40dd9e 100644 --- a/src/it/java/com/globalcollect/gateway/sdk/it/SDKProxyTest.java +++ b/src/it/java/com/globalcollect/gateway/sdk/it/SDKProxyTest.java @@ -1,5 +1,6 @@ package com.globalcollect.gateway.sdk.it; +import java.io.IOException; import java.lang.reflect.Field; import java.net.URISyntaxException; @@ -19,6 +20,7 @@ import com.globalcollect.gateway.sdk.java.defaultimpl.DefaultGcCommunicator; import com.globalcollect.gateway.sdk.java.defaultimpl.DefaultGcConnection; import com.globalcollect.gateway.sdk.java.defaultimpl.DefaultGcSession; +import com.globalcollect.gateway.sdk.java.gc.GcClient; import com.globalcollect.gateway.sdk.java.gc.merchant.services.ConvertAmountParams; import com.globalcollect.gateway.sdk.java.gc.merchant.services.ServicesClient; import com.globalcollect.gateway.sdk.java.gc.merchant.services.ServicesClientImpl; @@ -30,23 +32,29 @@ public class SDKProxyTest extends ItTest { * Smoke test for using a proxy configured through SDK properties. */ @Test - public void test() throws URISyntaxException { + public void test() throws URISyntaxException, IOException { ConvertAmountParams request = new ConvertAmountParams(); request.setAmount(123L); request.setSource("USD"); request.setTarget("EUR"); - ServicesClient services = getGcClientWithProxy().merchant("9991").services(); + GcClient client = getGcClientWithProxy(); + try { + ServicesClient services = client.merchant("9991").services(); - Assert.assertTrue(services instanceof ServicesClientImpl); - GcDefaultConfiguration configuration = getDefaultConfigurationWithProxy(); - Assert.assertNotNull(configuration.getProxyConfiguration()); - assertProxySet((ServicesClientImpl) services, configuration.getProxyConfiguration()); + Assert.assertTrue(services instanceof ServicesClientImpl); + GcDefaultConfiguration configuration = getDefaultConfigurationWithProxy(); + Assert.assertNotNull(configuration.getProxyConfiguration()); + assertProxySet((ServicesClientImpl) services, configuration.getProxyConfiguration()); - ConvertAmount response = services.convertAmount(request); + ConvertAmount response = services.convertAmount(request); - Assert.assertNotNull(response.getConvertedAmount()); + Assert.assertNotNull(response.getConvertedAmount()); + + } finally { + client.close(); + } } private void assertProxySet(GcApiResource resource, GcProxyConfiguration proxyConfiguration) { diff --git a/src/it/java/com/globalcollect/gateway/sdk/it/SystemProxyTest.java b/src/it/java/com/globalcollect/gateway/sdk/it/SystemProxyTest.java index dcf580079..6e8b1d2ee 100644 --- a/src/it/java/com/globalcollect/gateway/sdk/it/SystemProxyTest.java +++ b/src/it/java/com/globalcollect/gateway/sdk/it/SystemProxyTest.java @@ -1,5 +1,6 @@ package com.globalcollect.gateway.sdk.it; +import java.io.IOException; import java.net.Authenticator; import java.net.PasswordAuthentication; import java.net.URISyntaxException; @@ -9,6 +10,7 @@ import com.globalcollect.gateway.sdk.java.GcDefaultConfiguration; import com.globalcollect.gateway.sdk.java.GcFactory; +import com.globalcollect.gateway.sdk.java.gc.GcClient; import com.globalcollect.gateway.sdk.java.gc.merchant.services.ConvertAmountParams; import com.globalcollect.gateway.sdk.java.gc.services.ConvertAmount; @@ -18,7 +20,7 @@ public class SystemProxyTest extends ItTest { * Smoke test for using a proxy configured through system properties. */ @Test - public void test() throws URISyntaxException { + public void test() throws URISyntaxException, IOException { final boolean[] authenticationCalled = { false }; @@ -52,12 +54,18 @@ protected PasswordAuthentication getPasswordAuthentication() { request.setSource("USD"); request.setTarget("EUR"); - GcDefaultConfiguration defaultConfiguration = getDefaultConfiguration(); - defaultConfiguration.setProxyConfiguration(null); + GcDefaultConfiguration defaultConfiguration = getDefaultConfiguration() + .withProxyConfiguration(null); - ConvertAmount response = GcFactory.createClient(defaultConfiguration).merchant("9991").services().convertAmount(request); + GcClient client = GcFactory.createClient(defaultConfiguration); + try { + ConvertAmount response = client.merchant("9991").services().convertAmount(request); - Assert.assertNotNull(response.getConvertedAmount()); + Assert.assertNotNull(response.getConvertedAmount()); + + } finally { + client.close(); + } // for https, authentication may not be required if ("http".equalsIgnoreCase(defaultConfiguration.getBaseUri().getScheme())) { diff --git a/src/it/java/com/globalcollect/gateway/sdk/it/TokenTest.java b/src/it/java/com/globalcollect/gateway/sdk/it/TokenTest.java index 5b9924a16..fa2947f7a 100644 --- a/src/it/java/com/globalcollect/gateway/sdk/it/TokenTest.java +++ b/src/it/java/com/globalcollect/gateway/sdk/it/TokenTest.java @@ -1,5 +1,6 @@ package com.globalcollect.gateway.sdk.it; +import java.io.IOException; import java.net.URISyntaxException; import org.junit.Assert; @@ -21,9 +22,7 @@ public class TokenTest extends ItTest { * Smoke test for token calls. */ @Test - public void test() throws URISyntaxException { - - GcClient gcClient = getGcClient(); + public void test() throws URISyntaxException, IOException { CreateTokenRequest createTokenRequest = new CreateTokenRequest(); createTokenRequest.setPaymentProductId(1); @@ -43,12 +42,18 @@ public void test() throws URISyntaxException { cardWithoutCvv.setCardNumber("4567350000427977"); cardWithoutCvv.setExpiryDate("0820"); - CreateTokenResponse createTokenResponse = gcClient.merchant("9991").tokens().create(createTokenRequest); + GcClient client = getGcClient(); + try { + CreateTokenResponse createTokenResponse = client.merchant("9991").tokens().create(createTokenRequest); + + Assert.assertNotNull(createTokenResponse.getToken()); - Assert.assertNotNull(createTokenResponse.getToken()); + DeleteParams deleteTokenRequest = new DeleteParams(); - DeleteParams deleteTokenRequest = new DeleteParams(); + client.merchant("9991").tokens().delete(createTokenResponse.getToken(), deleteTokenRequest); - gcClient.merchant("9991").tokens().delete(createTokenResponse.getToken(), deleteTokenRequest); + } finally { + client.close(); + } } } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/GcClient.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/GcClient.java index acdf3a06d..3ed1c61bf 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/GcClient.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/GcClient.java @@ -34,10 +34,9 @@ public interface GcClient extends Closeable { /** * Resource /{merchantId} - * + * * @param merchantId String * @return Merchant */ MerchantClient merchant(String merchantId); - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/GcClientImpl.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/GcClientImpl.java index 8501de765..a32e55051 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/GcClientImpl.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/GcClientImpl.java @@ -2,7 +2,6 @@ import com.globalcollect.gateway.sdk.java.GcApiResource; import com.globalcollect.gateway.sdk.java.GcCommunicator; -import com.globalcollect.gateway.sdk.java.TypeWrapper; import com.globalcollect.gateway.sdk.java.gc.merchant.MerchantClient; import com.globalcollect.gateway.sdk.java.gc.merchant.MerchantClientImpl; import java.io.IOException; @@ -14,7 +13,7 @@ public class GcClientImpl extends GcApiResource implements GcClient { private static final Charset CHARSET = Charset.forName("UTF-8"); - + public GcClientImpl(GcCommunicator communicator) { this(communicator, null); } @@ -25,17 +24,17 @@ private GcClientImpl(GcCommunicator communicator, String clientMetaInfo) { @Override public GcClient withClientMetaInfo(String clientMetaInfo) { - + if (this.clientMetaInfo == null && clientMetaInfo == null) { return this; } else if (clientMetaInfo == null) { return new GcClientImpl(communicator, null); } else { // Checking to see if this is valid JSON (no JSON parse exceptions) - communicator.getMarshaller().unmarshal(clientMetaInfo, new TypeWrapper(Object.class)); - + communicator.getMarshaller().unmarshal(clientMetaInfo, Object.class); + clientMetaInfo = Base64.encodeBase64String(clientMetaInfo.getBytes(CHARSET)); - + if (clientMetaInfo.equals(this.clientMetaInfo)) { return this; } else { @@ -49,17 +48,10 @@ public void close() throws IOException { communicator.close(); } - /** - * Resource /{merchantId} - * - * @param merchantId String - * @return Merchant - */ @Override public MerchantClient merchant(String merchantId) { - Map subcontext = new TreeMap(); - subcontext.put("merchantId", merchantId); - return new MerchantClientImpl(this, subcontext); + Map subContext = new TreeMap(); + subContext.put("merchantId", merchantId); + return new MerchantClientImpl(this, subContext); } - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/errors/definitions/APIError.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/errors/definitions/APIError.java index 268106eb0..feab2b5be 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/errors/definitions/APIError.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/errors/definitions/APIError.java @@ -5,6 +5,8 @@ public class APIError { private String code = null; + private Integer httpStatusCode = null; + private String message = null; private String propertyName = null; @@ -19,6 +21,14 @@ public void setCode(String value) { this.code = value; } + public Integer getHttpStatusCode() { + return httpStatusCode; + } + + public void setHttpStatusCode(Integer value) { + this.httpStatusCode = value; + } + public String getMessage() { return message; } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/hostedcheckout/CreateHostedCheckoutRequest.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/hostedcheckout/CreateHostedCheckoutRequest.java index 0eaa5c2c4..d7e64e6ac 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/hostedcheckout/CreateHostedCheckoutRequest.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/hostedcheckout/CreateHostedCheckoutRequest.java @@ -5,7 +5,6 @@ import com.globalcollect.gateway.sdk.java.gc.payment.definitions.BankTransferPaymentMethodSpecificInputBase; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.CardPaymentMethodSpecificInputBase; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.CashPaymentMethodSpecificInputBase; -import com.globalcollect.gateway.sdk.java.gc.payment.definitions.CheckPaymentMethodSpecificInput; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.Order; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.RedirectPaymentMethodSpecificInputBase; @@ -20,8 +19,6 @@ public class CreateHostedCheckoutRequest { private CashPaymentMethodSpecificInputBase cashPaymentMethodSpecificInput = null; - private CheckPaymentMethodSpecificInput checkPaymentMethodSpecificInput = null; - private FraudFields fraudFields = null; private HostedCheckoutSpecificInput hostedCheckoutSpecificInput = null; @@ -54,14 +51,6 @@ public void setCashPaymentMethodSpecificInput(CashPaymentMethodSpecificInputBase this.cashPaymentMethodSpecificInput = value; } - public CheckPaymentMethodSpecificInput getCheckPaymentMethodSpecificInput() { - return checkPaymentMethodSpecificInput; - } - - public void setCheckPaymentMethodSpecificInput(CheckPaymentMethodSpecificInput value) { - this.checkPaymentMethodSpecificInput = value; - } - public FraudFields getFraudFields() { return fraudFields; } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/MerchantClient.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/MerchantClient.java index 244787c56..715dc0aeb 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/MerchantClient.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/MerchantClient.java @@ -18,7 +18,7 @@ public interface MerchantClient { /** * Resource /{merchantId}/payouts * Create, cancel and approve payouts - * + * * @return Payouts */ PayoutsClient payouts(); @@ -26,7 +26,7 @@ public interface MerchantClient { /** * Resource /{merchantId}/refunds * Create, cancel and approve refunds - * + * * @return Refunds */ RefundsClient refunds(); @@ -34,7 +34,7 @@ public interface MerchantClient { /** * Resource /{merchantId}/sessions * Create new Session for Client2Server API calls - * + * * @return Sessions */ SessionsClient sessions(); @@ -42,7 +42,7 @@ public interface MerchantClient { /** * Resource /{merchantId}/tokens * Create, delete and update tokens - * + * * @return Tokens */ TokensClient tokens(); @@ -50,7 +50,7 @@ public interface MerchantClient { /** * Resource /{merchantId}/hostedcheckouts * Create new hosted checkout - * + * * @return Hostedcheckouts */ HostedcheckoutsClient hostedcheckouts(); @@ -58,7 +58,7 @@ public interface MerchantClient { /** * Resource /{merchantId}/products * Get information about payment products - * + * * @return Products */ ProductsClient products(); @@ -66,7 +66,7 @@ public interface MerchantClient { /** * Resource /{merchantId}/payments * Create, cancel and approve payments - * + * * @return Payments */ PaymentsClient payments(); @@ -74,7 +74,7 @@ public interface MerchantClient { /** * Resource /{merchantId}/services * Several services to help you - * + * * @return Services */ ServicesClient services(); @@ -82,9 +82,8 @@ public interface MerchantClient { /** * Resource /{merchantId}/riskassessments * Perform risk assessments on your customer data - * + * * @return Riskassessments */ RiskassessmentsClient riskassessments(); - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/MerchantClientImpl.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/MerchantClientImpl.java index 113d787e2..d1b42fc03 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/MerchantClientImpl.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/MerchantClientImpl.java @@ -23,107 +23,52 @@ public class MerchantClientImpl extends GcApiResource implements MerchantClient { - public MerchantClientImpl(GcApiResource parent, Map context) { - super(parent, context); + public MerchantClientImpl(GcApiResource parent, Map pathContext) { + super(parent, pathContext); } - /** - * Resource /{merchantId}/payouts - * Create, cancel and approve payouts - * - * @return Payouts - */ @Override public PayoutsClient payouts() { return new PayoutsClientImpl(this, null); } - /** - * Resource /{merchantId}/refunds - * Create, cancel and approve refunds - * - * @return Refunds - */ @Override public RefundsClient refunds() { return new RefundsClientImpl(this, null); } - /** - * Resource /{merchantId}/sessions - * Create new Session for Client2Server API calls - * - * @return Sessions - */ @Override public SessionsClient sessions() { return new SessionsClientImpl(this, null); } - /** - * Resource /{merchantId}/tokens - * Create, delete and update tokens - * - * @return Tokens - */ @Override public TokensClient tokens() { return new TokensClientImpl(this, null); } - /** - * Resource /{merchantId}/hostedcheckouts - * Create new hosted checkout - * - * @return Hostedcheckouts - */ @Override public HostedcheckoutsClient hostedcheckouts() { return new HostedcheckoutsClientImpl(this, null); } - /** - * Resource /{merchantId}/products - * Get information about payment products - * - * @return Products - */ @Override public ProductsClient products() { return new ProductsClientImpl(this, null); } - /** - * Resource /{merchantId}/payments - * Create, cancel and approve payments - * - * @return Payments - */ @Override public PaymentsClient payments() { return new PaymentsClientImpl(this, null); } - /** - * Resource /{merchantId}/services - * Several services to help you - * - * @return Services - */ @Override public ServicesClient services() { return new ServicesClientImpl(this, null); } - /** - * Resource /{merchantId}/riskassessments - * Perform risk assessments on your customer data - * - * @return Riskassessments - */ @Override public RiskassessmentsClient riskassessments() { return new RiskassessmentsClientImpl(this, null); } - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/hostedcheckouts/HostedcheckoutsClient.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/hostedcheckouts/HostedcheckoutsClient.java index 60cb3a06e..fd26f2e38 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/hostedcheckouts/HostedcheckoutsClient.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/hostedcheckouts/HostedcheckoutsClient.java @@ -1,7 +1,9 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.hostedcheckouts; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiException; import com.globalcollect.gateway.sdk.java.GcAuthorizationException; +import com.globalcollect.gateway.sdk.java.GcIdempotenceException; import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcValidationException; import com.globalcollect.gateway.sdk.java.GlobalCollectException; @@ -17,7 +19,7 @@ public interface HostedcheckoutsClient { /** * Resource /{merchantId}/hostedcheckouts * Create hosted checkout - * + * * @param body CreateHostedCheckoutRequest * @return CreateHostedCheckoutResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -31,10 +33,29 @@ public interface HostedcheckoutsClient { */ CreateHostedCheckoutResponse create(CreateHostedCheckoutRequest body); + /** + * Resource /{merchantId}/hostedcheckouts + * Create hosted checkout + * + * @param body CreateHostedCheckoutRequest + * @param context CallContext + * @return CreateHostedCheckoutResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + CreateHostedCheckoutResponse create(CreateHostedCheckoutRequest body, CallContext context); + /** * Resource /{merchantId}/hostedcheckouts/{hostedCheckoutId} * Get hosted checkout status - * + * * @param hostedCheckoutId String * @return GetHostedCheckoutResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -48,4 +69,22 @@ public interface HostedcheckoutsClient { */ GetHostedCheckoutResponse get(String hostedCheckoutId); + /** + * Resource /{merchantId}/hostedcheckouts/{hostedCheckoutId} + * Get hosted checkout status + * + * @param hostedCheckoutId String + * @param context CallContext + * @return GetHostedCheckoutResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + GetHostedCheckoutResponse get(String hostedCheckoutId, CallContext context); } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/hostedcheckouts/HostedcheckoutsClientImpl.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/hostedcheckouts/HostedcheckoutsClientImpl.java index cfafff564..e659ca68e 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/hostedcheckouts/HostedcheckoutsClientImpl.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/hostedcheckouts/HostedcheckoutsClientImpl.java @@ -1,13 +1,8 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.hostedcheckouts; -import com.globalcollect.gateway.sdk.java.GcApiException; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiResource; -import com.globalcollect.gateway.sdk.java.GcAuthorizationException; -import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcResponseException; -import com.globalcollect.gateway.sdk.java.GcValidationException; -import com.globalcollect.gateway.sdk.java.GlobalCollectException; -import com.globalcollect.gateway.sdk.java.TypeWrapper; import com.globalcollect.gateway.sdk.java.gc.errors.ErrorResponse; import com.globalcollect.gateway.sdk.java.gc.hostedcheckout.CreateHostedCheckoutRequest; import com.globalcollect.gateway.sdk.java.gc.hostedcheckout.CreateHostedCheckoutResponse; @@ -17,28 +12,17 @@ public class HostedcheckoutsClientImpl extends GcApiResource implements HostedcheckoutsClient { - public HostedcheckoutsClientImpl(GcApiResource parent, Map context) { - super(parent, context); + public HostedcheckoutsClientImpl(GcApiResource parent, Map pathContext) { + super(parent, pathContext); } - /** - * Resource /{merchantId}/hostedcheckouts - * Create hosted checkout - * - * @param body CreateHostedCheckoutRequest - * @return CreateHostedCheckoutResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public CreateHostedCheckoutResponse create(CreateHostedCheckoutRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(CreateHostedCheckoutResponse.class); + return create(body, null); + } + + @Override + public CreateHostedCheckoutResponse create(CreateHostedCheckoutRequest body, CallContext context) { String uri = instantiateUri("/{merchantId}/hostedcheckouts", null); try { return communicator.post( @@ -46,56 +30,46 @@ public CreateHostedCheckoutResponse create(CreateHostedCheckoutRequest body) { getClientHeaders(), null, body, - typeWrapper); + CreateHostedCheckoutResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/hostedcheckouts/{hostedCheckoutId} - * Get hosted checkout status - * - * @param hostedCheckoutId String - * @return GetHostedCheckoutResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public GetHostedCheckoutResponse get(String hostedCheckoutId) { - TypeWrapper typeWrapper = new TypeWrapper(GetHostedCheckoutResponse.class); - Map callcontext = new TreeMap(); - callcontext.put("hostedCheckoutId", hostedCheckoutId); - String uri = instantiateUri("/{merchantId}/hostedcheckouts/{hostedCheckoutId}", callcontext); + return get(hostedCheckoutId, null); + } + + @Override + public GetHostedCheckoutResponse get(String hostedCheckoutId, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("hostedCheckoutId", hostedCheckoutId); + String uri = instantiateUri("/{merchantId}/hostedcheckouts/{hostedCheckoutId}", pathContext); try { return communicator.get( uri, getClientHeaders(), null, - typeWrapper); + GetHostedCheckoutResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payments/PaymentsClient.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payments/PaymentsClient.java index 9ad608bfa..1ec8a4587 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payments/PaymentsClient.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payments/PaymentsClient.java @@ -1,9 +1,11 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.payments; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiException; import com.globalcollect.gateway.sdk.java.GcAuthorizationException; import com.globalcollect.gateway.sdk.java.GcDeclinedPaymentException; import com.globalcollect.gateway.sdk.java.GcDeclinedRefundException; +import com.globalcollect.gateway.sdk.java.GcIdempotenceException; import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcValidationException; import com.globalcollect.gateway.sdk.java.GlobalCollectException; @@ -27,7 +29,7 @@ public interface PaymentsClient { /** * Resource /{merchantId}/payments/{paymentId}/refund * Create refund - * + * * @param paymentId String * @param body RefundRequest * @return RefundResponse @@ -43,10 +45,31 @@ public interface PaymentsClient { */ RefundResponse refund(String paymentId, RefundRequest body); + /** + * Resource /{merchantId}/payments/{paymentId}/refund + * Create refund + * + * @param paymentId String + * @param body RefundRequest + * @param context CallContext + * @return RefundResponse + * @throws GcDeclinedRefundException if the GlobalCollect platform declined / rejected the refund. The refund result will be available from the exception. + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + RefundResponse refund(String paymentId, RefundRequest body, CallContext context); + /** * Resource /{merchantId}/payments/{paymentId}/processchallenged * Approves challenged payment - * + * * @param paymentId String * @return PaymentResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -60,10 +83,29 @@ public interface PaymentsClient { */ PaymentResponse processchallenged(String paymentId); + /** + * Resource /{merchantId}/payments/{paymentId}/processchallenged + * Approves challenged payment + * + * @param paymentId String + * @param context CallContext + * @return PaymentResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + PaymentResponse processchallenged(String paymentId, CallContext context); + /** * Resource /{merchantId}/payments/{paymentId} * Retrieve payment - * + * * @param paymentId String * @return PaymentResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -77,10 +119,29 @@ public interface PaymentsClient { */ PaymentResponse get(String paymentId); + /** + * Resource /{merchantId}/payments/{paymentId} + * Retrieve payment + * + * @param paymentId String + * @param context CallContext + * @return PaymentResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + PaymentResponse get(String paymentId, CallContext context); + /** * Resource /{merchantId}/payments * Create payment - * + * * @param body CreatePaymentRequest * @return CreatePaymentResponse * @throws GcDeclinedPaymentException if the GlobalCollect platform declined / rejected the payment. The payment result will be available from the exception. @@ -95,10 +156,30 @@ public interface PaymentsClient { */ CreatePaymentResponse create(CreatePaymentRequest body); + /** + * Resource /{merchantId}/payments + * Create payment + * + * @param body CreatePaymentRequest + * @param context CallContext + * @return CreatePaymentResponse + * @throws GcDeclinedPaymentException if the GlobalCollect platform declined / rejected the payment. The payment result will be available from the exception. + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + CreatePaymentResponse create(CreatePaymentRequest body, CallContext context); + /** * Resource /{merchantId}/payments/{paymentId}/tokenize * Create a token from payment - * + * * @param paymentId String * @param body TokenizePaymentRequest * @return CreateTokenResponse @@ -113,10 +194,30 @@ public interface PaymentsClient { */ CreateTokenResponse tokenize(String paymentId, TokenizePaymentRequest body); + /** + * Resource /{merchantId}/payments/{paymentId}/tokenize + * Create a token from payment + * + * @param paymentId String + * @param body TokenizePaymentRequest + * @param context CallContext + * @return CreateTokenResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + CreateTokenResponse tokenize(String paymentId, TokenizePaymentRequest body, CallContext context); + /** * Resource /{merchantId}/payments/{paymentId}/cancel * Cancel payment - * + * * @param paymentId String * @return CancelPaymentResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -130,10 +231,29 @@ public interface PaymentsClient { */ CancelPaymentResponse cancel(String paymentId); + /** + * Resource /{merchantId}/payments/{paymentId}/cancel + * Cancel payment + * + * @param paymentId String + * @param context CallContext + * @return CancelPaymentResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + CancelPaymentResponse cancel(String paymentId, CallContext context); + /** * Resource /{merchantId}/payments/{paymentId}/approve * Capture payment - * + * * @param paymentId String * @param body ApprovePaymentRequest * @return PaymentApprovalResponse @@ -148,10 +268,30 @@ public interface PaymentsClient { */ PaymentApprovalResponse approve(String paymentId, ApprovePaymentRequest body); + /** + * Resource /{merchantId}/payments/{paymentId}/approve + * Capture payment + * + * @param paymentId String + * @param body ApprovePaymentRequest + * @param context CallContext + * @return PaymentApprovalResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + PaymentApprovalResponse approve(String paymentId, ApprovePaymentRequest body, CallContext context); + /** * Resource /{merchantId}/payments/{paymentId}/cancelapproval * Undo capture payment request - * + * * @param paymentId String * @return CancelApprovalPaymentResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -165,4 +305,22 @@ public interface PaymentsClient { */ CancelApprovalPaymentResponse cancelapproval(String paymentId); + /** + * Resource /{merchantId}/payments/{paymentId}/cancelapproval + * Undo capture payment request + * + * @param paymentId String + * @param context CallContext + * @return CancelApprovalPaymentResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + CancelApprovalPaymentResponse cancelapproval(String paymentId, CallContext context); } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payments/PaymentsClientImpl.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payments/PaymentsClientImpl.java index 373d97787..7b4a6abf7 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payments/PaymentsClientImpl.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payments/PaymentsClientImpl.java @@ -1,15 +1,8 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.payments; -import com.globalcollect.gateway.sdk.java.GcApiException; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiResource; -import com.globalcollect.gateway.sdk.java.GcAuthorizationException; -import com.globalcollect.gateway.sdk.java.GcDeclinedPaymentException; -import com.globalcollect.gateway.sdk.java.GcDeclinedRefundException; -import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcResponseException; -import com.globalcollect.gateway.sdk.java.GcValidationException; -import com.globalcollect.gateway.sdk.java.GlobalCollectException; -import com.globalcollect.gateway.sdk.java.TypeWrapper; import com.globalcollect.gateway.sdk.java.gc.errors.ErrorResponse; import com.globalcollect.gateway.sdk.java.gc.payment.ApprovePaymentRequest; import com.globalcollect.gateway.sdk.java.gc.payment.CancelApprovalPaymentResponse; @@ -29,162 +22,118 @@ public class PaymentsClientImpl extends GcApiResource implements PaymentsClient { - public PaymentsClientImpl(GcApiResource parent, Map context) { - super(parent, context); + public PaymentsClientImpl(GcApiResource parent, Map pathContext) { + super(parent, pathContext); } - /** - * Resource /{merchantId}/payments/{paymentId}/refund - * Create refund - * - * @param paymentId String - * @param body RefundRequest - * @return RefundResponse - * @throws GcDeclinedRefundException if the GlobalCollect platform declined / rejected the refund. The refund result will be available from the exception. - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public RefundResponse refund(String paymentId, RefundRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(RefundResponse.class); - Map callcontext = new TreeMap(); - callcontext.put("paymentId", paymentId); - String uri = instantiateUri("/{merchantId}/payments/{paymentId}/refund", callcontext); + return refund(paymentId, body, null); + } + + @Override + public RefundResponse refund(String paymentId, RefundRequest body, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("paymentId", paymentId); + String uri = instantiateUri("/{merchantId}/payments/{paymentId}/refund", pathContext); try { return communicator.post( uri, getClientHeaders(), null, body, - typeWrapper); + RefundResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 400 : - errorTypeWrapper = new TypeWrapper(RefundErrorResponse.class); + errorType = RefundErrorResponse.class; break; case 404 : - errorTypeWrapper = new TypeWrapper(RefundErrorResponse.class); + errorType = RefundErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/payments/{paymentId}/processchallenged - * Approves challenged payment - * - * @param paymentId String - * @return PaymentResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public PaymentResponse processchallenged(String paymentId) { - TypeWrapper typeWrapper = new TypeWrapper(PaymentResponse.class); - Map callcontext = new TreeMap(); - callcontext.put("paymentId", paymentId); - String uri = instantiateUri("/{merchantId}/payments/{paymentId}/processchallenged", callcontext); + return processchallenged(paymentId, null); + } + + @Override + public PaymentResponse processchallenged(String paymentId, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("paymentId", paymentId); + String uri = instantiateUri("/{merchantId}/payments/{paymentId}/processchallenged", pathContext); try { return communicator.post( uri, getClientHeaders(), null, null, - typeWrapper); + PaymentResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 404 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; case 405 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/payments/{paymentId} - * Retrieve payment - * - * @param paymentId String - * @return PaymentResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public PaymentResponse get(String paymentId) { - TypeWrapper typeWrapper = new TypeWrapper(PaymentResponse.class); - Map callcontext = new TreeMap(); - callcontext.put("paymentId", paymentId); - String uri = instantiateUri("/{merchantId}/payments/{paymentId}", callcontext); + return get(paymentId, null); + } + + @Override + public PaymentResponse get(String paymentId, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("paymentId", paymentId); + String uri = instantiateUri("/{merchantId}/payments/{paymentId}", pathContext); try { return communicator.get( uri, getClientHeaders(), null, - typeWrapper); + PaymentResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/payments - * Create payment - * - * @param body CreatePaymentRequest - * @return CreatePaymentResponse - * @throws GcDeclinedPaymentException if the GlobalCollect platform declined / rejected the payment. The payment result will be available from the exception. - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public CreatePaymentResponse create(CreatePaymentRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(CreatePaymentResponse.class); + return create(body, null); + } + + @Override + public CreatePaymentResponse create(CreatePaymentRequest body, CallContext context) { String uri = instantiateUri("/{merchantId}/payments", null); try { return communicator.post( @@ -192,209 +141,167 @@ public CreatePaymentResponse create(CreatePaymentRequest body) { getClientHeaders(), null, body, - typeWrapper); + CreatePaymentResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 400 : - errorTypeWrapper = new TypeWrapper(PaymentErrorResponse.class); + errorType = PaymentErrorResponse.class; break; case 402 : - errorTypeWrapper = new TypeWrapper(PaymentErrorResponse.class); + errorType = PaymentErrorResponse.class; break; case 403 : - errorTypeWrapper = new TypeWrapper(PaymentErrorResponse.class); + errorType = PaymentErrorResponse.class; break; case 502 : - errorTypeWrapper = new TypeWrapper(PaymentErrorResponse.class); + errorType = PaymentErrorResponse.class; break; case 503 : - errorTypeWrapper = new TypeWrapper(PaymentErrorResponse.class); + errorType = PaymentErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/payments/{paymentId}/tokenize - * Create a token from payment - * - * @param paymentId String - * @param body TokenizePaymentRequest - * @return CreateTokenResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public CreateTokenResponse tokenize(String paymentId, TokenizePaymentRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(CreateTokenResponse.class); - Map callcontext = new TreeMap(); - callcontext.put("paymentId", paymentId); - String uri = instantiateUri("/{merchantId}/payments/{paymentId}/tokenize", callcontext); + return tokenize(paymentId, body, null); + } + + @Override + public CreateTokenResponse tokenize(String paymentId, TokenizePaymentRequest body, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("paymentId", paymentId); + String uri = instantiateUri("/{merchantId}/payments/{paymentId}/tokenize", pathContext); try { return communicator.post( uri, getClientHeaders(), null, body, - typeWrapper); + CreateTokenResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 404 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/payments/{paymentId}/cancel - * Cancel payment - * - * @param paymentId String - * @return CancelPaymentResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public CancelPaymentResponse cancel(String paymentId) { - TypeWrapper typeWrapper = new TypeWrapper(CancelPaymentResponse.class); - Map callcontext = new TreeMap(); - callcontext.put("paymentId", paymentId); - String uri = instantiateUri("/{merchantId}/payments/{paymentId}/cancel", callcontext); + return cancel(paymentId, null); + } + + @Override + public CancelPaymentResponse cancel(String paymentId, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("paymentId", paymentId); + String uri = instantiateUri("/{merchantId}/payments/{paymentId}/cancel", pathContext); try { return communicator.post( uri, getClientHeaders(), null, null, - typeWrapper); + CancelPaymentResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 402 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/payments/{paymentId}/approve - * Capture payment - * - * @param paymentId String - * @param body ApprovePaymentRequest - * @return PaymentApprovalResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public PaymentApprovalResponse approve(String paymentId, ApprovePaymentRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(PaymentApprovalResponse.class); - Map callcontext = new TreeMap(); - callcontext.put("paymentId", paymentId); - String uri = instantiateUri("/{merchantId}/payments/{paymentId}/approve", callcontext); + return approve(paymentId, body, null); + } + + @Override + public PaymentApprovalResponse approve(String paymentId, ApprovePaymentRequest body, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("paymentId", paymentId); + String uri = instantiateUri("/{merchantId}/payments/{paymentId}/approve", pathContext); try { return communicator.post( uri, getClientHeaders(), null, body, - typeWrapper); + PaymentApprovalResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 402 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; case 404 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/payments/{paymentId}/cancelapproval - * Undo capture payment request - * - * @param paymentId String - * @return CancelApprovalPaymentResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public CancelApprovalPaymentResponse cancelapproval(String paymentId) { - TypeWrapper typeWrapper = new TypeWrapper(CancelApprovalPaymentResponse.class); - Map callcontext = new TreeMap(); - callcontext.put("paymentId", paymentId); - String uri = instantiateUri("/{merchantId}/payments/{paymentId}/cancelapproval", callcontext); + return cancelapproval(paymentId, null); + } + + @Override + public CancelApprovalPaymentResponse cancelapproval(String paymentId, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("paymentId", paymentId); + String uri = instantiateUri("/{merchantId}/payments/{paymentId}/cancelapproval", pathContext); try { return communicator.post( uri, getClientHeaders(), null, null, - typeWrapper); + CancelApprovalPaymentResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 404 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payouts/PayoutsClient.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payouts/PayoutsClient.java index 9e3c497d6..cffedcac0 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payouts/PayoutsClient.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payouts/PayoutsClient.java @@ -1,8 +1,10 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.payouts; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiException; import com.globalcollect.gateway.sdk.java.GcAuthorizationException; import com.globalcollect.gateway.sdk.java.GcDeclinedPayoutException; +import com.globalcollect.gateway.sdk.java.GcIdempotenceException; import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcValidationException; import com.globalcollect.gateway.sdk.java.GlobalCollectException; @@ -18,7 +20,7 @@ public interface PayoutsClient { /** * Resource /{merchantId}/payouts/{payoutId}/cancel * Cancel payout - * + * * @param payoutId String * @return Void * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -32,10 +34,29 @@ public interface PayoutsClient { */ Void cancel(String payoutId); + /** + * Resource /{merchantId}/payouts/{payoutId}/cancel + * Cancel payout + * + * @param payoutId String + * @param context CallContext + * @return Void + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + Void cancel(String payoutId, CallContext context); + /** * Resource /{merchantId}/payouts * Create payout - * + * * @param body CreatePayoutRequest * @return PayoutResponse * @throws GcDeclinedPayoutException if the GlobalCollect platform declined / rejected the payout. The payout result will be available from the exception. @@ -50,10 +71,30 @@ public interface PayoutsClient { */ PayoutResponse create(CreatePayoutRequest body); + /** + * Resource /{merchantId}/payouts + * Create payout + * + * @param body CreatePayoutRequest + * @param context CallContext + * @return PayoutResponse + * @throws GcDeclinedPayoutException if the GlobalCollect platform declined / rejected the payout. The payout result will be available from the exception. + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + PayoutResponse create(CreatePayoutRequest body, CallContext context); + /** * Resource /{merchantId}/payouts/{payoutId}/approve * Approve payout - * + * * @param payoutId String * @param body ApprovePayoutRequest * @return PayoutResponse @@ -68,10 +109,30 @@ public interface PayoutsClient { */ PayoutResponse approve(String payoutId, ApprovePayoutRequest body); + /** + * Resource /{merchantId}/payouts/{payoutId}/approve + * Approve payout + * + * @param payoutId String + * @param body ApprovePayoutRequest + * @param context CallContext + * @return PayoutResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + PayoutResponse approve(String payoutId, ApprovePayoutRequest body, CallContext context); + /** * Resource /{merchantId}/payouts/{payoutId}/cancelapproval * Undo approve payout - * + * * @param payoutId String * @return Void * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -85,10 +146,29 @@ public interface PayoutsClient { */ Void cancelapproval(String payoutId); + /** + * Resource /{merchantId}/payouts/{payoutId}/cancelapproval + * Undo approve payout + * + * @param payoutId String + * @param context CallContext + * @return Void + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + Void cancelapproval(String payoutId, CallContext context); + /** * Resource /{merchantId}/payouts/{payoutId} * Retrieve payout - * + * * @param payoutId String * @return PayoutResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -102,4 +182,22 @@ public interface PayoutsClient { */ PayoutResponse get(String payoutId); + /** + * Resource /{merchantId}/payouts/{payoutId} + * Retrieve payout + * + * @param payoutId String + * @param context CallContext + * @return PayoutResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + PayoutResponse get(String payoutId, CallContext context); } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payouts/PayoutsClientImpl.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payouts/PayoutsClientImpl.java index f0160f883..0fe4c9c08 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payouts/PayoutsClientImpl.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/payouts/PayoutsClientImpl.java @@ -1,14 +1,8 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.payouts; -import com.globalcollect.gateway.sdk.java.GcApiException; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiResource; -import com.globalcollect.gateway.sdk.java.GcAuthorizationException; -import com.globalcollect.gateway.sdk.java.GcDeclinedPayoutException; -import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcResponseException; -import com.globalcollect.gateway.sdk.java.GcValidationException; -import com.globalcollect.gateway.sdk.java.GlobalCollectException; -import com.globalcollect.gateway.sdk.java.TypeWrapper; import com.globalcollect.gateway.sdk.java.gc.errors.ErrorResponse; import com.globalcollect.gateway.sdk.java.gc.payout.ApprovePayoutRequest; import com.globalcollect.gateway.sdk.java.gc.payout.CreatePayoutRequest; @@ -19,72 +13,50 @@ public class PayoutsClientImpl extends GcApiResource implements PayoutsClient { - public PayoutsClientImpl(GcApiResource parent, Map context) { - super(parent, context); + public PayoutsClientImpl(GcApiResource parent, Map pathContext) { + super(parent, pathContext); } - /** - * Resource /{merchantId}/payouts/{payoutId}/cancel - * Cancel payout - * - * @param payoutId String - * @return Void - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public Void cancel(String payoutId) { - TypeWrapper typeWrapper = new TypeWrapper(Void.class); - Map callcontext = new TreeMap(); - callcontext.put("payoutId", payoutId); - String uri = instantiateUri("/{merchantId}/payouts/{payoutId}/cancel", callcontext); + return cancel(payoutId, null); + } + + @Override + public Void cancel(String payoutId, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("payoutId", payoutId); + String uri = instantiateUri("/{merchantId}/payouts/{payoutId}/cancel", pathContext); try { return communicator.post( uri, getClientHeaders(), null, null, - typeWrapper); + Void.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 402 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/payouts - * Create payout - * - * @param body CreatePayoutRequest - * @return PayoutResponse - * @throws GcDeclinedPayoutException if the GlobalCollect platform declined / rejected the payout. The payout result will be available from the exception. - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public PayoutResponse create(CreatePayoutRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(PayoutResponse.class); + return create(body, null); + } + + @Override + public PayoutResponse create(CreatePayoutRequest body, CallContext context) { String uri = instantiateUri("/{merchantId}/payouts", null); try { return communicator.post( @@ -92,149 +64,118 @@ public PayoutResponse create(CreatePayoutRequest body) { getClientHeaders(), null, body, - typeWrapper); + PayoutResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 400 : - errorTypeWrapper = new TypeWrapper(PayoutErrorResponse.class); + errorType = PayoutErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/payouts/{payoutId}/approve - * Approve payout - * - * @param payoutId String - * @param body ApprovePayoutRequest - * @return PayoutResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public PayoutResponse approve(String payoutId, ApprovePayoutRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(PayoutResponse.class); - Map callcontext = new TreeMap(); - callcontext.put("payoutId", payoutId); - String uri = instantiateUri("/{merchantId}/payouts/{payoutId}/approve", callcontext); + return approve(payoutId, body, null); + } + + @Override + public PayoutResponse approve(String payoutId, ApprovePayoutRequest body, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("payoutId", payoutId); + String uri = instantiateUri("/{merchantId}/payouts/{payoutId}/approve", pathContext); try { return communicator.post( uri, getClientHeaders(), null, body, - typeWrapper); + PayoutResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 402 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/payouts/{payoutId}/cancelapproval - * Undo approve payout - * - * @param payoutId String - * @return Void - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public Void cancelapproval(String payoutId) { - TypeWrapper typeWrapper = new TypeWrapper(Void.class); - Map callcontext = new TreeMap(); - callcontext.put("payoutId", payoutId); - String uri = instantiateUri("/{merchantId}/payouts/{payoutId}/cancelapproval", callcontext); + return cancelapproval(payoutId, null); + } + + @Override + public Void cancelapproval(String payoutId, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("payoutId", payoutId); + String uri = instantiateUri("/{merchantId}/payouts/{payoutId}/cancelapproval", pathContext); try { return communicator.post( uri, getClientHeaders(), null, null, - typeWrapper); + Void.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 405 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/payouts/{payoutId} - * Retrieve payout - * - * @param payoutId String - * @return PayoutResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public PayoutResponse get(String payoutId) { - TypeWrapper typeWrapper = new TypeWrapper(PayoutResponse.class); - Map callcontext = new TreeMap(); - callcontext.put("payoutId", payoutId); - String uri = instantiateUri("/{merchantId}/payouts/{payoutId}", callcontext); + return get(payoutId, null); + } + + @Override + public PayoutResponse get(String payoutId, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("payoutId", payoutId); + String uri = instantiateUri("/{merchantId}/payouts/{payoutId}", pathContext); try { return communicator.get( uri, getClientHeaders(), null, - typeWrapper); + PayoutResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 404 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/ProductsClient.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/ProductsClient.java index 7ecb8975c..d33964f36 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/ProductsClient.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/ProductsClient.java @@ -1,7 +1,9 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.products; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiException; import com.globalcollect.gateway.sdk.java.GcAuthorizationException; +import com.globalcollect.gateway.sdk.java.GcIdempotenceException; import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcValidationException; import com.globalcollect.gateway.sdk.java.GlobalCollectException; @@ -16,7 +18,7 @@ public interface ProductsClient { /** * Resource /{merchantId}/products/{paymentProductId} - * + * * @param paymentProductId Integer * @return PaymentProduct */ @@ -25,7 +27,7 @@ public interface ProductsClient { /** * Resource /{merchantId}/products * Retrieve payment products - * + * * @param query FindParams * @return PaymentProducts * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -39,10 +41,29 @@ public interface ProductsClient { */ PaymentProducts find(FindParams query); + /** + * Resource /{merchantId}/products + * Retrieve payment products + * + * @param query FindParams + * @param context CallContext + * @return PaymentProducts + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + PaymentProducts find(FindParams query, CallContext context); + /** * Resource /{merchantId}/products/{paymentProductId} * Retrieve payment product fields - * + * * @param paymentProductId Integer * @param query GetParams * @return PaymentProductResponse @@ -57,4 +78,23 @@ public interface ProductsClient { */ PaymentProductResponse get(Integer paymentProductId, GetParams query); + /** + * Resource /{merchantId}/products/{paymentProductId} + * Retrieve payment product fields + * + * @param paymentProductId Integer + * @param query GetParams + * @param context CallContext + * @return PaymentProductResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + PaymentProductResponse get(Integer paymentProductId, GetParams query, CallContext context); } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/ProductsClientImpl.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/ProductsClientImpl.java index b24ea4062..e6399acc1 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/ProductsClientImpl.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/ProductsClientImpl.java @@ -1,13 +1,8 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.products; -import com.globalcollect.gateway.sdk.java.GcApiException; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiResource; -import com.globalcollect.gateway.sdk.java.GcAuthorizationException; -import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcResponseException; -import com.globalcollect.gateway.sdk.java.GcValidationException; -import com.globalcollect.gateway.sdk.java.GlobalCollectException; -import com.globalcollect.gateway.sdk.java.TypeWrapper; import com.globalcollect.gateway.sdk.java.gc.errors.ErrorResponse; import com.globalcollect.gateway.sdk.java.gc.merchant.products.paymentproduct.PaymentProductClient; import com.globalcollect.gateway.sdk.java.gc.merchant.products.paymentproduct.PaymentProductClientImpl; @@ -18,98 +13,70 @@ public class ProductsClientImpl extends GcApiResource implements ProductsClient { - public ProductsClientImpl(GcApiResource parent, Map context) { - super(parent, context); + public ProductsClientImpl(GcApiResource parent, Map pathContext) { + super(parent, pathContext); } - /** - * Resource /{merchantId}/products/{paymentProductId} - * - * @param paymentProductId Integer - * @return PaymentProduct - */ @Override public PaymentProductClient paymentProduct(Integer paymentProductId) { - Map subcontext = new TreeMap(); - subcontext.put("paymentProductId", paymentProductId.toString()); - return new PaymentProductClientImpl(this, subcontext); + Map subContext = new TreeMap(); + subContext.put("paymentProductId", paymentProductId.toString()); + return new PaymentProductClientImpl(this, subContext); } - /** - * Resource /{merchantId}/products - * Retrieve payment products - * - * @param query FindParams - * @return PaymentProducts - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public PaymentProducts find(FindParams query) { - TypeWrapper typeWrapper = new TypeWrapper(PaymentProducts.class); + return find(query, null); + } + + @Override + public PaymentProducts find(FindParams query, CallContext context) { String uri = instantiateUri("/{merchantId}/products", null); try { return communicator.get( uri, getClientHeaders(), query, - typeWrapper); + PaymentProducts.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/products/{paymentProductId} - * Retrieve payment product fields - * - * @param paymentProductId Integer - * @param query GetParams - * @return PaymentProductResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public PaymentProductResponse get(Integer paymentProductId, GetParams query) { - TypeWrapper typeWrapper = new TypeWrapper(PaymentProductResponse.class); - Map callcontext = new TreeMap(); - callcontext.put("paymentProductId", paymentProductId.toString()); - String uri = instantiateUri("/{merchantId}/products/{paymentProductId}", callcontext); + return get(paymentProductId, query, null); + } + + @Override + public PaymentProductResponse get(Integer paymentProductId, GetParams query, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("paymentProductId", paymentProductId.toString()); + String uri = instantiateUri("/{merchantId}/products/{paymentProductId}", pathContext); try { return communicator.get( uri, getClientHeaders(), query, - typeWrapper); + PaymentProductResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/paymentproduct/PaymentProductClient.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/paymentproduct/PaymentProductClient.java index 2768b4134..cd29c4893 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/paymentproduct/PaymentProductClient.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/paymentproduct/PaymentProductClient.java @@ -1,7 +1,9 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.products.paymentproduct; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiException; import com.globalcollect.gateway.sdk.java.GcAuthorizationException; +import com.globalcollect.gateway.sdk.java.GcIdempotenceException; import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcValidationException; import com.globalcollect.gateway.sdk.java.GlobalCollectException; @@ -15,7 +17,7 @@ public interface PaymentProductClient { /** * Resource /{merchantId}/products/{paymentProductId}/directory * Retrieve payment product directory - * + * * @param query DirectoryParams * @return Directory * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -29,4 +31,22 @@ public interface PaymentProductClient { */ Directory directory(DirectoryParams query); + /** + * Resource /{merchantId}/products/{paymentProductId}/directory + * Retrieve payment product directory + * + * @param query DirectoryParams + * @param context CallContext + * @return Directory + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + Directory directory(DirectoryParams query, CallContext context); } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/paymentproduct/PaymentProductClientImpl.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/paymentproduct/PaymentProductClientImpl.java index 4661d2bde..6501823fb 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/paymentproduct/PaymentProductClientImpl.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/products/paymentproduct/PaymentProductClientImpl.java @@ -1,61 +1,45 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.products.paymentproduct; -import com.globalcollect.gateway.sdk.java.GcApiException; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiResource; -import com.globalcollect.gateway.sdk.java.GcAuthorizationException; -import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcResponseException; -import com.globalcollect.gateway.sdk.java.GcValidationException; -import com.globalcollect.gateway.sdk.java.GlobalCollectException; -import com.globalcollect.gateway.sdk.java.TypeWrapper; import com.globalcollect.gateway.sdk.java.gc.errors.ErrorResponse; import com.globalcollect.gateway.sdk.java.gc.product.Directory; import java.util.Map; public class PaymentProductClientImpl extends GcApiResource implements PaymentProductClient { - public PaymentProductClientImpl(GcApiResource parent, Map context) { - super(parent, context); + public PaymentProductClientImpl(GcApiResource parent, Map pathContext) { + super(parent, pathContext); } - /** - * Resource /{merchantId}/products/{paymentProductId}/directory - * Retrieve payment product directory - * - * @param query DirectoryParams - * @return Directory - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public Directory directory(DirectoryParams query) { - TypeWrapper typeWrapper = new TypeWrapper(Directory.class); + return directory(query, null); + } + + @Override + public Directory directory(DirectoryParams query, CallContext context) { String uri = instantiateUri("/{merchantId}/products/{paymentProductId}/directory", null); try { return communicator.get( uri, getClientHeaders(), query, - typeWrapper); + Directory.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 404 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/refunds/RefundsClient.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/refunds/RefundsClient.java index 26b1c536e..0141c2029 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/refunds/RefundsClient.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/refunds/RefundsClient.java @@ -1,7 +1,9 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.refunds; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiException; import com.globalcollect.gateway.sdk.java.GcAuthorizationException; +import com.globalcollect.gateway.sdk.java.GcIdempotenceException; import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcValidationException; import com.globalcollect.gateway.sdk.java.GlobalCollectException; @@ -16,7 +18,7 @@ public interface RefundsClient { /** * Resource /{merchantId}/refunds/{refundId}/cancel * Cancel refund - * + * * @param refundId String * @return Void * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -30,10 +32,29 @@ public interface RefundsClient { */ Void cancel(String refundId); + /** + * Resource /{merchantId}/refunds/{refundId}/cancel + * Cancel refund + * + * @param refundId String + * @param context CallContext + * @return Void + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + Void cancel(String refundId, CallContext context); + /** * Resource /{merchantId}/refunds/{refundId}/approve * Approve refund - * + * * @param refundId String * @param body ApproveRefundRequest * @return Void @@ -48,10 +69,30 @@ public interface RefundsClient { */ Void approve(String refundId, ApproveRefundRequest body); + /** + * Resource /{merchantId}/refunds/{refundId}/approve + * Approve refund + * + * @param refundId String + * @param body ApproveRefundRequest + * @param context CallContext + * @return Void + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + Void approve(String refundId, ApproveRefundRequest body, CallContext context); + /** * Resource /{merchantId}/refunds/{refundId}/cancelapproval * Undo approve refund - * + * * @param refundId String * @return Void * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -65,10 +106,29 @@ public interface RefundsClient { */ Void cancelapproval(String refundId); + /** + * Resource /{merchantId}/refunds/{refundId}/cancelapproval + * Undo approve refund + * + * @param refundId String + * @param context CallContext + * @return Void + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + Void cancelapproval(String refundId, CallContext context); + /** * Resource /{merchantId}/refunds/{refundId} * Retrieve refund - * + * * @param refundId String * @return RefundResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -82,4 +142,22 @@ public interface RefundsClient { */ RefundResponse get(String refundId); + /** + * Resource /{merchantId}/refunds/{refundId} + * Retrieve refund + * + * @param refundId String + * @param context CallContext + * @return RefundResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + RefundResponse get(String refundId, CallContext context); } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/refunds/RefundsClientImpl.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/refunds/RefundsClientImpl.java index f38926cf9..4b71e782f 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/refunds/RefundsClientImpl.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/refunds/RefundsClientImpl.java @@ -1,13 +1,8 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.refunds; -import com.globalcollect.gateway.sdk.java.GcApiException; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiResource; -import com.globalcollect.gateway.sdk.java.GcAuthorizationException; -import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcResponseException; -import com.globalcollect.gateway.sdk.java.GcValidationException; -import com.globalcollect.gateway.sdk.java.GlobalCollectException; -import com.globalcollect.gateway.sdk.java.TypeWrapper; import com.globalcollect.gateway.sdk.java.gc.errors.ErrorResponse; import com.globalcollect.gateway.sdk.java.gc.refund.ApproveRefundRequest; import com.globalcollect.gateway.sdk.java.gc.refund.RefundResponse; @@ -16,168 +11,126 @@ public class RefundsClientImpl extends GcApiResource implements RefundsClient { - public RefundsClientImpl(GcApiResource parent, Map context) { - super(parent, context); + public RefundsClientImpl(GcApiResource parent, Map pathContext) { + super(parent, pathContext); } - /** - * Resource /{merchantId}/refunds/{refundId}/cancel - * Cancel refund - * - * @param refundId String - * @return Void - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public Void cancel(String refundId) { - TypeWrapper typeWrapper = new TypeWrapper(Void.class); - Map callcontext = new TreeMap(); - callcontext.put("refundId", refundId); - String uri = instantiateUri("/{merchantId}/refunds/{refundId}/cancel", callcontext); + return cancel(refundId, null); + } + + @Override + public Void cancel(String refundId, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("refundId", refundId); + String uri = instantiateUri("/{merchantId}/refunds/{refundId}/cancel", pathContext); try { return communicator.post( uri, getClientHeaders(), null, null, - typeWrapper); + Void.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/refunds/{refundId}/approve - * Approve refund - * - * @param refundId String - * @param body ApproveRefundRequest - * @return Void - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public Void approve(String refundId, ApproveRefundRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(Void.class); - Map callcontext = new TreeMap(); - callcontext.put("refundId", refundId); - String uri = instantiateUri("/{merchantId}/refunds/{refundId}/approve", callcontext); + return approve(refundId, body, null); + } + + @Override + public Void approve(String refundId, ApproveRefundRequest body, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("refundId", refundId); + String uri = instantiateUri("/{merchantId}/refunds/{refundId}/approve", pathContext); try { return communicator.post( uri, getClientHeaders(), null, body, - typeWrapper); + Void.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/refunds/{refundId}/cancelapproval - * Undo approve refund - * - * @param refundId String - * @return Void - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public Void cancelapproval(String refundId) { - TypeWrapper typeWrapper = new TypeWrapper(Void.class); - Map callcontext = new TreeMap(); - callcontext.put("refundId", refundId); - String uri = instantiateUri("/{merchantId}/refunds/{refundId}/cancelapproval", callcontext); + return cancelapproval(refundId, null); + } + + @Override + public Void cancelapproval(String refundId, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("refundId", refundId); + String uri = instantiateUri("/{merchantId}/refunds/{refundId}/cancelapproval", pathContext); try { return communicator.post( uri, getClientHeaders(), null, null, - typeWrapper); + Void.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/refunds/{refundId} - * Retrieve refund - * - * @param refundId String - * @return RefundResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public RefundResponse get(String refundId) { - TypeWrapper typeWrapper = new TypeWrapper(RefundResponse.class); - Map callcontext = new TreeMap(); - callcontext.put("refundId", refundId); - String uri = instantiateUri("/{merchantId}/refunds/{refundId}", callcontext); + return get(refundId, null); + } + + @Override + public RefundResponse get(String refundId, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("refundId", refundId); + String uri = instantiateUri("/{merchantId}/refunds/{refundId}", pathContext); try { return communicator.get( uri, getClientHeaders(), null, - typeWrapper); + RefundResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/riskassessments/RiskassessmentsClient.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/riskassessments/RiskassessmentsClient.java index 87660b9ab..9b2d83fe8 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/riskassessments/RiskassessmentsClient.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/riskassessments/RiskassessmentsClient.java @@ -1,7 +1,9 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.riskassessments; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiException; import com.globalcollect.gateway.sdk.java.GcAuthorizationException; +import com.globalcollect.gateway.sdk.java.GcIdempotenceException; import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcValidationException; import com.globalcollect.gateway.sdk.java.GlobalCollectException; @@ -17,7 +19,7 @@ public interface RiskassessmentsClient { /** * Resource /{merchantId}/riskassessments/cards * Risk-assess card - * + * * @param body RiskAssessmentCard * @return RiskAssessmentResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -31,10 +33,29 @@ public interface RiskassessmentsClient { */ RiskAssessmentResponse cards(RiskAssessmentCard body); + /** + * Resource /{merchantId}/riskassessments/cards + * Risk-assess card + * + * @param body RiskAssessmentCard + * @param context CallContext + * @return RiskAssessmentResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + RiskAssessmentResponse cards(RiskAssessmentCard body, CallContext context); + /** * Resource /{merchantId}/riskassessments/bankaccounts * Risk-assess bank account - * + * * @param body RiskAssessmentBankAccount * @return RiskAssessmentResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -48,4 +69,22 @@ public interface RiskassessmentsClient { */ RiskAssessmentResponse bankaccounts(RiskAssessmentBankAccount body); + /** + * Resource /{merchantId}/riskassessments/bankaccounts + * Risk-assess bank account + * + * @param body RiskAssessmentBankAccount + * @param context CallContext + * @return RiskAssessmentResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + RiskAssessmentResponse bankaccounts(RiskAssessmentBankAccount body, CallContext context); } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/riskassessments/RiskassessmentsClientImpl.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/riskassessments/RiskassessmentsClientImpl.java index 989954a60..fdc02332f 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/riskassessments/RiskassessmentsClientImpl.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/riskassessments/RiskassessmentsClientImpl.java @@ -1,13 +1,8 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.riskassessments; -import com.globalcollect.gateway.sdk.java.GcApiException; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiResource; -import com.globalcollect.gateway.sdk.java.GcAuthorizationException; -import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcResponseException; -import com.globalcollect.gateway.sdk.java.GcValidationException; -import com.globalcollect.gateway.sdk.java.GlobalCollectException; -import com.globalcollect.gateway.sdk.java.TypeWrapper; import com.globalcollect.gateway.sdk.java.gc.errors.ErrorResponse; import com.globalcollect.gateway.sdk.java.gc.riskassessments.RiskAssessmentBankAccount; import com.globalcollect.gateway.sdk.java.gc.riskassessments.RiskAssessmentCard; @@ -16,28 +11,17 @@ public class RiskassessmentsClientImpl extends GcApiResource implements RiskassessmentsClient { - public RiskassessmentsClientImpl(GcApiResource parent, Map context) { - super(parent, context); + public RiskassessmentsClientImpl(GcApiResource parent, Map pathContext) { + super(parent, pathContext); } - /** - * Resource /{merchantId}/riskassessments/cards - * Risk-assess card - * - * @param body RiskAssessmentCard - * @return RiskAssessmentResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public RiskAssessmentResponse cards(RiskAssessmentCard body) { - TypeWrapper typeWrapper = new TypeWrapper(RiskAssessmentResponse.class); + return cards(body, null); + } + + @Override + public RiskAssessmentResponse cards(RiskAssessmentCard body, CallContext context) { String uri = instantiateUri("/{merchantId}/riskassessments/cards", null); try { return communicator.post( @@ -45,37 +29,27 @@ public RiskAssessmentResponse cards(RiskAssessmentCard body) { getClientHeaders(), null, body, - typeWrapper); + RiskAssessmentResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/riskassessments/bankaccounts - * Risk-assess bank account - * - * @param body RiskAssessmentBankAccount - * @return RiskAssessmentResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public RiskAssessmentResponse bankaccounts(RiskAssessmentBankAccount body) { - TypeWrapper typeWrapper = new TypeWrapper(RiskAssessmentResponse.class); + return bankaccounts(body, null); + } + + @Override + public RiskAssessmentResponse bankaccounts(RiskAssessmentBankAccount body, CallContext context) { String uri = instantiateUri("/{merchantId}/riskassessments/bankaccounts", null); try { return communicator.post( @@ -83,17 +57,17 @@ public RiskAssessmentResponse bankaccounts(RiskAssessmentBankAccount body) { getClientHeaders(), null, body, - typeWrapper); + RiskAssessmentResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/services/ServicesClient.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/services/ServicesClient.java index e5104697d..dd722370f 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/services/ServicesClient.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/services/ServicesClient.java @@ -1,7 +1,9 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.services; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiException; import com.globalcollect.gateway.sdk.java.GcAuthorizationException; +import com.globalcollect.gateway.sdk.java.GcIdempotenceException; import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcValidationException; import com.globalcollect.gateway.sdk.java.GlobalCollectException; @@ -20,7 +22,7 @@ public interface ServicesClient { /** * Resource /{merchantId}/services/convert/bankaccount * Convert Bankaccount - * + * * @param body BankDetailsRequest * @return BankDetailsResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -34,10 +36,29 @@ public interface ServicesClient { */ BankDetailsResponse bankaccount(BankDetailsRequest body); + /** + * Resource /{merchantId}/services/convert/bankaccount + * Convert Bankaccount + * + * @param body BankDetailsRequest + * @param context CallContext + * @return BankDetailsResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + BankDetailsResponse bankaccount(BankDetailsRequest body, CallContext context); + /** * Resource /{merchantId}/services/testconnection * Test connection - * + * * @return TestConnection * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) @@ -50,10 +71,28 @@ public interface ServicesClient { */ TestConnection testconnection(); + /** + * Resource /{merchantId}/services/testconnection + * Test connection + * + * @param context CallContext + * @return TestConnection + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + TestConnection testconnection(CallContext context); + /** * Resource /{merchantId}/services/getIINdetails * Retrieve IIN details - * + * * @param body BINLookupRequest * @return BINLookupResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -67,10 +106,29 @@ public interface ServicesClient { */ BINLookupResponse getIINdetails(BINLookupRequest body); + /** + * Resource /{merchantId}/services/getIINdetails + * Retrieve IIN details + * + * @param body BINLookupRequest + * @param context CallContext + * @return BINLookupResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + BINLookupResponse getIINdetails(BINLookupRequest body, CallContext context); + /** * Resource /{merchantId}/services/convert/amount * Convert amount - * + * * @param query ConvertAmountParams * @return ConvertAmount * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -84,4 +142,22 @@ public interface ServicesClient { */ ConvertAmount convertAmount(ConvertAmountParams query); + /** + * Resource /{merchantId}/services/convert/amount + * Convert amount + * + * @param query ConvertAmountParams + * @param context CallContext + * @return ConvertAmount + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + ConvertAmount convertAmount(ConvertAmountParams query, CallContext context); } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/services/ServicesClientImpl.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/services/ServicesClientImpl.java index fc0965102..629a74087 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/services/ServicesClientImpl.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/services/ServicesClientImpl.java @@ -1,13 +1,8 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.services; -import com.globalcollect.gateway.sdk.java.GcApiException; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiResource; -import com.globalcollect.gateway.sdk.java.GcAuthorizationException; -import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcResponseException; -import com.globalcollect.gateway.sdk.java.GcValidationException; -import com.globalcollect.gateway.sdk.java.GlobalCollectException; -import com.globalcollect.gateway.sdk.java.TypeWrapper; import com.globalcollect.gateway.sdk.java.gc.errors.ErrorResponse; import com.globalcollect.gateway.sdk.java.gc.services.BINLookupRequest; import com.globalcollect.gateway.sdk.java.gc.services.BINLookupResponse; @@ -19,28 +14,17 @@ public class ServicesClientImpl extends GcApiResource implements ServicesClient { - public ServicesClientImpl(GcApiResource parent, Map context) { - super(parent, context); + public ServicesClientImpl(GcApiResource parent, Map pathContext) { + super(parent, pathContext); } - /** - * Resource /{merchantId}/services/convert/bankaccount - * Convert Bankaccount - * - * @param body BankDetailsRequest - * @return BankDetailsResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public BankDetailsResponse bankaccount(BankDetailsRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(BankDetailsResponse.class); + return bankaccount(body, null); + } + + @Override + public BankDetailsResponse bankaccount(BankDetailsRequest body, CallContext context) { String uri = instantiateUri("/{merchantId}/services/convert/bankaccount", null); try { return communicator.post( @@ -48,76 +32,57 @@ public BankDetailsResponse bankaccount(BankDetailsRequest body) { getClientHeaders(), null, body, - typeWrapper); + BankDetailsResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/services/testconnection - * Test connection - * - * @return TestConnection - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public TestConnection testconnection() { - TypeWrapper typeWrapper = new TypeWrapper(TestConnection.class); + return testconnection(null); + } + + @Override + public TestConnection testconnection(CallContext context) { String uri = instantiateUri("/{merchantId}/services/testconnection", null); try { return communicator.get( uri, getClientHeaders(), null, - typeWrapper); + TestConnection.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 403 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/services/getIINdetails - * Retrieve IIN details - * - * @param body BINLookupRequest - * @return BINLookupResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public BINLookupResponse getIINdetails(BINLookupRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(BINLookupResponse.class); + return getIINdetails(body, null); + } + + @Override + public BINLookupResponse getIINdetails(BINLookupRequest body, CallContext context) { String uri = instantiateUri("/{merchantId}/services/getIINdetails", null); try { return communicator.post( @@ -125,57 +90,47 @@ public BINLookupResponse getIINdetails(BINLookupRequest body) { getClientHeaders(), null, body, - typeWrapper); + BINLookupResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 404 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/services/convert/amount - * Convert amount - * - * @param query ConvertAmountParams - * @return ConvertAmount - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public ConvertAmount convertAmount(ConvertAmountParams query) { - TypeWrapper typeWrapper = new TypeWrapper(ConvertAmount.class); + return convertAmount(query, null); + } + + @Override + public ConvertAmount convertAmount(ConvertAmountParams query, CallContext context) { String uri = instantiateUri("/{merchantId}/services/convert/amount", null); try { return communicator.get( uri, getClientHeaders(), query, - typeWrapper); + ConvertAmount.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/sessions/SessionsClient.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/sessions/SessionsClient.java index cc5599f03..f4eb49572 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/sessions/SessionsClient.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/sessions/SessionsClient.java @@ -1,7 +1,9 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.sessions; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiException; import com.globalcollect.gateway.sdk.java.GcAuthorizationException; +import com.globalcollect.gateway.sdk.java.GcIdempotenceException; import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcValidationException; import com.globalcollect.gateway.sdk.java.GlobalCollectException; @@ -16,7 +18,7 @@ public interface SessionsClient { /** * Resource /{merchantId}/sessions * Create Session - * + * * @param body SessionRequest * @return SessionResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -30,4 +32,22 @@ public interface SessionsClient { */ SessionResponse create(SessionRequest body); + /** + * Resource /{merchantId}/sessions + * Create Session + * + * @param body SessionRequest + * @param context CallContext + * @return SessionResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + SessionResponse create(SessionRequest body, CallContext context); } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/sessions/SessionsClientImpl.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/sessions/SessionsClientImpl.java index 394cc090d..de03066e3 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/sessions/SessionsClientImpl.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/sessions/SessionsClientImpl.java @@ -1,13 +1,8 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.sessions; -import com.globalcollect.gateway.sdk.java.GcApiException; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiResource; -import com.globalcollect.gateway.sdk.java.GcAuthorizationException; -import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcResponseException; -import com.globalcollect.gateway.sdk.java.GcValidationException; -import com.globalcollect.gateway.sdk.java.GlobalCollectException; -import com.globalcollect.gateway.sdk.java.TypeWrapper; import com.globalcollect.gateway.sdk.java.gc.errors.ErrorResponse; import com.globalcollect.gateway.sdk.java.gc.sessions.SessionRequest; import com.globalcollect.gateway.sdk.java.gc.sessions.SessionResponse; @@ -15,28 +10,17 @@ public class SessionsClientImpl extends GcApiResource implements SessionsClient { - public SessionsClientImpl(GcApiResource parent, Map context) { - super(parent, context); + public SessionsClientImpl(GcApiResource parent, Map pathContext) { + super(parent, pathContext); } - /** - * Resource /{merchantId}/sessions - * Create Session - * - * @param body SessionRequest - * @return SessionResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public SessionResponse create(SessionRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(SessionResponse.class); + return create(body, null); + } + + @Override + public SessionResponse create(SessionRequest body, CallContext context) { String uri = instantiateUri("/{merchantId}/sessions", null); try { return communicator.post( @@ -44,17 +28,17 @@ public SessionResponse create(SessionRequest body) { getClientHeaders(), null, body, - typeWrapper); + SessionResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/tokens/TokensClient.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/tokens/TokensClient.java index 0c3eb9780..3724dfce2 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/tokens/TokensClient.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/tokens/TokensClient.java @@ -1,7 +1,9 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.tokens; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiException; import com.globalcollect.gateway.sdk.java.GcAuthorizationException; +import com.globalcollect.gateway.sdk.java.GcIdempotenceException; import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcValidationException; import com.globalcollect.gateway.sdk.java.GlobalCollectException; @@ -19,7 +21,7 @@ public interface TokensClient { /** * Resource /{merchantId}/tokens * Create token - * + * * @param body CreateTokenRequest * @return CreateTokenResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -33,10 +35,29 @@ public interface TokensClient { */ CreateTokenResponse create(CreateTokenRequest body); + /** + * Resource /{merchantId}/tokens + * Create token + * + * @param body CreateTokenRequest + * @param context CallContext + * @return CreateTokenResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + CreateTokenResponse create(CreateTokenRequest body, CallContext context); + /** * Resource /{merchantId}/tokens/{tokenId}/approvesepadirectdebit * Approve SEPA DD mandate - * + * * @param tokenId String * @param body ApproveTokenRequest * @return Void @@ -51,10 +72,30 @@ public interface TokensClient { */ Void approvesepadirectdebit(String tokenId, ApproveTokenRequest body); + /** + * Resource /{merchantId}/tokens/{tokenId}/approvesepadirectdebit + * Approve SEPA DD mandate + * + * @param tokenId String + * @param body ApproveTokenRequest + * @param context CallContext + * @return Void + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + Void approvesepadirectdebit(String tokenId, ApproveTokenRequest body, CallContext context); + /** * Resource /{merchantId}/tokens/{tokenId} * Update token - * + * * @param tokenId String * @param body UpdateTokenRequest * @return Void @@ -69,10 +110,30 @@ public interface TokensClient { */ Void update(String tokenId, UpdateTokenRequest body); + /** + * Resource /{merchantId}/tokens/{tokenId} + * Update token + * + * @param tokenId String + * @param body UpdateTokenRequest + * @param context CallContext + * @return Void + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + Void update(String tokenId, UpdateTokenRequest body, CallContext context); + /** * Resource /{merchantId}/tokens/{tokenId} * Retrieve token - * + * * @param tokenId String * @return TokenResponse * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) @@ -86,10 +147,29 @@ public interface TokensClient { */ TokenResponse get(String tokenId); + /** + * Resource /{merchantId}/tokens/{tokenId} + * Retrieve token + * + * @param tokenId String + * @param context CallContext + * @return TokenResponse + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + TokenResponse get(String tokenId, CallContext context); + /** * Resource /{merchantId}/tokens/{tokenId} * Delete token - * + * * @param tokenId String * @param query DeleteParams * @return Void @@ -104,4 +184,23 @@ public interface TokensClient { */ Void delete(String tokenId, DeleteParams query); + /** + * Resource /{merchantId}/tokens/{tokenId} + * Delete token + * + * @param tokenId String + * @param query DeleteParams + * @param context CallContext + * @return Void + * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) + * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) + * @throws GcIdempotenceException if an idempotent request caused a conflict (HTTP status code 409) + * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, + * or there was a conflict (HTTP status code 404, 409 or 410) + * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, + * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, + * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) + * @throws GcApiException if the GlobalCollect platform returned any other error + */ + Void delete(String tokenId, DeleteParams query, CallContext context); } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/tokens/TokensClientImpl.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/tokens/TokensClientImpl.java index 5d9e147c6..332993778 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/tokens/TokensClientImpl.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/merchant/tokens/TokensClientImpl.java @@ -1,13 +1,8 @@ package com.globalcollect.gateway.sdk.java.gc.merchant.tokens; -import com.globalcollect.gateway.sdk.java.GcApiException; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiResource; -import com.globalcollect.gateway.sdk.java.GcAuthorizationException; -import com.globalcollect.gateway.sdk.java.GcReferenceException; import com.globalcollect.gateway.sdk.java.GcResponseException; -import com.globalcollect.gateway.sdk.java.GcValidationException; -import com.globalcollect.gateway.sdk.java.GlobalCollectException; -import com.globalcollect.gateway.sdk.java.TypeWrapper; import com.globalcollect.gateway.sdk.java.gc.errors.ErrorResponse; import com.globalcollect.gateway.sdk.java.gc.token.ApproveTokenRequest; import com.globalcollect.gateway.sdk.java.gc.token.CreateTokenRequest; @@ -19,28 +14,17 @@ public class TokensClientImpl extends GcApiResource implements TokensClient { - public TokensClientImpl(GcApiResource parent, Map context) { - super(parent, context); + public TokensClientImpl(GcApiResource parent, Map pathContext) { + super(parent, pathContext); } - /** - * Resource /{merchantId}/tokens - * Create token - * - * @param body CreateTokenRequest - * @return CreateTokenResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public CreateTokenResponse create(CreateTokenRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(CreateTokenResponse.class); + return create(body, null); + } + + @Override + public CreateTokenResponse create(CreateTokenRequest body, CallContext context) { String uri = instantiateUri("/{merchantId}/tokens", null); try { return communicator.post( @@ -48,187 +32,144 @@ public CreateTokenResponse create(CreateTokenRequest body) { getClientHeaders(), null, body, - typeWrapper); + CreateTokenResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 403 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/tokens/{tokenId}/approvesepadirectdebit - * Approve SEPA DD mandate - * - * @param tokenId String - * @param body ApproveTokenRequest - * @return Void - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public Void approvesepadirectdebit(String tokenId, ApproveTokenRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(Void.class); - Map callcontext = new TreeMap(); - callcontext.put("tokenId", tokenId); - String uri = instantiateUri("/{merchantId}/tokens/{tokenId}/approvesepadirectdebit", callcontext); + return approvesepadirectdebit(tokenId, body, null); + } + + @Override + public Void approvesepadirectdebit(String tokenId, ApproveTokenRequest body, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("tokenId", tokenId); + String uri = instantiateUri("/{merchantId}/tokens/{tokenId}/approvesepadirectdebit", pathContext); try { return communicator.post( uri, getClientHeaders(), null, body, - typeWrapper); + Void.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/tokens/{tokenId} - * Update token - * - * @param tokenId String - * @param body UpdateTokenRequest - * @return Void - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public Void update(String tokenId, UpdateTokenRequest body) { - TypeWrapper typeWrapper = new TypeWrapper(Void.class); - Map callcontext = new TreeMap(); - callcontext.put("tokenId", tokenId); - String uri = instantiateUri("/{merchantId}/tokens/{tokenId}", callcontext); + return update(tokenId, body, null); + } + + @Override + public Void update(String tokenId, UpdateTokenRequest body, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("tokenId", tokenId); + String uri = instantiateUri("/{merchantId}/tokens/{tokenId}", pathContext); try { return communicator.put( uri, getClientHeaders(), null, body, - typeWrapper); + Void.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/tokens/{tokenId} - * Retrieve token - * - * @param tokenId String - * @return TokenResponse - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public TokenResponse get(String tokenId) { - TypeWrapper typeWrapper = new TypeWrapper(TokenResponse.class); - Map callcontext = new TreeMap(); - callcontext.put("tokenId", tokenId); - String uri = instantiateUri("/{merchantId}/tokens/{tokenId}", callcontext); + return get(tokenId, null); + } + + @Override + public TokenResponse get(String tokenId, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("tokenId", tokenId); + String uri = instantiateUri("/{merchantId}/tokens/{tokenId}", pathContext); try { return communicator.get( uri, getClientHeaders(), null, - typeWrapper); + TokenResponse.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 404 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - /** - * Resource /{merchantId}/tokens/{tokenId} - * Delete token - * - * @param tokenId String - * @param query DeleteParams - * @return Void - * @throws GcValidationException if the request was not correct and couldn't be processed (HTTP status code 400) - * @throws GcAuthorizationException if the request was not allowed (HTTP status code 403) - * @throws GcReferenceException if an object was attempted to be referenced that doesn't exist or has been removed, - * or there was a conflict (HTTP status code 404, 409 or 410) - * @throws GlobalCollectException if something went wrong at the GlobalCollect platform, - * the GlobalCollect platform was unable to process a message from a downstream partner/acquirer, - * or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) - * @throws GcApiException if the GlobalCollect platform returned any other error - */ @Override public Void delete(String tokenId, DeleteParams query) { - TypeWrapper typeWrapper = new TypeWrapper(Void.class); - Map callcontext = new TreeMap(); - callcontext.put("tokenId", tokenId); - String uri = instantiateUri("/{merchantId}/tokens/{tokenId}", callcontext); + return delete(tokenId, query, null); + } + + @Override + public Void delete(String tokenId, DeleteParams query, CallContext context) { + Map pathContext = new TreeMap(); + pathContext.put("tokenId", tokenId); + String uri = instantiateUri("/{merchantId}/tokens/{tokenId}", pathContext); try { return communicator.delete( uri, getClientHeaders(), query, - typeWrapper); + Void.class, + context); } catch (GcResponseException e) { - final TypeWrapper errorTypeWrapper; + final Class errorType; switch (e.getStatusCode()) { case 404 : - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; default: - errorTypeWrapper = new TypeWrapper(ErrorResponse.class); + errorType = ErrorResponse.class; break; } - final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorTypeWrapper); - throw createException(e.getStatusCode(), e.getBody(), errorObject); + final Object errorObject = communicator.getMarshaller().unmarshal(e.getBody(), e.getStatusCode(), uri, errorType); + throw createException(e.getStatusCode(), e.getBody(), errorObject, context); } } - } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/CreatePaymentRequest.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/CreatePaymentRequest.java index 4097c8d48..698e6c4e0 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/CreatePaymentRequest.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/CreatePaymentRequest.java @@ -4,7 +4,6 @@ import com.globalcollect.gateway.sdk.java.gc.payment.definitions.BankTransferPaymentMethodSpecificInput; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.CardPaymentMethodSpecificInput; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.CashPaymentMethodSpecificInput; -import com.globalcollect.gateway.sdk.java.gc.payment.definitions.CheckPaymentMethodSpecificInput; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.InvoicePaymentMethodSpecificInput; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.NonSepaDirectDebitPaymentMethodSpecificInput; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.Order; @@ -22,8 +21,6 @@ public class CreatePaymentRequest { private CashPaymentMethodSpecificInput cashPaymentMethodSpecificInput = null; - private CheckPaymentMethodSpecificInput checkPaymentMethodSpecificInput = null; - private NonSepaDirectDebitPaymentMethodSpecificInput directDebitPaymentMethodSpecificInput = null; private String encryptedCustomerInput = null; @@ -62,14 +59,6 @@ public void setCashPaymentMethodSpecificInput(CashPaymentMethodSpecificInput val this.cashPaymentMethodSpecificInput = value; } - public CheckPaymentMethodSpecificInput getCheckPaymentMethodSpecificInput() { - return checkPaymentMethodSpecificInput; - } - - public void setCheckPaymentMethodSpecificInput(CheckPaymentMethodSpecificInput value) { - this.checkPaymentMethodSpecificInput = value; - } - public NonSepaDirectDebitPaymentMethodSpecificInput getDirectDebitPaymentMethodSpecificInput() { return directDebitPaymentMethodSpecificInput; } diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/definitions/CheckPaymentMethodSpecificInput.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/definitions/CheckPaymentMethodSpecificInput.java deleted file mode 100644 index d166a748d..000000000 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/definitions/CheckPaymentMethodSpecificInput.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.globalcollect.gateway.sdk.java.gc.payment.definitions; - -import com.globalcollect.gateway.sdk.java.gc.fei.definitions.AbstractPaymentMethodSpecificInput; - -public class CheckPaymentMethodSpecificInput extends AbstractPaymentMethodSpecificInput { -} diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/definitions/CheckPaymentMethodSpecificOutput.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/definitions/CheckPaymentMethodSpecificOutput.java deleted file mode 100644 index a8a93e12b..000000000 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/definitions/CheckPaymentMethodSpecificOutput.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.globalcollect.gateway.sdk.java.gc.payment.definitions; - -import com.globalcollect.gateway.sdk.java.gc.payment.definitions.AbstractPaymentMethodSpecificOutput; - -public class CheckPaymentMethodSpecificOutput extends AbstractPaymentMethodSpecificOutput { -} diff --git a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/definitions/PaymentOutput.java b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/definitions/PaymentOutput.java index f65852ac7..95ab5cf41 100644 --- a/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/definitions/PaymentOutput.java +++ b/src/main/generated/com/globalcollect/gateway/sdk/java/gc/payment/definitions/PaymentOutput.java @@ -3,7 +3,6 @@ import com.globalcollect.gateway.sdk.java.gc.payment.definitions.BankTransferPaymentMethodSpecificOutput; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.CardPaymentMethodSpecificOutput; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.CashPaymentMethodSpecificOutput; -import com.globalcollect.gateway.sdk.java.gc.payment.definitions.CheckPaymentMethodSpecificOutput; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.InvoicePaymentMethodSpecificOutput; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.NonSepaDirectDebitPaymentMethodSpecificOutput; import com.globalcollect.gateway.sdk.java.gc.payment.definitions.RedirectPaymentMethodSpecificOutput; @@ -20,8 +19,6 @@ public class PaymentOutput extends OrderOutput { private CashPaymentMethodSpecificOutput cashPaymentMethodSpecificOutput = null; - private CheckPaymentMethodSpecificOutput checkPaymentMethodSpecificOutput = null; - private NonSepaDirectDebitPaymentMethodSpecificOutput directDebitPaymentMethodSpecificOutput = null; private InvoicePaymentMethodSpecificOutput invoicePaymentMethodSpecificOutput = null; @@ -64,14 +61,6 @@ public void setCashPaymentMethodSpecificOutput(CashPaymentMethodSpecificOutput v this.cashPaymentMethodSpecificOutput = value; } - public CheckPaymentMethodSpecificOutput getCheckPaymentMethodSpecificOutput() { - return checkPaymentMethodSpecificOutput; - } - - public void setCheckPaymentMethodSpecificOutput(CheckPaymentMethodSpecificOutput value) { - this.checkPaymentMethodSpecificOutput = value; - } - public NonSepaDirectDebitPaymentMethodSpecificOutput getDirectDebitPaymentMethodSpecificOutput() { return directDebitPaymentMethodSpecificOutput; } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/CallContext.java b/src/main/java/com/globalcollect/gateway/sdk/java/CallContext.java new file mode 100644 index 000000000..27e7bd487 --- /dev/null +++ b/src/main/java/com/globalcollect/gateway/sdk/java/CallContext.java @@ -0,0 +1,46 @@ +package com.globalcollect.gateway.sdk.java; + +/** + * A call context can be used to send extra information with a request, and to receive extra information from a response. + *

+ * Please note that this class is not thread-safe. Each request should get its own call context instance. + */ +public class CallContext { + + private String idempotenceKey; + + private Long idempotenceRequestTimestamp; + + /** + * @return The idempotence key. + */ + public String getIdempotenceKey() { + return idempotenceKey; + } + + /** + * Sets the idempotence key to use for the next request for which this call context is used. + * @return This call context object. + */ + public CallContext withIdempotenceKey(String idempotenceKey) { + this.idempotenceKey = idempotenceKey; + return this; + } + + /** + * @return The idempotence request timestamp from the response to the last request for which this call context was used, + * or {@code null} if no idempotence request timestamp was present. + */ + public Long getIdempotenceRequestTimestamp() { + return idempotenceRequestTimestamp; + } + + /** + * Sets the idempotence request timestamp. + * This method should only be called by {@link GcCommunicator} objects based on the response to the request for which this + * call context was used. + */ + public void setIdempotenceRequestTimestamp(Long idempotenceRequestTimestamp) { + this.idempotenceRequestTimestamp = idempotenceRequestTimestamp; + } +} diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcApiException.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcApiException.java index e5d52c5c6..e9e8149d3 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcApiException.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcApiException.java @@ -29,28 +29,28 @@ public GcApiException(String message, int statusCode, String responseBody, Strin } /** - * Returns the HTTP status code that was returned by the GlobalCollect platform. + * @return The HTTP status code that was returned by the GlobalCollect platform. */ public int getStatusCode() { return statusCode; } /** - * Returns the raw response body that was returned by the GlobalCollect platform. + * @return The raw response body that was returned by the GlobalCollect platform. */ public String getResponseBody() { return responseBody; } /** - * Returns the error ID received from the GlobalCollect platform if available. + * @return The error ID received from the GlobalCollect platform if available. */ public String getErrorId() { return errorId; } /** - * Returns the error list received from the GlobalCollect platform if available. Never {@code null}. + * @return The error list received from the GlobalCollect platform if available. Never {@code null}. */ public List getErrors() { return errors; diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcApiResource.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcApiResource.java index cb5209d42..eeaa1ab0c 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcApiResource.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcApiResource.java @@ -17,26 +17,26 @@ public abstract class GcApiResource { private final GcApiResource parent; protected final GcCommunicator communicator; - private final Map context; + private final Map pathContext; protected final String clientMetaInfo; - protected GcApiResource(GcApiResource parent, Map context) { + protected GcApiResource(GcApiResource parent, Map pathContext) { if (parent == null) { throw new IllegalArgumentException("parent is required"); } this.parent = parent; this.communicator = parent.communicator; - this.context = context; + this.pathContext = pathContext; this.clientMetaInfo = parent.clientMetaInfo; } - protected GcApiResource(GcCommunicator communicator, String clientMetaInfo, Map context) { + protected GcApiResource(GcCommunicator communicator, String clientMetaInfo, Map pathContext) { if (communicator == null) { throw new IllegalArgumentException("communicator is required"); } this.parent = null; this.communicator = communicator; - this.context = context; + this.pathContext = pathContext; this.clientMetaInfo = clientMetaInfo; } @@ -52,30 +52,30 @@ protected List getClientHeaders() { } } - protected String instantiateUri(String uri, Map callContext) { - uri = replaceAll(uri, callContext); + protected String instantiateUri(String uri, Map pathContext) { + uri = replaceAll(uri, pathContext); uri = instantiateUri(uri); return uri; } private String instantiateUri(String uri) { - uri = replaceAll(uri, context); + uri = replaceAll(uri, pathContext); if (parent != null) { uri = parent.instantiateUri(uri); } return uri; } - private String replaceAll(String uri, Map context) { - if (context != null) { - for (Map.Entry entry : context.entrySet()) { + private String replaceAll(String uri, Map pathContext) { + if (pathContext != null) { + for (Map.Entry entry : pathContext.entrySet()) { uri = uri.replace(String.format("{%s}", entry.getKey()), entry.getValue()); } } return uri; } - protected RuntimeException createException(int statusCode, String responseBody, Object errorObject) { + protected RuntimeException createException(int statusCode, String responseBody, Object errorObject, CallContext context) { if (errorObject instanceof PaymentErrorResponse && ((PaymentErrorResponse) errorObject).getPaymentResult() != null) { return new GcDeclinedPaymentException(statusCode, responseBody, (PaymentErrorResponse) errorObject); } else if (errorObject instanceof PayoutErrorResponse && ((PayoutErrorResponse) errorObject).getPayoutResult() != null) { @@ -114,7 +114,13 @@ protected RuntimeException createException(int statusCode, String responseBody, case 404: return new GcReferenceException(statusCode, responseBody, errorId, errors); case 409: - return new GcReferenceException(statusCode, responseBody, errorId, errors); + if (isIdempotenceError(errors, context)) { + String idempotenceKey = context.getIdempotenceKey(); + Long idempotenceRequestTimestamp = context.getIdempotenceRequestTimestamp(); + return new GcIdempotenceException(idempotenceKey, idempotenceRequestTimestamp, statusCode, responseBody, errorId, errors); + } else { + return new GcReferenceException(statusCode, responseBody, errorId, errors); + } case 410: return new GcReferenceException(statusCode, responseBody, errorId, errors); case 500: @@ -127,4 +133,11 @@ protected RuntimeException createException(int statusCode, String responseBody, return new GcApiException(statusCode, responseBody, errorId, errors); } } + + private boolean isIdempotenceError(List errors, CallContext context) { + return context != null + && context.getIdempotenceKey() != null + && errors.size() == 1 + && "1409".equals(errors.get(0).getCode()); + } } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcAuthenticator.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcAuthenticator.java index 429767f70..9b44e4385 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcAuthenticator.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcAuthenticator.java @@ -11,10 +11,8 @@ public interface GcAuthenticator { /** * Creates a signature for the simple security model. * - * @param httpMethod - * The HTTP method. - * @param resourceUri - * resourceUri the {@link URI} of the resource. + * @param httpMethod The HTTP method. + * @param resourceUri The {@link URI} of the resource. * @param requestHeaders * A list of {@link RequestHeader}s. This list may not be * modified and may not contain headers with the same name. diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcCommunicator.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcCommunicator.java index ab3a80010..22fefbec8 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcCommunicator.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcCommunicator.java @@ -23,54 +23,67 @@ public interface GcCommunicator extends Closeable { /** * Corresponds to the HTTP GET method. * - * @throws GcCommunicationException - * when an exception occurred communicating with the GlobalCollect platform - * @throws GcResponseException - * when an error response was received from the GlobalCollect platform - * @throws GcApiException - * when an error response was received from the GlobalCollect platform which contained a list of errors + * @param relativePath The path to call, relative to the base URI. + * @param requestHeaders An optional list of request headers. + * @param requestParameters An optional set of request parameters. + * @param responseType The type of response to return. + * @param context The optional call context to use. + * @throws GcCommunicationException when an exception occurred communicating with the GlobalCollect platform + * @throws GcResponseException when an error response was received from the GlobalCollect platform + * @throws GcApiException when an error response was received from the GlobalCollect platform which contained a list of errors */ -

O get(String relativePath, List requestHeaders, P requestParameters, TypeWrapper responseTypeWrapper); +

O get(String relativePath, List requestHeaders, P requestParameters, + Class responseType, CallContext context); /** * Corresponds to the HTTP DELETE method. * - * @throws GcCommunicationException - * when an exception occurred communicating with the GlobalCollect platform - * @throws GcResponseException - * when an error response was received from the GlobalCollect platform - * @throws GcApiException - * when an error response was received from the GlobalCollect platform which contained a list of errors + * @param relativePath The path to call, relative to the base URI. + * @param requestHeaders An optional list of request headers. + * @param requestParameters An optional set of request parameters. + * @param responseType The type of response to return. + * @param context The optional call context to use. + * @throws GcCommunicationException when an exception occurred communicating with the GlobalCollect platform + * @throws GcResponseException when an error response was received from the GlobalCollect platform + * @throws GcApiException when an error response was received from the GlobalCollect platform which contained a list of errors */ -

O delete(String relativePath, List requestHeaders, P requestParameters, TypeWrapper responseTypeWrapper); +

O delete(String relativePath, List requestHeaders, P requestParameters, + Class responseType, CallContext context); /** * Corresponds to the HTTP POST method. * - * @throws GcCommunicationException - * when an exception occurred communicating with the GlobalCollect platform - * @throws GcResponseException - * when an error response was received from the GlobalCollect platform - * @throws GcApiException - * when an error response was received from the GlobalCollect platform which contained a list of errors + * @param relativePath The path to call, relative to the base URI. + * @param requestHeaders An optional list of request headers. + * @param requestParameters An optional set of request parameters. + * @param requestBody The optional request body to send. + * @param responseType The type of response to return. + * @param context The optional call context to use. + * @throws GcCommunicationException when an exception occurred communicating with the GlobalCollect platform + * @throws GcResponseException when an error response was received from the GlobalCollect platform + * @throws GcApiException when an error response was received from the GlobalCollect platform which contained a list of errors */ -

O post(String relativePath, List requestHeaders, P requestParameters, Object requestBody, TypeWrapper responseTypeWrapper); +

O post(String relativePath, List requestHeaders, P requestParameters, Object requestBody, + Class responseType, CallContext context); /** * Corresponds to the HTTP PUT method. * - * @throws GcCommunicationException - * when an exception occurred communicating with the GlobalCollect platform - * @throws GcResponseException - * when an error response was received from the GlobalCollect platform - * @throws GcApiException - * when an error response was received from the GlobalCollect platform which contained a list of errors + * @param relativePath The path to call, relative to the base URI. + * @param requestHeaders An optional list of request headers. + * @param requestParameters An optional set of request parameters. + * @param requestBody The optional request body to send. + * @param responseType The type of response to return. + * @param context The optional call context to use. + * @throws GcCommunicationException when an exception occurred communicating with the GlobalCollect platform + * @throws GcResponseException when an error response was received from the GlobalCollect platform + * @throws GcApiException when an error response was received from the GlobalCollect platform which contained a list of errors */ -

O put(String relativePath, List requestHeaders, P requestParameters, Object requestBody, TypeWrapper responseTypeWrapper); +

O put(String relativePath, List requestHeaders, P requestParameters, Object requestBody, + Class responseType, CallContext context); /** - * @return The {@link GcMarshaller} object associated with this communicator. - * Never {@code null}. + * @return The {@link GcMarshaller} object associated with this communicator. Never {@code null}. */ GcMarshaller getMarshaller(); } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcConnection.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcConnection.java index e85755be5..d9ea292ea 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcConnection.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcConnection.java @@ -16,8 +16,8 @@ public interface GcConnection extends Closeable { URI toURI(String relativePath, List requestParameters); /** - * Releases any system resources associated with this object. Should be - * called when this object is about to go out of scope. + * Releases any system resources associated with this object. + * Should be called when this object is about to go out of scope. */ @Override void close() throws IOException; @@ -25,40 +25,38 @@ public interface GcConnection extends Closeable { /** * Send a GET request to the GlobalCollect platform and return the response. * - * @throws GcCommunicationException - * when an exception occurred communicating with the GlobalCollect platform - * @throws GcResponseException - * when an error response was received from the GlobalCollect platform + * @param uri The URI to call, including any necessary query parameters. + * @param requestHeaders An optional list of request headers. + * @throws GcCommunicationException when an exception occurred communicating with the GlobalCollect platform */ - String get(String relativePath, List requestHeaders, List requestParameters); + GcResponse get(URI uri, List requestHeaders); /** * Send a DELETE request to the GlobalCollect platform and return the response. * - * @throws GcCommunicationException - * when an exception occurred communicating with the GlobalCollect platform - * @throws GcResponseException - * when an error response was received from the GlobalCollect platform + * @param uri The URI to call, including any necessary query parameters. + * @param requestHeaders An optional list of request headers. + * @throws GcCommunicationException when an exception occurred communicating with the GlobalCollect platform */ - String delete(String relativePath, List requestHeaders, List requestParameters); + GcResponse delete(URI uri, List requestHeaders); /** * Send a POST request to the GlobalCollect platform and return the response. * - * @throws GcCommunicationException - * when an exception occurred communicating with the GlobalCollect platform - * @throws GcResponseException - * when an error response was received from the GlobalCollect platform + * @param uri The URI to call, including any necessary query parameters. + * @param requestHeaders An optional list of request headers. + * @param body The optional body to send. + * @throws GcCommunicationException when an exception occurred communicating with the GlobalCollect platform */ - String post(String resourcePath, List requestHeaders, List requestParameters, String body); + GcResponse post(URI uri, List requestHeaders, String body); /** * Send a PUT request to the GlobalCollect platform and return the response. * - * @throws GcCommunicationException - * when an exception occurred communicating with the GlobalCollect platform - * @throws GcResponseException - * when an error response was received from the GlobalCollect platform + * @param uri The URI to call, including any necessary query parameters. + * @param requestHeaders An optional list of request headers. + * @param body The optional body to send. + * @throws GcCommunicationException when an exception occurred communicating with the GlobalCollect platform */ - String put(String resourcePath, List requestHeaders, List requestParameters, String body); + GcResponse put(URI uri, List requestHeaders, String body); } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcDeclinedPaymentException.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcDeclinedPaymentException.java index 72e3fc84c..7f12b8665 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcDeclinedPaymentException.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcDeclinedPaymentException.java @@ -27,7 +27,7 @@ private static String buildMessage(PaymentErrorResponse errors) { } /** - * Returns the result of creating a payment if available, otherwise returns null. + * @return The result of creating a payment if available, otherwise returns {@code null}. */ public CreatePaymentResult getCreatePaymentResult() { return errors == null ? null : errors.getPaymentResult(); diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcDeclinedPayoutException.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcDeclinedPayoutException.java index 3098e771b..9f9979805 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcDeclinedPayoutException.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcDeclinedPayoutException.java @@ -26,7 +26,7 @@ private static String buildMessage(PayoutErrorResponse errors) { } /** - * Returns the result of creating a payout if available, otherwise returns null. + * @return The result of creating a payout if available, otherwise returns {@code null}. */ public PayoutResult getPayoutResult() { return errors == null ? null : errors.getPayoutResult(); diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcDeclinedRefundException.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcDeclinedRefundException.java index a9da623ab..af8e48dc5 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcDeclinedRefundException.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcDeclinedRefundException.java @@ -26,7 +26,7 @@ private static String buildMessage(RefundErrorResponse errors) { } /** - * Returns the result of creating a refund if available, otherwise returns null. + * @return The result of creating a refund if available, otherwise returns {@code null}. */ public RefundResult getRefundResult() { return errors == null ? null : errors.getRefundResult(); diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcDefaultConfiguration.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcDefaultConfiguration.java index 50882c047..52725cf8f 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcDefaultConfiguration.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcDefaultConfiguration.java @@ -13,7 +13,6 @@ public class GcDefaultConfiguration { /** The default number of maximum connections. */ public static final int DEFAULT_MAX_CONNECTIONS = 10; - /** GlobalCollect platform base URI. */ private URI baseUri; private int connectTimeout; @@ -24,20 +23,8 @@ public class GcDefaultConfiguration { private AuthorizationType authorizationType; - /** - * An identifier for the secret API key. The {@code apiKeyId} can be - * retrieved from the Configuration Center. This identifier is visible in - * the HTTP request and is also used to identify the correct account. - */ private String apiKeyId; - /** - * A shared secret. The shared secret can be retrieved from the - * Configuration Center. An {@code apiKeyId} and {@code secretApiKey} always - * go hand-in-hand, the difference is that {@code secretApiKey} is never - * visible in the HTTP request. This secret is used as input for the HMAC - * algorithm. - */ private String secretApiKey; private GcProxyConfiguration proxyConfiguration; @@ -66,67 +53,106 @@ private int getProperty(Properties properties, String key, int defaultValue) { return propertyValue != null ? Integer.parseInt(propertyValue) : defaultValue; } + /** + * Returns the GlobalCollect platform base URI. + */ public URI getBaseUri() { return baseUri; } - public void setBaseUri(URI baseUri) { this.baseUri = baseUri; } + public GcDefaultConfiguration withBaseUri(URI baseUri) { + this.baseUri = baseUri; + return this; + } + /** + * An identifier for the secret API key. The {@code apiKeyId} can be + * retrieved from the Configuration Center. This identifier is visible in + * the HTTP request and is also used to identify the correct account. + */ public String getApiKeyId() { return apiKeyId; } - public void setApiKeyId(String apiKeyId) { this.apiKeyId = apiKeyId; } + public GcDefaultConfiguration withApiKeyId(String apiKeyId) { + this.apiKeyId = apiKeyId; + return this; + } + /** + * A shared secret. The shared secret can be retrieved from the + * Configuration Center. An {@code apiKeyId} and {@code secretApiKey} always + * go hand-in-hand, the difference is that {@code secretApiKey} is never + * visible in the HTTP request. This secret is used as input for the HMAC + * algorithm. + */ public String getSecretApiKey() { return secretApiKey; } - public void setSecretApiKey(String secretApiKey) { this.secretApiKey = secretApiKey; } + public GcDefaultConfiguration withSecretApiKey(String secretApiKey) { + this.secretApiKey = secretApiKey; + return this; + } public AuthorizationType getAuthorizationType() { return authorizationType; } - public void setAuthorizationType(AuthorizationType authorizationType) { this.authorizationType = authorizationType; } + public GcDefaultConfiguration withAuthorizationType(AuthorizationType authorizationType) { + this.authorizationType = authorizationType; + return this; + } public int getConnectTimeout() { return connectTimeout; } - public void setConnectTimeout(int connectTimeout) { this.connectTimeout = connectTimeout; } + public GcDefaultConfiguration withConnectTimeout(int connectTimeout) { + this.connectTimeout = connectTimeout; + return this; + } public int getSocketTimeout() { return socketTimeout; } - public void setSocketTimeout(int socketTimeout) { this.socketTimeout = socketTimeout; } + public GcDefaultConfiguration withSocketTimeout(int socketTimeout) { + this.socketTimeout = socketTimeout; + return this; + } public int getMaxConnections() { return maxConnections; } - public void setMaxConnections(int maxConnections) { this.maxConnections = maxConnections; } + public GcDefaultConfiguration withMaxConnections(int maxConnections) { + this.maxConnections = maxConnections; + return this; + } public GcProxyConfiguration getProxyConfiguration() { return proxyConfiguration; } - public void setProxyConfiguration(GcProxyConfiguration proxyConfiguration) { this.proxyConfiguration = proxyConfiguration; } + public GcDefaultConfiguration withProxyConfiguration(GcProxyConfiguration proxyConfiguration) { + this.proxyConfiguration = proxyConfiguration; + return this; + } } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcFactory.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcFactory.java index 590f66758..8d15f5bcc 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcFactory.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcFactory.java @@ -28,17 +28,16 @@ private GcFactory() {} */ public static GcDefaultConfiguration createDefaultConfiguration(URI configurationFileUri, String apiKeyId, String secretApiKey) { try { - InputStream configurationFileInputStream = configurationFileUri.toURL().openStream(); Properties defaultProperties = new Properties(); + InputStream configurationFileInputStream = configurationFileUri.toURL().openStream(); try { defaultProperties.load(configurationFileInputStream); } finally { configurationFileInputStream.close(); } - GcDefaultConfiguration defaultConfiguration = new GcDefaultConfiguration(defaultProperties); - defaultConfiguration.setApiKeyId(apiKeyId); - defaultConfiguration.setSecretApiKey(secretApiKey); - return defaultConfiguration; + return new GcDefaultConfiguration(defaultProperties) + .withApiKeyId(apiKeyId) + .withSecretApiKey(secretApiKey); } catch (IOException e) { throw new RuntimeException("Unable to load default properties", e); } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcIdempotenceException.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcIdempotenceException.java new file mode 100644 index 000000000..cd275156a --- /dev/null +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcIdempotenceException.java @@ -0,0 +1,44 @@ +package com.globalcollect.gateway.sdk.java; + +import java.util.List; + +import com.globalcollect.gateway.sdk.java.gc.errors.definitions.APIError; + +/** + * Represents an error response from the GlobalCollect platform when an idempotent request failed because the first request has not + * finished yet. + */ +@SuppressWarnings("serial") +public class GcIdempotenceException extends GcApiException { + + private final String idempotenceKey; + private final Long idempotenceRequestTimestamp; + + public GcIdempotenceException(String idempotenceKey, Long idempotenceRequestTimestamp, + int statusCode, String responseBody, String errorId, List errors) { + super("the GlobalCollect platform returned a duplicate request error response", statusCode, responseBody, errorId, errors); + this.idempotenceKey = idempotenceKey; + this.idempotenceRequestTimestamp = idempotenceRequestTimestamp; + } + + public GcIdempotenceException(String message, String idempotenceKey, Long idempotenceRequestTimestamp, + int statusCode, String responseBody, String errorId, List errors) { + super(message, statusCode, responseBody, errorId, errors); + this.idempotenceKey = idempotenceKey; + this.idempotenceRequestTimestamp = idempotenceRequestTimestamp; + } + + /** + * @return The key that was used for the idempotent request. + */ + public String getIdempotenceKey() { + return idempotenceKey; + } + + /** + * @return The request timestamp of the first idempotent request with the same key. + */ + public Long getIdempotenceRequestTimestamp() { + return idempotenceRequestTimestamp; + } +} diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcMarshaller.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcMarshaller.java index 0d84e9dd5..2d728400e 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcMarshaller.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcMarshaller.java @@ -6,26 +6,25 @@ public interface GcMarshaller { /** - * Unmarshal a request object to a JSON string. + * Marshal a request object to a JSON string. */ String marshal(Object requestObject); /** - * Marshal a JSON string to a response object, in case of an error. + * Unmarshal a JSON string to a response object, in case of an error. * - * @param statusCode this can be used to determine a specific course of action in case the JSON is not valid - * @param requestPath used for exception message - * - * @throws GcMarshallerSyntaxException - * if the JSON is not a valid representation for an object of the given type + * @param statusCode This can be used to determine a specific course of action in case the JSON is not valid + * @param requestPath Used for exception message + * @param type The response object type. + * @throws GcMarshallerSyntaxException if the JSON is not a valid representation for an object of the given type */ - T unmarshal(String responseJson, int statusCode, String requestPath, TypeWrapper typeWrapper); + T unmarshal(String responseJson, int statusCode, String requestPath, Class type); /** - * Marshal a JSON string to a response object. + * Unmarshal a JSON string to a response object. * - * @throws GcMarshallerSyntaxException - * if the JSON is not a valid representation for an object of the given type + * @param type The response object type. + * @throws GcMarshallerSyntaxException if the JSON is not a valid representation for an object of the given type */ - T unmarshal(String responseJson, TypeWrapper typeWrapper); + T unmarshal(String responseJson, Class type); } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcProxyConfiguration.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcProxyConfiguration.java index 8eb0d3b80..ea8bae806 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcProxyConfiguration.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcProxyConfiguration.java @@ -70,40 +70,55 @@ private static int getPort(URI address) { public String getScheme() { return scheme; } - public void setScheme(String scheme) { this.scheme = scheme; } + public GcProxyConfiguration withScheme(String scheme) { + this.scheme = scheme; + return this; + } public String getHost() { return host; } - public void setHost(String host) { this.host = host; } + public GcProxyConfiguration withHost(String host) { + this.host = host; + return this; + } public int getPort() { return port; } - public void setPort(int port) { this.port = port; } + public GcProxyConfiguration withPort(int port) { + this.port = port; + return this; + } public String getUsername() { return username; } - public void setUsername(String username) { this.username = username; } + public GcProxyConfiguration withUsername(String username) { + this.username = username; + return this; + } public String getPassword() { return password; } - public void setPassword(String password) { this.password = password; } + public GcProxyConfiguration withPassword(String password) { + this.password = password; + return this; + } } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcResponse.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcResponse.java new file mode 100644 index 000000000..f778b4e19 --- /dev/null +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcResponse.java @@ -0,0 +1,74 @@ +package com.globalcollect.gateway.sdk.java; + +import java.util.Collections; +import java.util.List; + +/** + * Thrown when a response was received from the GlobalCollect platform which indicates an error. + */ +public class GcResponse { + + private final int statusCode; + private final String body; + private final List headers; + + public GcResponse(int statusCode, String body, List headers) { + this.statusCode = statusCode; + this.body = body; + this.headers = headers != null ? Collections.unmodifiableList(headers) : Collections.emptyList(); + } + + /** + * @return The HTTP status code that was returned by the GlobalCollect platform. + */ + public int getStatusCode() { + return statusCode; + } + + /** + * @return The raw response body that was returned by the GlobalCollect platform. + */ + public String getBody() { + return body; + } + + /** + * @return The headers that were returned by the GlobalCollect platform. Never {@code null}. + */ + public List getHeaders() { + return headers; + } + + /** + * @return The header with the given name, or {@code null} if there was no such header. + */ + public ResponseHeader getHeader(String headerName) { + for (ResponseHeader header : headers) { + if (header.getName().equalsIgnoreCase(headerName)) { + return header; + } + } + return null; + } + + /** + * @return The value header with the given name, or {@code null} if there was no such header. + */ + public String getHeaderValue(String headerName) { + ResponseHeader header = getHeader(headerName); + return header != null ? header.getValue() : null; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(getClass().getName()) + .append("[statusCode=").append(statusCode); + if (body != null && body.length() > 0) { + sb.append(",body='").append(body).append("'"); + } + if (!headers.isEmpty()) { + sb.append(",headers=").append(headers); + } + return sb.append("]").toString(); + } +} diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcResponseException.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcResponseException.java index 2e626cc6c..651a34b77 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcResponseException.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcResponseException.java @@ -1,31 +1,73 @@ package com.globalcollect.gateway.sdk.java; +import java.util.List; + /** * Thrown when a response was received from the GlobalCollect platform which indicates an error. */ @SuppressWarnings("serial") public class GcResponseException extends RuntimeException { - private final int statusCode; - private final String body; + private final GcResponse response; - public GcResponseException(int statusCode, String body) { + public GcResponseException(GcResponse response) { super("the GlobalCollect platform returned an error response"); - this.statusCode = statusCode; - this.body = body; + this.response = response; + } + + /** + * @return The response that was returned by the GlobalCollect platform. + */ + public GcResponse getResponse() { + return response; } /** * @return The HTTP status code that was returned by the GlobalCollect platform. */ public int getStatusCode() { - return statusCode; + return response.getStatusCode(); } /** * @return The raw response body that was returned by the GlobalCollect platform. */ public String getBody() { - return body; + return response.getBody(); + } + + /** + * @return The headers that were returned by the GlobalCollect platform. Never {@code null}. + */ + public List getHeaders() { + return response.getHeaders(); + } + + /** + * @return The header with the given name, or {@code null} if there was no such header. + */ + public ResponseHeader getHeader(String headerName) { + return response.getHeader(headerName); + } + + /** + * @return The value header with the given name, or {@code null} if there was no such header. + */ + public String getHeaderValue(String headerName) { + return response.getHeaderValue(headerName); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(super.toString()); + int statusCode = response.getStatusCode(); + if (statusCode > 0) { + sb.append("; statusCode=").append(statusCode); + } + String responseBody = response.getBody(); + if (responseBody != null && responseBody.length() > 0) { + sb.append("; responseBody='").append(responseBody).append("'"); + } + return sb.toString(); } } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcSession.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcSession.java index 335ebd312..522a9b1bf 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcSession.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcSession.java @@ -6,20 +6,17 @@ public interface GcSession { /** - * @return The {@link GcConnection} object associated with this session. - * Never {@code null}. + * @return The {@link GcConnection} object associated with this session. Never {@code null}. */ GcConnection getConnection(); /** - * @return The {@link GcMetaDataProvider} object associated with this session. - * Never {@code null}. + * @return The {@link GcMetaDataProvider} object associated with this session. Never {@code null}. */ GcMetaDataProvider getMetaDataProvider(); /** - * @return The {@link GcAuthenticator} object associated with this session. - * Never {@code null}. + * @return The {@link GcAuthenticator} object associated with this session. Never {@code null}. */ GcAuthenticator getAuthenticator(); } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/GcSessionBuilder.java b/src/main/java/com/globalcollect/gateway/sdk/java/GcSessionBuilder.java index 43a80c469..f39ef1477 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/GcSessionBuilder.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/GcSessionBuilder.java @@ -23,8 +23,7 @@ public interface GcSessionBuilder { /** * Creates a fully initialized {@link GcSession} object. * - * @throws IllegalArgumentException - * if not all required components are set + * @throws IllegalArgumentException if not all required components are set */ GcSession build(); } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/RequestHeader.java b/src/main/java/com/globalcollect/gateway/sdk/java/RequestHeader.java index 134d08b8d..800b6e822 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/RequestHeader.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/RequestHeader.java @@ -1,12 +1,12 @@ package com.globalcollect.gateway.sdk.java; /** - * A single request parameter. + * A single request header. Immutable. */ public class RequestHeader { - private String name; - private String value; + private final String name; + private final String value; public RequestHeader(String name, String value) { if (name == null || name.trim().isEmpty()) { @@ -21,7 +21,7 @@ public String getName(){ }; /** - * Returns the unencoded value. + * @return The unencoded value. */ public String getValue() { return value; diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/RequestParam.java b/src/main/java/com/globalcollect/gateway/sdk/java/RequestParam.java index 0981cfab7..b85eacc57 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/RequestParam.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/RequestParam.java @@ -1,12 +1,12 @@ package com.globalcollect.gateway.sdk.java; /** - * A single request parameter. + * A single request parameter. Immutable. */ public class RequestParam { - private String name; - private String value; + private final String name; + private final String value; public RequestParam(String name, String value) { if (name == null || name.trim().isEmpty()) { diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/ResponseHeader.java b/src/main/java/com/globalcollect/gateway/sdk/java/ResponseHeader.java new file mode 100644 index 000000000..44f88f868 --- /dev/null +++ b/src/main/java/com/globalcollect/gateway/sdk/java/ResponseHeader.java @@ -0,0 +1,34 @@ +package com.globalcollect.gateway.sdk.java; + +/** + * A single response header. Immutable. + */ +public class ResponseHeader { + + private final String name; + private final String value; + + public ResponseHeader(String name, String value) { + if (name == null) { + throw new IllegalArgumentException("name is required"); + } + this.name = name; + this.value = value; + } + + public String getName(){ + return name; + }; + + /** + * @return The unencoded value. + */ + public String getValue() { + return value; + } + + @Override + public String toString() { + return getName() + ":" + getValue(); + } +} diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/TypeWrapper.java b/src/main/java/com/globalcollect/gateway/sdk/java/TypeWrapper.java deleted file mode 100644 index 8c6e9d63b..000000000 --- a/src/main/java/com/globalcollect/gateway/sdk/java/TypeWrapper.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.globalcollect.gateway.sdk.java; - -import java.lang.reflect.Type; - -/** - * This wrapper object can be used to pass {@link Type} information which would otherwise not be available at runtime. - */ -public class TypeWrapper { - - private final Class type; - - public TypeWrapper(Class type) { - this.type = type; - } - - public Class getType() { - return this.type; - } -} diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcAuthenticator.java b/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcAuthenticator.java index 656897f02..6f3be5b85 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcAuthenticator.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcAuthenticator.java @@ -40,8 +40,6 @@ public int compare(RequestHeader header1, RequestHeader header2) { private final String secretApiKey; /** - * Constructor. - * * @param authorizationType * Based on this value both the GlobalCollect platform and the merchant know * which security implementation is used. A version number is diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcCommunicator.java b/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcCommunicator.java index 4a8bf0271..0d8876ad0 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcCommunicator.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcCommunicator.java @@ -9,15 +9,21 @@ import java.util.Locale; import java.util.TimeZone; +import org.apache.http.HttpStatus; + +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcAuthenticator; +import com.globalcollect.gateway.sdk.java.GcCommunicationException; import com.globalcollect.gateway.sdk.java.GcCommunicator; import com.globalcollect.gateway.sdk.java.GcConnection; import com.globalcollect.gateway.sdk.java.GcMarshaller; +import com.globalcollect.gateway.sdk.java.GcNotFoundException; import com.globalcollect.gateway.sdk.java.GcParamRequest; +import com.globalcollect.gateway.sdk.java.GcResponse; +import com.globalcollect.gateway.sdk.java.GcResponseException; import com.globalcollect.gateway.sdk.java.GcSession; import com.globalcollect.gateway.sdk.java.RequestHeader; import com.globalcollect.gateway.sdk.java.RequestParam; -import com.globalcollect.gateway.sdk.java.TypeWrapper; /** * {@link GcCommunicator} implementation based on the components provided by {@link GcSession}. @@ -45,7 +51,8 @@ public void close() throws IOException { } @Override - public

O get(String relativePath, List requestHeaders, P requestParametersObject, TypeWrapper responseTypeWrapper) { + public

O get(String relativePath, List requestHeaders, P requestParametersObject, + Class responseType, CallContext context) { GcConnection connection = session.getConnection(); @@ -56,14 +63,15 @@ public

O get(String relativePath, List(); } - addGenericHeaders("GET", uri, requestHeaders); + addGenericHeaders("GET", uri, requestHeaders, context); - String responseJson = connection.get(relativePath, requestHeaders, requestParameters); - return marshaller.unmarshal(responseJson, responseTypeWrapper); + GcResponse response = connection.get(uri, requestHeaders); + return processResponse(response, responseType, relativePath, context); } @Override - public

O delete(String relativePath, List requestHeaders, P requestrequestParameters, TypeWrapper responseTypeWrapper) { + public

O delete(String relativePath, List requestHeaders, P requestrequestParameters, + Class responseType, CallContext context) { GcConnection connection = session.getConnection(); @@ -74,14 +82,15 @@ public

O delete(String relativePath, List(); } - addGenericHeaders("DELETE", uri, requestHeaders); + addGenericHeaders("DELETE", uri, requestHeaders, context); - String responseJson = connection.delete(relativePath, requestHeaders, requestParameters); - return marshaller.unmarshal(responseJson, responseTypeWrapper); + GcResponse response = connection.delete(uri, requestHeaders); + return processResponse(response, responseType, relativePath, context); } @Override - public

O post(String relativePath, List requestHeaders, P requestParamObject, Object requestBody, TypeWrapper responseTypeWrapper) { + public

O post(String relativePath, List requestHeaders, P requestParamObject, Object requestBody, + Class responseType, CallContext context) { GcConnection connection = session.getConnection(); @@ -99,14 +108,15 @@ public

O post(String relativePath, List O put(String relativePath, List requestHeaders, P requestParamObject, Object requestBody, TypeWrapper responseTypeWrapper) { + public

O put(String relativePath, List requestHeaders, P requestParamObject, Object requestBody, + Class responseType, CallContext context) { GcConnection connection = session.getConnection(); @@ -124,10 +134,10 @@ public

O put(String relativePath, List requestHeaders) { + protected void addGenericHeaders(String httpMethod, URI uri, List requestHeaders, CallContext context) { // add server meta info headers requestHeaders.addAll(session.getMetaDataProvider().getServerMetaDataHeaders()); @@ -143,6 +153,11 @@ protected void addGenericHeaders(String httpMethod, URI uri, List // add date header requestHeaders.add(new RequestHeader("Date", getHeaderDateString())); + // add context specific headers + if (context != null && context.getIdempotenceKey() != null) { + requestHeaders.add(new RequestHeader("X-GCS-Idempotence-Key", context.getIdempotenceKey())); + } + // add signature GcAuthenticator authenticator = session.getAuthenticator(); String authenticationSignature = authenticator.createSimpleAuthenticationSignature(httpMethod, uri, requestHeaders); @@ -158,4 +173,51 @@ protected String getHeaderDateString() { dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); return dateFormat.format(calendar.getTime()); } + + protected O processResponse(GcResponse response, Class responseType, String requestPath, CallContext context) { + + if (context != null) { + updateContext(response, context); + } + throwExceptionIfNecessary(response, requestPath); + return marshaller.unmarshal(response.getBody(), responseType); + } + + protected void updateContext(GcResponse response, CallContext context) { + + String idempotenceRequestTimestampValue = response.getHeaderValue("X-GCS-Idempotence-Request-Timestamp"); + if (idempotenceRequestTimestampValue != null) { + Long idempotenceRequestTimestamp = Long.valueOf(idempotenceRequestTimestampValue); + context.setIdempotenceRequestTimestamp(idempotenceRequestTimestamp); + } else { + context.setIdempotenceRequestTimestamp(null); + } + } + + /** + * Checks the {@link GcResponse} for errors and throws an exception if necessary. + */ + protected void throwExceptionIfNecessary(GcResponse response, String requestPath) throws GcResponseException, GcCommunicationException, GcNotFoundException { + + int statusCode = response.getStatusCode(); + // status codes in the 100 or 300 range are not expected + if (statusCode < 200 || statusCode >= 300) { + String body = response.getBody(); + if (body != null && !isJson(response)) { + GcResponseException cause = new GcResponseException(response); + if (statusCode == HttpStatus.SC_NOT_FOUND) { + throw new GcNotFoundException("The requested resource was not found; invalid path: " + requestPath, cause); + } else { + throw new GcCommunicationException(cause); + } + } else { + throw new GcResponseException(response); + } + } + } + + private boolean isJson(GcResponse response) { + String contentType = response.getHeaderValue("Content-Type"); + return contentType == null || "application/json".equalsIgnoreCase(contentType) || contentType.toLowerCase().startsWith("application/json"); + } } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcConnection.java b/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcConnection.java index 34527686e..4135a7d04 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcConnection.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcConnection.java @@ -5,6 +5,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.List; import org.apache.http.Header; @@ -49,9 +50,10 @@ import com.globalcollect.gateway.sdk.java.GcConnection; import com.globalcollect.gateway.sdk.java.GcDefaultConfiguration; import com.globalcollect.gateway.sdk.java.GcProxyConfiguration; -import com.globalcollect.gateway.sdk.java.GcResponseException; +import com.globalcollect.gateway.sdk.java.GcResponse; import com.globalcollect.gateway.sdk.java.RequestHeader; import com.globalcollect.gateway.sdk.java.RequestParam; +import com.globalcollect.gateway.sdk.java.ResponseHeader; /** * {@link GcConnection} implementation based on {@link HttpClient}. @@ -223,9 +225,8 @@ public URI toURI(String relativePath, List requestParameters) { } @Override - public String get(String relativePath, List requestHeaders, List requestParameters) { + public GcResponse get(URI uri, List requestHeaders) { - URI uri = toURI(relativePath, requestParameters); HttpGet httpGet = new HttpGet(uri); httpGet.setConfig(requestConfig); addHeaders(httpGet, requestHeaders); @@ -233,9 +234,8 @@ public String get(String relativePath, List requestHeaders, List< } @Override - public String delete(String relativePath, List requestHeaders, List requestParameters) { + public GcResponse delete(URI uri, List requestHeaders) { - URI uri = toURI(relativePath, requestParameters); HttpDelete httpDelete = new HttpDelete(uri); httpDelete.setConfig(requestConfig); addHeaders(httpDelete, requestHeaders); @@ -243,9 +243,8 @@ public String delete(String relativePath, List requestHeaders, Li } @Override - public String post(String relativePath, List requestHeaders, List requestParameters, String body) { + public GcResponse post(URI uri, List requestHeaders, String body) { - URI uri = toURI(relativePath, requestParameters); HttpPost httpPost = new HttpPost(uri); httpPost.setConfig(requestConfig); addHeaders(httpPost, requestHeaders); @@ -257,9 +256,8 @@ public String post(String relativePath, List requestHeaders, List } @Override - public String put(String relativePath, List requestHeaders, List requestParameters, String body) { + public GcResponse put(URI uri, List requestHeaders, String body) { - URI uri = toURI(relativePath, requestParameters); HttpPut httpPut = new HttpPut(uri); httpPut.setConfig(requestConfig); addHeaders(httpPut, requestHeaders); @@ -270,14 +268,16 @@ public String put(String relativePath, List requestHeaders, List< return executeRequest(httpPut); } - protected String executeRequest(HttpUriRequest request) { + protected GcResponse executeRequest(HttpUriRequest request) { try { CloseableHttpResponse httpResponse = httpClient.execute(request); HttpEntity entity = httpResponse.getEntity(); try { - throwExceptionIfNecessary(httpResponse); - return entity == null ? null : EntityUtils.toString(entity, CHARSET); + int statusCode = httpResponse.getStatusLine().getStatusCode(); + String body = entity == null ? null : EntityUtils.toString(entity, CHARSET); + List headers = getHeaders(httpResponse); + return new GcResponse(statusCode, body, headers); } finally { /* @@ -295,34 +295,6 @@ protected String executeRequest(HttpUriRequest request) { } } - /** - * Checks the {@link HttpResponse} for errors and throws an exception if necessary. - */ - protected void throwExceptionIfNecessary(HttpResponse httpResponse) throws GcResponseException, IOException { - - int statusCode = httpResponse.getStatusLine().getStatusCode(); - if (statusCode >= 200 && statusCode < 300) { // status codes in the 300 range are not expected - return; - } else { - String body = null; - HttpEntity entity = httpResponse.getEntity(); - if (entity != null) { - body = EntityUtils.toString(entity, CHARSET); - } - if (body != null && !isJson(httpResponse)) { - throw new GcCommunicationException(new GcResponseException(statusCode, body)); - } else { - throw new GcResponseException(statusCode, body); - } - } - } - - private boolean isJson(HttpResponse httpResponse) { - Header header = httpResponse.getFirstHeader("Content-Type"); - String contentType = header != null ? header.getValue() : null; - return contentType == null || "application/json".equalsIgnoreCase(contentType) || contentType.toLowerCase().startsWith("application/json"); - } - protected void addHeaders(HttpRequestBase httpRequestBase, List requestHeaders) { if (requestHeaders != null) { for (RequestHeader requestHeader: requestHeaders) { @@ -330,4 +302,13 @@ protected void addHeaders(HttpRequestBase httpRequestBase, List r } } } + + protected List getHeaders(HttpResponse httpResponse) { + Header[] headers = httpResponse.getAllHeaders(); + List result = new ArrayList(headers.length); + for (Header header : headers) { + result.add(new ResponseHeader(header.getName(), header.getValue())); + } + return result; + } } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcMarshaller.java b/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcMarshaller.java index 4ee80a532..2c9de6d0f 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcMarshaller.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcMarshaller.java @@ -5,7 +5,6 @@ import com.globalcollect.gateway.sdk.java.GcMarshaller; import com.globalcollect.gateway.sdk.java.GcMarshallerSyntaxException; import com.globalcollect.gateway.sdk.java.GcNotFoundException; -import com.globalcollect.gateway.sdk.java.TypeWrapper; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; @@ -14,19 +13,22 @@ */ public class DefaultGcMarshaller implements GcMarshaller { + // Gson instances are thread-safe, so reuse one single instance + private static final Gson GSON = new Gson(); + public static final DefaultGcMarshaller INSTANCE = new DefaultGcMarshaller(); protected DefaultGcMarshaller() {} @Override public String marshal(Object requestObject) { - return new Gson().toJson(requestObject); + return GSON.toJson(requestObject); } @Override - public T unmarshal(String responseJson, int statusCode, String requestPath, TypeWrapper typeWrapper) { + public T unmarshal(String responseJson, int statusCode, String requestPath, Class type) { try { - return new Gson().fromJson(responseJson, typeWrapper.getType()); + return GSON.fromJson(responseJson, type); } catch (JsonSyntaxException e) { if (statusCode == HttpStatus.SC_NOT_FOUND) { throw new GcNotFoundException("The requested resource was not found; invalid path: " + requestPath, e); @@ -37,9 +39,9 @@ public T unmarshal(String responseJson, int statusCode, String requestPath, } @Override - public T unmarshal(String responseJson, TypeWrapper typeWrapper) { + public T unmarshal(String responseJson, Class type) { try { - return new Gson().fromJson(responseJson, typeWrapper.getType()); + return GSON.fromJson(responseJson, type); } catch (JsonSyntaxException e) { throw new GcMarshallerSyntaxException(e); } diff --git a/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcMetaDataProvider.java b/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcMetaDataProvider.java index 517380043..7f1178df0 100644 --- a/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcMetaDataProvider.java +++ b/src/main/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcMetaDataProvider.java @@ -1,5 +1,7 @@ package com.globalcollect.gateway.sdk.java.defaultimpl; +import java.io.IOException; +import java.io.InputStream; import java.nio.charset.Charset; import java.util.Collection; import java.util.Collections; @@ -9,7 +11,6 @@ import com.globalcollect.gateway.sdk.java.GcMetaDataProvider; import com.globalcollect.gateway.sdk.java.RequestHeader; -import com.google.gson.Gson; /** * Default {@link GcMetaDataProvider} implementation. @@ -32,8 +33,8 @@ public DefaultGcMetaDataProvider() { serverMetaInfo.platformIdentifier = getPlatformIdentifier(); serverMetaInfo.sdkIdentifier = getSdkIdentifier(); - Gson gson = new Gson(); - RequestHeader serverMetaInfoHeader = new RequestHeader("X-GCS-ServerMetaInfo", Base64.encodeBase64String(gson.toJson(serverMetaInfo).getBytes(CHARSET))); + String serverMetaInfoString = DefaultGcMarshaller.INSTANCE.marshal(serverMetaInfo); + RequestHeader serverMetaInfoHeader = new RequestHeader("X-GCS-ServerMetaInfo", Base64.encodeBase64String(serverMetaInfoString.getBytes(CHARSET))); metaDataHeaders = Collections.singletonList(serverMetaInfoHeader); } @@ -64,6 +65,24 @@ protected String getPlatformIdentifier() { } protected String getSdkIdentifier() { - return "1.0"; + String sdkIdentifier = "unknown"; + + // don't use getClass() because of possible overrides + InputStream pomProperties = DefaultGcMetaDataProvider.class.getResourceAsStream("/META-INF/maven/com.ingenico.connect.gateway/connect-sdk-java/pom.properties"); + if (pomProperties != null) { + try { + try { + Properties properties = new Properties(); + properties.load(pomProperties); + sdkIdentifier = properties.getProperty("version", sdkIdentifier); + } finally { + pomProperties.close(); + } + } catch (IOException e) { + // ignore the exception + } + } + + return sdkIdentifier; } } diff --git a/src/test/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcConnectionIdempotenceTest.java b/src/test/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcConnectionIdempotenceTest.java new file mode 100644 index 000000000..171f17f0f --- /dev/null +++ b/src/test/java/com/globalcollect/gateway/sdk/java/defaultimpl/DefaultGcConnectionIdempotenceTest.java @@ -0,0 +1,364 @@ +package com.globalcollect.gateway.sdk.java.defaultimpl; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.apache.http.Header; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.localserver.LocalServerTestBase; +import org.apache.http.protocol.HttpContext; +import org.apache.http.protocol.HttpRequestHandler; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.globalcollect.gateway.sdk.java.CallContext; +import com.globalcollect.gateway.sdk.java.GcAuthenticator; +import com.globalcollect.gateway.sdk.java.GcCommunicator; +import com.globalcollect.gateway.sdk.java.GcConnection; +import com.globalcollect.gateway.sdk.java.GcDeclinedPaymentException; +import com.globalcollect.gateway.sdk.java.GcFactory; +import com.globalcollect.gateway.sdk.java.GcIdempotenceException; +import com.globalcollect.gateway.sdk.java.GcMetaDataProvider; +import com.globalcollect.gateway.sdk.java.GcSession; +import com.globalcollect.gateway.sdk.java.gc.GcClient; +import com.globalcollect.gateway.sdk.java.gc.fei.definitions.Address; +import com.globalcollect.gateway.sdk.java.gc.fei.definitions.AmountOfMoney; +import com.globalcollect.gateway.sdk.java.gc.fei.definitions.Card; +import com.globalcollect.gateway.sdk.java.gc.payment.CreatePaymentRequest; +import com.globalcollect.gateway.sdk.java.gc.payment.CreatePaymentResponse; +import com.globalcollect.gateway.sdk.java.gc.payment.definitions.CardPaymentMethodSpecificInput; +import com.globalcollect.gateway.sdk.java.gc.payment.definitions.Customer; +import com.globalcollect.gateway.sdk.java.gc.payment.definitions.Order; + +@RunWith(MockitoJUnitRunner.class) +public class DefaultGcConnectionIdempotenceTest extends LocalServerTestBase { + + @Mock HttpRequestHandler requestHandler; + + @Test + public void testIdempotenceFirstRequest() throws Exception { + + final String body = getResource("idempotence_success.json"); + final String idempotenceKey = UUID.randomUUID().toString(); + + Map responseHeaders = new HashMap(1); + responseHeaders.put("Location", "http://localhost/v1/20000/payments/000002000020142549460000100001"); + + Map requestHeaders = new HashMap(); + + Mockito.doAnswer(setResponse(body, 201, responseHeaders, requestHeaders)) + .when(requestHandler).handle(Matchers.any(), Matchers.any(), Matchers.any()); + + serverBootstrap.registerHandler("/v1/20000/payments", requestHandler); + HttpHost host = start(); + + CallContext context = new CallContext().withIdempotenceKey(idempotenceKey); + + GcClient client = createClient(host); + try { + + CreatePaymentRequest request = createRequest(); + + CreatePaymentResponse response = client.merchant("20000").payments().create(request, context); + + Assert.assertNotNull(response); + Assert.assertNotNull(response.getPayment()); + Assert.assertNotNull(response.getPayment().getId()); + + } finally { + client.close(); + } + + Assert.assertEquals(idempotenceKey, requestHeaders.get("X-GCS-Idempotence-Key")); + + Assert.assertEquals(idempotenceKey, context.getIdempotenceKey()); + Assert.assertNull(context.getIdempotenceRequestTimestamp()); + } + + @Test + public void testIdempotenceSecondRequest() throws Exception { + + String body = getResource("idempotence_success.json"); + + final Long idempotenceRequestTimestamp = System.currentTimeMillis(); + + Map responseHeaders = new HashMap(2); + responseHeaders.put("Location", "http://localhost/v1/20000/payments/000002000020142549460000100001"); + responseHeaders.put("X-GCS-Idempotence-Request-Timestamp", idempotenceRequestTimestamp.toString()); + + Map requestHeaders = new HashMap(); + + Mockito.doAnswer(setResponse(body, 201, responseHeaders, requestHeaders)) + .when(requestHandler).handle(Matchers.any(), Matchers.any(), Matchers.any()); + + serverBootstrap.registerHandler("/v1/20000/payments", requestHandler); + HttpHost host = start(); + + final String idempotenceKey = UUID.randomUUID().toString(); + CallContext context = new CallContext().withIdempotenceKey(idempotenceKey); + + GcClient client = createClient(host); + try { + + CreatePaymentRequest request = createRequest(); + + CreatePaymentResponse response = client.merchant("20000").payments().create(request, context); + + Assert.assertNotNull(response); + Assert.assertNotNull(response.getPayment()); + Assert.assertNotNull(response.getPayment().getId()); + + } finally { + client.close(); + } + + Assert.assertEquals(idempotenceKey, requestHeaders.get("X-GCS-Idempotence-Key")); + + Assert.assertEquals(idempotenceKey, context.getIdempotenceKey()); + Assert.assertEquals(idempotenceRequestTimestamp, context.getIdempotenceRequestTimestamp()); + } + + @Test + public void testIdempotenceFirstFailure() throws Exception { + + String body = getResource("idempotence_rejected.json"); + + Map responseHeaders = new HashMap(); + + Map requestHeaders = new HashMap(); + + Mockito.doAnswer(setResponse(body, 402, responseHeaders, requestHeaders)) + .when(requestHandler).handle(Matchers.any(), Matchers.any(), Matchers.any()); + + serverBootstrap.registerHandler("/v1/20000/payments", requestHandler); + HttpHost host = start(); + + final String idempotenceKey = UUID.randomUUID().toString(); + CallContext context = new CallContext().withIdempotenceKey(idempotenceKey); + + GcClient client = createClient(host); + try { + + CreatePaymentRequest request = createRequest(); + + client.merchant("20000").payments().create(request, context); + + Assert.fail("Expected GcDeclinedPaymentException"); + + } catch (GcDeclinedPaymentException e) { + + Assert.assertEquals(402, e.getStatusCode()); + Assert.assertEquals(body, e.getResponseBody()); + + } finally { + client.close(); + } + + Assert.assertEquals(idempotenceKey, requestHeaders.get("X-GCS-Idempotence-Key")); + + Assert.assertEquals(idempotenceKey, context.getIdempotenceKey()); + Assert.assertNull(context.getIdempotenceRequestTimestamp()); + } + + @Test + public void testIdempotenceSecondFailure() throws Exception { + + String body = getResource("idempotence_rejected.json"); + + final Long idempotenceRequestTimestamp = System.currentTimeMillis(); + + Map responseHeaders = new HashMap(2); + responseHeaders.put("X-GCS-Idempotence-Request-Timestamp", idempotenceRequestTimestamp.toString()); + + Map requestHeaders = new HashMap(); + + Mockito.doAnswer(setResponse(body, 402, responseHeaders, requestHeaders)) + .when(requestHandler).handle(Matchers.any(), Matchers.any(), Matchers.any()); + + serverBootstrap.registerHandler("/v1/20000/payments", requestHandler); + HttpHost host = start(); + + final String idempotenceKey = UUID.randomUUID().toString(); + CallContext context = new CallContext().withIdempotenceKey(idempotenceKey); + + GcClient client = createClient(host); + try { + + CreatePaymentRequest request = createRequest(); + + client.merchant("20000").payments().create(request, context); + + Assert.fail("Expected GcDeclinedPaymentException"); + + } catch (GcDeclinedPaymentException e) { + + Assert.assertEquals(402, e.getStatusCode()); + Assert.assertEquals(body, e.getResponseBody()); + + } finally { + client.close(); + } + + Assert.assertEquals(idempotenceKey, requestHeaders.get("X-GCS-Idempotence-Key")); + + Assert.assertEquals(idempotenceKey, context.getIdempotenceKey()); + Assert.assertEquals(idempotenceRequestTimestamp, context.getIdempotenceRequestTimestamp()); + } + + @Test + public void testIdempotenceDuplicateRequest() throws Exception { + + String body = getResource("idempotence_duplicate_failure.json"); + + final Long idempotenceRequestTimestamp = System.currentTimeMillis(); + + Map responseHeaders = new HashMap(2); + responseHeaders.put("Location", "http://localhost/v1/20000/payments/000002000020142549460000100001"); + responseHeaders.put("X-GCS-Idempotence-Request-Timestamp", idempotenceRequestTimestamp.toString()); + + Map requestHeaders = new HashMap(); + + Mockito.doAnswer(setResponse(body, 409, responseHeaders, requestHeaders)) + .when(requestHandler).handle(Matchers.any(), Matchers.any(), Matchers.any()); + + serverBootstrap.registerHandler("/v1/20000/payments", requestHandler); + HttpHost host = start(); + + final String idempotenceKey = UUID.randomUUID().toString(); + CallContext context = new CallContext().withIdempotenceKey(idempotenceKey); + + GcClient client = createClient(host); + try { + + CreatePaymentRequest request = createRequest(); + + client.merchant("20000").payments().create(request, context); + + Assert.fail("Expected GcIdempotenceException"); + + } catch (GcIdempotenceException e) { + + Assert.assertEquals(409, e.getStatusCode()); + Assert.assertEquals(body, e.getResponseBody()); + Assert.assertEquals(idempotenceKey, e.getIdempotenceKey()); + Assert.assertEquals(idempotenceRequestTimestamp, e.getIdempotenceRequestTimestamp()); + + } finally { + client.close(); + } + + Assert.assertEquals(idempotenceKey, requestHeaders.get("X-GCS-Idempotence-Key")); + + Assert.assertEquals(idempotenceKey, context.getIdempotenceKey()); + Assert.assertEquals(idempotenceRequestTimestamp, context.getIdempotenceRequestTimestamp()); + } + + private String getResource(String resource) { + StringWriter sw = new StringWriter(); + try { + Reader reader = new InputStreamReader(getClass().getResourceAsStream(resource)); + try { + char[] buffer = new char[1024]; + int len; + while ((len = reader.read(buffer)) != -1) { + sw.write(buffer, 0, len); + } + } finally { + reader.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + return sw.toString(); + } + + private Answer setResponse(final String body, final int statusCode, final Map responseHeaders, + final Map requestHeaders) { + + return new Answer() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + HttpRequest request = invocation.getArgumentAt(0, HttpRequest.class); + HttpResponse response = invocation.getArgumentAt(1, HttpResponse.class); + + if (requestHeaders != null) { + for (Header header : request.getAllHeaders()) { + requestHeaders.put(header.getName(), header.getValue()); + } + } + + response.setStatusCode(statusCode); + response.setHeader("Content-Type", "application/json"); + + for (Map.Entry entry : responseHeaders.entrySet()) { + response.setHeader(entry.getKey(), entry.getValue()); + } + + response.setEntity(new StringEntity(body, ContentType.APPLICATION_JSON)); + + return null; + } + }; + } + + @SuppressWarnings("resource") + private GcClient createClient(HttpHost host) { + + GcConnection connection = new DefaultGcConnection(host.getSchemeName(), host.getHostName(), host.getPort(), "/v1", 500, 500); + GcAuthenticator authenticator = new DefaultGcAuthenticator(AuthorizationType.V1HMAC, "apiKey", "secret"); + GcMetaDataProvider metaDataProvider = new DefaultGcMetaDataProvider(); + GcSession session = new DefaultGcSession(connection, authenticator, metaDataProvider); + GcCommunicator communicator = GcFactory.createCommunicator(session); + GcClient client = GcFactory.createClient(communicator); + return client; + } + + 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; + } +} diff --git a/src/test/java/com/globalcollect/gateway/sdk/java/gc/merchant/payments/PaymentsClientTest.java b/src/test/java/com/globalcollect/gateway/sdk/java/gc/merchant/payments/PaymentsClientTest.java index 47416f172..8eb00e304 100644 --- a/src/test/java/com/globalcollect/gateway/sdk/java/gc/merchant/payments/PaymentsClientTest.java +++ b/src/test/java/com/globalcollect/gateway/sdk/java/gc/merchant/payments/PaymentsClientTest.java @@ -5,6 +5,7 @@ import java.io.Reader; import java.io.StringWriter; import java.net.URI; +import java.util.Arrays; import java.util.List; import org.junit.Assert; @@ -16,16 +17,24 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.runners.MockitoJUnitRunner; import org.mockito.stubbing.Answer; +import org.mockito.stubbing.OngoingStubbing; +import com.globalcollect.gateway.sdk.java.CallContext; import com.globalcollect.gateway.sdk.java.GcApiException; +import com.globalcollect.gateway.sdk.java.GcCommunicationException; import com.globalcollect.gateway.sdk.java.GcConnection; import com.globalcollect.gateway.sdk.java.GcDeclinedPaymentException; import com.globalcollect.gateway.sdk.java.GcFactory; +import com.globalcollect.gateway.sdk.java.GcIdempotenceException; +import com.globalcollect.gateway.sdk.java.GcNotFoundException; +import com.globalcollect.gateway.sdk.java.GcReferenceException; +import com.globalcollect.gateway.sdk.java.GcResponse; import com.globalcollect.gateway.sdk.java.GcResponseException; import com.globalcollect.gateway.sdk.java.GcSession; import com.globalcollect.gateway.sdk.java.GcValidationException; import com.globalcollect.gateway.sdk.java.RequestHeader; import com.globalcollect.gateway.sdk.java.RequestParam; +import com.globalcollect.gateway.sdk.java.ResponseHeader; import com.globalcollect.gateway.sdk.java.defaultimpl.AuthorizationType; import com.globalcollect.gateway.sdk.java.defaultimpl.DefaultGcAuthenticator; import com.globalcollect.gateway.sdk.java.defaultimpl.DefaultGcMetaDataProvider; @@ -67,36 +76,9 @@ public void testCreateSuccess() { GcClient client = GcFactory.createClient(session); String responseBody = getResource("pending_approval.json"); - Mockito.when(connection.post(Mockito.anyString(), Mockito.>any(), Mockito.>any(), Mockito.anyString())) - .thenReturn(responseBody); + whenPost().thenReturn(new GcResponse(201, responseBody, null)); - 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); + CreatePaymentRequest body = createRequest(); CreatePaymentResponse response = client.merchant("merchantId").payments().create(body); Assert.assertEquals("000002000020142549460000100001", response.getPayment().getId()); @@ -111,36 +93,9 @@ public void testCreateRejected() { GcClient client = GcFactory.createClient(session); String responseBody = getResource("rejected.json"); - Mockito.when(connection.post(Mockito.anyString(), Mockito.>any(), Mockito.>any(), Mockito.anyString())) - .thenThrow(new GcResponseException(400, responseBody)); - - 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); + whenPost().thenReturn(new GcResponse(400, responseBody, null)); - 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); + CreatePaymentRequest body = createRequest(); try { client.merchant("merchantId").payments().create(body); @@ -163,92 +118,134 @@ public void testCreateInvalidRequest() { GcClient client = GcFactory.createClient(session); String responseBody = getResource("invalid_request.json"); - Mockito.when(connection.post(Mockito.anyString(), Mockito.>any(), Mockito.>any(), Mockito.anyString())) - .thenThrow(new GcResponseException(400, responseBody)); + whenPost().thenReturn(new GcResponse(400, responseBody, null)); - CreatePaymentRequest body = new CreatePaymentRequest(); + CreatePaymentRequest body = createRequest(); - Order order = new Order(); + try { + client.merchant("merchantId").payments().create(body); + Assert.fail("Expected GcValidationException"); + } catch (GcValidationException e) { + Assert.assertTrue(e.toString().contains(responseBody)); + } + } - AmountOfMoney amountOfMoney = new AmountOfMoney(); - amountOfMoney.setAmount(2345L); - amountOfMoney.setCurrencyCode("CAD"); - order.setAmountOfMoney(amountOfMoney); + /** + * Tests that a 401 failure response without a payment result will throw a {@link GcApiException}. + */ + @Test + public void testCreateInvalidAuthorization() { - Customer customer = new Customer(); + GcClient client = GcFactory.createClient(session); + String responseBody = getResource("invalid_authorization.json"); + whenPost().thenReturn(new GcResponse(401, responseBody, null)); - Address billingAddress = new Address(); - billingAddress.setCountryCode("CA"); - customer.setBillingAddress(billingAddress); + CreatePaymentRequest body = createRequest(); - order.setCustomer(customer); + try { + client.merchant("merchantId").payments().create(body); + Assert.fail("Expected GcApiException"); + } catch (GcApiException e) { + Assert.assertTrue(e.toString().contains(responseBody)); + } + } - CardPaymentMethodSpecificInput cardPaymentMethodSpecificInput = new CardPaymentMethodSpecificInput(); - cardPaymentMethodSpecificInput.setPaymentProductId(1); + /** + * Tests that a 409 failure response with a duplicate request code but without an idempotence key will throw a + * {@link GcReferenceException}. + */ + @Test + public void testCreateReferenceError() { - Card card = new Card(); - card.setCvv("123"); - card.setCardNumber("4567350000427977"); - card.setExpiryDate("1210"); - cardPaymentMethodSpecificInput.setCard(card); + GcClient client = GcFactory.createClient(session); + String responseBody = getResource("duplicate_request.json"); + whenPost().thenReturn(new GcResponse(409, responseBody, null)); - body.setCardPaymentMethodSpecificInput(cardPaymentMethodSpecificInput); + CreatePaymentRequest body = createRequest(); try { client.merchant("merchantId").payments().create(body); - Assert.fail("Expected GcValidationException"); - } catch (GcValidationException e) { + Assert.fail("Expected GcApiException"); + } catch (GcReferenceException e) { Assert.assertTrue(e.toString().contains(responseBody)); } } /** - * Tests that a 401 failure response without a payment result will throw a {@link GcApiException}. + * Tests that a 409 failure response with a duplicate request code and an idempotence key will throw a {@link GcReferenceException}. */ @Test - public void testCreateInvalidAuthorization() { + public void testCreateIdempotenceError() { GcClient client = GcFactory.createClient(session); - String responseBody = getResource("invalid_authorization.json"); - Mockito.when(connection.post(Mockito.anyString(), Mockito.>any(), Mockito.>any(), Mockito.anyString())) - .thenThrow(new GcResponseException(401, responseBody)); + String responseBody = getResource("duplicate_request.json"); + whenPost().thenReturn(new GcResponse(409, responseBody, null)); - CreatePaymentRequest body = new CreatePaymentRequest(); + CreatePaymentRequest body = createRequest(); - Order order = new Order(); + CallContext context = new CallContext().withIdempotenceKey("key"); - AmountOfMoney amountOfMoney = new AmountOfMoney(); - amountOfMoney.setAmount(2345L); - amountOfMoney.setCurrencyCode("CAD"); - order.setAmountOfMoney(amountOfMoney); + try { + client.merchant("merchantId").payments().create(body, context); + Assert.fail("Expected GcApiException"); + } catch (GcIdempotenceException e) { + Assert.assertTrue(e.toString().contains(responseBody)); + Assert.assertEquals(context.getIdempotenceKey(), e.getIdempotenceKey()); + } + } - Customer customer = new Customer(); + /** + * Tests that a 404 response with a non-JSON response will throw a {@link GcNotFoundException}. + */ + @Test + public void testCreateNotFound() { - Address billingAddress = new Address(); - billingAddress.setCountryCode("CA"); - customer.setBillingAddress(billingAddress); + GcClient client = GcFactory.createClient(session); + String responseBody = getResource("not_found.html"); + whenPost().thenReturn(new GcResponse(404, responseBody, Arrays.asList( + new ResponseHeader("content-type", "text/html") + ))); - order.setCustomer(customer); + CreatePaymentRequest body = createRequest(); - CardPaymentMethodSpecificInput cardPaymentMethodSpecificInput = new CardPaymentMethodSpecificInput(); - cardPaymentMethodSpecificInput.setPaymentProductId(1); + try { + client.merchant("merchantId").payments().create(body); + Assert.fail("Expected GcNotFoundException"); + } catch (GcNotFoundException e) { + Assert.assertNotNull(e.getCause()); + Assert.assertEquals(GcResponseException.class, e.getCause().getClass()); + Assert.assertTrue(e.getCause().toString().contains(responseBody)); + } + } - Card card = new Card(); - card.setCvv("123"); - card.setCardNumber("4567350000427977"); - card.setExpiryDate("1210"); - cardPaymentMethodSpecificInput.setCard(card); + /** + * Tests that a 405 response with a non-JSON response will throw a {@link GcCommunicationException}. + */ + @Test + public void testCreateMethodNotAllowed() { - body.setCardPaymentMethodSpecificInput(cardPaymentMethodSpecificInput); + GcClient client = GcFactory.createClient(session); + String responseBody = getResource("method_not_allowed.html"); + whenPost().thenReturn(new GcResponse(405, responseBody, Arrays.asList( + new ResponseHeader("content-type", "text/html") + ))); + + CreatePaymentRequest body = createRequest(); try { client.merchant("merchantId").payments().create(body); - Assert.fail("Expected GcApiException"); - } catch (GcApiException e) { - Assert.assertTrue(e.toString().contains(responseBody)); + Assert.fail("Expected GcCommunicationException"); + } catch (GcCommunicationException e) { + Assert.assertNotNull(e.getCause()); + Assert.assertEquals(GcResponseException.class, e.getCause().getClass()); + Assert.assertTrue(e.getCause().toString().contains(responseBody)); } } + private OngoingStubbing whenPost() { + return Mockito.when(connection.post(Mockito.any(), Mockito.>any(), Mockito.anyString())); + } + private String getResource(String resource) { StringWriter sw = new StringWriter(); try { @@ -267,4 +264,37 @@ private String getResource(String resource) { } return sw.toString(); } + + 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; + } } diff --git a/src/test/resources/com/globalcollect/gateway/sdk/java/defaultimpl/idempotence_duplicate_failure.json b/src/test/resources/com/globalcollect/gateway/sdk/java/defaultimpl/idempotence_duplicate_failure.json new file mode 100644 index 000000000..d39e54962 --- /dev/null +++ b/src/test/resources/com/globalcollect/gateway/sdk/java/defaultimpl/idempotence_duplicate_failure.json @@ -0,0 +1,8 @@ +{ + "errorId" : "75b0f13a-04a5-41b3-83b8-b295ddb23439-000013c6", + "errors" : [ { + "code" : "1409", + "message" : "DUPLICATE REQUEST IN PROGRESS", + "httpStatusCode" : 409 + } ] +} diff --git a/src/test/resources/com/globalcollect/gateway/sdk/java/defaultimpl/idempotence_rejected.json b/src/test/resources/com/globalcollect/gateway/sdk/java/defaultimpl/idempotence_rejected.json new file mode 100644 index 000000000..875b38e08 --- /dev/null +++ b/src/test/resources/com/globalcollect/gateway/sdk/java/defaultimpl/idempotence_rejected.json @@ -0,0 +1,46 @@ +{ + "errorId": "2c164323-20d3-4e9e-8578-dc562cd7506c-0000003c", + "errors": [ + { + "code": "21000020", + "requestId": "2001798", + "message": "VALUE **************** OF FIELD CREDITCARDNUMBER DID NOT PASS THE LUHNCHECK" + } + ], + "paymentResult": { + "creationOutput": { + "additionalReference": "00000200002014254436", + "externalReference": "000002000020142544360000100001" + }, + "payment": { + "id": "000002000020142544360000100001", + "paymentOutput": { + "amountOfMoney": { + "amount": 2345, + "currencyCode": "CAD" + }, + "references": { + "paymentReference": "0" + }, + "paymentMethod": "card", + "cardPaymentMethodSpecificOutput": { + "paymentProductId": 1 + } + }, + "status": "REJECTED", + "statusOutput": { + "errors": [ + { + "code": "21000020", + "requestId": "2001798", + "message": "VALUE **************** OF FIELD CREDITCARDNUMBER DID NOT PASS THE LUHNCHECK" + } + ], + "isCancellable": false, + "statusCode": 100, + "statusCodeChangeDateTime": "20150330173151", + "isAuthorized": false + } + } + } +} diff --git a/src/test/resources/com/globalcollect/gateway/sdk/java/defaultimpl/idempotence_success.json b/src/test/resources/com/globalcollect/gateway/sdk/java/defaultimpl/idempotence_success.json new file mode 100644 index 000000000..fd52fd955 --- /dev/null +++ b/src/test/resources/com/globalcollect/gateway/sdk/java/defaultimpl/idempotence_success.json @@ -0,0 +1,39 @@ +{ + "creationOutput": { + "additionalReference": "00000200002014254946", + "externalReference": "000002000020142549460000100001" + }, + "payment": { + "id": "000002000020142549460000100001", + "paymentOutput": { + "amountOfMoney": { + "amount": 2345, + "currencyCode": "CAD" + }, + "references": { + "paymentReference": "0" + }, + "paymentMethod": "card", + "cardPaymentMethodSpecificOutput": { + "paymentProductId": 1, + "authorisationCode": "OK1131", + "card": { + "cardNumber": "************9176", + "expiryDate": "1220" + }, + "fraudResults": { + "fraudServiceResult": "error", + "avsResult": "X", + "cvvResult": "M" + } + } + }, + "status": "PENDING_APPROVAL", + "statusOutput": { + "isCancellable": true, + "statusCode": 600, + "statusCodeChangeDateTime": "20150331120036", + "isAuthorized": true + } + } +} \ No newline at end of file diff --git a/src/test/resources/com/globalcollect/gateway/sdk/java/gc/merchant/payments/duplicate_request.json b/src/test/resources/com/globalcollect/gateway/sdk/java/gc/merchant/payments/duplicate_request.json new file mode 100644 index 000000000..d39e54962 --- /dev/null +++ b/src/test/resources/com/globalcollect/gateway/sdk/java/gc/merchant/payments/duplicate_request.json @@ -0,0 +1,8 @@ +{ + "errorId" : "75b0f13a-04a5-41b3-83b8-b295ddb23439-000013c6", + "errors" : [ { + "code" : "1409", + "message" : "DUPLICATE REQUEST IN PROGRESS", + "httpStatusCode" : 409 + } ] +} diff --git a/src/test/resources/com/globalcollect/gateway/sdk/java/gc/merchant/payments/method_not_allowed.html b/src/test/resources/com/globalcollect/gateway/sdk/java/gc/merchant/payments/method_not_allowed.html new file mode 100644 index 000000000..772cdf01d --- /dev/null +++ b/src/test/resources/com/globalcollect/gateway/sdk/java/gc/merchant/payments/method_not_allowed.html @@ -0,0 +1 @@ +Method Not Allowed \ No newline at end of file diff --git a/src/test/resources/com/globalcollect/gateway/sdk/java/gc/merchant/payments/not_found.html b/src/test/resources/com/globalcollect/gateway/sdk/java/gc/merchant/payments/not_found.html new file mode 100644 index 000000000..853730769 --- /dev/null +++ b/src/test/resources/com/globalcollect/gateway/sdk/java/gc/merchant/payments/not_found.html @@ -0,0 +1 @@ +Not Found \ No newline at end of file