Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I don't have session.payment_intent in stripe

I had implemeted stripe wallet in next.js and I created a test account for developing.

**this is my server_side codes : **

checkout_session.js

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const stripe = require("stripe")(
  "sk_test_xxxxx"
);

export default async function handler(req, res) {
  if (req.method === "POST") {
    try {
      // Create Checkout Sessions from body params.
      const session = await stripe.checkout.sessions.create({
        line_items: [
          {
            // Provide the exact Price ID (for example, pr_1234) of the product you want to sell
            price: "price_1NhWxaIjDax7Fiks0djPOJXF",
            quantity: 1,
          },
        ],
        mode: "payment",
        success_url: `${req.headers.origin}/?success=true`,
        cancel_url: `${req.headers.origin}/?canceled=true`,
      });
      console.log(session);
      res.redirect(303, session.url);
      // res.status(200).json({ client_secret: session.payment_intent });
    } catch (err) {
      res.status(err.statusCode || 500).json(err.message);
    }
  } else {
    res.setHeader("Allow", "POST");
    res.status(405).end("Method Not Allowed");
  }
}

after successfully payment, I did not have client_secret in session.payment_intent and when I loged it by console.log, I relized that my payment_intent property is null

im using test mode and test data for payment

>Solution :

Checkout Sessions don’t return a Payment Intent object since API version 2022-08-01:
https://stripe.com/docs/upgrades#2022-08-01
Instead, you will find it in the Session once it is completed (checkout.session.completed event).

If you want your code to work, you’d have to hardset an older version like 2020-08-27 (although you should go along with the changes made):
https://stripe.com/docs/libraries/set-version

I’m confused as to why you want the client_secret though. You can’t confirm Payment Intents created by Checkout Sessions, they confirm themselves when the Customer completes the Session.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading