![](/img/trans.png)
[英]How to use the good event with Stripe PHP and webhook, to compare number of payments received and cancel a subscription
[英]How to increment the number of payments with Stripe and PHP (for a subscription)
我正在尝试设置订阅并计算付款次数(使用 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 示例代码):
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
感谢您的帮助 !
您需要使用“更新订阅 API”来更新这里的元数据: https : //stripe.com/docs/api/subscriptions/update?lang=ruby#update_subscription- metadata
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.