#kevinx-checkout-docs

1 messages · Page 1 of 1 (latest)

turbid bisonBOT
jaunty horizon
#

👋 Hey @odd night Please try to write a detailed question when you post your first message. It makes it easier to know what you need help with and answer you

odd night
#

sure, how to make the payment method reusable when set up checkout session

// This is your test secret API key.
const stripe = require('stripe')('sk_test);
const express = require('express');
const app = express();
app.use(express.static('public'));

const YOUR_DOMAIN = 'http://localhost:4242';

app.post('/create-checkout-session', async (req, res) => {
  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_ID}}',
        quantity: 1,
      },
    ],
    mode: 'payment',
    success_url: `${YOUR_DOMAIN}/success.html`,
    cancel_url: `${YOUR_DOMAIN}/cancel.html`,
  });

  res.redirect(303, session.url);
});

app.listen(4242, () => console.log('Running on port 4242'));
#

can two modes be used like payment and setup

jaunty horizon
#

Please remove your API key and roll it immediately even ifjust test mode

#

Also this is just a dump of a basic sample. What is your real question, what have you tried, what doc did you read, etc.?

odd night
#

my question is how to save the payment method user used in this session for future charges

#

didn't find any useful info here in this doc

jaunty horizon
#

kevinx-checkout-docs

odd night
#

Great, thanks, will take a look, two more related questions please

  1. Is the price converted to local currency automatically when checkout? if I setup the price in USD, someone in UK get GBP price?
  2. If I want to also set up the PortalSession, do I need to save the checkout session id and retrieve portal session based on the id?
odd night
#
  1. why is the customer null in the returned checkout session
#

customer: null,

jaunty horizon
#
  1. No sure what that means
#

I'm sorry, you're really asking extremely simple questions without trying and this isn't really scalable

#

Please try to read the docs, try to read what things mean. We're happy to help with questions that you are confused on, but this isn't a place to get real time rubber duck debugging

odd night
jaunty horizon
#

@odd night I am happy to help if you put in some work upfront. Please try to ask clear and crisp questions, share the doc(s) you are on and what is confusing you.

#

There is no link whatsoever between a Checkout Session and a CustomerPortal Session. They are unrelated products with different APIs, and the id of one would do nothing to the other one

odd night
#
export default async function handler(req, res) {
  // For demonstration purposes, we're using the Checkout session to retrieve the customer ID.
  // Typically this is stored alongside the authenticated user in your database.
  const { session_id } = req.body;
  const checkoutSession = await stripe.checkout.sessions.retrieve(session_id);

  // This is the url to which the customer will be redirected when they are done
  // managing their billing with the portal.
  const returnUrl = YOUR_DOMAIN;

  const portalSession = await stripe.billingPortal.sessions.create({
    customer: checkoutSession.customer,
    return_url: returnUrl,
  });

  // Authenticate your user.
  //   const session = await stripe.billingPortal.sessions.create({
  //     customer: "{{CUSTOMER_ID}}",
  //     return_url: "https://example.com/account",
  //   });

  res.redirect(303, portalSession.url);
}

this is the sample code to create portal session, it's based on checkoutSession. customer, the the checkoutSession.customer I got from the checkout session returns null

#

all these are from the doc btw

jaunty horizon
#

Sure but you're taking code, copy-pasting it and then saying "explain it". So I'm saying: play with it, you're a dev, it'll take you 5 minutes and then you'll understand it.
You definitely can't come all day and just ask us to explain docs

odd night
#
stripeSession: {
...
  customer: null,
  customer_creation: 'if_required',
  customer_details: {
    address: {
      city: null,
      country: 'US',
      line1: null,
      line2: null,
      postal_code: '98056',
      state: null
    },
    email: 'forkevinsun@gmail.com',
    name: 'Kevin',
    phone: null,
    tax_exempt: 'none',
    tax_ids: []
  },
  customer_email: null,
  expires_at: 1692828507,

  livemode: false,
  locale: null,
...
}

checkout session returned, customer is null, I did a test checkout

jaunty horizon
#

what is right there right below customer: null? Could it be related? Could the docs explain this?

#

Did you figure it out?

odd night
#

Yeah, I figured it out, but the doc is confusing

#

It says when using payment or sub mode, it will create a new customer object

#

now seems like I need to setup customer_creation: always

jaunty horizon
#

sure but you took a picture of the wrong doc

odd night
#

It is in the same doc, if you scroll up and find the customer attribute, that's where the screen shot is

jaunty horizon
#

Sure I know that. But at the end of the day if you read the doc for that exact parameter, it's really clear when one is created. If you read the wrong doc then it won't be clear

odd night
#

No, sound like you need a vacation dude

#

obviously there is a link between checkout session and portal session, which you claim these two are not related

#

then when the doc contradict to each other, one says it will create a new customer obj, then next says it requires another key turn

#

but thanks for the hint, with attitude