Search in sources :

Example 1 with GatewayOrder

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

the class EpdqPayloadDefinition method createGatewayOrder.

public GatewayOrder createGatewayOrder() {
    ArrayList<NameValuePair> params = new ArrayList<>(extract());
    String signature = SIGNATURE_GENERATOR.sign(params, getShaInPassphrase());
    params.add(new BasicNameValuePair("SHASIGN", signature));
    String payload = URLEncodedUtils.format(params, EPDQ_APPLICATION_X_WWW_FORM_URLENCODED_CHARSET);
    return new GatewayOrder(getOrderRequestType(), payload, MediaType.APPLICATION_FORM_URLENCODED_TYPE);
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder)

Example 2 with GatewayOrder

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

the class EpdqPayloadDefinitionForCancelOrderTest method payloadIsAsExpectedWithPayId.

@Test
public void payloadIsAsExpectedWithPayId() {
    var epdqPayloadDefinitionForCancelOrder = new EpdqPayloadDefinitionForCancelOrder();
    epdqPayloadDefinitionForCancelOrder.setPassword("password");
    epdqPayloadDefinitionForCancelOrder.setUserId("username");
    epdqPayloadDefinitionForCancelOrder.setPspId("merchant-id");
    epdqPayloadDefinitionForCancelOrder.setPayId("payId");
    epdqPayloadDefinitionForCancelOrder.setShaInPassphrase("sha-passphrase");
    GatewayOrder gatewayOrder = epdqPayloadDefinitionForCancelOrder.createGatewayOrder();
    assertEquals(TestTemplateResourceLoader.load(EPDQ_CANCEL_REQUEST_WITH_PAYID), gatewayOrder.getPayload());
    assertEquals(OrderRequestType.CANCEL, gatewayOrder.getOrderRequestType());
}
Also used : EpdqPayloadDefinitionForCancelOrder(uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForCancelOrder) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder) Test(org.junit.Test)

Example 3 with GatewayOrder

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

the class WorldpayPaymentProviderTest method assert_authorization_header_is_passed_to_gateway_client.

@Test
void assert_authorization_header_is_passed_to_gateway_client() throws Exception {
    String providerSessionId = "provider-session-id";
    ChargeEntity mockChargeEntity = chargeEntityFixture.withExternalId("uniqueSessionId").withTransactionId("MyUniqueTransactionId!").withProviderSessionId(providerSessionId).withGatewayAccountCredentialsEntity(aGatewayAccountCredentialsEntity().withPaymentProvider("worldpay").withCredentials(Map.of(CREDENTIALS_MERCHANT_ID, "MERCHANTCODE", CREDENTIALS_USERNAME, "worldpay-password", CREDENTIALS_PASSWORD, "password")).build()).build();
    when(authoriseClient.postRequestFor(any(URI.class), eq(WORLDPAY), eq("test"), any(GatewayOrder.class), anyList(), anyMap())).thenThrow(new GatewayException.GatewayErrorException("Unexpected HTTP status code 400 from gateway"));
    worldpayPaymentProvider.authorise3dsResponse(get3dsResponseGatewayRequest(mockChargeEntity));
    ArgumentCaptor<GatewayOrder> gatewayOrderArgumentCaptor = ArgumentCaptor.forClass(GatewayOrder.class);
    ArgumentCaptor<Map<String, String>> headers = ArgumentCaptor.forClass(Map.class);
    verify(authoriseClient).postRequestFor(eq(WORLDPAY_URL), eq(WORLDPAY), eq("test"), gatewayOrderArgumentCaptor.capture(), anyList(), headers.capture());
    assertThat(headers.getValue().size(), is(1));
    assertThat(headers.getValue(), is(AuthUtil.getGatewayAccountCredentialsAsAuthHeader(gatewayAccountEntity.getGatewayAccountCredentials().get(0).getCredentials())));
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) GatewayException(uk.gov.pay.connector.gateway.GatewayException) URI(java.net.URI) Map(java.util.Map) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder) Test(org.junit.jupiter.api.Test)

Example 4 with GatewayOrder

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

the class WorldpayAuthoriseHandlerTest method should_not_include_email_when_not_present_and_send_email_to_gateway_enabled_and_3ds_disabled.

