#ghost_dev
1 messages · Page 1 of 1 (latest)
hello
on node.js-javascript
if i do
console.log(event.data.object)
i can see it but if i go to the logs there is no meta-data
and if i do stripe subscriptions retrieve sub_....
i dont see the metadata
// Create the checkout session with dynamic line items
const session = await stripe.checkout.sessions.create({
ui_mode: 'embedded',
line_items: lineItems,
mode: 'subscription',
return_url: returnUrl,
metadata:{
guild_id:'234',
},
automatic_tax: { enabled: true },
});
// Handle the event
switch (event.type) {
case 'checkout.session.completed':
console.log('Checkout session completed:', event.data.object);
// Add logic here to update your database or perform other actions for successful subscriptions
break;
case 'customer.subscription.created':
console.log('Subscription created:', event.data.object);
const metadata = event.data.object.metadata;
if (metadata && metadata.guild_id) {
const guildId = metadata.guild_id; // Retrieve guild ID from metadata
// Add logic here to handle subscription creation
} else {
console.log('Guild ID metadata is missing.');
}
break;
i tried client_referance_id but i still had some problems because it
Hi, I think the issue is in the nesting. What does that console log return?
is there another way to store little data to an object that i will be able to fetch?
Ahh, you're using Checkout
yeah
Checkout session completed: {
id: 'cs_test_a1tImu7o37twVgf9mcu6UHdOg5870idwOL8fVPiKc6Rq4zfDyqXpWFaxu4',
object: 'checkout.session',
after_expiration: null,
allow_promotion_codes: null,
amount_subtotal: 499,
amount_total: 499,
automatic_tax: { enabled: true, liability: { type: 'self' }, status: 'complete' },
billing_address_collection: null,
cancel_url: null,
client_reference_id: null,
client_secret: null,
consent: null,
consent_collection: null,
created: 1707937021,
currency: 'eur',
currency_conversion: null,
custom_fields: [],
custom_text: {
after_submit: null,
shipping_address: null,
submit: null,
terms_of_service_acceptance: null
},
....
},
....
},
customer_email: null,
expires_at: 1708023421,
invoice: 'in_1Ojne9FTcNVt1uk9TeUOxfnT',
invoice_creation: null,
livemode: false,
locale: null,
metadata: { guild_id: '234' },
mode: 'subscription',
payment_intent: null,
payment_link: null,
payment_method_collection: 'always',
payment_method_configuration_details: null,
payment_method_options: {},
payment_method_types: [ 'card' ],
payment_status: 'paid',
phone_number_collection: { enabled: false },
recovered_from: null,
redirect_on_completion: 'always',
return_url: 'http://localhost:3000/dashboard/964052685403873292/autorole/return?session_id={CHECKOUT_SESSION_ID}',
setup_intent: null,
shipping_address_collection: null,
shipping_cost: null,
shipping_details: null,
shipping_options: [],
status: 'complete',
submit_type: null,
subscription: 'sub_1Ojne9FTcNVt1uk9LlbtlCSi',
success_url: null,
total_details: { amount_discount: 0, amount_shipping: 0, amount_tax: 0 },
ui_mode: 'embedded',
url: null
}
and the logs in the stripe dont have meta data and the promt doesnt have too
promt
So the way metadata works here is when you create the Checkout Session and pass in metadata, you're setting it on the Chekout object.
so i need to pass it with the session
If you want to see the metadata on the Subscription object, you need to specify the subscription metadata passing https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata.
i still dont get it let me check
okay i see it
well i dont know if i can fix it because i am not 100% sure
still trying to figure it out
From looking at your code, it looks like you're looking at customer.subscription.created event. At this time, you only set the metadata on the Checkout object. If you want to show the metadata on the subscription object, you need to pass it under the subscription_data. Then, look at the customer.subscription.created event.
ohhhh my god
true
fixed it thankssssssss
you saved me bro i wasted so much time on trying to find what was wrong
10/10 support
So glad it is fixed now!