#sadegh-akbari_api

1 messages ยท Page 1 of 1 (latest)

brave pivotBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1339183430155636830

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

soft parrot
#

hi there!

native aurora
#

hi

soft parrot
#

you need to check your browser console or backend server log to get a full error message.

native aurora
#

full error is this => message
:
"We're sorry, but we're unable to serve your request."
this error return from stripe
i using stripe in my nextjs backend

  try {
    const { priceId } = await req.json();

    const customer = await stripe.customers.create();

    // Create a subscription
    const subscription = await stripe.subscriptions.create({
      customer: customer.id,
      items: [{ price: priceId }],
      payment_behavior: "default_incomplete",
      // payment_behavior: "error_if_incomplete",
      expand: ["latest_invoice", "latest_invoice.payment_intent"],
      // trial_period_days: 3,
    });

    const latestInvoice = subscription.latest_invoice as Stripe.Invoice;
    const clientSecret = latestInvoice.payment_intent
      ? (latestInvoice.payment_intent as Stripe.PaymentIntent).client_secret
      : null;

    return NextResponse.json({
      subscriptionDetails: subscription,
      subscriptionId: subscription.id,
      clientSecret,
    });

  } catch (error) {
    return NextResponse.json(
      { message: error instanceof Error ? error.message : "Something went wrong" },
      { status: 400 }
    );
  }
}```
#

in localhost worked correctly but in production given this error

soft parrot
#

"We're sorry, but we're unable to serve your request."
can you share more details? you made an API request and this was returned by Stripe? which API request you amde exactly?

native aurora
#

ok please wait a moment

#

this is my console error

soft parrot
#

that error comes from your backend. so can you check your backend logs to check the exact issue?

native aurora
#

this error return in my catch, catch returned stripe error

import Stripe from "stripe";

const stripe = new Stripe(process.env.NEXT_PUBLIC_STRIPE_SECRET_KEY as string, {
  apiVersion: "2024-04-10" as any,
});

export async function POST(req: Request) {
  try {
    const { priceId } = await req.json();

    const customer = await stripe.customers.create();

    // Create a subscription
    const subscription = await stripe.subscriptions.create({
      customer: customer.id,
      items: [{ price: priceId }],
      payment_behavior: "default_incomplete",
      // payment_behavior: "error_if_incomplete",
      expand: ["latest_invoice", "latest_invoice.payment_intent"],
      // trial_period_days: 3,
    });

    const latestInvoice = subscription.latest_invoice as Stripe.Invoice;
    const clientSecret = latestInvoice.payment_intent
      ? (latestInvoice.payment_intent as Stripe.PaymentIntent).client_secret
      : null;

    return NextResponse.json({
      subscriptionDetails: subscription,
      subscriptionId: subscription.id,
      clientSecret,
    });

  } catch (error) {
    return NextResponse.json(
      { message: error instanceof Error ? error.message : "Something went wrong" },
      { status: 400 }
    );
  }
}
#

please see up code

soft parrot
#

please share the exact line that is returning the error. I don't need your full code.

native aurora
#

 
// Create a subscription
   const subscription = await stripe.subscriptions.create({
      customer: customer.id,
      items: [{ price: priceId }],
      payment_behavior: "default_incomplete",
      expand: ["latest_invoice", "latest_invoice.payment_intent"],
  });```
soft parrot
native aurora
#

please wait

#

???

soft parrot
#

I don't understand your question. if you are in live mode, then share a livemode request.

native aurora
#

ok please wait ๐Ÿ™

brave pivotBOT
native aurora
#

req_fdjNy8kGmzOsOz

#

this is my req id

sturdy monolith
#

Where did you find that? That doesn't exist according to our systems

native aurora
#

see this photo

sturdy monolith
#

In any case, the reason for the failed request is due to your location. We cannot serve requests from your country