【问题标题】:Saving card details to customer using Stripe Elements使用 Stripe Elements 将卡详细信息保存给客户
【发布时间】: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


    【解决方案1】:

    听起来您可能想在付款过程中保存一张卡:https://stripe.com/docs/payments/save-during-payment

    【讨论】:

    • 我认为你是对的,不知道为什么我搜索它时它没有出现!
    • 您似乎必须创建初始付款,然后再创建订阅?我不确定这会如何工作。
    • 您也可以不付款直接保存:stripe.com/docs/payments/save-and-reuse
    猜你喜欢
    • 2016-08-08
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    • 2020-03-28
    • 2017-02-08
    • 1970-01-01
    • 2020-05-21
    • 2019-06-24
    相关资源
    最近更新 更多