Search in sources :

Example 1 with PostLink

use of uk.gov.pay.api.model.links.PostLink 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 2 with PostLink

use of uk.gov.pay.api.model.links.PostLink 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 3 with PostLink

use of uk.gov.pay.api.model.links.PostLink 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

PactVerification (au.com.dius.pact.consumer.PactVerification)3 Test (org.junit.Test)3 CardPayment (uk.gov.pay.api.model.CardPayment)3 PaymentState (uk.gov.pay.api.model.PaymentState)3 PaymentWithAllLinks (uk.gov.pay.api.model.links.PaymentWithAllLinks)3 PostLink (uk.gov.pay.api.model.links.PostLink)3 Pacts (uk.gov.service.payments.commons.testing.pact.consumers.Pacts)3 Account (uk.gov.pay.api.auth.Account)2 Link (uk.gov.pay.api.model.links.Link)2 Address (uk.gov.pay.api.model.Address)1 ExternalMetadata (uk.gov.service.payments.commons.model.charge.ExternalMetadata)1