Search in sources :

Example 1 with GatewayClient

use of uk.gov.pay.connector.gateway.GatewayClient in project pay-connector by alphagov.

the class SmartpayPaymentProviderTest method getSmartpayPaymentProvider.

private PaymentProvider getSmartpayPaymentProvider() {
    Client client = TestClientFactory.createJerseyClient();
    GatewayClient gatewayClient = new GatewayClient(client, mockMetricRegistry);
    GatewayClientFactory gatewayClientFactory = mock(GatewayClientFactory.class);
    when(gatewayClientFactory.createGatewayClient(any(PaymentGatewayName.class), any(MetricRegistry.class))).thenReturn(gatewayClient);
    GatewayConfig gatewayConfig = mock(GatewayConfig.class);
    when(gatewayConfig.getUrls()).thenReturn(Map.of(TEST.toString(), url));
    ConnectorConfiguration configuration = mock(ConnectorConfiguration.class);
    when(configuration.getGatewayConfigFor(SMARTPAY)).thenReturn(gatewayConfig);
    return new SmartpayPaymentProvider(configuration, gatewayClientFactory, mockEnvironment);
}
Also used : GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) GatewayClientFactory(uk.gov.pay.connector.gateway.GatewayClientFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) ConnectorConfiguration(uk.gov.pay.connector.app.ConnectorConfiguration) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) Client(javax.ws.rs.client.Client) GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) GatewayConfig(uk.gov.pay.connector.app.GatewayConfig) SmartpayPaymentProvider(uk.gov.pay.connector.gateway.smartpay.SmartpayPaymentProvider)

Example 2 with GatewayClient

use of uk.gov.pay.connector.gateway.GatewayClient in project pay-connector by alphagov.

the class GatewayClientTest method setup.

@BeforeEach
public void setup() {
    gatewayClient = new GatewayClient(mockClient, mockMetricRegistry);
    when(mockClient.target(WORLDPAY_API_ENDPOINT)).thenReturn(mockWebTarget);
}
Also used : GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with GatewayClient

use of uk.gov.pay.connector.gateway.GatewayClient in project pay-connector by alphagov.

the class WorldpayPaymentProviderTest method getValidWorldpayPaymentProvider.

private WorldpayPaymentProvider getValidWorldpayPaymentProvider() {
    GatewayClient gatewayClient = new GatewayClient(ClientBuilder.newClient(), mockMetricRegistry);
    GatewayClientFactory gatewayClientFactory = mock(GatewayClientFactory.class);
    when(gatewayClientFactory.createGatewayClient(any(PaymentGatewayName.class), any(GatewayOperation.class), any(MetricRegistry.class))).thenReturn(gatewayClient);
    return new WorldpayPaymentProvider(gatewayUrlMap(), gatewayClient, gatewayClient, gatewayClient, new WorldpayWalletAuthorisationHandler(gatewayClient, gatewayUrlMap()), new WorldpayAuthoriseHandler(gatewayClient, gatewayUrlMap()), new WorldpayCaptureHandler(gatewayClient, gatewayUrlMap()), new WorldpayRefundHandler(gatewayClient, gatewayUrlMap()), new AuthorisationService(mockCardExecutorService, mockEnvironment), new AuthorisationLogger(new AuthorisationRequestSummaryStringifier(), new AuthorisationRequestSummaryStructuredLogging()), mock(ChargeDao.class), mock(EventService.class));
}
Also used : WorldpayPaymentProvider(uk.gov.pay.connector.gateway.worldpay.WorldpayPaymentProvider) WorldpayAuthoriseHandler(uk.gov.pay.connector.gateway.worldpay.WorldpayAuthoriseHandler) AuthorisationService(uk.gov.pay.connector.paymentprocessor.service.AuthorisationService) GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) GatewayOperation(uk.gov.pay.connector.gateway.GatewayOperation) MetricRegistry(com.codahale.metrics.MetricRegistry) WorldpayWalletAuthorisationHandler(uk.gov.pay.connector.gateway.worldpay.wallets.WorldpayWalletAuthorisationHandler) WorldpayRefundHandler(uk.gov.pay.connector.gateway.worldpay.WorldpayRefundHandler) EventService(uk.gov.pay.connector.events.EventService) AuthorisationRequestSummaryStructuredLogging(uk.gov.pay.connector.gateway.util.AuthorisationRequestSummaryStructuredLogging) WorldpayCaptureHandler(uk.gov.pay.connector.gateway.worldpay.WorldpayCaptureHandler) GatewayClientFactory(uk.gov.pay.connector.gateway.GatewayClientFactory) AuthorisationLogger(uk.gov.pay.connector.logging.AuthorisationLogger) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) ChargeDao(uk.gov.pay.connector.charge.dao.ChargeDao) AuthorisationRequestSummaryStringifier(uk.gov.pay.connector.gateway.util.AuthorisationRequestSummaryStringifier)

Example 4 with GatewayClient

use of uk.gov.pay.connector.gateway.GatewayClient in project pay-connector by alphagov.

the class EpdqPaymentProviderTest method setUp.

