如何在设置意图方法中添加付款详细信息 - Stripe Python

问题描述

您好,我想在 SetupIntent.create 方法添加付款详细信息。

我会用 API 来做到这一点 使用类似这样的东西:

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)

但是如何使用 Python Stripe Lib 做到这一点?

我试过这个代码

import stripe

stripe.api_key = "sk_live_xxxxx"

r = stripe.PaymentIntent.create(
                              payment_method_types=["card"],customer="cu_xxx",confirm=True
    )

print(r)

但是,我将如何在其中添加付款详细信息?

我检查了文档及其示例,但它只有添加付款方式类型的示例,而不是付款详细信息,例如抄送号码、cvc、到期月份和年份。

我想添加客户并附上付款方式并向他收费。有人可以帮我吗?

谢谢!

解决方法

使用 SetupIntent 时,您将保存客户付款凭证以备日后收费,通常是在非会议期间。创建(或确认)SetupIntent 时需要 PaymentMethod 对象 ID。

建议您在前端应用中使用 Stripe.js capture customer payment details,并在创建(或确认)SetupIntent 时传递生成的 PaymentMethod 对象 ID(pm_xxx)。然后,Stripe.js 可以处理生成的 PaymentMethod 上的任何必需操作,例如 3DS 身份验证。

有一个完整的 SetupIntent 集成示例 here,它使用 Python 客户端库和 Stripe.js