#Robin020

1 messages · Page 1 of 1 (latest)

charred turtleBOT
bleak mango
#

It should not. Have you timed the Stripe calls and saw that they took 20 seconds? Or is this the time from a user clicking a button on your page to being redirected?

tacit obsidian
#

yeah i timed it myself as well

#

To set up the first session normally takes around 15 seconds

#

How long should it take?

bleak mango
#

Do you have the ID of a specific checkout session that took this long? (cs_test_1234)

#

I can check the end to end time from our side and look at it overall.

#

Not immediately sure on the average time but that does sound long

tacit obsidian
#

I dont have an ID atm

#

I do have another question

#

Can I ask here?

bleak mango
#

Do you have your account ID? I should be able to check from that

#

And yes, ask away

tacit obsidian
#

Can I send node JS code here?

karmic seal
#

👋 stepping in

tacit obsidian
#

app.post("/create-checkout-session", async (req, res) => {
const { prod, id, email, startDatum, coupon } = req.body;
console.log("Create checkout session...");

const couponEdit = coupon.toLowerCase().trim();
let activeCoupon;

switch (couponEdit) {
case "first50":
activeCoupon = prod ? "NRKitQnJ" : "123456";
break;
case "first100":
activeCoupon = "first100";
break;
default:
break;
}

try {
const YOUR_DOMAIN = prod
? "https://hulpmethuren.nl/activeren"
: "http://127.0.0.1:5173/activeren";
const SUCCESS = prod
? "https://hulpmethuren.nl/welkom"
: "http://127.0.0.1:5173/welkom";

const customer = await stripe.customers.create({
  metadata: {
    id,
    email,
    startDatum,
  },
});

const session = await stripe.checkout.sessions.create({
  billing_address_collection: "auto",
  line_items: [
    {
      price: prod
        ? "price_1MQme0FM0KvL0X1JsXhSJlJU"
        : "price_1MQZowFM0KvL0X1Ju1THqKR8",
      // For metered billing, do not pass quantity
      quantity: 1,
    },
  ],
  subscription_data: {
    trial_period_days: 7,
  },
  discounts: [
    {
      coupon: activeCoupon,
    },
  ],
  mode: "subscription",
  customer: customer.id,
  success_url: `${SUCCESS}/?success=true&session_id={CHECKOUT_SESSION_ID}`,
  cancel_url: `${YOUR_DOMAIN}?canceled=true`,
});

res.send(session);

} catch (error) {
console.error(error);
res
.status(500)
.send(
"Error creating checkout session. Please try again later." +
error.message
);
}
});

karmic seal
#

Put the code between 3 backticks helps for readability. Like this

tacit obsidian
#

Oh sorry lol

karmic seal
#

All good

tacit obsidian
#
  const { prod, id, email, startDatum, coupon } = req.body;
  console.log("Create checkout session...");

  const couponEdit = coupon.toLowerCase().trim();
  let activeCoupon;

  switch (couponEdit) {
    case "first50":
      activeCoupon = prod ? "NRKitQnJ" : "123456";
      break;
    case "first100":
      activeCoupon = "first100";
      break;
    default:
      break;
  }

  try {
    const YOUR_DOMAIN = prod
      ? "https://hulpmethuren.nl/activeren"
      : "http://127.0.0.1:5173/activeren";
    const SUCCESS = prod
      ? "https://hulpmethuren.nl/welkom"
      : "http://127.0.0.1:5173/welkom";

    const customer = await stripe.customers.create({
      metadata: {
        id,
        email,
        startDatum,
      },
    });

    const session = await stripe.checkout.sessions.create({
      billing_address_collection: "auto",
      line_items: [
        {
          price: prod
            ? "price_1MQme0FM0KvL0X1JsXhSJlJU"
            : "price_1MQZowFM0KvL0X1Ju1THqKR8",
          // For metered billing, do not pass quantity
          quantity: 1,
        },
      ],
      subscription_data: {
        trial_period_days: 7,
      },
      discounts: [
        {
          coupon: activeCoupon,
        },
      ],
      mode: "subscription",
      customer: customer.id,
      success_url: `${SUCCESS}/?success=true&session_id={CHECKOUT_SESSION_ID}`,
      cancel_url: `${YOUR_DOMAIN}?canceled=true`,
    });

    res.send(session);
  } catch (error) {
    console.error(error);
    res
      .status(500)
      .send(
        "Error creating checkout session. Please try again later." +
          error.message
      );
  }
});
#

I am creating a customer, and getting a notification on my phone with customer created with ID 123...

#
  1. is it even necessasry to create a customer? This way I am creating customers also when they dont finish checkout

  2. How do I arrange that I receive the name of the customer instead of the ID

karmic seal
#
  1. is it even necessasry to create a customer? This way I am creating customers also when they dont finish checkout
    Yes you need a Customer in order to have a Subscription, however you can have the Checkout Session create the Customer if you so desire. That is up to you really.
#

Are you asking how you see this on your phone?

tacit obsidian
#

Kinda

#

yes

karmic seal
#

Are you getting a push notification from Stripe here or is this your own integration sending your phone a message?

tacit obsidian
#

Push from Stripe

karmic seal
#

I'm not familiar with our push notifications

tacit obsidian
#

Oke

karmic seal
tacit obsidian
#

Alright, so then for the first question

#

Can I remove the create customer function

#

And pass in my own id as customer (property)

#

in the line below mode: subscription

karmic seal
#

No you can't use your own ID

#

That has to be a Stripe Customer ID

#

If you don't pass the customer parameter there at all then we will create a Customer for you

tacit obsidian
#

Any benefits or risks in there?

#

Said anotherway: If I leave both the create customer function and the customer paramter out

#

Stripe will create a customer when someone finish their checkout session

karmic seal
#

Yep

#

No risk

#

The benefit of how you are doing it is it seems you are collecting more data about the Customer

#

Since you are passing metadata

tacit obsidian
#

True story

#

Thanks for the information

#

I'll consider

#

Enjoy work