From e5fdab1bc879843453ce1f2be02fda41a6eab359 Mon Sep 17 00:00:00 2001 From: Ravi Khadiwala Date: Wed, 14 Aug 2024 16:10:10 -0500 Subject: [PATCH] Return 400 if a client specifies paypal where it's not supported --- .../textsecuregcm/controllers/SubscriptionController.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java index 56247d23f..f9f2a03a2 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java @@ -253,6 +253,10 @@ public class SubscriptionController { SubscriberCredentials subscriberCredentials = SubscriberCredentials.process(authenticatedAccount, subscriberId, clock); + if (paymentMethodType == PaymentMethod.PAYPAL) { + throw new BadRequestException("The PAYPAL payment type must use create_payment_method/paypal"); + } + final SubscriptionPaymentProcessor subscriptionPaymentProcessor = getManagerForPaymentMethod(paymentMethodType); return subscriptionManager.addPaymentMethodToCustomer( @@ -301,7 +305,10 @@ public class SubscriptionController { private SubscriptionPaymentProcessor getManagerForPaymentMethod(PaymentMethod paymentMethod) { return switch (paymentMethod) { + // Today, we always choose stripe to process non-paypal payment types, however we could use braintree to process + // other types (like CARD) in the future. case CARD, SEPA_DEBIT, IDEAL -> stripeManager; + // PAYPAL payments can only be processed with braintree case PAYPAL -> braintreeManager; case UNKNOWN -> throw new BadRequestException("Invalid payment method"); };