Stripe create Checkout session only with total price

Viewed 1582

I'm currently working in a (small) project where we want to create a shop but we aren't selling anything yet. We are storing our products that we want to sell in our own database. However I wanted to implement a feature that simulates the payment of an order and I was recommended to use Stripe for it. However as far as I know I can't create a checkout session without providing a list of products stored in my Stripe account? So I would need to create all the products in Stripe as well (and have them in my own database too)

Is there no way to just create a checkout session with a total price and when the payment succeeds I can move on?

1 Answers

Yes it’s possible to use Checkout without creating products and prices in Stripe. You need to pass the line_items.price_data object as a parameter when creating the CheckoutSession in order to specify the details of the payment inline (or "ad-hoc").

Here’s an example of how it could look like in node.js:

const session = await stripe.checkout.sessions.create({
  line_items: [
    {
      price_data: {
        currency: "usd",
        unit_amount: 500,
        product_data: {
          name: "name of the product",
        },
      },
      quantity: 1,
    },
  ],
  mode: "payment",
  success_url: "http://example.com/success",
  cancel_url: "http://example.com/",
});

You can learn more about Checkout on this documentation page.

Related