#gabrielvrl

1 messages · Page 1 of 1 (latest)

patent pelicanBOT
#

Hello! 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.

faint schooner
#

Can you elaborate?

meager fog
#

yeah i can

#

can this chat be private?

#

i may share sensitive information with you

faint schooner
#

What type of sensitive info? You can DM me URLs and specific login details, but largely you should be able to explain what you're seeing without giving sensitive info

meager fog
#

ok, no problem

#

so, i'm having a problem redirecting my customer to the checkout page

#

i coded a new flow that when the user log in, i check with the stripe api if this user has a active subscription

#

this part is working

#

but if the user does not have a active subscription, i redirect than to the checkout

#

at the development environment it works

#

on my machine you know

#

but it doesn't at production or homolog

#

i'm not sure why

#

it doesn't call the api, kinda of

#

i'm not sure, i may have made a mistake somewhere, but it works locally

#

do you follow?

#

still there?

faint schooner
#

Apologies, the server is busy. Getting back to you now.

I follow, but I'm still a bit limited in how I can help. Are you able to step through your code and add log lines to all the function calls you make to see where the issue starts?

meager fog
#

yeah sure, i did that

#

everything works in development

#

running on my machine

#

i didn't want to add console logs to homolog or production before i talked to you

#

because i need to created pull requests and all that

#

i don't know, just seems like some stripe configuration

#

for the live mode

#

i can share my code with you, that's not a problem, but the thing is

#

it works on development

faint schooner
#

Do you have your API keys switched over? You have test mode a live mode API keys

#

Not sure if that's helpful. We can't really look through an entire integration's worth of code to see why something isn't working. We need you to be able to step through the code and ask specific questions about why a specific method or block isn't working

patent pelicanBOT
meager fog
#

it's not switched

#

it works if i go throught other flows

#

like, api calls

faint schooner
#

Do you have a URL where we can see what's happening? Can you also be a bit more specific about what's not working?

meager fog
#

i do

#

i will send it to you on the dm

faint schooner
#

Okay, and can you elaborate on what is going wrong? You said it's not redirecting to Checkout, which tells me this is something that's going wrong with your server's workflow for redirecting, which is not really a Stripe issue as far as I can tell right?

meager fog
#

not exactly, because my logic works on development

#

why shouldnt work on homolog

faint schooner
#

There are a lot of things that might stop it from working and our limited visibility doesn't really give us a lot of insight into what could be going wrong

meager fog
#

yeah, i sent to you

#

the url where you can chec

#

check*

#

on the dm

faint schooner
#

It's in another language and even if it were in english, we need you to be able to identify where it's not working by checking your server logs and looking in the console/network logs of the browser. We cannot debug a problem this vague unfortunately

kindred lily
#

How are you redirecting to checkout, exactly? Can you share a snippet of your code?

meager fog
#

yeah i can

#

i cant send you a dm @kindred lily

#

and i cant past it here

#

paste it *

kindred lily
#

Why can't you paste it here?

#

Just a snippet showing session creation / redirect

#

Nothing sensitive

meager fog
#

ok, i can delete it after

kindred lily
#

Ok, and what exactly is the issue?

meager fog
#

it doesn't redirect on homolog and production

kindred lily
#

ok, but you didnt show any redirect logic

#

There was some kind of "shouldUseCheckout" param that lead to "handleCheckout" via another method not specified

meager fog
#

there's literally a method called handleCheckoutStripe

kindred lily
#

So what happens in that method?

#

Sure, but what does that do?

meager fog
#

it creates a session with stripe.checkout.sessions.create()

#

and redirects

#

i don't to like share the whole company code, but i can send snippets

#

and delete after

kindred lily
#

Sure, and how are you redirecting, can you show that part?

meager fog
#

yeah, i can

kindred lily
#
const checkoutSession = await stripe.checkout.sessions.create({
     ....
    });

    window.location.href = checkoutSession.url || "";

This doesn't really make sense.

#

await stripe.checkout.sessions.create should only be run server-side with your secret key to create a session

#

