我坚持的基本问题:
如果我收到带有以下 JSON 的 POST 请求:
JSON: {
"type": "invoice.payment_succeeded",
"pending_webhooks": 0,
"created": 1357936579,
"object": "event",
"livemode": false,
"id": "evt_15PLdo9JdZ2yN4",
"data": {
"object": {
"subtotal": 3500,
"attempted": true,
"paid": true,
"amount_due": 3500,
"closed": true,
"period_end": 1357936578,
"lines": {
"url": "/v1/invoices/in_15PLg6oL0IiYYj/lines",
"count": 1,
"object": "list",
"data": [
{
"type": "subscription",
"period": {
"end": 1360614978,
"start": 1357936578
},
"livemode": false,
"object": "line_item",
"proration": false,
"amount": 3500,
"quantity": 1,
"plan": {
"interval_count": 1,
"livemode": false,
"object": "plan",
"amount": 3500,
"trial_period_days": null,
"name": "forecast3",
"currency": "usd",
"id": "forecast3",
"interval": "month"
},
"id": "su_15PLVebFWecrdQ",
"currency": "usd",
"description": null
}
]
},
"starting_balance": 0,
"charge": "ch_15PLYLUiVusQDH",
"object": "invoice",
"total": 3500,
"ending_balance": 0,
"date": 1357936578,
"period_start": 1357936087,
"attempt_count": 0,
"discount": null,
"livemode": false,
"id": "in_15PLg6oL0IiYYj",
"next_payment_attempt": null,
"customer": "cus_15OrEWGsLN3CkP",
"currency": "usd"
}
}
}
我如何解析它以访问参数"id": "in_15PLg6oL0IiYYj"
谢谢!!
注意:这是来自通过 Stripe Payment Processing 的 webhook。
我已经尝试了一些变体,但似乎在绕圈子:
# Parse JSON
event_data = JSON.parse(json)
# Get Invoice id
invoice_id = Stripe::Invoice.retrieve(event_data.data.object.id)