I am trying to access some metadata from a Stripe Invoice. I am running into an issue on this particular query even though I don't have trouble with any others, so I'm hoping a fresh set of eyes can see a mistake I'm making.
Here is an example response from 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
}
}
Now here is my php code to first retrieve the invoice, and then to query for a specific line:
** Note: in this case, $invoice is dynamic and is returning correctly.
$charge = \Stripe\Invoice::retrieve( $invoice );
$notes = $charge->lines->data->plan->metadata->customer_notes;
This is returning blank. I must be missing a level somewhere for the JSON query. Any help is appreciated.
UPDATE
As requested, here is a bit of the response for var_dump($charge)
. Stripe doesn't display the entire response, but this is a copy of the amount of info they do return:
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...