use of uk.gov.pay.api.exception.CreateChargeException in project pay-publicapi by alphagov.
the class CreatePaymentServiceTest method shouldThrowExceptionWithIdentifierAccountNotLinkedToPSP_IfGatewayAccountCredentialIsNotConfiguredInConnector.
@Test
@PactVerification({ "connector" })
@Pacts(pacts = { "publicapi-connector-create-payment-with-credentials-in-created-not-allowed" })
public void shouldThrowExceptionWithIdentifierAccountNotLinkedToPSP_IfGatewayAccountCredentialIsNotConfiguredInConnector() {
Account account = new Account("444", 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();
try {
createPaymentService.create(account, requestPayload);
fail("Expected CreateChargeException to be thrown");
} catch (CreateChargeException e) {
assertThat(e.getErrorIdentifier(), is(ErrorIdentifier.ACCOUNT_NOT_LINKED_WITH_PSP));
}
}
use of uk.gov.pay.api.exception.CreateChargeException in project pay-publicapi by alphagov.
the class CreatePaymentService method create.
public PaymentWithAllLinks create(Account account, CreateCardPaymentRequest createCardPaymentRequest) {
Response connectorResponse = createCharge(account, createCardPaymentRequest);
if (!createdSuccessfully(connectorResponse)) {
throw new CreateChargeException(connectorResponse);
}
ChargeFromResponse chargeFromResponse = connectorResponse.readEntity(ChargeFromResponse.class);
return buildResponseModel(Charge.from(chargeFromResponse));
}
use of uk.gov.pay.api.exception.CreateChargeException in project pay-publicapi by alphagov.
the class CreateChargeExceptionMapperTest method testExceptionMapping.
@ParameterizedTest
@CsvSource({ "TELEPHONE_PAYMENT_NOTIFICATIONS_NOT_ALLOWED, RESOURCE_ACCESS_FORBIDDEN, 403", "ACCOUNT_NOT_LINKED_WITH_PSP, ACCOUNT_NOT_LINKED_WITH_PSP, 403", "MOTO_NOT_ALLOWED, CREATE_PAYMENT_MOTO_NOT_ENABLED, 422" })
public void testExceptionMapping(String errorIdentifier, String paymentError, int expectedStatusCode) {
when(mockResponse.readEntity(ConnectorErrorResponse.class)).thenReturn(new ConnectorErrorResponse(ErrorIdentifier.valueOf(errorIdentifier), null, null));
Response returnedResponse = mapper.toResponse(new CreateChargeException(mockResponse));
PaymentError returnedError = (PaymentError) returnedResponse.getEntity();
PaymentError expectedError = aPaymentError(PaymentError.Code.valueOf(paymentError));
assertThat(returnedResponse.getStatus(), is(expectedStatusCode));
assertThat(returnedError.getDescription(), is(expectedError.getDescription()));
assertThat(returnedError.getCode(), is(expectedError.getCode()));
}
use of uk.gov.pay.api.exception.CreateChargeException in project pay-publicapi by alphagov.
the class CreateTelephonePaymentService method create.
public Pair<TelephonePaymentResponse, Integer> create(Account account, CreateTelephonePaymentRequest createTelephonePaymentRequest) {
Response connectorResponse = createTelephoneCharge(account, createTelephonePaymentRequest);
if (!createdSuccessfully(connectorResponse)) {
throw new CreateChargeException(connectorResponse);
}
ChargeFromResponse chargeFromResponse = connectorResponse.readEntity(ChargeFromResponse.class);
TelephonePaymentResponse telephonePaymentResponse = TelephonePaymentResponse.from(chargeFromResponse);
return Pair.of(telephonePaymentResponse, connectorResponse.getStatus());
}
Aggregations