php - json 解析 Stripe 发票响应
问题描述
我正在尝试从 Stripe Invoice 访问一些元数据。我在这个特定的查询上遇到了一个问题,即使我没有遇到任何其他问题,所以我希望有一双新的眼睛可以看到我正在犯的错误。
这是来自 Stripe 的示例响应:
{
"object": {
"id": "in_1DYkdY2Y54K5YG39D4uaDtnj",
"object": "invoice",
"amount_due": 1600,
"amount_paid": 1600,
"amount_remaining": 0,
"application_fee": null,
"attempt_count": 1,
"attempted": true,
"auto_advance": false,
"billing": "charge_automatically",
"billing_reason": "subscription_update",
"charge": "ch_1DYkdZ2Y54K5YG39rqyAJ1Ca",
"closed": true,
"currency": "usd",
"customer": "cus_DnCcf39Nqp4RwF",
"date": 1542764176,
"default_source": null,
"description": null,
"discount": null,
"due_date": null,
"ending_balance": 0,
"finalized_at": 1542764176,
"forgiven": false,
"hosted_invoice_url": "https://pay.stripe.com/invoice/invst_aqIp3rAKOfGvBgeaTNpGMO9iLj",
"invoice_pdf": "https://pay.stripe.com/invoice/invst_aqIp3rAKOfGvBgeaTNpGMO9iLj/pdf",
"lines": {
"object": "list",
"data": [
{
"id": "sli_f14f8ad4d41b05",
"object": "line_item",
"amount": 1600,
"currency": "usd",
"description": "1 × Weekly-IbcrdPR83CjRKx (at $16.00 / week)",
"discountable": true,
"livemode": false,
"metadata": {
},
"period": {
"end": 1543368976,
"start": 1542764176
},
"plan": {
"id": "Weekly-IbcrdPR83CjRKx",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 1600,
"billing_scheme": "per_unit",
"created": 1542764176,
"currency": "usd",
"interval": "week",
"interval_count": 1,
"livemode": false,
"metadata": {
"customer_name": "",
"customer_email": "",
"customer_phone": "",
"billing_address_line": "",
"billing_address_state": "",
"billing_address_city": "",
"billing_address_zip": "",
"billing_address_country": "",
"customer_notes": "testing notes"
},
"nickname": null,
"product": "prod_E0mBKUu2oscBpr",
"tiers": null,
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"proration": false,
"quantity": 1,
"subscription": "sub_E0mBjQnLQj7Gb3",
"subscription_item": "si_E0mBf46EMlWF3F",
"type": "subscription"
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/invoices/in_1DYkdY2Y54K5YG39D4uaDtnj/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"number": "9CBEAF8-0029",
"paid": true,
"payment_intent": null,
"period_end": 1542764176,
"period_start": 1542764176,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "paid",
"subscription": "sub_E0mBjQnLQj7Gb3",
"subtotal": 1600,
"tax": 0,
"tax_percent": null,
"total": 1600,
"webhooks_delivered_at": null
}
}
现在这是我的 php 代码,用于首先检索发票,然后查询特定行:
** 注意:在这种情况下,$invoice 是动态的并且正确返回。
$charge = \Stripe\Invoice::retrieve( $invoice );
$notes = $charge->lines->data->plan->metadata->customer_notes;
这是返回空白。我必须在某处缺少 JSON 查询的级别。任何帮助表示赞赏。
更新
根据要求,这里是对 的一些响应var_dump($charge)
。Stripe 不会显示整个响应,但这是它们返回的信息量的副本:
object(Stripe\Invoice)#708 (44) { ["id"]=> string(27) "in_1DYl032Y54K5YG39yiSWVthU" ["object"]=> string(7) "invoice" ["amount_due"]=> int(1700) ["amount_paid"]=> int(1700) ["amount_remaining"]=> int(0) ["application_fee"]=> NULL ["attempt_count"]=> int(1) ["attempted"]=> bool(true) ["auto_advance"]=> bool(false) ["billing"]=> string(20) "charge_automatically" ["billing_reason"]=> string(19) "subscription_update" ["charge"]=> string(27) "ch_1DYl032Y54K5YG394aoxZfbd" ["closed"]=> bool(true) ["currency"]=> string(3) "usd" ["customer"]=> string(18) "cus_DnCcf39Nqp4RwF" ["date"]=> int(1542765571) ["default_source"]=> NULL ["description"]=> NULL ["discount"]=> NULL ["due_date"]=> NULL ["ending_balance"]=> int(0) ["finalized_at"]=> int(1542765571) ["forgiven"]=> bool(false) ["hosted_invoice_url"]=> string(63) "https://pay.stripe.com/invoice/invst_SahhlLyii55mPqzmEDMFJWJeLt" ["invoice_pdf"]=> string(67) "https://pay.st...
解决方案
推荐阅读
- android - 通过多次查找从 Firebase 检索正确信息时遇到问题
- xaml - CommandBar AppBarButton 图标大小
- json - 当我遍历'JSON'结果时,错误“类型'Any'不符合协议'Sequence”是什么意思?
- node.js - ubuntu 上的 Selenium 错误:未知错误:Chrome 无法启动:异常退出
- windows - 在 Visual Studio 上使用 MASM 将 hello world 写入带有 DOS 中断的控制台
- visual-studio-code - VSCode 是否有一个插件可以“学习”最常用的代码片段?
- django - 如何访问查询集中的缓存属性
- c++ - 无法打印在在线编译器中打印完美的心形
- javascript - 如何在循环中保存对象的“上一个”和“下一个”迭代?
- android - 将 SVG 转换为 Android Vector Drawable