【发布时间】:2020-07-02 14:29:56
【问题描述】:
我正在建立一个小商店,到目前为止,它相对简单。您可以一次性、每周或每月订购产品。
我已经在 Stripe Dashboard 中设置了相应的产品。
如果客户发送他们想要一个定期订单,它会创建一个带有他们的信息的Customer。
但每当我尝试创建定期订单时,我都会收到This customer has no attached payment source or default payment method. thrown in。
我正在使用 Stripe Elements,由于卡数据永远不会发送到我的服务器,我不知道如何向 Customer 添加付款方式。
创建订阅:
\Stripe\Subscription::create([
'customer' => $customer_id,
'items' => [
[
'price' => 'price_id_2',
'quantity' => $qty_1,
'price' => 'price_id_2',
'quantity' => $qty_2,
],
],
]);
$.post 发送数据到 PHP 文件
$.post('./secret.php', data, null, "json")
.done(function(data) {
clientSecret = data.client_secret;
stripe.confirmCardPayment(clientSecret, {
payment_method: {
card: card,
}
}).then(function(result) {
if (result.error) {
console.log(result.error.message);
} else {
if (result.paymentIntent.status === 'succeeded') {
console.log("Payment success.");
document.getElementById("processing").classList.add("hide");
document.getElementById("order-success").classList.remove("hide");
}
}
})
})
.fail(function(xhr, status, error) {
document.getElementById("processing").classList.add("hide");
document.getElementById("order-failure").classList.remove("hide");
});
我的一次性订单工作正常,但我就是不明白如何执行此操作。文档将“保存卡数据”显示为已弃用的实用程序,因此我不确定该怎么做。
【问题讨论】:
标签: php stripe-payments