Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PP-13511: Reject payment of <30p for a Stripe account #5704

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
import static uk.gov.pay.connector.charge.model.domain.ChargeStatus.PAYMENT_NOTIFICATION_CREATED;
import static uk.gov.pay.connector.charge.model.domain.ChargeStatus.fromString;
import static uk.gov.pay.connector.charge.model.domain.Exemption3dsType.CORPORATE;
import static uk.gov.pay.connector.gateway.PaymentGatewayName.STRIPE;
import static uk.gov.pay.connector.gateway.PaymentGatewayName.WORLDPAY;
import static uk.gov.pay.connector.paymentprocessor.model.Exemption3ds.EXEMPTION_NOT_REQUESTED;
import static uk.gov.service.payments.commons.model.AuthorisationMode.AGREEMENT;
Expand All @@ -155,6 +156,7 @@
import static uk.gov.service.payments.commons.model.ErrorIdentifier.NON_HTTPS_RETURN_URL_NOT_ALLOWED_FOR_A_LIVE_ACCOUNT;
import static uk.gov.service.payments.commons.model.Source.CARD_AGENT_INITIATED_MOTO;
import static uk.gov.service.payments.commons.model.Source.CARD_API;
import static uk.gov.service.payments.commons.model.Source.CARD_EXTERNAL_TELEPHONE;
import static uk.gov.service.payments.commons.model.Source.CARD_PAYMENT_LINK;

public class ChargeService {
Expand Down Expand Up @@ -1177,7 +1179,7 @@ private void checkIfGatewayAccountDisabled(GatewayAccountEntity gatewayAccount)
}

private void checkIfAmountBelowMinimum(Source source, Long amount, GatewayAccountEntity gatewayAccount, String paymentProvider) {
if (source == CARD_API && amount < MINIMUM_STRIPE_PAYMENT_AMOUNT && PaymentGatewayName.valueFrom(paymentProvider) == PaymentGatewayName.STRIPE) {
if (source != CARD_EXTERNAL_TELEPHONE && amount < MINIMUM_STRIPE_PAYMENT_AMOUNT && PaymentGatewayName.valueFrom(paymentProvider) == STRIPE) {
throw new ChargeException("Payments under 30 pence are not allowed for Stripe accounts", AMOUNT_BELOW_MINIMUM, SC_UNPROCESSABLE_ENTITY);
}
checkIfZeroAmountAllowed(amount, gatewayAccount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
Expand Down Expand Up @@ -729,8 +730,9 @@ void shouldThrowException_whenGatewayAccountDisabled() {
verify(mockedChargeDao, never()).persist(any(ChargeEntity.class));
}

@Test
void shouldThrowException_whenPaymentProviderIsStripeAndAmountUnder30Pence() {
@ParameterizedTest
@EnumSource(value = Source.class, names = { "CARD_API", "CARD_PAYMENT_LINK", "CARD_AGENT_INITIATED_MOTO" })
void shouldThrowException_whenPaymentProviderIsStripeAndAmountUnder30Pence(Source source) {
GatewayAccountCredentialsEntity stripeGatewayAccountCredentialsEntity = GatewayAccountCredentialsEntityFixture
.aGatewayAccountCredentialsEntity()
.withGatewayAccountEntity(gatewayAccount)
Expand All @@ -740,7 +742,7 @@ void shouldThrowException_whenPaymentProviderIsStripeAndAmountUnder30Pence() {
.build();
ChargeCreateRequest request = requestBuilder
.withAmount(29)
.withSource(CARD_API)
.withSource(source)
.build();
when(mockedGatewayAccountDao.findById(GATEWAY_ACCOUNT_ID)).thenReturn(Optional.of(gatewayAccount));
when(mockGatewayAccountCredentialsService.getCurrentOrActiveCredential(gatewayAccount)).thenReturn(stripeGatewayAccountCredentialsEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.ValueSource;
import uk.gov.pay.connector.extension.AppWithPostgresAndSqsExtension;
import uk.gov.pay.connector.gateway.PaymentGatewayName;
import uk.gov.pay.connector.gatewayaccount.model.GatewayAccountType;
import uk.gov.pay.connector.it.base.ITestBaseExtension;
import uk.gov.pay.connector.it.dao.DatabaseFixtures;
import uk.gov.service.payments.commons.model.ErrorIdentifier;
import uk.gov.service.payments.commons.model.Source;

import javax.ws.rs.core.Response.Status;
import java.sql.Timestamp;
Expand Down Expand Up @@ -383,8 +387,9 @@ void when_amount_is_zero_and_account_does_not_allow_zero_amount() {
.body("error_identifier", is(ErrorIdentifier.ZERO_AMOUNT_NOT_ALLOWED.toString()));
}

@Test
void when_amount_is_under_30p_for_api_payment_for_Stripe_account() {
@ParameterizedTest
@ValueSource( strings = { "CARD_API", "CARD_PAYMENT_LINK", "CARD_AGENT_INITIATED_MOTO" })
void when_amount_is_under_30p_for_api_payment_for_Stripe_account(String source) {
DatabaseFixtures.TestAccount stripeTestAccount = app.getDatabaseFixtures()
.aTestAccount()
.withPaymentProvider("stripe")
Expand All @@ -397,7 +402,7 @@ void when_amount_is_under_30p_for_api_payment_for_Stripe_account() {
"reference", "Test reference",
"description", "Test description",
"return_url", "http://service.local/success-page/",
"source", "CARD_API"
"source", source
)))
.post(format("/v1/api/accounts/%s/charges", stripeTestAccount.getAccountId()))
.then()
Expand Down Expand Up @@ -900,8 +905,9 @@ void when_amount_is_zero_if_account_does_not_allow_zero_amount() {
.body("error_identifier", is(ErrorIdentifier.ZERO_AMOUNT_NOT_ALLOWED.toString()));
}

@Test
void when_amount_is_under_30p_for_api_payment_for_Stripe_account() {
@ParameterizedTest
@ValueSource( strings = { "CARD_API", "CARD_PAYMENT_LINK", "CARD_AGENT_INITIATED_MOTO" })
void when_amount_is_under_30p_for_api_payment_for_Stripe_account(String source) {
DatabaseFixtures.TestAccount stripeTestAccount = app.getDatabaseFixtures()
.aTestAccount()
.withPaymentProvider("stripe")
Expand All @@ -915,7 +921,7 @@ void when_amount_is_under_30p_for_api_payment_for_Stripe_account() {
"reference", "Test reference",
"description", "Test description",
"return_url", "http://service.local/success-page/",
"source", "CARD_API"
"source", source
)))
.post(format("/v1/api/service/%s/account/%s/charges", VALID_SERVICE_ID, GatewayAccountType.TEST))
.then()
Expand Down
Loading