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

Add back failure if no payment method on confirm #229

Closed
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
8 changes: 5 additions & 3 deletions localstripe/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2769,16 +2769,18 @@ def _api_confirm(cls, id, use_stripe_sdk=None, client_secret=None,
pm = PaymentMethod(**payment_method_data)
obj._attach_pm(pm)
elif obj.payment_method is None:
obj.status = 'requires_payment_method'
obj.next_action = None
# If no payment method was specified upon SetupIntent creation, and
# none was specified in the confirm request, there's nothing to
# confirm. Stripe returns a 400 error in this case:
raise UserError(400, 'Bad request')
else:
obj.status = 'succeeded'
obj.next_action = None

return obj

def _attach_pm(self, pm):
self.payment_method = pm.id
self.payment_method_types = [pm.type]

if pm._attaching_is_declined():
self.status = 'canceled'
Expand Down
9 changes: 8 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,14 @@ res=$(curl -sSfg -u $SK: $HOST/v1/setup_intents -X POST)
seti=$(echo "$res" | grep '"id"' | grep -oE 'seti_\w+' | head -n 1)
seti_secret=$(echo $res | grep -oE 'seti_\w+_secret_\w+' | head -n 1)

curl -sSfg -u $SK: $HOST/v1/setup_intents/$seti/confirm -X POST
# If there's no payment_method in the either the SetupIntent creation or the
# confirm call, the confirm call fails:
code=$(curl -sg -o /dev/null -w '%{http_code}' -u $SK: \
-X POST $HOST/v1/setup_intents/$seti/confirm)
[ "$code" -eq 400 ]

curl -sSfg -u $SK: $HOST/v1/setup_intents/$seti/confirm -X POST \
-d payment_method=pm_card_visa

curl -sSfg -u $SK: $HOST/v1/setup_intents/$seti/cancel -X POST

Expand Down
Loading