Stripe payments stripe.confirmCardSetup未将卡附加到客户
我使用的是正面带有sapper/svelte的expressjs 我正在尝试使用stripe SetupIntent api和stripe.confirmCardSetup保存卡的详细信息,并将其附加到客户以备将来使用。我相信在阅读了文档之后,我理解了流程的流程,我的代码基于他们的示例 提交信用卡表格后,我一无所获。没有卡连接到客户,没有控制台日志输出,我的应用程序中也没有错误。setupIntent已成功创建,我可以在stripe仪表板中查看它,但没有创建卡(paymentMethod)并将其附加到客户。以下是我的步骤:Stripe payments stripe.confirmCardSetup未将卡附加到客户,stripe-payments,Stripe Payments,我使用的是正面带有sapper/svelte的expressjs 我正在尝试使用stripe SetupIntent api和stripe.confirmCardSetup保存卡的详细信息,并将其附加到客户以备将来使用。我相信在阅读了文档之后,我理解了流程的流程,我的代码基于他们的示例 提交信用卡表格后,我一无所获。没有卡连接到客户,没有控制台日志输出,我的应用程序中也没有错误。setupIntent已成功创建,我可以在stripe仪表板中查看它,但没有创建卡(paymentMethod)并将其
1- When a user create an account, I create a customer in stripe and
save the stripe customer's id in my db
2- I use that stripe customerid to create a setupIntent on the server
const intent = stripe.setupIntents.create({
customer: customer
}).then(intent => {
return res.end(JSON.stringify({ info: intent.client_secret }));
});
在此阶段,我需要客户端_secret在前面与我的卡元素一起使用,以便将卡的详细信息安全地提交给stripe。我确认setupIntent确实在我的stripe仪表板中。所以这部分很好 现在转到我的代码的前面部分: 我在我的应用程序前面获得了client_secret,并使用stripe.js收集并提交卡的详细信息,作为一种支付方式附加到客户(client_secret具有customer.id),因此代码为:
let clientsecret
let stripe = null
let cardelement = null
stripe = await loadStripe('pk_test_mykeys');
var elements = await stripe.elements();
cardelement = await elements.create('card');
cardelement.on('ready', ()=>{});
cardelement.on('change', ({error}) => {
const displayError = document.getElementById('card-errors');
if (error) {
displayError.textContent = error.message;
} else {
displayError.textContent = '';
}
}); //end of card.on fn
cardelement.mount("#card-element");
return{
stripe : stripe,
cardelement : cardelement
}
function clickhandle(){
stripe = stripe
stripe.confirmCardSetup( csec , {
payment_method: {
card: cardelement,
billing_details: { user : "testing setupIntent"
}
},
setup_future_usage : 'on_session'
})
.then(function(result) {
if (result.error) {
console.log("there is an error")
}
if(result.setupIntent){
console.log("here is the setupintent success result")
}
});
}
Stripe.js之所以有效,是因为我在应用程序的不同部分测试了paymentIntent和信用卡收费,执行的费用显示在Stripe仪表板中,所以它不是Stripe.js脚本
我的流程正确吗?使用stripe customer id在我的服务器和前面创建setupIntent,上面的代码收集卡的详细信息,并使用stripe.confirmCardSetup提交,它将从setupIntent客户端将付款方法/卡的详细信息附加到客户
当我阅读文档时,如果有任何帮助,我将不胜感激,因为文档清晰明了。我一步一步地跟着它。我遗漏了什么?这里描述了正确的过程:您所做的事情有点不同,这可能会导致一些问题
我怀疑您将
未来的使用方法纳入其中可能是问题所在。在阅读了@floatingLomas注释后,我又回去仔细阅读了文档。以下是需要澄清的问题:
1-装入#卡元素的表单需要包含客户端#机密,无论是在隐藏字段中还是使用数据属性。
阅读
所以--请注意数据机密属性--我的表单代码现在是:
<form data-secret={customersecret} on:submit={stripehandle} id="payment-form">
<label for="card-element">Enter Your Credit Card Details:</label>
<div id="card-element"></div>
<div id="card-errors" role="alert"></div>
<button id="submit">Pay -svelte2 component</button>
</form>
谢谢我将检查我的代码并修复所有差异。我会把结果报告给你。很高兴你让它工作了;我希望我的答案能被接受,因为它是有效的完成。再次感谢。
stripe.confirmCardSetup( csec , {
payment_method: {
card: cardelement,
billing_details: { "name" : "testing setupIntent" }
}
})
.then(function(result) {
console.log("result :", result)
})