#dalel.elth-api-key

1 messages Β· Page 1 of 1 (latest)

vestal vale
#

@dense atlas that means your code uses an API key that is expired really

dense atlas
#

Hey @vestal vale !

#

That’s what I thought but all use of my api key in my app originated from the environment variables

#

Which contain the brand new API keys

vestal vale
#

I think you assume they do, but if you were to log the API key you're using you'd see the old expired key

#

you must not have updated your environment variables properly or restarted your app to pick up new values

dense atlas
#

Hmm okay

#

How would you recommend logging it?

vestal vale
#

I would add a log line before the code that initializes Stripe.

dense atlas
#

Alright let me see what I can do πŸ™‚

dense atlas
#

Doesn't seem like a lot of room for error

vestal vale
#

@dense atlas well you could have changed the wrong file. Or not restarted your app (the env file is read on app load that's it)

dense atlas
#

ahh okay

#

@vestal vale I logged the keys

#

it is indeed the updated key

#

the brand new one

#

any idea what could be going wrong?

#

is there a reason why the key provided in the error message begins with "rk" when my secret key (the one I am using in my application) begins with sk?

#

"rk_test_*********************************************************************************************iLVHWL""

mellow lagoon
#

that is a restricted access API key, so secret keys are sk_test_123 and restricted access ones are rk_test_4566 etc

are you using Restricted Access keys anywhere ? have you ever generated one?

dense atlas
#

i have not

mellow lagoon
#

where were you getting that error, do you know what Stripe API endpoint that occurred on? (the original 401)

dense atlas
#

I got that error @mellow lagoon when running "stripe listen --forward-to"

#

for webhooks

mellow lagoon
#

ah

#

it originated from the CLI

dense atlas
#

but I'm also unable to load a stripe checkout session on the frontend

mellow lagoon
#

you should have started with that haha

dense atlas
#

sorry sorry πŸ˜‚

mellow lagoon
#

but I'm also unable to load a stripe checkout session on the frontend
that would be a separate issue aside from CLI

#

would have to do with what API keys are being used considering you just rolled them

#

for CLI, do a new stripe login and that generates a new restricted Stripe CLI keyu for you

dense atlas
#

gotcha

#

let me see how that works

#

are you able to help me troubleshoot the frontend issue if this works? πŸ˜…

mellow lagoon
#

1/share with me what CheckoutSession you created (the request ID)
2/ and how you are redirecting to it

that should give me direction

dense atlas
#

okay got the cli running!

#

so the checkout session stuff has been working

#

for months

#

the only thing that has changed is that I rolled the keys

#

I don't think it's an implementation issue for that reason

#

is a checkout session ID created if the request fails?

mellow lagoon
#

there are 2 steps

1/ create CheckoutSession
2/ redirect to it (either server-side or client-side)

so if 1/ does not work, you'd see a 400'ing request in your logs and no CheckoutSession

dense atlas
#

So i've got this here....on click of my submit button it calls my payments endpoint to create the checkout session ~

        session = stripe.checkout.Session.create(
            payment_method_types=["card"],
            line_items=[{"price": request.data["price_id"], "quantity": 1}],
            mode="subscription",
            client_reference_id=request.user.id,
            success_url=FRONTEND_URL + "/profile/" + str(request.user.id),
            cancel_url=FRONTEND_URL,
            customer_email=request.user.email,
            metadata=metadata
        )
#

then the redirect happens

#

to get that for you?

#

cs_test_a1aszrXWtw9izflFlmJ8bm4Z7EcpbWs1mvRKMr4pRK1QbYLZsRIFlzrsAb

#

@mellow lagoon

mellow lagoon
#

ok the the CheckoutSession is being created

#

so step 2, how are you redirecting to it?

using Stripe.js? or a server-side redirect?

dense atlas
#

here's the function -

#

const stripe = await stripePromise;
const stripeSessionData = await axios.post(
${API_ENDPOINT}/payments/session/,
{ price_id: ANNUAL_PRICE_ID }
);
const sessionId = stripeSessionData.data["session_id"];
await stripe.redirectToCheckout({
sessionId,
});

mellow lagoon
#

perfect, that is what I thought, so something tells me that the publishable key you're using in intializing Stripe here is not the same account as the serverside secret key

#

can you double check those

dense atlas
#

AH

#

right you are

#

I totally forgot I had it stored with my frontend endpoints

#

one more question @mellow lagoon

mellow lagoon
#

ask away, a team member is around and will answer

dense atlas
#

I am now running webhooks and got my checkout session to render as expected...redirect works fine!

#

the only thing is...with webhooks running, I expected to see a "checkout session created" event roll in

#

but not seeing anything on my webhooks server

#

I am testing something very specific regarding the checkout session completed event

#

so I want to be sure before I go through that checkout process that the webhooks in general are being received on the CLI server

#

does that make sense?

jagged charm
#

Hello! Yep, that makes sense. Can you give me the ID of the Checkout Session which you expected to generate the checkout.session.completed event?

dense atlas
#

cs_test_a19AVgeaz6IcakcbDSQ9IhVyZh1FVv2qRQQGosaKQsRx52jXmNho5EXipO

#

thanks @jagged charm πŸ™‚

#

man you guys are quick haha

jagged charm
#

It doesn't look like that Checkout Session was never completed, which explains why there's no event.

#

Did you load the Checkout page and successfully pay?

dense atlas
#

have not successfully paid

#

I'm watching for "checkout session created" tho

#

want to make sure that works before completing the session

jagged charm
#

There is no such event.

dense atlas
#

ohhh okay

#

let's see, then

jagged charm
#

Sorry, I misread your earlier message. πŸ˜…

#

But yeah, there's only checkout.session.completed, no creation event.

dense atlas
#

I completed the checkout session

#

no event fired

#

😦

jagged charm
#

Let me take a look, hang on...

dense atlas
#

thanks!

jagged charm
dense atlas
#

shitttt πŸ˜‚

#

strange

#

this webhooks configuration has worked for me before

#

actually - I was missing the webhook secret value in .env

#

ahhh that didn't do it

jagged charm
#

You said you're using Stripe CLI?

#

The stripe listen command?

dense atlas
#

Yes indeed!

jagged charm
#

What do you see in the output of the stripe listen command? Does the event show up there?

dense atlas
#

No - no output at all

#

"Ready! Your webhook signing secret is whsec_AWw15sktkMmPSTOymCmSGOfenx6Wd***(^C to quit)"

#

this is all I see

jagged charm
#

Is Stripe CLI logged in to the same account as the one you're testing on?

#

What's the exact stripe listen command you're using?

dense atlas
#

It is, yes

jagged charm
#

Try adding --latest to that command and try again.

dense atlas
#

as I mentioned before, this has worked for months

#

but okay I'll try that

jagged charm
#

Yeah, see if that makes a difference or not.

dense atlas
#

"stripe listen does not take any positional arguments. See stripe listen --help for supported flags and usage"

jagged charm
#

Oh, my fault...

#

stripe listen --latest --forward-to http://localhost:8000/api/payments/stripe/webhook/

#

--latest needs to go in front of --forward-to.

dense atlas
#

WOOOOOOOO

#

that did it

#

thank you!

#

oh man

#

sometimes it is just so reassuring to see things work the way they're supposed to πŸ˜‚

#

but the bug that I have been trying to fix through all of this manual testing is still broken

#

I take it that's not something you guys can help me with...it is related to the dj-stripe library for Django

jagged charm
#

The --latest is a workaround until we fix the issue.