#tobi_code
1 messages Ā· Page 1 of 1 (latest)
š Welcome to your new thread!
ā²ļø We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
ā±ļø We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
š This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1318586915729051690
š Have more to share? Add more details, code, screenshots, videos, etc. below.
Here is my checkout code:
const session = await stripe.checkout.sessions.create({
customer: user.stripeCustomerId,
mode: "subscription",
line_items: [
{
price: id,
quantity: 1,
},
],
subscription_data: {
trial_settings: {
end_behavior: {
missing_payment_method: "cancel",
},
},
trial_period_days: 7,
},
success_url: new URL(
`/success?session={CHECKOUT_SESSION_ID}`,
basepath
).toString(),
cancel_url: new URL(
"/cancel?session={CHECKOUT_SESSION_ID}",
basepath
).toString(),
metadata: {
vendorId: vendorId,
},
allow_promotion_codes: true,
locale: "pt-BR",
client_reference_id: user.id,
});
In the dashboard, payments tab
I get this
I tried adding all columns and I still get only this metadata
That comes from the checkout
But when the billing cycle restarts it creates a new id without the metadata, and I don't see a way to add it to it
This is how I update the metadata in the payment intent
async function onPaymentIntentSucceed(event: Stripe.Event) {
const paymentIntent = event.data.object as Stripe.PaymentIntent;
try {
// Retrieve the associated customer
const customer = await stripe.customers.retrieve(
paymentIntent.customer as string
);
if (customer.deleted) {
console.warn(`Customer ${customer.id} has been deleted.`);
return;
}
// Get vendorId from customer metadata
const vendorId = customer.metadata?.vendorId;
if (!vendorId) {
console.warn("No affiliate ID found in customer metadata");
return;
}
// Update the PaymentIntent metadata
await stripe.paymentIntents.update(paymentIntent.id, {
metadata: {
vendorId: vendorId,
},
});
} catch (error) {
console.error("Error updating PaymentIntent metadata:", error);
}
}
As you can see in the image, it does work, but I can't see this data in the export file.
How are you setting this metadata exactly?
Right now when I receive the payment_intent.succeeded event through the webhook
And I handle it through this last snippet of code I sent
Why are you not setting it on the other PaymentIntents?
Oh well, I guess it wasn't working before for some reason
Now it does update
I actually don't need this metadata in the checkout
Thanks. I thought that this was the metadata from the checkout, but apparently it was the PaymentIntent, and I rushed things so I forgot to test it again š¤¦āāļø
Are you able to copy the metadata every time a new PaymentIntent is created?
Yeah