Search in sources :

Example 1 with CreateChargeException

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));
    }
}
Also used : Account(uk.gov.pay.api.auth.Account) CreateChargeException(uk.gov.pay.api.exception.CreateChargeException) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Example 2 with CreateChargeException

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));
}
Also used : Response(javax.ws.rs.core.Response) ChargeFromResponse(uk.gov.pay.api.model.ChargeFromResponse) CreateChargeException(uk.gov.pay.api.exception.CreateChargeException) ChargeFromResponse(uk.gov.pay.api.model.ChargeFromResponse)

Example 3 with CreateChargeException

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()));
}
Also used : ConnectorErrorResponse(uk.gov.pay.api.exception.ConnectorResponseErrorException.ConnectorErrorResponse) Response(javax.ws.rs.core.Response) CreateChargeException(uk.gov.pay.api.exception.CreateChargeException) ConnectorErrorResponse(uk.gov.pay.api.exception.ConnectorResponseErrorException.ConnectorErrorResponse) PaymentError.aPaymentError(uk.gov.pay.api.model.PaymentError.aPaymentError) PaymentError(uk.gov.pay.api.model.PaymentError) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with CreateChargeException

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());
}
Also used : Response(javax.ws.rs.core.Response) ChargeFromResponse(uk.gov.pay.api.model.ChargeFromResponse) TelephonePaymentResponse(uk.gov.pay.api.model.telephone.TelephonePaymentResponse) TelephonePaymentResponse(uk.gov.pay.api.model.telephone.TelephonePaymentResponse) CreateChargeException(uk.gov.pay.api.exception.CreateChargeException) ChargeFromResponse(uk.gov.pay.api.model.ChargeFromResponse)

Aggregations

CreateChargeException (uk.gov.pay.api.exception.CreateChargeException)4 Response (javax.ws.rs.core.Response)3 ChargeFromResponse (uk.gov.pay.api.model.ChargeFromResponse)2 PactVerification (au.com.dius.pact.consumer.PactVerification)1 Test (org.junit.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1 Account (uk.gov.pay.api.auth.Account)1 ConnectorErrorResponse (uk.gov.pay.api.exception.ConnectorResponseErrorException.ConnectorErrorResponse)1 PaymentError (uk.gov.pay.api.model.PaymentError)1 PaymentError.aPaymentError (uk.gov.pay.api.model.PaymentError.aPaymentError)1 TelephonePaymentResponse (uk.gov.pay.api.model.telephone.TelephonePaymentResponse)1 Pacts (uk.gov.service.payments.commons.testing.pact.consumers.Pacts)1