#tyler_code

1 messages ¡ Page 1 of 1 (latest)

glacial grottoBOT
#

👋 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/1339303481999097876

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

frigid pasture
#

Hi, are you saying that in test mode things are working as expected but in live mode things are breaking? What does the error look like? When exactly do you see the error? At what stage?

latent echo
#

So if i take all env variables that are meant in production and click my subscribe button here is takes me to the stripe checkout like its suppose to using all the same env varibales for prod this is in my local env

#

But if i try on my deployed app via AWS Amplify when i click the subscribe button nothing happens and i get

#

Which is confusing because at first maybe i thought it was the production env variables, but when i switched to them in my env folder, i was taken to checkout page for the subcription with no issues

#

then i add all the same env variables in my deployed version and im getting that error and not taken to the stripe checkout page for the subscription

#

I double chcked to make sure nothing was spelled wrong in live version also for variables

#

I can show you here the action thats triggered when the button is clicked in my nextjs app ```js "use server";

import { stripe } from ".././lib/stripe";

type Props = {
companyId: string;
userEmail: string;
priceId: string;
};

export const subscribeAction = async ({
companyId,
userEmail,
priceId,
}: Props) => {
if (!companyId || !userEmail || !priceId) {
throw new Error("Missing required params");
}

try {
const existingCustomer = await stripe.customers.list({
email: userEmail,
limit: 1,
});
let customerId =
existingCustomer.data.length > 0 ? existingCustomer.data[0]?.id : null;

if (!customerId) {
  const customer = await stripe.customers.create({
    email: userEmail,
  });
  customerId = customer.id;
}

const { url } = await stripe.checkout.sessions.create({
  customer: customerId,
  payment_method_types: ["card"],
  line_items: [
    {
      price: priceId,
      quantity: 1,
    },
  ],
  metadata: {
    companyId,
    userEmail,
  },
  mode: "subscription",
  billing_address_collection: "required",
  customer_update: {
    name: "auto",
    address: "auto",
  },
  success_url: `${process.env.NEXTAUTH_URL}/payments/success`,
  cancel_url: `${process.env.NEXTAUTH_URL}/payments/cancel`,
});

return url;

} catch (error) {
console.error("Stripe subscription error:", error);
throw new Error("Subscription failed. Please try again.");
}
};

#

This is triggered when they this runs ```js const handleClickSubscribeButton = async () => {
try {
const url = await subscribeAction({
companyId: companyId || "",
userEmail: userEmail || "",
priceId: process.env.NEXT_PUBLIC_STRIPE_MONTHLY_PRICE_ID!,
});

  console.log("Subscription URL:", url);

  if (url) {
    router.push(url);
  } else {
    throw new Error("Failed to subscribe");
  }
} catch (error) {
  console.error("Subscription error:", error);
}

};

frigid pasture
#

That error does not seem to be coming from Stripe. I do not know that it's a Stripe related error