From 7b17b8161d29c095de81a2db356b162541041cec Mon Sep 17 00:00:00 2001 From: Alex Bishop Date: Wed, 1 Jul 2020 16:02:25 +0100 Subject: [PATCH] PP-6712 Make subclasses of EpdqPayloadDefinition not be singletons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make subclasses of EpdqPayloadDefinition not be singletons for they will soon hold state (except for EpdqPayloadDefinitionForNew3dsOrder and EpdqPayloadDefinitionForNew3ds2Order, which already aren’t singletons and hold state). Fun fact: despite being annotated with @Singleton, EpdqPayloadDefinitionForRefundOrder wasn’t a singleton. --- .../gateway/epdq/EpdqCaptureHandler.java | 8 ++--- .../gateway/epdq/EpdqPaymentProvider.java | 34 +++++-------------- .../EpdqPayloadDefinitionForRefundOrder.java | 5 ++- .../epdq/BaseEpdqPaymentProviderIT.java | 8 ----- .../gateway/epdq/EpdqCaptureHandlerTest.java | 5 ++- .../it/contract/EpdqPaymentProviderTest.java | 8 ----- 6 files changed, 15 insertions(+), 53 deletions(-) diff --git a/src/main/java/uk/gov/pay/connector/gateway/epdq/EpdqCaptureHandler.java b/src/main/java/uk/gov/pay/connector/gateway/epdq/EpdqCaptureHandler.java index 86d99f0e5f..347418fe49 100644 --- a/src/main/java/uk/gov/pay/connector/gateway/epdq/EpdqCaptureHandler.java +++ b/src/main/java/uk/gov/pay/connector/gateway/epdq/EpdqCaptureHandler.java @@ -25,14 +25,10 @@ public class EpdqCaptureHandler implements CaptureHandler { private final GatewayClient client; private final Map gatewayUrlMap; - private final EpdqPayloadDefinitionForCaptureOrder epdqPayloadDefinitionForCaptureOrder; - public EpdqCaptureHandler(GatewayClient client, - Map gatewayUrlMap, - EpdqPayloadDefinitionForCaptureOrder epdqPayloadDefinitionForCaptureOrder) { + public EpdqCaptureHandler(GatewayClient client, Map gatewayUrlMap) { this.client = client; this.gatewayUrlMap = gatewayUrlMap; - this.epdqPayloadDefinitionForCaptureOrder = epdqPayloadDefinitionForCaptureOrder; } @Override @@ -58,6 +54,6 @@ private GatewayOrder buildCaptureOrder(CaptureGatewayRequest request) { templateData.setMerchantCode(request.getGatewayAccount().getCredentials().get(CREDENTIALS_MERCHANT_ID)); templateData.setTransactionId(request.getTransactionId()); - return epdqPayloadDefinitionForCaptureOrder.createGatewayOrder(templateData); + return new EpdqPayloadDefinitionForCaptureOrder().createGatewayOrder(templateData); } } diff --git a/src/main/java/uk/gov/pay/connector/gateway/epdq/EpdqPaymentProvider.java b/src/main/java/uk/gov/pay/connector/gateway/epdq/EpdqPaymentProvider.java index 4bbf7ee02e..eb4276506e 100644 --- a/src/main/java/uk/gov/pay/connector/gateway/epdq/EpdqPaymentProvider.java +++ b/src/main/java/uk/gov/pay/connector/gateway/epdq/EpdqPaymentProvider.java @@ -22,9 +22,7 @@ import uk.gov.pay.connector.gateway.epdq.model.response.EpdqAuthorisationResponse; import uk.gov.pay.connector.gateway.epdq.model.response.EpdqCancelResponse; import uk.gov.pay.connector.gateway.epdq.model.response.EpdqQueryResponse; -import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinition; import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForCancelOrder; -import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForCaptureOrder; import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForNew3ds2Order; import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForNew3dsOrder; import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForNewOrder; @@ -82,27 +80,13 @@ public class EpdqPaymentProvider implements PaymentProvider { private final GatewayClient cancelClient; private final ExternalRefundAvailabilityCalculator externalRefundAvailabilityCalculator; private final Map gatewayUrlMap; - private final EpdqPayloadDefinitionForCancelOrder epdqPayloadDefinitionForCancelOrder; - private final EpdqPayloadDefinitionForNewOrder epdqPayloadDefinitionForNewOrder; - private final EpdqPayloadDefinitionForQueryOrder epdqPayloadDefinitionForQueryOrder; private final EpdqCaptureHandler epdqCaptureHandler; private final EpdqRefundHandler epdqRefundHandler; private final Clock clock; @Inject - public EpdqPaymentProvider(ConnectorConfiguration configuration, - GatewayClientFactory gatewayClientFactory, - Environment environment, - EpdqPayloadDefinitionForCancelOrder epdqPayloadDefinitionForCancelOrder, - EpdqPayloadDefinitionForCaptureOrder epdqPayloadDefinitionForCaptureOrder, - EpdqPayloadDefinitionForNewOrder epdqPayloadDefinitionForNewOrder, - EpdqPayloadDefinitionForQueryOrder epdqPayloadDefinitionForQueryOrder, - Clock clock) { - + public EpdqPaymentProvider(ConnectorConfiguration configuration, GatewayClientFactory gatewayClientFactory, Environment environment, Clock clock) { gatewayUrlMap = configuration.getGatewayConfigFor(EPDQ).getUrls(); - this.epdqPayloadDefinitionForCancelOrder = epdqPayloadDefinitionForCancelOrder; - this.epdqPayloadDefinitionForNewOrder = epdqPayloadDefinitionForNewOrder; - this.epdqPayloadDefinitionForQueryOrder = epdqPayloadDefinitionForQueryOrder; authoriseClient = gatewayClientFactory.createGatewayClient(EPDQ, AUTHORISE, environment.metrics()); cancelClient = gatewayClientFactory.createGatewayClient(EPDQ, CANCEL, environment.metrics()); GatewayClient captureClient = gatewayClientFactory.createGatewayClient(EPDQ, CAPTURE, environment.metrics()); @@ -110,7 +94,7 @@ public EpdqPaymentProvider(ConnectorConfiguration configuration, frontendUrl = configuration.getLinks().getFrontendUrl(); metricRegistry = environment.metrics(); externalRefundAvailabilityCalculator = new EpdqExternalRefundAvailabilityCalculator(); - epdqCaptureHandler = new EpdqCaptureHandler(captureClient, gatewayUrlMap, epdqPayloadDefinitionForCaptureOrder); + epdqCaptureHandler = new EpdqCaptureHandler(captureClient, gatewayUrlMap); epdqRefundHandler = new EpdqRefundHandler(refundClient, gatewayUrlMap); this.clock = clock; } @@ -294,7 +278,7 @@ private GatewayOrder buildQueryOrderRequestFor(Auth3dsResponseGatewayRequest req templateData.setShaInPassphrase(request.getGatewayAccount().getCredentials().get(CREDENTIALS_SHA_IN_PASSPHRASE)); templateData.setUserId(request.getGatewayAccount().getCredentials().get(CREDENTIALS_USERNAME)); templateData.setMerchantCode(request.getGatewayAccount().getCredentials().get(CREDENTIALS_MERCHANT_ID)); - return epdqPayloadDefinitionForQueryOrder.createGatewayOrder(templateData); + return new EpdqPayloadDefinitionForQueryOrder().createGatewayOrder(templateData); } private GatewayOrder buildQueryOrderRequestFor(ChargeEntity charge) { @@ -304,7 +288,7 @@ private GatewayOrder buildQueryOrderRequestFor(ChargeEntity charge) { templateData.setShaInPassphrase(charge.getGatewayAccount().getCredentials().get(CREDENTIALS_SHA_IN_PASSPHRASE)); templateData.setUserId(charge.getGatewayAccount().getCredentials().get(CREDENTIALS_USERNAME)); templateData.setMerchantCode(charge.getGatewayAccount().getCredentials().get(CREDENTIALS_MERCHANT_ID)); - return epdqPayloadDefinitionForQueryOrder.createGatewayOrder(templateData); + return new EpdqPayloadDefinitionForQueryOrder().createGatewayOrder(templateData); } private GatewayOrder buildAuthoriseOrder(CardAuthorisationGatewayRequest request, String frontendUrl) { @@ -318,8 +302,8 @@ private GatewayOrder buildAuthoriseOrder(CardAuthorisationGatewayRequest request templateData.setAmount(request.getAmount()); templateData.setAuthCardDetails(request.getAuthCardDetails()); - EpdqPayloadDefinition epdqPayloadDefinition; - + EpdqPayloadDefinitionForNewOrder epdqPayloadDefinition; + if (request.getGatewayAccount().isRequires3ds()) { if (request.getGatewayAccount().getIntegrationVersion3ds() == 2) { epdqPayloadDefinition = new EpdqPayloadDefinitionForNew3ds2Order(frontendUrl, request.getGatewayAccount().isSendPayerIpAddressToGateway(), request.getCharge().getLanguage(), clock); @@ -327,9 +311,9 @@ private GatewayOrder buildAuthoriseOrder(CardAuthorisationGatewayRequest request epdqPayloadDefinition = new EpdqPayloadDefinitionForNew3dsOrder(frontendUrl); } } else { - epdqPayloadDefinition = epdqPayloadDefinitionForNewOrder; + epdqPayloadDefinition = new EpdqPayloadDefinitionForNewOrder(); } - + return epdqPayloadDefinition.createGatewayOrder(templateData); } @@ -345,6 +329,6 @@ private GatewayOrder buildCancelOrder(CancelGatewayRequest request) { templateData::setTransactionId, () -> templateData.setOrderId(request.getExternalChargeId())); - return epdqPayloadDefinitionForCancelOrder.createGatewayOrder(templateData); + return new EpdqPayloadDefinitionForCancelOrder().createGatewayOrder(templateData); } } diff --git a/src/main/java/uk/gov/pay/connector/gateway/epdq/payload/EpdqPayloadDefinitionForRefundOrder.java b/src/main/java/uk/gov/pay/connector/gateway/epdq/payload/EpdqPayloadDefinitionForRefundOrder.java index 63bd7d1788..0d66b8a963 100644 --- a/src/main/java/uk/gov/pay/connector/gateway/epdq/payload/EpdqPayloadDefinitionForRefundOrder.java +++ b/src/main/java/uk/gov/pay/connector/gateway/epdq/payload/EpdqPayloadDefinitionForRefundOrder.java @@ -2,10 +2,8 @@ import uk.gov.pay.connector.gateway.model.OrderRequestType; -import javax.inject.Singleton; - -@Singleton public class EpdqPayloadDefinitionForRefundOrder extends EpdqPayloadDefinitionForMaintenanceOrder { + @Override protected String getOperationType() { return "RFD"; @@ -15,4 +13,5 @@ protected String getOperationType() { protected OrderRequestType getOrderRequestType() { return OrderRequestType.REFUND; } + } diff --git a/src/test/java/uk/gov/pay/connector/gateway/epdq/BaseEpdqPaymentProviderIT.java b/src/test/java/uk/gov/pay/connector/gateway/epdq/BaseEpdqPaymentProviderIT.java index ca2ccd7d9d..e45c33df0c 100644 --- a/src/test/java/uk/gov/pay/connector/gateway/epdq/BaseEpdqPaymentProviderIT.java +++ b/src/test/java/uk/gov/pay/connector/gateway/epdq/BaseEpdqPaymentProviderIT.java @@ -17,10 +17,6 @@ import uk.gov.pay.connector.gateway.GatewayClientFactory; import uk.gov.pay.connector.gateway.GatewayOperation; import uk.gov.pay.connector.gateway.PaymentGatewayName; -import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForCancelOrder; -import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForCaptureOrder; -import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForNewOrder; -import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForQueryOrder; import uk.gov.pay.connector.gateway.model.Auth3dsResult; import uk.gov.pay.connector.gateway.model.AuthCardDetails; import uk.gov.pay.connector.gateway.model.GatewayError; @@ -123,10 +119,6 @@ public void setup() { configuration, gatewayClientFactory, environment, - new EpdqPayloadDefinitionForCancelOrder(), - new EpdqPayloadDefinitionForCaptureOrder(), - new EpdqPayloadDefinitionForNewOrder(), - new EpdqPayloadDefinitionForQueryOrder(), Clock.fixed(Instant.parse("2020-01-01T10:10:10.100Z"), ZoneOffset.UTC)); } diff --git a/src/test/java/uk/gov/pay/connector/gateway/epdq/EpdqCaptureHandlerTest.java b/src/test/java/uk/gov/pay/connector/gateway/epdq/EpdqCaptureHandlerTest.java index 6c1d335fc1..f372bd903f 100644 --- a/src/test/java/uk/gov/pay/connector/gateway/epdq/EpdqCaptureHandlerTest.java +++ b/src/test/java/uk/gov/pay/connector/gateway/epdq/EpdqCaptureHandlerTest.java @@ -12,7 +12,6 @@ import uk.gov.pay.connector.gateway.GatewayClient; import uk.gov.pay.connector.gateway.GatewayException.GatewayErrorException; import uk.gov.pay.connector.gateway.GatewayOrder; -import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForCaptureOrder; import uk.gov.pay.connector.gateway.model.request.CaptureGatewayRequest; import uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity; @@ -26,13 +25,13 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.Mockito.when; +import static uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity; import static uk.gov.pay.connector.gateway.model.ErrorType.GATEWAY_ERROR; import static uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_MERCHANT_ID; import static uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_PASSWORD; import static uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_SHA_IN_PASSPHRASE; import static uk.gov.pay.connector.gatewayaccount.model.GatewayAccount.CREDENTIALS_USERNAME; import static uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity.Type.TEST; -import static uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity; import static uk.gov.pay.connector.util.TestTemplateResourceLoader.load; @RunWith(MockitoJUnitRunner.class) @@ -47,7 +46,7 @@ public class EpdqCaptureHandlerTest { @Before public void setup() { - epdqCaptureHandler = new EpdqCaptureHandler(client, emptyMap(), new EpdqPayloadDefinitionForCaptureOrder()); + epdqCaptureHandler = new EpdqCaptureHandler(client, emptyMap()); } @Test diff --git a/src/test/java/uk/gov/pay/connector/it/contract/EpdqPaymentProviderTest.java b/src/test/java/uk/gov/pay/connector/it/contract/EpdqPaymentProviderTest.java index bca7423532..653e4aba52 100644 --- a/src/test/java/uk/gov/pay/connector/it/contract/EpdqPaymentProviderTest.java +++ b/src/test/java/uk/gov/pay/connector/it/contract/EpdqPaymentProviderTest.java @@ -27,10 +27,6 @@ import uk.gov.pay.connector.gateway.GatewayOperation; import uk.gov.pay.connector.gateway.PaymentGatewayName; import uk.gov.pay.connector.gateway.epdq.EpdqPaymentProvider; -import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForCancelOrder; -import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForCaptureOrder; -import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForNewOrder; -import uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForQueryOrder; import uk.gov.pay.connector.gateway.model.Auth3dsResult; import uk.gov.pay.connector.gateway.model.AuthCardDetails; import uk.gov.pay.connector.gateway.model.request.Auth3dsResponseGatewayRequest; @@ -137,10 +133,6 @@ public void setUp() { mockConnectorConfiguration, mockGatewayClientFactory, mockEnvironment, - new EpdqPayloadDefinitionForCancelOrder(), - new EpdqPayloadDefinitionForCaptureOrder(), - new EpdqPayloadDefinitionForNewOrder(), - new EpdqPayloadDefinitionForQueryOrder(), Clock.fixed(Instant.parse("2020-01-01T10:10:10.100Z"), ZoneOffset.UTC)); }