【问题标题】:How to increment the number of payments with Stripe and PHP (for a subscription)如何使用 Stripe 和 PHP 增加付款次数(订阅)
【发布时间】:2020-04-20 11:27:21
【问题描述】:

我正在尝试设置订阅并计算付款次数(使用 webhook)。 我正在使用这个文档: https://stripe.com/docs/recipes/installment-plan#signing-up-a-customer-for-an-installment-plan

但它是 Ruby on Rails。 我尝试添加元数据来计算付款:

       $subscription = \Stripe\Subscription::create(array(
  "customer" => $customer->id,
  "items" => array(
      array(
          "plan" => $plan->id,
      ),
  ),   
   "metadata" => ["number_payments" => 0]));

然后在我的 webhook 页面中,我想检索订阅并增加付款次数,但我不明白也不知道如何使用 PHP(来自 Stripe 示例代码here):

def increment_payments_count(event)
# Grab the subscription line item.
sub =  event.data.object.lines.data[0]

# Execute only for installment plans.
if !sub.metadata[:installments_paid].nil?
# Recommendation: Log invoices and check for duplicate events.
# Recommendation: Note that we send $0 invoices for trials.
#                 You can verify the `amount_paid` attribute of
#                 the invoice object before incrementing the count.

    # Retrieve and increment the number of payments.
    count = sub.metadata[:installments_paid].to_i
    count += 1

感谢您的帮助!

【问题讨论】:

    标签: php stripe-payments


    【解决方案1】:

    您需要使用“更新订阅 API”在此处更新元数据:https://stripe.com/docs/api/subscriptions/update?lang=ruby#update_subscription-metadata

    【讨论】:

      猜你喜欢
      • 2015-01-10
      • 1970-01-01
      • 2018-11-21
      • 2017-06-19
      • 1970-01-01
      • 2022-07-21
      • 2018-11-07
      • 2023-02-04
      • 1970-01-01
      相关资源
      最近更新 更多