Search in sources :

Example 1 with PaymentState

use of uk.gov.pay.api.model.PaymentState 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())));
}
Also used : PaymentState(uk.gov.pay.api.model.PaymentState) CardDetails(uk.gov.pay.api.model.CardDetails)

Example 2 with PaymentState

use of uk.gov.pay.api.model.PaymentState 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())));
}
Also used : Address(uk.gov.pay.api.model.Address) PaymentState(uk.gov.pay.api.model.PaymentState) CardDetails(uk.gov.pay.api.model.CardDetails) Date(java.util.Date)

Example 3 with PaymentState

use of uk.gov.pay.api.model.PaymentState in project pay-publicapi by alphagov.

the class CreatePaymentServiceTest method testCreatePayment.

@Test
@PactVerification({ "connector" })
@Pacts(pacts = { "publicapi-connector-create-payment" })
public void testCreatePayment() {
    Map<String, Object> metadata = Map.of("ledger_code", 123, "fund_code", "ISIN122038", "cancellable", false);
    var requestPayload = CreateCardPaymentRequestBuilder.builder().amount(100).returnUrl("https://somewhere.gov.uk/rainbow/1").reference("a reference").description("a description").metadata(new ExternalMetadata(metadata)).delayedCapture(Boolean.TRUE).moto(Boolean.TRUE).language(SupportedLanguage.WELSH).email("joe.bogs@example.org").cardholderName("J. Bogs").addressLine1("address line 1").addressLine2("address line 2").city("address city").postcode("AB1 CD2").country("GB").build();
    PaymentWithAllLinks paymentResponse = createPaymentService.create(account, requestPayload);
    CardPayment payment = (CardPayment) paymentResponse.getPayment();
    assertThat(payment.getPaymentId(), is("ch_ab2341da231434l"));
    assertThat(payment.getAmount(), is(100L));
    assertThat(payment.getReference(), is("a reference"));
    assertThat(payment.getDescription(), is("a description"));
    assertThat(payment.getState(), is(new PaymentState("created", false)));
    assertThat(payment.getReturnUrl().get(), is("https://somewhere.gov.uk/rainbow/1"));
    assertThat(payment.getPaymentProvider(), is("Sandbox"));
    assertThat(payment.getCreatedDate(), is("2016-01-01T12:00:00Z"));
    assertThat(paymentResponse.getLinks().getSelf(), is(new Link("http://publicapi.test.localhost/v1/payments/ch_ab2341da231434l", "GET")));
    assertThat(paymentResponse.getLinks().getNextUrl(), is(new Link("http://frontend_connector/charge/token_1234567asdf", "GET")));
    PostLink expectedLink = new PostLink("http://frontend_connector/charge/", "POST", "application/x-www-form-urlencoded", Collections.singletonMap("chargeTokenId", "token_1234567asdf"));
    assertThat(paymentResponse.getLinks().getNextUrlPost(), is(expectedLink));
    assertThat(payment.getMetadata().getMetadata(), is(metadata));
    assertThat(payment.getDelayedCapture(), is(true));
    assertThat(payment.getLanguage(), is(SupportedLanguage.WELSH));
    assertThat(payment.getEmail().isPresent(), is(true));
    assertThat(payment.getEmail().get(), is("joe.bogs@example.org"));
    assertThat(payment.getCardDetails().isPresent(), is(true));
    assertThat(payment.getCardDetails().get().getCardHolderName(), is("J. Bogs"));
    assertThat(payment.getCardDetails().get().getBillingAddress().isPresent(), is(true));
    Address billingAddress = payment.getCardDetails().get().getBillingAddress().get();
    assertThat(billingAddress.getLine1(), is("address line 1"));
    assertThat(billingAddress.getLine2(), is("address line 2"));
    assertThat(billingAddress.getCity(), is("address city"));
    assertThat(billingAddress.getPostcode(), is("AB1 CD2"));
    assertThat(billingAddress.getCountry(), is("GB"));
}
Also used : CardPayment(uk.gov.pay.api.model.CardPayment) Address(uk.gov.pay.api.model.Address) PaymentWithAllLinks(uk.gov.pay.api.model.links.PaymentWithAllLinks) PaymentState(uk.gov.pay.api.model.PaymentState) ExternalMetadata(uk.gov.service.payments.commons.model.charge.ExternalMetadata) Link(uk.gov.pay.api.model.links.Link) PostLink(uk.gov.pay.api.model.links.PostLink) PostLink(uk.gov.pay.api.model.links.PostLink) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Example 4 with PaymentState

use of uk.gov.pay.api.model.PaymentState in project pay-publicapi by alphagov.

the class CreatePaymentServiceTest method testCreatePaymentWithMinimumFields.