@Test
void should_not_include_email_when_not_present_and_send_email_to_gateway_enabled_and_3ds_disabled() throws Exception {
    when(authorisationSuccessResponse.getEntity()).thenReturn(load(WORLDPAY_AUTHORISATION_SUCCESS_RESPONSE));
    ChargeEntity chargeEntity = chargeEntityFixture.withExternalId("uniqueSessionId").withAmount(500L).withDescription("This is a description").withTransactionId("transaction-id").withEmail(null).build();
    gatewayAccountEntity.setRequires3ds(false);
    gatewayAccountEntity.setSendPayerEmailToGateway(true);
    when(authoriseClient.postRequestFor(any(URI.class), eq(WORLDPAY), eq("test"), any(GatewayOrder.class), anyMap())).thenReturn(authorisationSuccessResponse);
    worldpayAuthoriseHandler.authoriseWithoutExemption((new CardAuthorisationGatewayRequest(chargeEntity, getValidTestCard())));
    ArgumentCaptor<GatewayOrder> gatewayOrderArgumentCaptor = ArgumentCaptor.forClass(GatewayOrder.class);
    verify(authoriseClient).postRequestFor(eq(WORLDPAY_URL), eq(WORLDPAY), eq("test"), gatewayOrderArgumentCaptor.capture(), anyMap());
    assertXMLEqual(load(WORLDPAY_VALID_AUTHORISE_WORLDPAY_REQUEST_EXCLUDING_3DS), gatewayOrderArgumentCaptor.getValue().getPayload());
}
Also used : ChargeEntityFixture.aValidChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity) ChargeEntity(uk.gov.pay.connector.charge.model.domain.ChargeEntity) URI(java.net.URI) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.jupiter.api.Test)

Example 5 with GatewayOrder

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

the class WorldpayAuthoriseHandlerTest method should_not_include_elements_when_worldpay_3ds_flex_ddc_result_is_not_present.

@Test
void should_not_include_elements_when_worldpay_3ds_flex_ddc_result_is_not_present() throws Exception {
    gatewayAccountEntity.setRequires3ds(true);
    when(authorisationSuccessResponse.getEntity()).thenReturn(load(WORLDPAY_AUTHORISATION_SUCCESS_RESPONSE));
    when(authoriseClient.postRequestFor(any(URI.class), eq(WORLDPAY), eq("test"), any(GatewayOrder.class), anyMap())).thenReturn(authorisationSuccessResponse);
    worldpayAuthoriseHandler.authoriseWithoutExemption(new CardAuthorisationGatewayRequest(chargeEntityFixture.build(), getValidTestCard()));
    ArgumentCaptor<GatewayOrder> gatewayOrderArgumentCaptor = ArgumentCaptor.forClass(GatewayOrder.class);
    verify(authoriseClient).postRequestFor(eq(WORLDPAY_URL), eq(WORLDPAY), eq("test"), gatewayOrderArgumentCaptor.capture(), anyMap());
    Document document = XPathUtils.getDocumentXmlString(gatewayOrderArgumentCaptor.getValue().getPayload());
    XPath xPath = XPathFactory.newInstance().newXPath();
    assertThat(getNodeListFromExpression(document, "/paymentService/submit/order/additional3DSData").getLength(), is(0));
    assertThat(xPath.evaluate("/paymentService/submit/order/paymentDetails/session/@id", document), not(emptyString()));
    assertThat(xPath.evaluate("/paymentService/submit/order/shopper/browser/acceptHeader", document), not(emptyString()));
    assertThat(xPath.evaluate("/paymentService/submit/order/shopper/browser/userAgentHeader", document), not(emptyString()));
}
Also used : XPath(javax.xml.xpath.XPath) Document(org.w3c.dom.Document) URI(java.net.URI) GatewayOrder(uk.gov.pay.connector.gateway.GatewayOrder) CardAuthorisationGatewayRequest(uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest) Test(org.junit.jupiter.api.Test)

Aggregations

GatewayOrder (uk.gov.pay.connector.gateway.GatewayOrder)62 Test (org.junit.Test)42 URI (java.net.URI)20 AuthCardDetails (uk.gov.pay.connector.gateway.model.AuthCardDetails)19 Test (org.junit.jupiter.api.Test)18 ChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntity)15 ChargeEntityFixture.aValidChargeEntity (uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity)15 Address (uk.gov.pay.connector.common.model.domain.Address)14 CardAuthorisationGatewayRequest (uk.gov.pay.connector.gateway.model.request.CardAuthorisationGatewayRequest)12 Document (org.w3c.dom.Document)6 XPath (javax.xml.xpath.XPath)5 GatewayException (uk.gov.pay.connector.gateway.GatewayException)4 GooglePayAuthRequestFixture (uk.gov.pay.connector.model.domain.googlepay.GooglePayAuthRequestFixture)4 GooglePayAuthRequestFixture.anGooglePayAuthRequestFixture (uk.gov.pay.connector.model.domain.googlepay.GooglePayAuthRequestFixture.anGooglePayAuthRequestFixture)4 GatewayClient (uk.gov.pay.connector.gateway.GatewayClient)3 WalletPaymentInfo (uk.gov.pay.connector.wallets.model.WalletPaymentInfo)3 Parameters (junitparams.Parameters)2 CaptureResponse (uk.gov.pay.connector.gateway.CaptureResponse)2 EpdqPayloadDefinitionForCancelOrder (uk.gov.pay.connector.gateway.epdq.payload.EpdqPayloadDefinitionForCancelOrder)2 ArrayList (java.util.ArrayList)1