#mmmh

1 messages · Page 1 of 1 (latest)

meager lionBOT
strong rune
#

it depends on how you want to do it, either you create the Customer prior to the user paying for it and pass that in when creating the Checkout Session, or you retrieve the customer id from the completed Checkout Session

vale field
#

How do I initiate a Checkout Session? I'm only redirecting a user to a subscription checkout page via url.

strong rune
#

what guide are you referring to implement Checkout? can you share the URL?

vale field
#

I'm not referring into anything specific. We already have a checkout page built via stripe and we open a new tab and redirect the user to that page.

strong rune
#

can you share your account id? i'll take a look at how you're currently integrating

vale field
#

acct_1MbyRTJ2MMj0BE3B

#

test account

strong rune
#

i need the livemode account id to view how you're currently integrating with us

vale field
#

this is it

#

I want to create a subscription and allow users to subscribe to it via a checkout page similar to this https://buy.stripe.com/dR6eY16yTfBlbssdQV
and then be able to associate the customer with a user in our database

strong rune
#

did you post the livemode account id? i might have missed it

vale field
#

acct_1MbyRTJ2MMj0BE3B

#

same

strong rune
#

there's no live requests on that account though, the only requests that exist are in test mode

vale field
#

Yes, that's because I just started working on this.

#

there is nothing live yet

#

Does creating a checkout session stripe.checkout.sessions.create automatically redirect the user to the stripe subscription page?

strong rune
vale field
#

Is it necessary to create a customer object?

#

or will the checkout it self create one?

#

is the PRICE_LOOKUP_KEY the SUBSCRIPTION ITEM ID?

pine viper
#

👋 taking over

#

It's recommend to create a customer beforehand

#

and no they are different Ids

vale field
#

I just created a subscription, how do I find the lookup key for it and also the checkout page for the subscription

The id of the subscription i created, sub_1MeAUmJ2MMj0BE3Be8T2BuvO

pine viper
#

No you are doing it incorrectly. You create a Checkout Session. After the customer authenticate and paid, it will generate a Subscription for you

vale field
#

Don't I need to create an item first? Otherwise, what is the user subscribing to?

#

the line_items that is

pine viper
#

I think you can also specify the Price properties on-the-fly but it's recommended to create the Price first

vale field
#

Okay created a product and a price

#
const stripe = new Stripe(process.env.STRIPE_API_KEY_DEV ?? '', {
        apiVersion: '2022-11-15',
    })

    const session = await stripe.checkout.sessions.create({
        success_url:
            'https://example.com/success.html?session_id={CHECKOUT_SESSION_ID}',
        cancel_url: 'https://example.com/canceled.html',
        line_items: [{ price: 'price_1MeAl6J2MMj0BE3BmoovLnLO', quantity: 1 }],
        mode: 'subscription',
    })

    if (session.url) res.redirect(303, session.url)
#

But it is not redirecting

pine viper
vale field
#

Yes, it succeeds

#
{
  id: 'cs_test_a1h31jwkvfchpn32L2XcgYqWQFlBRaarouelXUnkcGXLcei5duKrVBMLuN',
  object: 'checkout.session',
  after_expiration: null,
  allow_promotion_codes: null,
  amount_subtotal: 3999,
  amount_total: 3999,
  automatic_tax: { enabled: false, status: null },
  billing_address_collection: null,
  cancel_url: 'https://example.com/canceled.html',
  client_reference_id: null,
  consent: null,
  consent_collection: null,
  created: 1677043707,
  currency: 'usd',
  custom_fields: [],
  custom_text: { shipping_address: null, submit: null },
  customer: null,
  customer_creation: 'always',
  customer_details: null,
  customer_email: null,
  expires_at: 1677130107,
  invoice: null,
  invoice_creation: null,
  livemode: false,
  locale: null,
  metadata: {},
  mode: 'subscription',
  payment_intent: null,
  payment_link: null,
  payment_method_collection: 'always',
  payment_method_options: null,
  payment_method_types: [ 'card' ],
  payment_status: 'unpaid',
  phone_number_collection: { enabled: false },
  recovered_from: null,
  setup_intent: null,
  shipping_address_collection: null,
  shipping_cost: null,
  shipping_details: null,
  shipping_options: [],
  status: 'open',
  submit_type: null,
  subscription: null,
  success_url: 'https://example.com/success.html?session_id={CHECKOUT_SESSION_ID}',
  total_details: { amount_discount: 0, amount_shipping: 0, amount_tax: 0 },
  url: 'https://checkout.stripe.com/c/pay/cs_test_a1h31jwkvfchpn32L2XcgYqWQFlBRaarouelXUnkcGXLcei5duKrVBMLuN#fidkdWxOYHwnPyd1blpxYHZxWjA0SGd8V1FPN0hIbzVHQDZHRkw0VGs0NU9ibUs2dGB1QUhITmtTYzFhYmg9QTRAS1RXMnR9b2YzPGNmVTw3NT1Sb1xHS3E3N0dzSVBpSWMzR1B0PXE0a1NHNTVRbE1rM29OfScpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl'
}
pine viper
#

So this is not working

if (session.url) res.redirect(303, session.url)
#

Not sure why but can you put it in proper brackets?

vale field
#

No it's not working

pine viper
#

If you log out session.url will you see the value above?

vale field
#

yes

#

could the redirect be done in the frontend?

pine viper
#

It could, but redirect in backend is recommended. I think there is some issue with your server redirection setting

#

Like, can you simply redirect to some static url such as google.com?

vale field
#

No, that doesn't work either

#

I'm using nest.js

#
Access to XMLHttpRequest at 'https://google.com/' (redirected from 'http://localhost:3000/api/stripe/checkout') from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the 
pine viper
#

do you see the same if replace with the Session Url above?

vale field
#

nope

#

I don't see anything when using session.url

pine viper
#

But just not redirecting?

vale field
#

it's not redirecting as well