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