Skip to content

Commit

Permalink
Return 409 when setting a payment method that hasn't finished initial…
Browse files Browse the repository at this point in the history
…ization
  • Loading branch information
ravi-signal authored and jon-signal committed Dec 17, 2024
1 parent a96c0ec commit 6460327
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,11 @@ private CompletableFuture<Response> setDefaultPaymentMethod(final CustomerAwareS
// a missing customer ID indicates the client made requests out of order,
// and needs to call create_payment_method to create a customer for the given payment method
new ClientErrorException(Status.CONFLICT)))
.exceptionally(ExceptionUtils.exceptionallyHandler(SubscriptionException.InvalidArguments.class, e -> {
// Here, invalid arguments must mean that the client has made requests out of order, and needs to finish
// setting up the paymentMethod first
throw new ClientErrorException(Status.CONFLICT);
}))
.thenApply(customer -> Response.ok().build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.stripe.StripeClient;
import com.stripe.exception.CardException;
import com.stripe.exception.IdempotencyException;
import com.stripe.exception.InvalidRequestException;
import com.stripe.exception.StripeException;
import com.stripe.model.Charge;
import com.stripe.model.Customer;
Expand Down Expand Up @@ -171,6 +172,9 @@ public CompletableFuture<Void> setDefaultPaymentMethodForCustomer(String custome
try {
stripeClient.customers().update(customerId, params, commonOptions());
return null;
} catch (InvalidRequestException e) {
// Could happen if the paymentMethodId was bunk or the client didn't actually finish setting it up
throw ExceptionUtils.wrap(new SubscriptionException.InvalidArguments(e.getMessage()));
} catch (StripeException e) {
throw new CompletionException(e);
}
Expand Down

0 comments on commit 6460327

Please sign in to comment.