use of uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity in project pay-products by alphagov.
the class PaymentResourceIT method findAPaymentByGatewayAccountIdAndReferenceNumber_shouldSucceed.
@Test
public void findAPaymentByGatewayAccountIdAndReferenceNumber_shouldSucceed() {
String productExternalId = randomUuid();
ProductEntity productEntity = ProductEntityFixture.aProductEntity().withGatewayAccountId(gatewayAccountId).withExternalId(productExternalId).build();
Product product = productEntity.toProduct();
databaseHelper.addProduct(product);
Integer productId = databaseHelper.findProductId(productExternalId);
productEntity.setId(productId);
String externalId = randomUuid();
String referenceNumber = externalId.substring(0, 9);
PaymentEntity payment = aPaymentEntity().withExternalId(externalId).withProduct(productEntity).withNextUrl(nextUrl).withGatewayAccountId(productEntity.getGatewayAccountId()).withReferenceNumber(referenceNumber).build();
databaseHelper.addPayment(payment.toPayment(), productEntity.getGatewayAccountId());
ValidatableResponse response = givenSetup().when().accept(APPLICATION_JSON).get(format("/v1/api/payments/%s/%s", gatewayAccountId, referenceNumber)).then().statusCode(200);
response.body("external_id", is(payment.getExternalId())).body("govuk_payment_id", is(payment.getGovukPaymentId())).body("product_external_id", is(product.getExternalId())).body("status", is(payment.getStatus().toString())).body("amount", is(payment.getAmount().intValue())).body("reference_number", is(referenceNumber)).body("_links", hasSize(2)).body("_links[0].href", matchesPattern(paymentsUrl + externalId)).body("_links[0].method", is(HttpMethod.GET)).body("_links[0].rel", is("self")).body("_links[1].href", is(nextUrl)).body("_links[1].method", is(HttpMethod.GET)).body("_links[1].rel", is("next"));
}
use of uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity in project pay-products by alphagov.
the class PaymentResourceIT method shouldReturn400_whenReferenceEnabledAndNoReferencePresent.
@Test
public void shouldReturn400_whenReferenceEnabledAndNoReferencePresent() {
String productExternalId = randomUuid();
ProductEntity productEntity = ProductEntityFixture.aProductEntity().withGatewayAccountId(gatewayAccountId).withExternalId(productExternalId).withReferenceEnabled(true).withReferenceLabel("A ref label").build();
Product product = productEntity.toProduct();
databaseHelper.addProduct(product);
givenSetup().accept(APPLICATION_JSON).post(format("/v1/api/products/%s/payments", product.getExternalId())).then().statusCode(400).body("errors", hasSize(1)).body("errors[0]", is("User defined reference is enabled but missing"));
}
use of uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity in project pay-products by alphagov.
the class PaymentResourceIT method shouldSucceed_whenUserEnteredReferenceIsEnabled_andReferenceAlreadyExists.
@Test
public void shouldSucceed_whenUserEnteredReferenceIsEnabled_andReferenceAlreadyExists() throws Exception {
String userDefinedReference = randomUuid().substring(1, 15);
String productExternalId = randomUuid();
ProductEntity productEntity = ProductEntityFixture.aProductEntity().withGatewayAccountId(gatewayAccountId).withExternalId(productExternalId).withReferenceEnabled(true).withReferenceLabel("Reference label").withLanguage(SupportedLanguage.WELSH).build();
Product product = productEntity.toProduct();
databaseHelper.addProduct(product);
Integer productId = databaseHelper.findProductId(productExternalId);
productEntity.setId(productId);
String externalId = randomUuid();
PaymentEntity payment = aPaymentEntity().withExternalId(externalId).withProduct(productEntity).withNextUrl(nextUrl).withGatewayAccountId(productEntity.getGatewayAccountId()).withReferenceNumber(userDefinedReference).build();
databaseHelper.addPayment(payment.toPayment(), productEntity.getGatewayAccountId());
String govukPaymentId = "govukPaymentId";
String nextUrl = "http://next.url";
Long priceOverride = 501L;
setupResponseToCreatePaymentRequest(productEntity.getPayApiToken(), createPaymentResponsePayload(govukPaymentId, priceOverride, userDefinedReference, productEntity.getName(), productEntity.getReturnUrl(), nextUrl, productEntity.getLanguage().toString(), null));
Map<String, String> payload = ImmutableMap.of("price", priceOverride.toString(), "reference_number", userDefinedReference);
givenSetup().accept(APPLICATION_JSON).body(mapper.writeValueAsString(payload)).post(format("/v1/api/products/%s/payments", productEntity.getExternalId())).then().statusCode(201);
}
use of uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity in project pay-products by alphagov.
the class PaymentResourceIT method findAllPaymentsOfAProduct_shouldSucceed.
@Test
public void findAllPaymentsOfAProduct_shouldSucceed() {
String productExternalId = randomUuid();
String paymentExternalId1 = randomUuid();
String paymentExternalId2 = randomUuid();
ProductEntity productEntity = ProductEntityFixture.aProductEntity().withGatewayAccountId(gatewayAccountId).withExternalId(productExternalId).build();
Product product = productEntity.toProduct();
databaseHelper.addProduct(product);
Integer productId = databaseHelper.findProductId(productExternalId);
productEntity.setId(productId);
PaymentEntity payment1 = aPaymentEntity().withExternalId(paymentExternalId1).withProduct(productEntity).withNextUrl(nextUrl).withReferenceNumber(paymentExternalId1.substring(0, 9)).build();
databaseHelper.addPayment(payment1.toPayment(), gatewayAccountId);
PaymentEntity payment2 = aPaymentEntity().withExternalId(paymentExternalId2).withProduct(productEntity).withNextUrl(nextUrl).withReferenceNumber(paymentExternalId2.substring(0, 9)).build();
databaseHelper.addPayment(payment2.toPayment(), gatewayAccountId);
ValidatableResponse response = givenSetup().when().accept(APPLICATION_JSON).get(format("v1/api/products/%s/payments", productExternalId)).then().statusCode(200);
response.body("", hasSize(2)).body("[0].external_id", is(payment1.getExternalId())).body("[0].govuk_payment_id", is(payment1.getGovukPaymentId())).body("[0].product_external_id", is(product.getExternalId())).body("[0].status", is(payment1.getStatus().toString())).body("[0].amount", is(payment1.getAmount().intValue())).body("[0].reference_number", is(paymentExternalId1.substring(0, 9))).body("[0]._links", hasSize(2)).body("[0]._links[0].href", matchesPattern(paymentsUrl + payment1.getExternalId())).body("[0]._links[0].method", is(HttpMethod.GET)).body("[0]._links[0].rel", is("self")).body("[0]._links[1].href", is(nextUrl)).body("[0]._links[1].method", is(HttpMethod.GET)).body("[0]._links[1].rel", is("next")).body("[1].external_id", is(payment2.getExternalId())).body("[1].govuk_payment_id", is(payment2.getGovukPaymentId())).body("[1].product_external_id", is(product.getExternalId())).body("[1].status", is(payment2.getStatus().toString())).body("[1].amount", is(payment2.getAmount().intValue())).body("[1].reference_number", is(paymentExternalId2.substring(0, 9))).body("[1]._links", hasSize(2)).body("[1]._links[0].href", matchesPattern(paymentsUrl + payment2.getExternalId())).body("[1]._links[0].method", is(HttpMethod.GET)).body("[1]._links[0].rel", is("self")).body("[1]._links[1].href", is(nextUrl)).body("[1]._links[1].method", is(HttpMethod.GET)).body("[1]._links[1].rel", is("next"));
}
use of uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity in project pay-products by alphagov.
the class PaymentResourceIT method findAPayment_shouldSucceed.
@Test
public void findAPayment_shouldSucceed() {
String productExternalId = randomUuid();
ProductEntity productEntity = ProductEntityFixture.aProductEntity().withGatewayAccountId(gatewayAccountId).withExternalId(productExternalId).build();
Product product = productEntity.toProduct();
databaseHelper.addProduct(product);
Integer productId = databaseHelper.findProductId(productExternalId);
productEntity.setId(productId);
String externalId = randomUuid();
String referenceNumber = externalId.substring(0, 9);
PaymentEntity payment = aPaymentEntity().withExternalId(externalId).withProduct(productEntity).withNextUrl(nextUrl).withGatewayAccountId(productEntity.getGatewayAccountId()).withReferenceNumber(referenceNumber).build();
databaseHelper.addPayment(payment.toPayment(), productEntity.getGatewayAccountId());
ValidatableResponse response = givenSetup().when().accept(APPLICATION_JSON).get(format("/v1/api/payments/%s", externalId)).then().statusCode(200);
response.body("external_id", is(payment.getExternalId())).body("govuk_payment_id", is(payment.getGovukPaymentId())).body("product_external_id", is(product.getExternalId())).body("status", is(payment.getStatus().toString())).body("amount", is(payment.getAmount().intValue())).body("reference_number", is(referenceNumber)).body("_links", hasSize(2)).body("_links[0].href", matchesPattern(paymentsUrl + externalId)).body("_links[0].method", is(HttpMethod.GET)).body("_links[0].rel", is("self")).body("_links[1].href", is(nextUrl)).body("_links[1].method", is(HttpMethod.GET)).body("_links[1].rel", is("next"));
}
Aggregations