#Coach Leyton
1 messages · Page 1 of 1 (latest)
Putting .NET aside, the flow you describe sounds good to me
Here is the important code snippet. As you can see, I make an incomplete subscription. Adding meta data to this object will result in the meta data being present in the initial customer.subscription.created event, which fires immediately upon creation (before the user has paid!). I need some method of adding that metadata to the invoice instead:
var subscriptionCreateOptions = new Stripe.SubscriptionCreateOptions
{
Customer = user.StripeCustomerId,
Items = new List<Stripe.SubscriptionItemOptions>
{
new Stripe.SubscriptionItemOptions
{
Price = targetPrice.Id,
}
},
PaymentSettings = new Stripe.SubscriptionPaymentSettingsOptions()
{
PaymentMethodTypes = new List<string> { "card" },
SaveDefaultPaymentMethod = "on_subscription"
},
PaymentBehavior = "default_incomplete",
Expand = new List<string> { "latest_invoice.payment_intent" },
Metadata = new Dictionary<string, string>
{
{ "planId", planId.ToString() }
},
TrialPeriodDays = plan.TrialPeriodDays,
};
If I manage to attach that meta data to the invoice instead, then the meta data will only appear in the event that triggers AFTER the user has paid
I read somewhere that I could just update that invoice, but there would be a race condition between the stripe webhook and the update
best current solution is to just store that meta data from the initial immediate webhook, put it in some temporary location, and then retrieve it on invoice.payment_success. Just seems hacky
Sorry I may be lost. Metadata is per-object, meaning it's either on the Subscription or on the Invoice
you want the metadata on the Invoice, correct?
So you just listen to invoice.payment_succeeded and call Update Invoice and append the metadata you want
Sorry for the confusion. The meta-data contains a planId. Not a Stripe Plan, but a custom entity of my own. This planId is then set on a User in my database, thus granting them access to whatever features that plan allows for.
The reason I want it to appear on the invoice.payment_succeeded event, rather than the customer.subscription.created event is because I need to know that the user has actually paid beforehand.
The exact value of this meta-data plan Id can vary, so I can't simply wait for the invoice.payment_succeeded event, and update the invoice.
I need some method of communicating the planId that the user has selected from the subscription creation. I assumed there was a built in way to do this, and thus I'm asking your team here.
if there is no way to attach meta-data to the created invoice immediately, then I suppose I could just store it in some temporary column on the user entity upon subscription creation, and then fetch it upon payment suceeded.
Oh I see what you mean
Yes there is no method of communicating "Set this metadata on every Invoice generated by this Subscription". So yes you would need to save it somewhere, and set it upon payment succeeded, as you said
By somewhere, I think it could be the Subscription metadata as well, ie. if you want Invoice to have key:value, you can temporarily set on the Subscription future_key:value
When received invoice.payment_succeeded, trace back the Subscription, takes the metadata, modify a bit then set back to the Invoice