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);
}
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());
}
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())));
}
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());
}
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()));
}
Aggregations