#luft-checkout-connect

1 messages · Page 1 of 1 (latest)

meager geodeBOT
#

Hello! We'll be with you shortly. 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.

glacial wyvern
#

luft-checkout-connect

wraith grove
#

Here is the code that the entire issue is about: `app.post("/createStripeCheckout", async (req, res) => {
try {
const { price, quantity, customerCurrency, destinationId } = req.body;

const createdCustomer = await stripe.customers.create({
  name: req.body.customer.id,
  metadata: { ...req.body.customer, customerCurrency },
});

console.log("Created Customer:", createdCustomer);

const session = await stripe.checkout.sessions.create({
  ui_mode: "embedded",
  mode: "payment",
  line_items: [{ price, quantity }],
  customer: createdCustomer.id,
  invoice_creation: {
    enabled: true,
  },
  return_url: "http://localhost:3000",
  payment_method_configuration: "pmc_1OH8ZAL8z1e5mvb67NMMunj5",
}, {
  stripeAccount: destinationId,
});

console.log("Created Session:", session);

res.json({ clientSecret: session.client_secret, sessioned: session });

} catch (error) {
console.log(error);
console.error("Error creating checkout session:", error.message);
res.status(500).send("Internal Server Error");
}
});`

glacial wyvern
#

👋 @wraith grove when you pass a Customer id cus_123 in your request it has to exist on that specific Stripe account. So if you pass stripeAccount: 'acct_123' then the Customer must exist there.
And it looks like you're mixing things up and passing a Customer id that exists in your own platform instead

#

Also you seem to be using Express accounts. So you should never use Direct Charges.

wraith grove
#

Ok, and is there a possibility to add this destination id to the checkout?

#

Or do i have to update the paymentIntent in the webhook?

wraith grove
#

ok, will see if it will work in a second.

#

Before I start the code, do you think it's ok? `app.post("/createStripeCheckout", async (req, res) => {
try {
const { price, quantity, customerCurrency, destinationId } = req.body;

const createdCustomer = await stripe.customers.create({
  name: req.body.customer.id,
  metadata: { ...req.body.customer, customerCurrency },
});

console.log("Created Customer:", createdCustomer);

const session = await stripe.checkout.sessions.create({
  ui_mode: "embedded",
  mode: "payment",
  line_items: [{ price, quantity }],
  customer: createdCustomer.id,
  invoice_creation: {
    enabled: true,
  },
  return_url: "http://localhost:3000",
  payment_method_configuration: "pmc_1OH8ZAL8z1e5mvb67NMMunj5",
  payment_intent_data: {
    transfer_data: {
      destination: destinationId,
    },
  },
});

console.log("Created Session:", session);

res.json({ clientSecret: session.client_secret, sessioned: session });

} catch (error) {
console.log(error);
console.error("Error creating checkout session:", error.message);
res.status(500).send("Internal Server Error");
}
});`

#

And btw, I do apologize for such an mistakes, but the docs are large and as you can see after work with it for over a week, I still get discombobulated.

glacial wyvern
#

totally understandable. I have worked here for years and I get lost too. I just know the API by heart at this point, definitely not just you

#

and yes the code you have works. Note that you don't pass on_behalf_of so you will be the merchant of record. Read this section to understand the difference and decide if you need it or not

wraith grove
#

Ok, I see it works. Thank you, I owe u something.