【发布时间】:2015-03-14 22:56:29
【问题描述】:
在我的应用程序中,我有客户可以有多个订阅。当某些订阅付款失败时,我通过条带 webhook 将此参数发送到我的服务器:
{
"created"=>1326853478,
"livemode"=>false,
"id"=>"evt_00000000000000",
"type"=>"invoice.payment_failed",
"object"=>"event",
"request"=>nil,
"pending_webhooks"=>1,
"api_version"=>"2015-02-18",
"data"=>{
"object"=>{
"date"=>1426238137,
"id"=>"in_00000000000000",
"period_start"=>1426232774,
"period_end"=>1426238137,
"lines"=>{
"data"=>[
{
"id"=>"sub_5rZCR6ApQpG5fJ",
"object"=>"line_item",
"type"=>"subscription",
"livemode"=>true,
"amount"=>2500,
"currency"=>"usd",
"proration"=>false,
"period"=>{
"start"=>1428921062,
"end"=>1431513062
},
"subscription"=>nil,
"quantity"=>1,
"plan"=>{
"interval"=>"month",
"name"=>"Monthly device subscription",
"created"=>1426232489,
"amount"=>2500,
"currency"=>"usd",
"id"=>"monthly-device",
"object"=>"plan",
"livemode"=>false,
"interval_count"=>1,
"trial_period_days"=>nil,
"metadata"=>{
},
"statement_descriptor"=>nil
},
"description"=>nil,
"metadata"=>{
}
}
],
"total_count"=>1,
"object"=>"list",
"url"=>"/v1/invoices/in_15fotJEFda5OVrS251rpXd9l/lines"
},
"subtotal"=>2500,
"total"=>2500,
"customer"=>"cus_00000000000000",
"object"=>"invoice",
"attempted"=>true,
"closed"=>false,
"forgiven"=>false,
"paid"=>false,
"livemode"=>false,
"attempt_count"=>1,
"amount_due"=>2500,
"currency"=>"usd",
"starting_balance"=>0,
"ending_balance"=>0,
"next_payment_attempt"=>nil,
"webhooks_delivered_at"=>1426238137,
"charge"=>"ch_00000000000000",
"discount"=>nil,
"application_fee"=>nil,
"subscription"=>"sub_00000000000000",
"tax_percent"=>nil,
"tax"=>nil,
"metadata"=>{
},
"statement_descriptor"=>nil,
"description"=>nil,
"receipt_number"=>nil
}
},
"webhook"=>{
"created"=>1326853478,
"livemode"=>false,
"id"=>"evt_00000000000000",
"type"=>"invoice.payment_failed",
"object"=>"event",
"request"=>nil,
"pending_webhooks"=>1,
"api_version"=>"2015-02-18",
"data"=>{
"object"=>{
"date"=>1426238137,
"id"=>"in_00000000000000",
"period_start"=>1426232774,
"period_end"=>1426238137,
"lines"=>{
"data"=>[
{
"id"=>"sub_5rZCR6ApQpG5fJ",
"object"=>"line_item",
"type"=>"subscription",
"livemode"=>true,
"amount"=>2500,
"currency"=>"usd",
"proration"=>false,
"period"=>{
"start"=>1428921062,
"end"=>1431513062
},
"subscription"=>nil,
"quantity"=>1,
"plan"=>{
"interval"=>"month",
"name"=>"Monthly device subscription",
"created"=>1426232489,
"amount"=>2500,
"currency"=>"usd",
"id"=>"monthly-device",
"object"=>"plan",
"livemode"=>false,
"interval_count"=>1,
"trial_period_days"=>nil,
"metadata"=>{
},
"statement_descriptor"=>nil
},
"description"=>nil,
"metadata"=>{
}
}
],
"total_count"=>1,
"object"=>"list",
"url"=>"/v1/invoices/in_15fotJEFda5OVrS251rpXd9l/lines"
},
"subtotal"=>2500,
"total"=>2500,
"customer"=>"cus_00000000000000",
"object"=>"invoice",
"attempted"=>true,
"closed"=>false,
"forgiven"=>false,
"paid"=>false,
"livemode"=>false,
"attempt_count"=>1,
"amount_due"=>2500,
"currency"=>"usd",
"starting_balance"=>0,
"ending_balance"=>0,
"next_payment_attempt"=>nil,
"webhooks_delivered_at"=>1426238137,
"charge"=>"ch_00000000000000",
"discount"=>nil,
"application_fee"=>nil,
"subscription"=>"sub_00000000000000",
"tax_percent"=>nil,
"tax"=>nil,
"metadata"=>{
},
"statement_descriptor"=>nil,
"description"=>nil,
"receipt_number"=>nil
}
}
}
}
现在我想从这个 params stripe subscription_id 中获取。但是我不知道哪个是对的,因为我们在这个参数中有以下数据:
"id"=>"sub_5rZCR6ApQpG5fJ" - 第 19 行 - 始终条带订阅开始
有 sub 所以这可能是订阅 ID?
"subscription"=>"sub_00000000000000" - 第 77 行 - 也许是这个?
请帮助我在条带文档中找不到有关此的任何信息...
【问题讨论】:
标签: ruby-on-rails ruby stripe-payments