use of uk.gov.pay.api.model.CardDetails in project pay-publicapi by alphagov.
the class ConnectorMockClient method respondOk_whenCreateTelephoneCharge.
public void respondOk_whenCreateTelephoneCharge(String gatewayAccountId, CreateTelephonePaymentRequest requestParams) {
var responseFromConnector = aCreateOrGetChargeResponseFromConnector().withAmount(requestParams.getAmount()).withDescription(requestParams.getDescription()).withReference(requestParams.getReference()).withProcessorId(requestParams.getProcessorId()).withProviderId(requestParams.getProviderId()).withCardDetails(new CardDetails(requestParams.getLastFourDigits().orElse(null), requestParams.getFirstSixDigits().orElse(null), requestParams.getNameOnCard().orElse(null), requestParams.getCardExpiry().orElse(null), null, requestParams.getCardType().orElse(null), null)).withPaymentOutcome(requestParams.getPaymentOutcome()).withChargeId("dummypaymentid123notpersisted").withDelayedCapture(false).withState(new PaymentState("success", true, null, null));
requestParams.getCreatedDate().ifPresent(responseFromConnector::withCreatedDate);
requestParams.getAuthorisedDate().ifPresent(responseFromConnector::withAuthorisedDate);
requestParams.getEmailAddress().ifPresent(responseFromConnector::withEmail);
requestParams.getTelephoneNumber().ifPresent(responseFromConnector::withTelephoneNumber);
requestParams.getAuthCode().ifPresent(responseFromConnector::withAuthCode);
mockCreateTelephoneCharge(gatewayAccountId, aResponse().withStatus(OK_200).withHeader(CONTENT_TYPE, APPLICATION_JSON).withBody(buildTelephoneChargeResponse(responseFromConnector.buildTelephoneChargeResponse())));
}
use of uk.gov.pay.api.model.CardDetails in project pay-publicapi by alphagov.
the class ConnectorMockClient method respondOk_whenCreateCharge.
public void respondOk_whenCreateCharge(String gatewayAccountId, CreateChargeRequestParams requestParams) {
var responseFromConnector = aCreateOrGetChargeResponseFromConnector().withAmount(requestParams.getAmount()).withChargeId("chargeId").withState(new PaymentState("created", false, null, null)).withReturnUrl(requestParams.getReturnUrl()).withDescription(requestParams.getDescription()).withReference(requestParams.getReference()).withPaymentProvider("Sandbox").withGatewayTransactionId("gatewayTransactionId").withCreatedDate(SDF.format(new Date())).withLanguage(SupportedLanguage.ENGLISH).withDelayedCapture(false).withCardDetails(new CardDetails("1234", "123456", "Mr. Payment", "12/19", null, "Mastercard", "debit")).withLink(validGetLink(chargeLocation(gatewayAccountId, "chargeId"), "self")).withLink(validGetLink(nextUrl("chargeTokenId"), "next_url")).withLink(validPostLink(nextUrlPost(), "next_url_post", "application/x-www-form-urlencoded", getChargeIdTokenMap("chargeTokenId")));
if (!requestParams.getMetadata().isEmpty())
responseFromConnector.withMetadata(requestParams.getMetadata());
if (requestParams.getEmail() != null) {
responseFromConnector.withEmail(requestParams.getEmail());
}
if (requestParams.getCardholderName().isPresent() || requestParams.getAddressLine1().isPresent() || requestParams.getAddressLine2().isPresent() || requestParams.getAddressPostcode().isPresent() || requestParams.getAddressCity().isPresent() || requestParams.getAddressCountry().isPresent()) {
Address billingAddress = new Address(requestParams.getAddressLine1().orElse(null), requestParams.getAddressLine2().orElse(null), requestParams.getAddressPostcode().orElse(null), requestParams.getAddressCity().orElse(null), requestParams.getAddressCountry().orElse(null));
CardDetails cardDetails = new CardDetails(null, null, requestParams.getCardholderName().orElse(null), null, billingAddress, null, null);
responseFromConnector.withCardDetails(cardDetails);
}
mockCreateCharge(gatewayAccountId, aResponse().withStatus(CREATED_201).withHeader(CONTENT_TYPE, APPLICATION_JSON).withHeader(LOCATION, chargeLocation(gatewayAccountId, "chargeId")).withBody(buildChargeResponse(responseFromConnector.build())));
}
use of uk.gov.pay.api.model.CardDetails in project pay-publicapi by alphagov.
the class PaymentResourceSearchIT method searchPayments_getsResults_withNoBillingAddress.
@Test
public void searchPayments_getsResults_withNoBillingAddress() {
String payments = aPaginatedPaymentSearchResult().withPayments(aSuccessfulSearchPayment().withCardDetails(new CardDetails("1234", "1234", "Card Holder", "11/21", null, "Visa", "credit")).withNumberOfResults(1).getResults()).build();
ledgerMockClient.respondOk_whenSearchCharges(payments);
ImmutableMap<String, String> queryParams = ImmutableMap.of();
searchPayments(queryParams).statusCode(200).contentType(JSON).body("results[0].card_details", hasKey("billing_address")).body("results[0].card_details.billing_address", is(nullValue())).body("results[0].card_details.first_digits_card_number", is("1234"));
}
use of uk.gov.pay.api.model.CardDetails in project pay-publicapi by alphagov.
the class GetPaymentIT method getPaymentWithNullCardTypeThroughConnector_ReturnsPaymentWithNullCardType.
@Test
public void getPaymentWithNullCardTypeThroughConnector_ReturnsPaymentWithNullCardType() {
connectorMockClient.respondWithChargeFound(CHARGE_TOKEN_ID, GATEWAY_ACCOUNT_ID, getConnectorCharge().withState(AWAITING_CAPTURE_REQUEST).withCardDetails(new CardDetails("1234", "123456", "Mr. Payment", "12/19", BILLING_ADDRESS, CARD_BRAND_LABEL, null)).withCorporateCardSurcharge(0L).withTotalAmount(0L).build());
getPaymentResponse(CHARGE_ID).statusCode(200).contentType(JSON).body("card_details.card_type", is(nullValue()));
}
use of uk.gov.pay.api.model.CardDetails in project pay-publicapi by alphagov.
the class GetPaymentIT method getPaymentThroughConnector_DoesNotReturnCardDigits_IfNotPresentInCardDetails.
@Test
public void getPaymentThroughConnector_DoesNotReturnCardDigits_IfNotPresentInCardDetails() {
CardDetails cardDetails = new CardDetails(null, null, "Mr. Payment", "12/19", BILLING_ADDRESS, CARD_BRAND_LABEL, CARD_TYPE);
connectorMockClient.respondWithChargeFound(CHARGE_TOKEN_ID, GATEWAY_ACCOUNT_ID, getConnectorCharge().withCardDetails(cardDetails).build());
assertPaymentWithoutCardDetails(getPaymentResponse(CHARGE_ID));
}
Aggregations