#gabrielvrl
1 messages · Page 1 of 1 (latest)
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.
- gabrielvrl-customer-portal, 1 day ago, 68 messages
Can you elaborate?
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
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?
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?
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
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
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?
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?
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
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
How are you redirecting to checkout, exactly? Can you share a snippet of your code?
Why can't you paste it here?
Just a snippet showing session creation / redirect
Nothing sensitive
ok, i can delete it after
Ok, and what exactly is the issue?
it doesn't redirect on homolog and production
ok, but you didnt show any redirect logic
There was some kind of "shouldUseCheckout" param that lead to "handleCheckout" via another method not specified
there's literally a method called handleCheckoutStripe
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
Sure, and how are you redirecting, can you show that part?
yeah, i can
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
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
ok, but any issues with the customer/subscription list logic feels unrelated to Checkout url redirection
Aside: I will say you really should not be doing secret key operations client-side, that is not secure
but given you have the url clientside, the href setting should work.
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
[]
Ok, so I'd suggest working on that logic, which seems to be a failure much earlier than checkout redirect
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?
No, I we can help with your other logic too, i just mean this sounds completely different than "checkout redirect does not work"
ok, i agree
this is an issue with your customer/siubscription list logic
ok, agreed
So let's back up to the empty data array
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)
go back a layer, where do you list the customers by email
both functions
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
ok, following
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
const { data } = await stripe.customers.list({
email: userEmail,
});
ok
What is the full return value from that call?
const result = await stripe.customers.list()
data should be the list of customers, yes, but that suggests you have a non-matching email with no customers
or filtered by the email?
if it is empty
ok, that only means this new customer hasn't bought anything yet
which is fine
it's not on stripe yet
Ok, then you need to handle that in your logic instead of assuming data[0].id is defined
{
"object": "list",
"data": [],
"has_more": false,
"url": "/v1/customers"
}
whole result
nowhere do you check if the customer list is empty
right, that
You need to handle that case, no customer results
you're correct my friend
like this:
if(data && data.length === 0){
console.log("entrou no if do data")
return await handleCheckoutStripe();
}
Yep, something like that