#diavo-elements

1 messages · Page 1 of 1 (latest)

limber flame
#

@reef rain that's not something we support today, those are HTML inputs you'd build as part of your overall form, we only have Elements for the card inputs themselves

reef rain
#

So i cant add additionnal existing Stripe element in my stripe form ?

#

Because when a customer pay on my app atm, in dashboard he doesnt have billing adress or adress

#

His name is determined from his credit card name

limber flame
#

do you use Elements or Checkout, or something else?

reef rain
#

nothing

#

just create checkout session

limber flame
#

so you use Checkout

reef rain
#

so i just have to add this on my stripe.checkout.sessions.create ?

#

wait a minute, i didnt pay anything to use checkout, am i doing something wrong ?

limber flame
limber flame
reef rain
limber flame
#

hmm

#

I mean, you can, but that's an entirely different integration and much more work than using Checkout so I don't see why you'd do it.

#

or you could copy the fields from the billing_details of the PaymentMethod across to the Customer object by writing some custom code as part of handling the checkout.session.completed webhook event, as another example.

reef rain
#

so i guess there is no way to put a checkbox with GTC popup that needs to be read before clicking pay ?

limber flame
reef rain
#

ok thanks mate, so i create ````form action"/create-customer" method="POST"``` to create a customer ?

#

to get his customerid with adress, name on /create-checkout session

limber flame
#

hmm, maybe? you're skipping some steps there so I don't really know what you mean

reef rain
#
  1. User click on a item to buy (15 dollars sub per month). 2. He get a form when enter his name, adress, phone number(if possible), card then he click pay and its done
#

This is what i want to achieve

#
  const { sessionId } = req.query;
  const session = await stripe.checkout.sessions.retrieve(sessionId);
  res.send(session);
});



app.post("/create-checkout-session", async (req, res) => {
  const domainURL = process.env.DOMAIN;
  const { priceId } = req.body;

  // Create new Checkout Session for the order
  // Other optional params include:
  // [billing_address_collection] - to display billing address details on the page
  // [customer] - if you have an existing Stripe Customer ID
  // [customer_email] - lets you prefill the email input in the form
  // [automatic_tax] - to automatically calculate sales tax, VAT and GST in the checkout page
  // For full details see https://stripe.com/docs/api/checkout/sessions/create
  try {
    const session = await stripe.checkout.sessions.create({
      billing_address_collection: 'required', 
      mode: "subscription",
      payment_method_types: ["card"],
      line_items: [
        {
          price: priceId,
          quantity: 1,
        },
      ],
      // ?session_id={CHECKOUT_SESSION_ID} means the redirect will have the session ID set as a query param
      success_url: `${domainURL}/success.html?session_id={CHECKOUT_SESSION_ID}`,
      cancel_url: `${domainURL}/canceled.html`,
      // automatic_tax: { enabled: true }
    });

    return res.redirect(303, session.url);
  } catch (e) {
    res.status(400);
    return res.send({
      error: {
        message: e.message,
      }
    });
  }
});

app.get("/config", (req, res) => {
  res.send({
    publishableKey: process.env.STRIPE_PUBLISHABLE_KEY,
    basicPrice: process.env.BASIC_PRICE_ID,
    proPrice: process.env.PRO_PRICE_ID,
  });
});```` i have this code from stripe github
limber flame
#

cool, that looks like a working simple enough integration of Checkout. You can start experimenting with these extra parameters I've been linking you to so you can test out/see how things work and look.

reef rain
#

ok thanks mate

#

Ok, where do i put my const customer = await stripe.customers.create({ description: 'My First Test Customer (created for API docs)', }); to make it work ? Because i cant see here why it would work if i put it like that on my server.js file, sorry againb for dumb question

limber flame
#

you don't have to create a customer separately , but you can as an option. I'd try using the parameters to Checkout mentioned above first and see if it works for your use case before going down that path

reef rain
#

Yyeah i can get the adress but number form doesnt show up with the snippet on doc

limber flame
#

you're using phone_number_collection[enabled]:true and it doesn't result in the Checkout page asking for one?

reef rain
#

well i'm using "phone_number_collection: {
enabled: true,
}," and it doesnt show up

limber flame
oak pelican
#

hey there, sorry just picking this up -- i've tested this feature so let me see what's going on here

#

ahh, we've got a bug @reef rain -- actively working on resolving it, should be working again shortly!

reef rain
#

ok thanks mate