mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-01 16:16:47 +00:00
Validate level in OneTimeDonationController
This commit is contained in:
1 parent
ea1e4f02d0
commit
09c18205d4
2 files changed
+15
-8
No files matched your search
+10
-3
@@ -127,7 +127,8 @@ public class OneTimeDonationController {
|
||||
@Min(1)
|
||||
public long amount;
|
||||
|
||||
@Schema(description = "The level for the boost payment", defaultValue = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "The level for the boost payment", defaultValue = "1", minimum = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Min(1)
|
||||
public long level = 1;
|
||||
|
||||
@Schema(description = "The payment method", defaultValue = "CARD")
|
||||
@@ -177,14 +178,20 @@ public class OneTimeDonationController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the currency is supported by the {@code manager} and {@code request.paymentMethod} and that the
|
||||
* amount meets minimum and maximum constraints.
|
||||
* Validates that the request level is valid, the currency is supported by the {@code manager} and {@code request.paymentMethod},
|
||||
* and that the amount meets minimum and maximum constraints.
|
||||
*
|
||||
* @throws BadRequestException indicates validation failed. Inspect {@code response.error} for details
|
||||
*/
|
||||
private void validateRequestCurrencyAmount(final CreateBoostRequest request, final BigDecimal amount,
|
||||
final CustomerAwareSubscriptionPaymentProcessor manager) {
|
||||
|
||||
if (!(request.level == oneTimeDonationConfiguration.gift().level()
|
||||
|| request.level == oneTimeDonationConfiguration.boost().level())) {
|
||||
throw new BadRequestException(
|
||||
Response.status(Response.Status.BAD_REQUEST).entity(Map.of("error", "invalid_level")).build());
|
||||
}
|
||||
|
||||
if (!manager.getSupportedCurrenciesForPaymentMethod(request.paymentMethod)
|
||||
.contains(request.currency.toLowerCase(Locale.ROOT))) {
|
||||
throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST)
|
||||
|
||||
+5
-5
@@ -104,8 +104,7 @@ class OneTimeDonationControllerTest extends AbstractV1SubscriptionControllerTest
|
||||
.post(Entity.json("""
|
||||
{
|
||||
"currency": "USD",
|
||||
"amount": 249,
|
||||
"level": null
|
||||
"amount": 249
|
||||
}
|
||||
"""));
|
||||
assertThat(response.getStatus()).isEqualTo(400);
|
||||
@@ -125,7 +124,6 @@ class OneTimeDonationControllerTest extends AbstractV1SubscriptionControllerTest
|
||||
{
|
||||
"currency": "EUR",
|
||||
"amount": 1000001,
|
||||
"level": null,
|
||||
"paymentMethod": "SEPA_DEBIT"
|
||||
}
|
||||
"""));
|
||||
@@ -147,7 +145,6 @@ class OneTimeDonationControllerTest extends AbstractV1SubscriptionControllerTest
|
||||
{
|
||||
"currency": "USD",
|
||||
"amount": 3000,
|
||||
"level": null,
|
||||
"paymentMethod": "SEPA_DEBIT"
|
||||
}
|
||||
"""));
|
||||
@@ -170,7 +167,10 @@ class OneTimeDonationControllerTest extends AbstractV1SubscriptionControllerTest
|
||||
|
||||
final Response response = RESOURCE_EXTENSION.target("/v1/subscription/boost/create")
|
||||
.request()
|
||||
.post(Entity.json("{\"currency\": \"USD\", \"amount\": 300, \"level\": null}"));
|
||||
.post(Entity.json("""
|
||||
{"currency": "USD", "amount": 300}
|
||||
"""
|
||||
));
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user