-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support confirmation of SetupIntents with a payment method ID
Previously localstripe only supported confirmation of SetupIntents with payment_method_data, which is a dictionary containing the information needed to create a PaymentMethod. The Stripe SetupIntents API also allows the caller to pass in an already-created PaymentMethod, by ID. This change adds that capability to localstripe. I also added a few of the canonical test articles you can use as a payment method ID. These generally map 1:1 with the test card numbers.
- Loading branch information
Showing
2 changed files
with
118 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -560,35 +560,35 @@ cus=$(curl -sSfg -u $SK: $HOST/v1/customers \ | |
-d [email protected] \ | ||
| grep -oE 'cus_\w+' | head -n 1) | ||
|
||
pm=$(curl -sSfg -u $SK: $HOST/v1/payment_methods \ | ||
pm_card_okay=$(curl -sSfg -u $SK: $HOST/v1/payment_methods \ | ||
-d type=card \ | ||
-d card[number]=4242424242424242 \ | ||
-d card[exp_month]=12 \ | ||
-d card[exp_year]=2020 \ | ||
-d card[cvc]=123 \ | ||
| grep -oE 'pm_\w+' | head -n 1) | ||
|
||
curl -sSfg -u $SK: $HOST/v1/payment_methods/$pm/attach \ | ||
curl -sSfg -u $SK: $HOST/v1/payment_methods/$pm_card_okay/attach \ | ||
-d customer=$cus | ||
|
||
curl -sSfg -u $SK: $HOST/v1/customers/$cus \ | ||
-d invoice_settings[default_payment_method]=$pm | ||
-d invoice_settings[default_payment_method]=$pm_card_okay | ||
|
||
curl -sSfg -u $SK: $HOST/v1/customers/$cus?expand[]=invoice_settings.default_payment_method | ||
|
||
curl -sSfg -u $SK: $HOST/v1/payment_methods?customer=$cus\&type=card | ||
|
||
curl -sSfg -u $SK: $HOST/v1/payment_methods/$pm/detach -X POST | ||
curl -sSfg -u $SK: $HOST/v1/payment_methods/$pm_card_okay/detach -X POST | ||
|
||
pm=$(curl -sSfg -u $SK: $HOST/v1/payment_methods \ | ||
pm_card_decline_on_attach=$(curl -sSfg -u $SK: $HOST/v1/payment_methods \ | ||
-d type=card \ | ||
-d card[number]=4000000000000002 \ | ||
-d card[exp_month]=4 \ | ||
-d card[exp_year]=2042 \ | ||
-d card[cvc]=123 \ | ||
| grep -oE 'pm_\w+' | head -n 1) | ||
code=$(curl -sg -o /dev/null -w "%{http_code}" -u $SK: \ | ||
$HOST/v1/payment_methods/$pm/attach \ | ||
$HOST/v1/payment_methods/$pm_card_decline_on_attach/attach \ | ||
-d customer=$cus) | ||
[ "$code" = 402 ] | ||
|
||
|
@@ -618,6 +618,53 @@ curl -sSfg $HOST/v1/setup_intents/$seti/confirm \ | |
-d payment_method_data[card][exp_year]=24 \ | ||
-d payment_method_data[billing_details][address][postal_code]=42424 | ||
|
||
# We can also pass a payment method ID to setup_intents/*/confirm: | ||
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) | ||
status=$( | ||
curl -sSfg $HOST/v1/setup_intents/$seti/confirm \ | ||
-d key=pk_test_sldkjflaksdfj \ | ||
-d client_secret=$seti_secret \ | ||
-d payment_method=$pm_card_okay \ | ||
| grep -oE '"status": "succeeded"') | ||
[ -n "$status" ] | ||
|
||
# ... and payment method IDs on bad cards fail on setup_intents/*/confirm: | ||
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) | ||
code=$( | ||
curl -sg -w "%{http_code}" -o /dev/null $HOST/v1/setup_intents/$seti/confirm \ | ||
-d key=pk_test_sldkjflaksdfj \ | ||
-d client_secret=$seti_secret \ | ||
-d payment_method=$pm_card_decline_on_attach) | ||
[ "$code" = 402 ] | ||
|
||
# We can also pass a special well-known payment method ID to | ||
# setup_intents/*/confirm: | ||
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) | ||
status=$( | ||
curl -sSfg $HOST/v1/setup_intents/$seti/confirm \ | ||
-d key=pk_test_sldkjflaksdfj \ | ||
-d client_secret=$seti_secret \ | ||
-d payment_method=pm_card_visa \ | ||
| grep -oE '"status": "succeeded"') | ||
[ -n "$status" ] | ||
|
||
# ... including well-known bad payment method IDs: | ||
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) | ||
code=$( | ||
curl -sg -w "%{http_code}" -o /dev/null $HOST/v1/setup_intents/$seti/confirm \ | ||
-d key=pk_test_sldkjflaksdfj \ | ||
-d client_secret=$seti_secret \ | ||
-d payment_method=pm_card_visa_chargeDeclined) | ||
[ "$code" = 402 ] | ||
|
||
# off_session cannot be used when confirm is false | ||
code=$( | ||
curl -sg -o /dev/null -w "%{http_code}" \ | ||
|