#nikivi

1 messages · Page 1 of 1 (latest)

eager falconBOT
queen rune
#

i want to deploy my app finally

shut drift
#

Can you share the event id?

shut drift
#

Those aren't events

#

evt_123

#

Whichever one is giving you the above error

queen rune
#

evt_1N8io4KmRnbuc3WvwmPbLb95

#

perhaps this

#

not sure which one it was

#

I have few questions also to simplify the code if I may ask

shut drift
#

One thing at a time

queen rune
#

ok

#

lets solve first thing

#

i had it working yesterday

#

its just im trying to deploy now

shut drift
#

That event wasn't sent to any endpoints it looks like

queen rune
#

ok let me go over what i did

#

my app has 4 pricing points

#

i now have this switch case

#

if it passes either of these 4 strings

#

it creates a new session

#

I don't know if i can turn monthly to yearly

#

as one session as part of parameter

#

would simplify code

#

otherwise i thought I made 4 products

#

is what I have now

shut drift
#

Ok

#

I just need an event id to investigate the webhook issue

#

And your code snippet for that endpoint

queen rune
#

ok so code is here

#

i run via node index.js

#

on node 18

#

in nother tab i run stripe listen --forward-to localhost:4242/webhook

#

import * as dotenv from "dotenv"

#

actually it might be i missed this

#

as i added those process.env

#

going to try with this

#

ah this is some node troubles

#

i tried running it with bun

#

as it auto loads .env

#

but thats what caused this

#

so i guess bun is not supported

#

or maybe i have wrong code

shut drift
#

You said it was working yesterday. What changed?

queen rune
#

i added process.env

#

as i wanted to commit to repo

#

and can't expose secrets

shut drift
#

So before it worked with just hardcoding the variables?

queen rune
#

yes

#

it only worked for 2 payments

#

i since added year

#

with discount

#

needed to set those up

#

but first want to get 2 working

#

i assume year is just passing a paramter

#

ok go it running

#

const dotenv = require("dotenv")

#

had to use this

#

const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY)

#

for some reason stripe docs use old require syntax

#

not es6

#

so everything has to be require now

shut drift
#

So it's working now?

queen rune
#

still undefined

#

my env file is all right values

#

so dont know whats up

shut drift
#

What is your code doing

queen rune
shut drift
#

Send your webhook endpoint code

queen rune
#

it listens to events

shut drift
#

Oh you did thanks

queen rune
#

i pushed

#

dotenv changes

shut drift
#

So for some reason you're getting undefined events being sent to the endpoint

#

What made those requests to the endpoint?

#

That corresponded to the "Unhandled event type" errors

queen rune
#

so i do this

#

which calls this function

#

for normalMonthly

#

it creates this session

#

and returns url from it

#

which is what i click and fill details

#

after filling payment

#

stripe calls that web hook endpoint

#

thats my understanding of it at least

#

in theory

#

case "checkout.session.completed":

#

should fire

#

but i get undefined i guess

shut drift
#

Oh

queen rune
shut drift
#

It might not be pulling in your env variables

queen rune
#

is that listener

#

dotenv.config()

#

i thought this one did it

shut drift
#

Log endpointSecret as the first line in your endpoint code

#

Make sure it's actually pulling in the variable

queen rune
#

yes you are right

#

do i need to move dotenv.config()

#

into the app.post?

