Search in sources :

Example 1 with Link

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

the class LedgerMockClient method respondWithSearchRefunds.

public void respondWithSearchRefunds(RefundTransactionFromLedgerFixture... refunds) {
    Map<String, Link> links = (ImmutableMap.of("first_page", new Link("http://server:port/first-link?page=1"), "prev_page", new Link("http://server:port/prev-link?page=2"), "self", new Link("http://server:port/self-link?page=3"), "last_page", new Link("http://server:port/last-link?page=5"), "next_page", new Link("http://server:port/next-link?page=4")));
    JsonStringBuilder jsonStringBuilder = new JsonStringBuilder().add("total", 1).add("count", 1).add("page", 1).add("results", Arrays.asList(refunds)).add("_links", links);
    ledgerMock.stubFor(get(urlPathEqualTo("/v1/transaction")).willReturn(aResponse().withStatus(OK_200).withHeader(CONTENT_TYPE, APPLICATION_JSON).withBody(jsonStringBuilder.build())));
}
Also used : JsonStringBuilder(uk.gov.pay.api.utils.JsonStringBuilder) Link(uk.gov.pay.api.model.links.Link)

Example 2 with Link

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

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

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

the class ConnectorMockClient method buildGetRefundResponse.

private String buildGetRefundResponse(String refundId, int amount, int refundAmountAvailable, String status, String createdDate) {
    List<Map<String, Link>> links = new ArrayList<>();
    links.add(ImmutableMap.of("self", new Link("http://server:port/self-link")));
    links.add(ImmutableMap.of("payment", new Link("http://server:port/payment-link")));
    JsonStringBuilder jsonStringBuilder = new JsonStringBuilder().add("refund_id", refundId).add("amount", amount).add("refund_amount_available", refundAmountAvailable).add("status", status).add("created_date", createdDate).add("_links", links);
    return jsonStringBuilder.build();
}
Also used : ArrayList(java.util.ArrayList) JsonStringBuilder(uk.gov.pay.api.utils.JsonStringBuilder) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Link(uk.gov.pay.api.model.links.Link)

Example 5 with Link

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

the class ConnectorMockClient method respondWithGetAllRefunds.

public void respondWithGetAllRefunds(String gatewayAccountId, String chargeId, PaymentRefundJsonFixture... refunds) {
    Map<String, List<PaymentRefundJsonFixture>> refundList = new HashMap<>();
    refundList.put("refunds", Arrays.asList(refunds));
    List<Map<String, Link>> links = new ArrayList<>();
    links.add(ImmutableMap.of("self", new Link("http://server:port/self-link")));
    links.add(ImmutableMap.of("payment", new Link("http://server:port/payment-link")));
    JsonStringBuilder embedded = new JsonStringBuilder().noPrettyPrint();
    embedded.add("refunds", refundList);
    JsonStringBuilder jsonStringBuilder = new JsonStringBuilder().add("payment_id", chargeId).add("_links", links).add("_embedded", refundList);
    whenGetAllRefunds(gatewayAccountId, chargeId, aResponse().withStatus(OK_200).withHeader(CONTENT_TYPE, APPLICATION_JSON).withBody(jsonStringBuilder.build()));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) JsonStringBuilder(uk.gov.pay.api.utils.JsonStringBuilder) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Link(uk.gov.pay.api.model.links.Link)

Aggregations

Link (uk.gov.pay.api.model.links.Link)5 JsonStringBuilder (uk.gov.pay.api.utils.JsonStringBuilder)3 PactVerification (au.com.dius.pact.consumer.PactVerification)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 CardPayment (uk.gov.pay.api.model.CardPayment)2 PaymentState (uk.gov.pay.api.model.PaymentState)2 PaymentWithAllLinks (uk.gov.pay.api.model.links.PaymentWithAllLinks)2 PostLink (uk.gov.pay.api.model.links.PostLink)2 Pacts (uk.gov.service.payments.commons.testing.pact.consumers.Pacts)2 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Account (uk.gov.pay.api.auth.Account)1 Address (uk.gov.pay.api.model.Address)1 ExternalMetadata (uk.gov.service.payments.commons.model.charge.ExternalMetadata)1