@Test
@PactVerification({ "connector" })
@Pacts(pacts = { "publicapi-connector-create-payment-with-minimum-fields" })
public void testCreatePaymentWithMinimumFields() {
    Account account = new Account("123456", TokenPaymentType.CARD, "a-token-link");
    var requestPayload = CreateCardPaymentRequestBuilder.builder().amount(100).returnUrl("https://somewhere.gov.uk/rainbow/1").reference("a reference").description("a description").build();
    PaymentWithAllLinks paymentResponse = createPaymentService.create(account, requestPayload);
    CardPayment payment = (CardPayment) paymentResponse.getPayment();
    assertThat(payment.getPaymentId(), is("ch_ab2341da231434l"));
    assertThat(payment.getAmount(), is(100L));
    assertThat(payment.getReference(), is("a reference"));
    assertThat(payment.getDescription(), is("a description"));
    assertThat(payment.getEmail(), is(Optional.empty()));
    assertThat(payment.getState(), is(new PaymentState("created", false)));
    assertThat(payment.getReturnUrl().get(), is("https://somewhere.gov.uk/rainbow/1"));
    assertThat(payment.getPaymentProvider(), is("Sandbox"));
    assertThat(payment.getCreatedDate(), is("2016-01-01T12:00:00Z"));
    assertThat(payment.getLanguage(), is(SupportedLanguage.ENGLISH));
    assertThat(payment.getDelayedCapture(), is(false));
    assertThat(payment.getMoto(), is(false));
    assertThat(paymentResponse.getLinks().getSelf(), is(new Link("http://publicapi.test.localhost/v1/payments/ch_ab2341da231434l", "GET")));
    assertThat(paymentResponse.getLinks().getNextUrl(), is(new Link("http://frontend_connector/charge/token_1234567asdf", "GET")));
    PostLink expectedLink = new PostLink("http://frontend_connector/charge/", "POST", "application/x-www-form-urlencoded", Collections.singletonMap("chargeTokenId", "token_1234567asdf"));
    assertThat(paymentResponse.getLinks().getNextUrlPost(), is(expectedLink));
}
Also used : Account(uk.gov.pay.api.auth.Account) CardPayment(uk.gov.pay.api.model.CardPayment) PaymentWithAllLinks(uk.gov.pay.api.model.links.PaymentWithAllLinks) PaymentState(uk.gov.pay.api.model.PaymentState) Link(uk.gov.pay.api.model.links.Link) PostLink(uk.gov.pay.api.model.links.PostLink) PostLink(uk.gov.pay.api.model.links.PostLink) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Example 5 with PaymentState

use of uk.gov.pay.api.model.PaymentState in project pay-publicapi by alphagov.

the class GetPaymentServiceTest method testGetPayment.

@Test
@PactVerification({ "connector" })
@Pacts(pacts = { "publicapi-connector-get-created-payment" })
public void testGetPayment() {
    Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, "a-token-link");
    PaymentWithAllLinks paymentResponse = getPaymentService.getPayment(account, CHARGE_ID);
    CardPayment payment = (CardPayment) paymentResponse.getPayment();
    assertThat(payment.getAmount(), is(100L));
    assertThat(payment.getState(), is(new PaymentState("created", false)));
    assertThat(payment.getDescription(), is("Test description"));
    assertThat(payment.getReference(), is("aReference"));
    assertThat(payment.getLanguage(), is(SupportedLanguage.ENGLISH));
    assertThat(payment.getPaymentId(), is(CHARGE_ID));
    assertThat(payment.getReturnUrl().get(), is("https://somewhere.gov.uk/rainbow/1"));
    assertThat(payment.getPaymentProvider(), is("sandbox"));
    assertThat(payment.getCreatedDate(), is("2018-09-07T13:12:02.121Z"));
    assertThat(payment.getMoto(), is(false));
    assertThat(payment.getDelayedCapture(), is(true));
    assertThat(payment.getCorporateCardSurcharge(), is(Optional.empty()));
    assertThat(payment.getTotalAmount(), is(Optional.empty()));
    assertThat(paymentResponse.getLinks().getSelf().getHref(), containsString("v1/payments/" + CHARGE_ID));
    assertThat(paymentResponse.getLinks().getSelf().getMethod(), is("GET"));
    assertThat(paymentResponse.getLinks().getRefunds().getHref(), containsString("v1/payments/" + CHARGE_ID + "/refunds"));
    assertThat(paymentResponse.getLinks().getRefunds().getMethod(), is("GET"));
    assertThat(paymentResponse.getLinks().getNextUrl().getHref(), containsString("secure/ae749781-6562-4e0e-8f56-32d9639079dc"));
    assertThat(paymentResponse.getLinks().getNextUrl().getMethod(), is("GET"));
    assertThat(paymentResponse.getLinks().getNextUrlPost(), is(new PostLink("https://card_frontend/secure", "POST", "application/x-www-form-urlencoded", Collections.singletonMap("chargeTokenId", "ae749781-6562-4e0e-8f56-32d9639079dc"))));
    assertThat(paymentResponse.getLinks().getCapture(), is(nullValue()));
}
Also used : Account(uk.gov.pay.api.auth.Account) CardPayment(uk.gov.pay.api.model.CardPayment) PaymentWithAllLinks(uk.gov.pay.api.model.links.PaymentWithAllLinks) PaymentState(uk.gov.pay.api.model.PaymentState) PostLink(uk.gov.pay.api.model.links.PostLink) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Aggregations

PaymentState (uk.gov.pay.api.model.PaymentState)8 PactVerification (au.com.dius.pact.consumer.PactVerification)5 Test (org.junit.Test)5 Pacts (uk.gov.service.payments.commons.testing.pact.consumers.Pacts)5 Account (uk.gov.pay.api.auth.Account)4 CardPayment (uk.gov.pay.api.model.CardPayment)4 PaymentWithAllLinks (uk.gov.pay.api.model.links.PaymentWithAllLinks)4 Address (uk.gov.pay.api.model.Address)3 CardDetails (uk.gov.pay.api.model.CardDetails)3 PostLink (uk.gov.pay.api.model.links.PostLink)3 Link (uk.gov.pay.api.model.links.Link)2 Date (java.util.Date)1 TransactionSearchParams (uk.gov.pay.api.ledger.model.TransactionSearchParams)1 TransactionSearchResults (uk.gov.pay.api.ledger.model.TransactionSearchResults)1 PaymentForSearchResult (uk.gov.pay.api.model.search.card.PaymentForSearchResult)1 ExternalMetadata (uk.gov.service.payments.commons.model.charge.ExternalMetadata)1