I am using stripe API and .net to create subscriptions.
my issue is that when i create a subscription the meta data is saved on the subscription instead of being saved on the payment. is there a way to save the meta data on the first subscription payment instead?
that is what i have tried so far :
var subscriptionOptions = new SubscriptionCreateOptions
{
Customer = customerID,
Items = new List<SubscriptionItemOptions>
{
new SubscriptionItemOptions
{
Price = priceID,
Quantity = 1
},
},
PaymentBehavior = "default_incomplete",
Metadata = new Dictionary<string, string>
{
{ "id", "123"},
{ "name", "david" },
},
};
subscriptionOptions.AddExpand("latest_invoice.payment_intent");
var subscriptionService = new SubscriptionService();
try
{
Subscription subscription = await subscriptionService.CreateAsync(subscriptionOptions);
return new SubscriptionCreateResponse
{
SubscriptionId = subscription.Id,
ClientSecret = subscription.LatestInvoice.PaymentIntent.ClientSecret,
};
}
CodePudding user response:
No, the subscription metadata
is not propagated to the generated invoices or the payment intents used within those invoices. If you want metadata
on either of those, you'll need to set up a process to update that using your own code.
You could, for example, set this up using webhooks. You could listen for invoice.paid
webhooks and then retrieve the subscription to get the metadata
and update the Payment Intent related to that invoice.