woocommerce - 如何设置重复收费?
问题描述
我正在 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
谢谢
解决方案
可以在此处找到设置订阅(即经常性费用)的过程 [1]。提供的代码仅创建一次性费用。元数据是一种通过 API [2] 在对象上传递临时数据的方法,因此在这种情况下不相关。PaymentIntents 是进行计费集成的方式,因为它们已准备好 SCA [3]。
[1] https://stripe.com/docs/billing/subscriptions/fixed-price
推荐阅读
- pandas - 如何匹配来自两个数据帧的相应数据?
- websocket - 将消息从 Kafka 路由到连接到应用程序服务器集群的 Web 套接字客户端
- python - 将 CSV 文件导入为 PySpark 数据集(不是数据框)
- visual-studio - 在 NuGet 中从 Entity Framework 6.2 升级到 6.3.0
- zsh - 使用带有 zparseopts 的关联数组
- javascript - 将变量操作数应用于运算符
- php - 如何在没有函数的 PHP 中设置和检索动态全局变量
- python - 我正在尝试从列表中删除死链接的 id(错误 403),但我的代码总是跳过一些 id,尽管它们已经死了,但它们重新出现在列表中
- google-app-engine - 云运行是否有套接字配额?
- sql - 如何重置 SQL Server 内置函数(DAY)