#aooa-checkout-lineitems

1 messages · Page 1 of 1 (latest)

hidden cobaltBOT
#

Hello aooa1009, we'll be with you shortly! Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
https://discord.com/channels/841573134531821608/1162130771386056785, 6 days ago, 11 messages

silver moat
#

aooa-checkout-lineitems

#

@potent olive that's impossible, our API does not support per line-item metadata/details like this. The best option is to store this in your own system/database, or globally on the Checkout Session's own metadata

potent olive
#

how can i save it in the metadata?

#

okay

#

i can just add it

#

okk

silver moat
#

yes on that line 51 you have one metadata key/value and you can add more

potent olive
#

okk

#

do i have to define it somewhere

#

in the stripe dashboard

#

as a string

#

i keep getting the error

hidden cobaltBOT
silver moat
#

those are just pictures with no real info

potent olive
#

no

#

i addedit to my metadata

#

i have 2 types of products

#

one a subscription and another buying loose credits

#

when they buy a subcription, they get some credits

#

they can buy loose credits as well

#

so when the api/webhooks/stripe/route.ts runs

#

and a subscription purchase or credits purchase is made

silver moat
#

sorry those are a lot of really short sentences with no info.

potent olive
#

i need to updae my database

#

but im unable to

silver moat
#

Please breathe, take a step back from your own code and focus on your exact question, developer to developer

potent olive
#

because the error it gives me is Type 'string | number' is not assignable to type 'number | undefined'. Type 'string' is not assignable to type 'number'.

#

sorry,

#

im trying to explain the scenario

#

const stripeSession = await stripe.checkout.sessions.create({ success_url: successUrl, cancel_url: billingUrl, payment_method_types: ['card'], mode: 'subscription', billing_address_collection: 'auto', customer_email: email, line_items: [ { price: stripePriceId, quantity: 1 } ], metadata: { userId: userId, creditsGiven: creditsGiven } })

#

here, can i just automatically add an attr to metadata

#

or do i need to se its type somewhere, like the stripe dashboard

silver moat
#

everything inside metadata is always a string

potent olive
#

ohh

#

but i need to pass an integer

#

the number of credits they get from buying the subscription

#

how can i do that

vale sorrel
#

👋 hopping in here - can you try casting your integer to a string and seeing if that works?

potent olive
#

lemme try

#

it worked!

#

thank you!

vale sorrel
#

👍

potent olive
#

guys

#

@vale sorrel

#

it didnt work

#

i tried variants of typecasting

#

its a string im trying to cast as an integer

vale sorrel
#

What specifically isn't working? Didn'tyou say it was working before?

potent olive
#

i made a mistake in calculating
thinking the credit Count increased after buying a subscripion

#

but it isnt

#

just need help with one thing here

vale sorrel
#

What does that have to do with casting a string to an integer?

potent olive
#

because the casting isnt happening

#

i think im doing it wrong
I tried it in a couple of ways

#

one way

#

another way

#

but when i try these methods normally, they are able to cast a string to int

#

but not in here

#

I'm using typescript and nextjs if it matters

#

you mustve typecast metadata to integer before

#

is this how you do it

vale sorrel
#

What debugging have you done so far? Have you tried logging session1.metadata.creditsGiven to see what value is there

potent olive
#

in the console log
the number is correct

vale sorrel
#

And what's the error you get when you try and cast it?

potent olive
#

no error
It needs to increase the creditCount attr of the user by the amount

#

but it doesnt

vale sorrel
#

Did you log incrementvalue and confirm that's what you expect?

potent olive
#

no

#

lemme do that

vale sorrel
#

What value did you get?

hidden cobaltBOT
potent olive
#

it doesnt come up on either console

quiet hedge
#

Let's be clear. I see you have 2 condition on L69 and L74. You would want to console.log to see the exact value and type you got there first, before thinking of increment the value

#

It's more of js casting and debug here

potent olive
#

I tried a bunch of things

#

nothing gets logged

#

im checking both the console in the terminal

#

and in the chrome dev tools

#

im just confused at this point

#

I'm shot as to why it isnt updating the creditCount

#

it updates in in the scenario of a credit purchase, but not when they buy a subscription

quiet hedge
#

You need to check your terminal console, when you run your app

#

checking incrementValue on both condition, and check its typeof

potent olive
#

does this look right to you

#

the debug statements