【发布时间】:2020-06-16 06:23:50
【问题描述】:
我使用Intent API(currency, amount only) 和confirmCardPayment 和Stripe rendered HTML input 进行结帐。
现在我想实现保存的信用卡,可以保存,但是不知道怎么用传递给confirmCardPayment。
我目前工作的confirmCardPayment 代码是这样的
Stripe.confirmCardPayment(intent.client_secret, {
payment_method: {
/**
* I'm using Vue here
* If I'm using a saved card, what should I pass here?
**/
card: this.$refs.stripeCardRef.cardNumberElement,
},
setup_future_usage: "off_session",
});
如果我使用的是已保存的卡,我应该将什么传递给 confirmCardPayment,以及 Intent API(我使用的是货币,现在只需要金额)?
所以我可以使用stripe.paymentMethods.list 来获取客户所有保存的信用卡,并将其返回到前端,如下所示:
// Server
export async function listPaymentMethods(userId: string) {
const customer = await getOrCreateCustomer(userId);
return stripe.paymentMethods.list({
customer: customer.id,
type: "card",
});
}
然后,我的前端得到这样的响应
{
"object": "list",
"data": [
{
"id": "pm_1GuBTiICxYQTNr22LwKB6rfy",
"object": "payment_method",
"billing_details": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": null,
"name": null,
"phone": null
},
"card": {
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": null,
"cvc_check": "pass"
},
"country": "US",
"exp_month": 1,
"exp_year": 2023,
"fingerprint": "riI755UKjfafxa3C",
"funding": "credit",
"generated_from": null,
"last4": "4242",
"networks": {
"available": ["visa"],
"preferred": null
},
"three_d_secure_usage": {
"supported": true
},
"wallet": null
},
"created": 1592201250,
"customer": "cus_HPOXLjeqF24rBn",
"livemode": false,
"metadata": [],
"type": "card"
}
],
"has_more": false,
"url": "/v1/payment_methods"
}
我如何使用这个回复数据到confirmCardPayment?
我的意图 API 是否也需要更改?
【问题讨论】:
-
如果您已保存该卡以供将来使用:stripe.com/docs/api/payment_intents/… 并且您正在确认从现有卡付款,您将传递付款方式 ID stripe.com/docs/js/payment_intents/…。希望有帮助!
标签: stripe-payments