From b4ea9513cea4db3cfb65895e60616a6fa7d9d093 Mon Sep 17 00:00:00 2001 From: Alena Dudzinskaya Date: Sun, 17 Mar 2019 16:31:42 -0700 Subject: [PATCH 1/2] Adds applepay and googlepay support --- pom.xml | 2 +- .../api/mapping/PaymentInfoMappingService.java | 16 +++++++++++++--- .../payment/builder/PaymentRequestBuilder.java | 17 ++++++++++------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 1762f4c6..7615357f 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.kill-bill.billing.plugin.java adyen-plugin Kill Bill OSGI Adyen plugin - 0.5.15 + 0.5.16-SNAPSHOT bundle Kill Bill Adyen plugin http://github.com/killbill/killbill-adyen-plugin diff --git a/src/main/java/org/killbill/billing/plugin/adyen/api/mapping/PaymentInfoMappingService.java b/src/main/java/org/killbill/billing/plugin/adyen/api/mapping/PaymentInfoMappingService.java index ba8bfc75..18eec70a 100644 --- a/src/main/java/org/killbill/billing/plugin/adyen/api/mapping/PaymentInfoMappingService.java +++ b/src/main/java/org/killbill/billing/plugin/adyen/api/mapping/PaymentInfoMappingService.java @@ -134,6 +134,19 @@ private static void set3DSecureFields(final PaymentInfo paymentInfo, final Itera final String mpiDataAuthenticationResponse = PluginProperties.findPluginPropertyValue(PROPERTY_MPI_DATA_AUTHENTICATION_RESPONSE, properties); paymentInfo.setMpiDataAuthenticationResponse(mpiDataAuthenticationResponse); + final String mpiDataEci = PluginProperties.findPluginPropertyValue(PROPERTY_MPI_DATA_ECI, properties); + paymentInfo.setMpiDataEci(mpiDataEci); + + final String selectedBrand = PluginProperties.findPluginPropertyValue(PROPERTY_SELECTED_BRAND, properties); + + if (selectedBrand != null) { + paymentInfo.setMpiDataDirectoryResponse("Y"); + paymentInfo.setMpiDataAuthenticationResponse("Y"); + if (mpiDataEci == null || mpiDataEci.isEmpty()) { + paymentInfo.setMpiDataEci("7"); + } + } + final String mpiDataCavv = PluginProperties.findPluginPropertyValue(PROPERTY_MPI_DATA_CAVV, properties); paymentInfo.setMpiDataCavv(mpiDataCavv); @@ -143,9 +156,6 @@ private static void set3DSecureFields(final PaymentInfo paymentInfo, final Itera final String mpiDataXid = PluginProperties.findPluginPropertyValue(PROPERTY_MPI_DATA_XID, properties); paymentInfo.setMpiDataXid(mpiDataXid); - final String mpiDataEci = PluginProperties.findPluginPropertyValue(PROPERTY_MPI_DATA_ECI, properties); - paymentInfo.setMpiDataEci(mpiDataEci); - final String mpiImplementationType = PluginProperties.findPluginPropertyValue(PROPERTY_MPI_IMPLEMENTATION_TYPE, properties); paymentInfo.setMpiImplementationType(mpiImplementationType); if (mpiImplementationType != null) { diff --git a/src/main/java/org/killbill/billing/plugin/adyen/client/payment/builder/PaymentRequestBuilder.java b/src/main/java/org/killbill/billing/plugin/adyen/client/payment/builder/PaymentRequestBuilder.java index 17cb783c..63cfd84e 100644 --- a/src/main/java/org/killbill/billing/plugin/adyen/client/payment/builder/PaymentRequestBuilder.java +++ b/src/main/java/org/killbill/billing/plugin/adyen/client/payment/builder/PaymentRequestBuilder.java @@ -134,13 +134,16 @@ private void set3DSecureFields() { final BigDecimal amount = paymentData.getAmount(); final PaymentInfo paymentInfo = paymentData.getPaymentInfo(); - boolean thresholdReached = false; - if (amount != null && paymentInfo.getThreeDThreshold() != null) { - final Long amountMinorUnits = toMinorUnits(amount, paymentData.getCurrency().name()); - thresholdReached = amountMinorUnits.compareTo(paymentInfo.getThreeDThreshold()) >= 0; - } - if (!thresholdReached) { - return; + // applepay and googlepay require mpidata + if (paymentInfo.getSelectedBrand() == null) { + boolean thresholdReached = false; + if (amount != null && paymentInfo.getThreeDThreshold() != null) { + final Long amountMinorUnits = toMinorUnits(amount, paymentData.getCurrency().name()); + thresholdReached = amountMinorUnits.compareTo(paymentInfo.getThreeDThreshold()) >= 0; + } + if (!thresholdReached) { + return; + } } final BrowserInfo browserInfo = new BrowserInfo(); From 3907f0dbeb5af7e46cfb9c9b4e861ff72d7cdf00 Mon Sep 17 00:00:00 2001 From: Alena Dudzinskaya Date: Tue, 9 Apr 2019 11:46:26 -0700 Subject: [PATCH 2/2] Applepay and googlepay tests --- .../adyen/api/TestAdyenPaymentPluginApi.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/test/java/org/killbill/billing/plugin/adyen/api/TestAdyenPaymentPluginApi.java b/src/test/java/org/killbill/billing/plugin/adyen/api/TestAdyenPaymentPluginApi.java index d7e437ca..0dc657b2 100644 --- a/src/test/java/org/killbill/billing/plugin/adyen/api/TestAdyenPaymentPluginApi.java +++ b/src/test/java/org/killbill/billing/plugin/adyen/api/TestAdyenPaymentPluginApi.java @@ -107,6 +107,30 @@ public class TestAdyenPaymentPluginApi extends TestAdyenPaymentPluginApiBase { .put(AdyenPaymentPluginApi.PROPERTY_TERM_URL, "dummy://url") .put(AdyenPaymentPluginApi.PROPERTY_THREE_D_THRESHOLD, "25000") .build()); + private final Iterable propertiesWithGooglePay = PluginProperties.buildPluginProperties(ImmutableMap.builder() + .put(AdyenPaymentPluginApi.PROPERTY_CC_LAST_NAME, "Googlepaytester") + .put(AdyenPaymentPluginApi.PROPERTY_SELECTED_BRAND, "paywithgoogle") + .put(AdyenPaymentPluginApi.PROPERTY_MPI_DATA_CAVV, "AAAAAAAAt5fMJPDr320qAAALwwA=hq0BA9EAAAGXIJcAGAAAABKU0+s=") + .put(AdyenPaymentPluginApi.PROPERTY_MPI_DATA_ECI, "7") + .put(AdyenPaymentPluginApi.PROPERTY_CC_NUMBER, CC_3DS_NUMBER) + .put(AdyenPaymentPluginApi.PROPERTY_CC_EXPIRATION_MONTH, "10") + .put(AdyenPaymentPluginApi.PROPERTY_CC_EXPIRATION_YEAR, "2020") + .put(AdyenPaymentPluginApi.PROPERTY_USER_AGENT, "Java/1.8") + .put(AdyenPaymentPluginApi.PROPERTY_ACCEPT_HEADER, "application/json") + .put(AdyenPaymentPluginApi.PROPERTY_TERM_URL, "dummy://url") + .build()); + private final Iterable propertiesWithApplePay = PluginProperties.buildPluginProperties(ImmutableMap.builder() + .put(AdyenPaymentPluginApi.PROPERTY_CC_LAST_NAME, "Applepaytester") + .put(AdyenPaymentPluginApi.PROPERTY_SELECTED_BRAND, "applepay") + .put(AdyenPaymentPluginApi.PROPERTY_MPI_DATA_CAVV, "AAAAAAAAt5fMJPDr320qAAALwwA=hq0BA9EAAAGXIJcAGAAAABKU0+s=") + .put(AdyenPaymentPluginApi.PROPERTY_MPI_DATA_ECI, "7") + .put(AdyenPaymentPluginApi.PROPERTY_CC_NUMBER, CC_3DS_NUMBER) + .put(AdyenPaymentPluginApi.PROPERTY_CC_EXPIRATION_MONTH, String.valueOf(CC_EXPIRATION_MONTH)) + .put(AdyenPaymentPluginApi.PROPERTY_CC_EXPIRATION_YEAR, String.valueOf(CC_EXPIRATION_YEAR)) + .put(AdyenPaymentPluginApi.PROPERTY_USER_AGENT, "Java/1.8") + .put(AdyenPaymentPluginApi.PROPERTY_ACCEPT_HEADER, "application/json") + .put(AdyenPaymentPluginApi.PROPERTY_TERM_URL, "dummy://url") + .build()); private final Iterable propertiesWithAVSInfo = PluginProperties.buildPluginProperties(ImmutableMap.builder() .put(AdyenPaymentPluginApi.PROPERTY_CC_TYPE, CC_TYPE) .put(AdyenPaymentPluginApi.PROPERTY_CC_LAST_NAME, "Avschecker") @@ -425,6 +449,46 @@ public void testAuthorizeAndCheckAVSResult() throws Exception { assertEquals(avsResult, "7 Both postal code and address match"); } + @Test(groups = "integration") + public void testAuthorizeWithGooglePay() throws Exception { + adyenPaymentPluginApi.addPaymentMethod(account.getId(), account.getPaymentMethodId(), adyenEmptyPaymentMethodPlugin(), true, propertiesWithGooglePay, context); + final Payment payment = TestUtils.buildPayment(account.getId(), account.getPaymentMethodId(), account.getCurrency(), killbillApi); + + final PaymentTransaction authorizationTransaction = TestUtils.buildPaymentTransaction(payment, TransactionType.AUTHORIZE, new BigDecimal("25"), account.getCurrency()); + + final PaymentTransactionInfoPlugin authorizationInfoPlugin = adyenPaymentPluginApi.authorizePayment(account.getId(), + payment.getId(), + authorizationTransaction.getId(), + account.getPaymentMethodId(), + authorizationTransaction.getAmount(), + authorizationTransaction.getCurrency(), + propertiesWithGooglePay, + context); + + assertNull(authorizationInfoPlugin.getGatewayErrorCode()); + assertEquals(authorizationInfoPlugin.getStatus(), PaymentPluginStatus.PROCESSED); + } + + @Test(groups = "integration") + public void testAuthorizeWithApplePay() throws Exception { + adyenPaymentPluginApi.addPaymentMethod(account.getId(), account.getPaymentMethodId(), adyenEmptyPaymentMethodPlugin(), true, propertiesWithApplePay, context); + final Payment payment = TestUtils.buildPayment(account.getId(), account.getPaymentMethodId(), account.getCurrency(), killbillApi); + + final PaymentTransaction authorizationTransaction = TestUtils.buildPaymentTransaction(payment, TransactionType.AUTHORIZE, new BigDecimal("260"), account.getCurrency()); + + final PaymentTransactionInfoPlugin authorizationInfoPlugin = adyenPaymentPluginApi.authorizePayment(account.getId(), + payment.getId(), + authorizationTransaction.getId(), + account.getPaymentMethodId(), + authorizationTransaction.getAmount(), + authorizationTransaction.getCurrency(), + propertiesWithApplePay, + context); + + assertNull(authorizationInfoPlugin.getGatewayErrorCode()); + assertEquals(authorizationInfoPlugin.getStatus(), PaymentPluginStatus.PROCESSED); + } + @Test(groups = "integration") public void testAuthorizeAndCheckBadAVSResult() throws Exception { adyenPaymentPluginApi.addPaymentMethod(account.getId(), account.getPaymentMethodId(), adyenEmptyPaymentMethodPlugin(), true, propertiesWithAVSInfo, context);