while window.location.href only makes sense in a browser (client-side)

#

Those two lines should never be run in the same context/environment

meager fog
#

i know, that's a whole other story

#

i do not have a backend at the moment

#

and i will not have

#

and i agree with you

#

but that's not the point rn

#

at the moment it tries to redirect

#

but later if i try just pressing the button again

#

been logged in

#

it works

kindred lily
#

ok, but any issues with the customer/subscription list logic feels unrelated to Checkout url redirection

meager fog
#

ok, now we know that

#

but i didn't at the start of the conversation

kindred lily
#

Aside: I will say you really should not be doing secret key operations client-side, that is not secure

meager fog
#

i know

#

100% agree with you

kindred lily
#

but given you have the url clientside, the href setting should work.

meager fog
#

that's one of the reasons i didn't want to share the code

#

but that's my managers point of view

#

we had LONG conversations about it

#

i know

#

so, now the problem seems to be

#

that when i do this:

  const { data } = await stripe.customers.list({
    email: userEmail,
  });
#

it's fine if i do not have a customer with this email yet

#

it returns an empty array

#

[]

kindred lily
#

Ok, so I'd suggest working on that logic, which seems to be a failure much earlier than checkout redirect

meager fog
#

but when i do this operation:

stripe.subscriptions.list(
{ customer: data[0].id },

it shows me this error:

error TypeError: Cannot read properties of undefined (reading 'id')
at handleCustomerRetrieve (stripe-checkout-helper.ts:58:29)
at async handleRetrieve (index.tsx:310:7)

#

ok, but you only help with checkout?

kindred lily
#

No, I we can help with your other logic too, i just mean this sounds completely different than "checkout redirect does not work"

meager fog
#

ok, i agree

kindred lily
#

this is an issue with your customer/siubscription list logic

meager fog
#

ok, agreed

kindred lily
#

So let's back up to the empty data array

meager fog
#

but why it returns an error?

#

ok

#

thanks

kindred lily
#

TypeError: Cannot read properties of undefined (reading 'id')

#

This is a JS runtime error because you try to access id on undefined (data[0] is undefined)

meager fog
#

the block

#

ok

kindred lily
#

go back a layer, where do you list the customers by email

meager fog
#

both functions

kindred lily
#
const userEmail = sessionStorage.getItem("userEmail");
  console.log("userEmail", userEmail)
  if (userEmail) {
    console.log("entrou no if", userEmail)
    try {
      const { data } = await stripe.customers.list({
        email: userEmail,
      });
#

that

meager fog
#

ok, following

kindred lily
#

check if sessionStorage.getItem("userEmail"); is set or not, you said logging in fixed the issue, you like have empty storage, completely unrelated to any stripe SDK calls

meager fog
#

it is

#

it goes into that if

kindred lily
#
const { data } = await stripe.customers.list({
        email: userEmail,
      });
meager fog
#

ok

kindred lily
#

What is the full return value from that call?

meager fog
#

and that's right there

#

1 min

kindred lily
#

const result = await stripe.customers.list()

meager fog
#

ok, one minute

#

i mean, the whole list?

kindred lily
#

data should be the list of customers, yes, but that suggests you have a non-matching email with no customers

meager fog
#

or filtered by the email?

kindred lily
#

if it is empty

meager fog
#

ok, that only means this new customer hasn't bought anything yet

#

which is fine

#

it's not on stripe yet

kindred lily
#

Ok, then you need to handle that in your logic instead of assuming data[0].id is defined

meager fog
#

{
"object": "list",
"data": [],
"has_more": false,
"url": "/v1/customers"
}

#

whole result

kindred lily
#

nowhere do you check if the customer list is empty

#

right, that

#

You need to handle that case, no customer results

meager fog
#

you're correct my friend

#

like this:

  if(data && data.length === 0){
    console.log("entrou no if do data")
    return await handleCheckoutStripe();
  }
kindred lily
#

Yep, something like that

meager fog
#

give me a minute

#

it's fine, you can close this chat if you want

#

i can't take it from here

#

thanks a lot