#
app.post(
  "/webhook",
  express.raw({ type: "application/json" }),
  async (request, response) => {
    dotenv.config()
#

like so?

#

never worked with express + env vars

#

yea that did not help 😦

#

trying with this

#
const dotenv = require("dotenv")
dotenv.config()

// This is your test secret API key.
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY)
#

this*

#

okk

#

that worked

#

i get stuff back

#

thank god

#

ok now how can i may year plans work without duplicating code

#

for creating sessions

#

or I can't

#

the way it works

#

subscription.current_period_end

#

i use this to update user model

#

to know the date until user is subscribed

#

reading this

#

can't find period

#

or something like this

#

seems i have to make whole new product for it

shut drift
queen rune
#

ok doing it this way

#

@shut drift is it possible

#

i realise i created all these projects

#

live

#

can i copy to test

#

or i have to manually redo

#

products*

shut drift
#

Have to manually

#

You can create multiple prices under the same product though

#

Would make sense to have 2 products: KusKus and KusKus Pro

#

Then you could have all the different pricing options under those 2 products as different price objects in stripe

queen rune
#

i thought it was thesse things

#

where do i get url

#
        const normalMonthly = await stripe.checkout.sessions.create({
          success_url: process.env.STRIPE_SUCCESS_URL!,
          mode: "subscription",
          metadata: {
            userDetailsId: userDetailsId,
          },
          line_items: [
            {
              quantity: 1,
              price: process.env.STRIPE_NORMAL_MONTH_SUBSCRIPTION!,
            },
          ],
        })
        return {
          stripeCheckoutUrl: normalMonthly.url,
        }
#

is my code

#

where STRIPE_NORMAL_MONTH_SUBSCRIPTION

#

is that id

#

yea

#

cant find in ui

#

price urls

#

@shut drift

#

i did how you said

#

not helpful 😦

#

im actually surprised

#

i remember using those ids before

#

why did it suddently start breaking

shut drift
#

Can you share the request id

queen rune
#

req_EfKEw9hCsdiLZH

shut drift
#

You passed a price id to the success_url

queen rune
#

ok that is fixed

#

but this

#

it should say 1 year

#

its in test mode

#

STRIPE_NORMAL_YEAR_SUBSCRIPTION=price_1N9ZKsKmRnbuc3WvqnUTPFqa

#

i make sure its right

#

maybe its no up to date?

#

tried again

#

oh

#

i see it shows description there

#

so like

#

@shut drift

shut drift
#

What's the problem?

queen rune
#

if i do this thing

#

with 2 products

#

and 2 prices

#

how can i show 1 year here

#

i thoguht thats what this was for

shut drift
#

Create a new session and see if it's fixed

queen rune
#

just did

#

thats new

#

removed description

#

thought it would fix it

#

now it shows nothing

shut drift
#

Try adding again

#

With updated text

queen rune
#

price descirption?

#

ok doing this update

#

yea

#

no change

#

anything else i can try?

shut drift
#

Paste the checkout session id or link so I can take a look

queen rune
#

this is api

#

how in dashboard

shut drift
#

No the actual checkout session link

shut drift
#

I still see no description

queen rune
shut drift
#

Create a new link now

queen rune
#

im confused

shut drift
#

A new checkout session

shut drift
#

That looks like the exact same link you just sent

queen rune
#
      case "normalYearly":
        const normalYearly = await stripe.checkout.sessions.create({
          success_url: process.env.STRIPE_SUCCESS_URL!,
          mode: "subscription",
          metadata: {
            userDetailsId: userDetailsId,
          },
          line_items: [
            {
              quantity: 1,
              price: process.env.STRIPE_NORMAL_YEAR_SUBSCRIPTION!,
            },
          ],
        })
        return {
          stripeCheckoutUrl: normalYearly.url,
        }
#

so every time it hits this

#

it returns same one

#

is this expected

shut drift
#

No

queen rune
#

how can i force new one

#

there is no caching

shut drift
#

Are you passing an idempotency key?

queen rune
#

i dont

#

its just this

#

ok

#

this is first time i make this link

#

its still no description

#

should be this

#

is it some caching issue or something

#

im confused

#

also i have question

#

in my web hook code

#

how can I know that on case "checkout.session.completed":

#

it was pro product

#

and not normal

#

i can send metadata

#

but i wonder if there is way to do without

#

like if I can get name of product

#

in the checkout session

shut drift
#

Just store the price id's on your end

#

and compare

queen rune
#

ok can do that