diff --git a/localstripe/resources.py b/localstripe/resources.py index 62067ef..5e02f09 100644 --- a/localstripe/resources.py +++ b/localstripe/resources.py @@ -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' diff --git a/test.sh b/test.sh index 7bffac7..72e3b9c 100755 --- a/test.sh +++ b/test.sh @@ -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