#arya_code

1 messages ¡ Page 1 of 1 (latest)

nocturne rootBOT
#

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

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

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

cedar pewter
#

Build an integration where you can render the Payment Element prior to creating a PaymentIntent or SetupIntent.

Learn how to use the Payment Intents API for Stripe payments.

real bison
cedar pewter
#

POST /api/payments/create-payment-intent 404 1.557 ms - 174
Getting this

real bison
#

Can you share more please?

cedar pewter
#

const createPaymentIntent = async (req, res) => {
try {
const { amount, currency, customerId, packageId, email } = req.body;

// Validate request data
if (!amount || !currency || !customerId || !packageId || !email) {
  return res.status(400).json({ error: "Missing required parameters" });
}

// Check for existing incomplete subscription
const subscriptions = await stripe.subscriptions.list({
  customer: customerId,
  status: "incomplete",
  limit: 1,
});

if (subscriptions.data.length > 0) {
  return res
    .status(400)
    .json({ error: "An incomplete subscription already exists." });
}

// Create a payment intent with 'incomplete' subscription mode
const paymentIntent = await stripe.paymentIntents.create(
  {
    amount,
    currency,
    customer: customerId,
    description: `Payment for package ID: ${packageId}`,
    setup_future_usage: "off_session", // To save the card for future use
    automatic_payment_methods: { enabled: true },
    metadata: { packageId, email },
  },
  {
    idempotencyKey: `${customerId}_${packageId}`, // Prevents duplicate charges
  }
);

res.status(200).json({
  success: true,
  message: "Client Secret Created",
  result: paymentIntent.client_secret,
});

} catch (error) {
console.error("Error creating payment intent:", error.message);
res.status(500).json({ error: error.message });
}
};
This is the code, while I hit the api, it just send 404

real bison
#

Please note that I can't audit/review your code for you. If can share the specific request id, I'm happy to assist further

cedar pewter
#

Sorry, I just created word mistakes in write the api path

real bison
#

Ah, so are you unblocked?

cedar pewter
#

Yups, I need more help

#

Or it will be self handle if payment is done?

real bison
#

What do you mean by that? Can you reword the ask a bit?

cedar pewter
real bison
cedar pewter
#

And How will I handle the submit button of the payment page?

cedar pewter
#

Ok, thanks