【发布时间】: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