#snackdex
1 messages · Page 1 of 1 (latest)
Where are you setting metadata?
Metadata isn't automatically copied across events
If you set it on the subscription it won't be copied to the payment intent
oh ok. how would i get it in the payment intent?
const subscription = await stripe.subscriptions.create({
expand: ["latest_invoice.payment_intent"],
customer: stripeCustomerId,
payment_behavior: "default_incomplete",
items: [{ price: membershipPrice.stripePriceId }],
add_invoice_items: additionalInvoiceItems,
metadata: stripeMetadata
});
const latestInvoice = subscription.latest_invoice as Stripe.Invoice;
return latestInvoice.payment_intent as Stripe.PaymentIntent;
that is where i am setting the metadata
There's not a way to do that exactly
Not without a lot of trouble
What's your goal?
What are you trying to do? Maybe I can suggest something better
the stripe payment intent webhook that i have accepts multiple "orderTypes". this "orderType" is added when i create the payment intent and then read from the webhook. based on the orderType i do different actions
Ok. Recommend you listen to invoice.paid instead. That way you get the subscription id on the invoice object and can just retrieve the subscription object to see its metadata
in my other orderTypes I just do:
return await stripe.paymentIntents.create({
// amount needs to be an integer in the currency's smallest amount
// So, if order.amount === $2.04, the payment intent amount must be
// 204 (cents)
amount: parseInt((+cart.finalPrice * 100).toFixed(0), 10),
customer: stripeCustomerId,
currency: "usd",
payment_method_types: ["card"],
metadata: stripeMetadata
});
would the invoice.paid get triggered there?
That doesn't make sense though
Why create a subscription and payment intent
If you create a payment intent directly and set metadata on it, then the metadata will be on the payment intent
yes. that is what i was originally doing.
but i was told that i can't create a payment intent directly for a subscription
That's correct
So why do you still have code that creates payment intents directly
invoice.paid doesn't get generated for payment intents
we still need to support the old method until we update all of our logic to use this method instead
Gotcha
i think i have enough to go on though, but my only question is could i just turn this to one time payment into an invoice as well:
return await stripe.paymentIntents.create({
// amount needs to be an integer in the currency's smallest amount
// So, if order.amount === $2.04, the payment intent amount must be
// 204 (cents)
amount: parseInt((+cart.finalPrice * 100).toFixed(0), 10),
customer: stripeCustomerId,
currency: "usd",
payment_method_types: ["card"],
metadata: stripeMetadata
});
You could yes
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
awesome! i think i have enough to go on. thank you