首页 > 解决方案 > 如何设置重复收费?

问题描述

我正在 WooCommerce Stripe 插件已经提供的功能之上构建一项新功能,以使客户能够更改他们现有的正在进行的订阅,这基本上会取消他们当前的订阅并设置一个新的订阅以在他们之前的订阅结束时开始。我通过 Stripe API 做到这一点,然后在 WooCommerce 中相应地更新它,效果很好。

我似乎遗漏了一部分,以确保重复收费。有谁知道 WooCommerce Subscriptions 如何为未来使用 Stripe 付款设置重复收费?

在此处输入图像描述

我通过以下方式发起收费:

    $charge = $stripe->charges->create([
        'amount' => intval( $newOrder->get_total() * 100 ),
        'currency' => 'gbp',
        'source' => $card,
        'description' => 'Subscription Update ' . $user->user_email,
        'metadata' => [
            'Order ID' => $newOrder->get_id(),
            'payment_type' => 'recurring',
        ...

我注意到他们将“payment_type”的元数据字段设置为重复,所以我添加了它。

我确实找到了这篇文章来设置未来付款的卡,但我不确定这是否是我需要的,或者我是否必须以不同的方式来做?

https://stripe.com/docs/payments/save-and-reuse

我应该使用 PaymentIntent 而不是 Charge?

https://stripe.com/docs/api/payment_intents/create

谢谢

标签: woocommercestripe-paymentssubscription

解决方案


可以在此处找到设置订阅(即经常性费用)的过程 [1]。提供的代码仅创建一次性费用。元数据是一种通过 API [2] 在对象上传递临时数据的方法,因此在这种情况下不相关。PaymentIntents 是进行计费集成的方式,因为它们已准备好 SCA [3]。

[1] https://stripe.com/docs/billing/subscriptions/fixed-price

[2] https://stripe.com/docs/api/metadata

[3] https://stripe.com/docs/strong-customer-authentication


推荐阅读