Hola I would like to Add payment details in SetupIntent.create Method.
I would do that with API Using something like this :
import requests
url = "https://api.stripe.com/v1/setup_intents"
params = {
"key": "sk_live_xxxxx",
"payment_method_data[type]": "card",
"confirm": True,
"customer": "cu_xxxx",
"payment_method_data[card][number]": "cc number",
"payment_method_data[card][exp_month]": "exp_mnth",
"payment_method_data[card][exp_year]": "exp_year",
"payment_method_data[card][cvc]": "xxx"
}
response = requests.post(url, params=params).text
print(response)
But How do this with Python Stripe Lib?
I tried this Code :
import stripe
stripe.api_key = "sk_live_xxxxx"
r = stripe.PaymentIntent.create(
payment_method_types=["card"],
customer="cu_xxx",
confirm=True
)
print(r)
But, How will I add payment details in it?
I checked the the docs & it's examples but it only has examples adding payment method types, not payment details like cc number, cvc, expiry month & year.
I want to add customer & attach payment method & charge him. Can anyone help me?
Thank you!
When working with a SetupIntent you're saving customer payment credentials to charge later date, generally off-session. A PaymentMethod object ID is required when creating (or confirming) a SetupIntent.
It is recommended that you capture customer payment details in your front-end application with Stripe.js, and pass the generated PaymentMethod object ID (pm_xxx
) when creating (or confirming) the SetupIntent. Stripe.js can then handle any required actions on the generated PaymentMethod, such as 3DS authentication.
There's a full SetupIntent integration example here, which uses the Python client library with Stripe.js