#shadowrockzzz

1 messages · Page 1 of 1 (latest)

hallow lavaBOT
short ridge
#

Hi, let me help you with this.

#

You might be trying to access an expired Checkout URL.

unkempt gale
#

@short ridge , Where can I check if my checkout URL got expired or not?

short ridge
#

Usually, if you're worrying about expiry, the integration is not done correctly.
Normally, you should create a Checkout Session and redirect to the URL immediately.

hallow lavaBOT
unkempt gale
#

Hi @short ridge , @halcyon ferry , I checked my console and this is the error, I am getting , but I can see that I am only passing priceId as input and is not passing any personal authentication inputs from my end (not sure if the stripe internal code might pass), Can you please let me know which part I should edit to resolve this issue?

halcyon ferry
#

what code exactly do you use to create and then redirect to the CheckoutSession?

unkempt gale
#

This is my frontend code : export class StripeService {

constructor() { }

private stripePromise = loadStripe('ypk_test_51OaEFsSCqY0t9WjtAQx2aePczKbl9dpUeRsb5RC6GGDK4RSdTS10mzG0guCD4Rl7DBzdDwlgJmVIjbQl1Erqtcyx00osoZnz9k');

async checkout(): Promise<void> {
const stripe = await this.stripePromise;
const sessionId = await this.createCheckoutSession();
if(stripe){
const { error } = await stripe.redirectToCheckout({
sessionId: sessionId,
});
if (error) {
console.error('Error redirecting to Checkout:', error);
}
}
else{
console.log("Error in creation of stripe session")
}
}

private async createCheckoutSession(): Promise<string> {
const response = await fetch('http://localhost:3030/api/create-checkout-session', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
priceId: 'price_1OaF2ESCqY0t9WjtaSFCJmYO',
}),
});

const data = await response.json();
return data.id;

}
}

halcyon ferry
#

you have a typo

#

ypk_test_ , that y should not be there

unkempt gale
#

And this is my backend code "router.post('/api/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
{
price: req.body.priceId,
quantity: 1,
},
],
mode: 'payment',
success_url: 'http://localhost:4200/',
cancel_url: 'http://localhost:4200/',
});

r"

#

Yep, Thank you so much , You have saved my day!!!