#vnadygin - stripe.js
1 messages · Page 1 of 1 (latest)
Hi
Could you provide more details here? I'm not sure I understand your question
Sure
here is the link
You can try to "Continue to checkout", it works after you refrest the page
But do not work then you open it first time
The code is pretty simple, i'll share it with you
So, const stripe = await getStripe(); never get initialised and never throw an error on a first load
after user refresh a page it works
cc @dark locust who is taking over
Let me know you I can provide more info for you
Do you get an error/exception when you load Stripe.js?
it's not super clear what the URL you shared is showing
No, it's in infinite load
Looking at that page the Continue to Checkout button doesn't seem to work for me at all, no matter how many times I reload the page. After filling out a name and email and pressing the button I get a loading spinner and then nothing happens. Can you add logging to the code that handles that button press to find exactly where it gets stuck?
@dark locust Sure thing. We've trying to debug it many times
Here is the video\
Let me add logs to the console and provide you a link
Can you provide a minimal test case to reproduce? There's a lot going on on that page.
@dark locust We will make a minimal test case tomorrow
But in a mean time you can check this this test link:
https://web-j87kl046n-by-rotation.vercel.app/events
Here is the code we use on submit:
const formik = useFormik({
validationSchema,
validateOnChange: false,
validateOnBlur: false,
initialValues: {
buyerName: "",
buyerEmail: "",
ticketVariant: ticketsVariants?.[0],
},
onSubmit: async (values) => {
setLoading(true);
try {
const { data } = await createEventTicketPaymentSession({
buyerName: values.buyerName,
buyerEmail: values.buyerEmail,
ticketVariantId: values?.ticketVariant?.id,
amount: values?.ticketVariant?.amount,
eventId: event?.id,
});
const sessionId = data?.createEventTicketPaymentSession;
console.log(
"sessionId has been initialized from the console: ",
sessionId
);
console.log("try to create stripe instance");
const stripe = await getStripe();
console.log("stripe instance has been created", stripe);
console.log("try to redirect to stripe checkout link");
const result = await stripe?.redirectToCheckout({
sessionId,
});
} catch (error) {
console.log(error);
} finally {
setLoading(false);
}
},
});
Those errors seem unrelated, but it's hard to tell because the filenames on the right are cut off.
Looks like the Checkout Session is being created.
Let me share another screenshot
It gets stuck on try to create stripe instance
Can you wrap const stripe = await getStripe(); in a try/catch and see if that catches anything?
Oh, you've got that whole thing in try/catch, my fault.
So what is getStripe? Where is that coming from?
import { getStripe } from "~/lib/stripe";
What is ~/lib/stripe?
let stripePromise: Promise<Stripe | null>;
export const getStripe = () => {
if (!stripePromise) {
stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PK!);
}
return stripePromise;
};
actually we've trying a few options, and none of them worked out
i mean we've trying to import and initialise stripe in the same file and also using React.useEffect and React.useState
Now it's more like singletone
Also, it's never work on localhost, so we need to deploy it so debug that makes it's even more complicated
Why do you have getStripe instead of using loadStripe directly?
Also why are you returning the promise like that? Wouldn't the promise already be resolved by then?
@dark locust it doesn’t really matter, then you return a promise from function, it’s works the same way
I can rebuild it with a direct import
Yeah, instead of await getStripe(); try await loadStripe(...); and let me know if that changes anything.
@dark locust same thing
The UK's leading peer-to-peer fashion rental app. Hire luxury designer clothes and accessories from top brands in London and the UK. No waiting list. No subscription fees.
now the code are looks like this:
import { loadStripe, Stripe } from "@stripe/stripe-js";
...
onSubmit: async (values) => {
setLoading(true);
try {
const { data } = await createEventTicketPaymentSession({
buyerName: values.buyerName,
buyerEmail: values.buyerEmail,
ticketVariantId: values?.ticketVariant?.id,
amount: values?.ticketVariant?.amount,
eventId: event?.id,
});
const sessionId = data?.createEventTicketPaymentSession;
console.log(
"sessionId has been initialized from the console: ",
sessionId
);
console.log("try to create stripe instance");
const stripe = await loadStripe(process.env.NEXT_PUBLIC_STRIPE_PK!);
console.log("stripe instance has been created", stripe);
console.log("try to redirect to stripe checkout link");
const result = await stripe?.redirectToCheckout({
sessionId,
});
} catch (error) {
console.log(error);
} finally {
setLoading(false);
}
},
});
It's getting suck here:
start() {
void 0 === this.evalLoop && (Zi("Starting evaluation loop"),
this.evalLoop = setInterval((()=>this.performClientMatching()), 500))
}
That evalLoop keeps looping over and over.
It goes through a lot of minified code to get there though, so I can't really tell what's happening. A minimal test case should help a lot.
Okey, I will provide tomorrow
@dark locust one question. Should it work on local host?
What is "it"?