@Before
public void setUp() {
    when(mockConnectorConfiguration.getLinks()).thenReturn(mockLinksConfig);
    when(mockConnectorConfiguration.getGatewayConfigFor(EPDQ)).thenReturn(mockGatewayConfig);
    when(mockLinksConfig.getFrontendUrl()).thenReturn("http://frontendUrl");
    when(mockGatewayConfig.getUrls()).thenReturn(Map.of(TEST.toString(), url));
    when(mockMetricRegistry.histogram(anyString())).thenReturn(mockHistogram);
    when(mockEnvironment.metrics()).thenReturn(mockMetricRegistry);
    Client client = TestClientFactory.createJerseyClient();
    GatewayClient gatewayClient = new GatewayClient(client, mockMetricRegistry);
    when(mockGatewayClientFactory.createGatewayClient(any(PaymentGatewayName.class), any(GatewayOperation.class), any())).thenReturn(gatewayClient);
    paymentProvider = new EpdqPaymentProvider(mockConnectorConfiguration, mockGatewayClientFactory, mockEnvironment, Clock.fixed(Instant.parse("2020-01-01T10:10:10.100Z"), ZoneOffset.UTC));
}
Also used : GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) GatewayOperation(uk.gov.pay.connector.gateway.GatewayOperation) PaymentGatewayName(uk.gov.pay.connector.gateway.PaymentGatewayName) Client(javax.ws.rs.client.Client) GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) EpdqPaymentProvider(uk.gov.pay.connector.gateway.epdq.EpdqPaymentProvider) Before(org.junit.Before)

Example 5 with GatewayClient

use of uk.gov.pay.connector.gateway.GatewayClient in project pay-connector by alphagov.

the class GooglePayForWorldpayTest method sendPaymentToWorldpay.

@Test
public void sendPaymentToWorldpay() throws Exception {
    GatewayAccountEntity gatewayAccount = new GatewayAccountEntity();
    gatewayAccount.setType(GatewayAccountType.TEST);
    gatewayAccount.setGatewayAccountCredentials(List.of(aGatewayAccountCredentialsEntity().withCredentials(Map.of(CREDENTIALS_USERNAME, worldpayUsername, CREDENTIALS_PASSWORD, worldpayPassword)).withGatewayAccountEntity(gatewayAccount).withPaymentProvider(WORLDPAY.getName()).build()));
    String payload = load("templates/worldpay/WorldpayAuthoriseGooglePayOrderTemplate.xml").replace("${amount}", "100").replace("${merchantCode}", merchantCode).replace("${transactionId?xml}", Integer.toString(RandomUtils.nextInt())).replace("${walletAuthorisationData.encryptedPaymentData.signature?xml}", signature).replace("${walletAuthorisationData.encryptedPaymentData.protocolVersion?xml}", protocolVersion).replace("${walletAuthorisationData.encryptedPaymentData.signedMessage?xml}", signedMessage);
    GatewayClient authoriseClient = getGatewayClient();
    GatewayOrder gatewayOrder = new GatewayOrder(OrderRequestType.AUTHORISE, payload, APPLICATION_XML_TYPE);
    GatewayClient.Response response = authoriseClient.postRequestFor(URI.create("https://secure-test.worldpay.com/jsp/merchant/xml/paymentService.jsp"), WORLDPAY, "test", gatewayOrder, getGatewayAccountCredentialsAsAuthHeader(gatewayAccount.getCredentials(WORLDPAY.getName())));
    assertThat(response.getStatus(), is(HttpStatus.SC_OK));
    String entity = response.getEntity();
    System.out.println(entity);
    WorldpayOrderStatusResponse worldpayOrderStatusResponse = XMLUnmarshaller.unmarshall(entity, WorldpayOrderStatusResponse.class);
    assertTrue(worldpayOrderStatusResponse.getLastEvent().isPresent());
    assertThat(worldpayOrderStatusResponse.getLastEvent(), is("AUTHORISED"));
}
Also used : GatewayClient(uk.gov.pay.connector.gateway.GatewayClient) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) WorldpayOrderStatusResponse(uk.gov.pay.connector.gateway.worldpay.WorldpayOrderStatusResponse) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder) Test(org.junit.Test)

Aggregations

GatewayClient (uk.gov.pay.connector.gateway.GatewayClient)6 PaymentGatewayName (uk.gov.pay.connector.gateway.PaymentGatewayName)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 Client (javax.ws.rs.client.Client)2 Test (org.junit.Test)2 GatewayClientFactory (uk.gov.pay.connector.gateway.GatewayClientFactory)2 GatewayOperation (uk.gov.pay.connector.gateway.GatewayOperation)2 Before (org.junit.Before)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ConnectorConfiguration (uk.gov.pay.connector.app.ConnectorConfiguration)1 GatewayConfig (uk.gov.pay.connector.app.GatewayConfig)1 ChargeDao (uk.gov.pay.connector.charge.dao.ChargeDao)1 EventService (uk.gov.pay.connector.events.EventService)1 GatewayOrder (uk.gov.pay.connector.gateway.GatewayOrder)1 EpdqPaymentProvider (uk.gov.pay.connector.gateway.epdq.EpdqPaymentProvider)1 SmartpayPaymentProvider (uk.gov.pay.connector.gateway.smartpay.SmartpayPaymentProvider)1 AuthorisationRequestSummaryStringifier (uk.gov.pay.connector.gateway.util.AuthorisationRequestSummaryStringifier)1 AuthorisationRequestSummaryStructuredLogging (uk.gov.pay.connector.gateway.util.AuthorisationRequestSummaryStructuredLogging)1 WorldpayAuthoriseHandler (uk.gov.pay.connector.gateway.worldpay.WorldpayAuthoriseHandler)1 WorldpayCaptureHandler (uk.gov.pay.connector.gateway.worldpay.WorldpayCaptureHandler)1