In the Stripe api when a webhook event is triggered at my endpoint after submitting an order for payment, i get a invoice.payment_succeeded event object. However it's payload does not contain any field i can readily exploit to tell me what subscription a payment is for. The only field that holds the name of a subscription is field "description" in object "line_item" but Stripe fills in itself in a free form. For example if i have a product name called Gold Account, this description field for line_items shows:
"1 × Gold Account (at £99.00 / month)"
But this is Stripe writing this. There is no Name field next to the descritpion field and metadata and nickname are always empty as follows:
"metadata": {
},
//...
"nickname\": null
I need to know why setting metadata for the following objects when putting together subscriptions for payment always show empty metadata fields in the webhook event object: SubscriptionItemOptions, ProductCreateOptions, PriceCreateOptions, PlanCreateOptions. The same goes when i try setting Name fields where available such as Price.Nickname, PriceCreateOptions.Nickname, SessionLineItemPriceDataProductDataOptions.Name, PlanProductOptions.Name, ProductCreateOptions.Name. Setting all these fields be them Metadata, Name or Nickname shows nothing in the webhook event objects. The dashboard does show the correct info for the various fields except for Metadata which is always empty. If I query Stripe directly with an invoice line item via a HttpClient the same empty fields are retrieved. Please advise.
It really depends what you're looking for.
The
.subscriptionfield is the IDsub_xxxof the Subscription object that is associated with the Invoice, for example.If you what you want is name of the Products that are being invoiced for, then for example
lines.data[0].price.productis the IDprod_xxxof the Product; and then you can call https://stripe.com/docs/api/products/retrieve to get that full object and look to it's.description.