#ghost64

1 messages · Page 1 of 1 (latest)

vernal pantherBOT
sturdy oyster
#

No that would not be expected - can you share an example of a CHeckout Session ID where you see this happening?

austere crescent
#

This is my code
const session = await stripe.checkout.sessions.create(
{
line_items: [
{
price: price.id,
quantity: 1,
},
],
metadata: {
restroId,
orderId,
isPayFirst,
items: JSON.stringify(itemIdArray),
tax,
serviceCharge,
discount,
tip,
priceId: price.id,
},
mode: "payment",

        success_url: `https://restro.dev/customer?success=true&&orderId=${orderId}`,
        cancel_url: `https://restro.dev/api/order/stripeCanceled?canceled=true&&priceId=${price.id}`,

        payment_intent_data: {
          application_fee_amount: 10,
        },
      },
      {
        stripeAccount: stripeAccountId,
      }
    );

    res.json({ url: session.url });

    await updatePaymentHold(restroSchema, orderId, itemIdArray, true)
      .then(() => {
        const timer = setTimeout(async () => {
          await updatePaymentHold(restroSchema, orderId, itemIdArray, false)
            .then(async () => {
              console.log("session deleted");
              await stripe.checkout.sessions.expire(session.id);
              timers.delete(price.id);
            })
            .catch((error: Error) => {
              console.log(error);
            });
        }, 1 * 60 * 1000);
        timers.set(price.id, timer);
      })
      .catch((Error) => {
        console.error();
      });
  }
#

cs_test_a13xFnrF7Rl5oydb4hfzIYD7T16teTfz51I23i3dlbb9dLK04ftbh36ySJ

sturdy oyster
#

Are you sure your CHeckout Session expiration code is being run? I don't see any recent expiration requests happening for that accuont at all

austere crescent
#

Yeah seems I get StripeInvalidRequestError: No such checkout session: 'cs_test_a13xFnrF7Rl5oydb4hfzIYD7T16teTfz51I23i3dlbb9dLK04ftbh36ySJ'

#

But according to the code session.id should be giving me that id that I just created, shouldnt it?

sturdy oyster
#

Can you share the request ID that's giving you the "No such checkout session" error?

austere crescent
#

req_HnYM21dUPYooL3

sturdy oyster
#

Ah I see the issue - when you created the CHeckoutSession you set stripeAccount: stripeAccountId,

#

You need to do the same for your code that expires the Checkout Session

#

Because right now your request is being made on the platform account, but the Checkout Session was created on the connected account

austere crescent
#

Ahh ok, so how do I do it

sturdy oyster
austere crescent
#

Yeah but the session expire says it doesnt take any parameters

#

try it with this?

var stripe = Stripe('{{PLATFORM_PUBLISHABLE_KEY}}', {
stripeAccount: '{{CONNECTED_STRIPE_ACCOUNT_ID}}',
});

sturdy oyster
#

It's not a parameter, you need to specify it in a separate hash - probably something like this:
await stripe.checkout.sessions.expire(session.id, { stripeAccount: stripeAccountId, } );

austere crescent
#

ahh nice that makes sense. Thank you will check now

#

Is there any way I can redirect the page to the previous page if the session expires

sturdy oyster
#

No that I know of

austere crescent
#

Ahh thats enough for me. Thank you soo much for your help. Really appreciate it.