#mmmh
1 messages · Page 1 of 1 (latest)
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
How do I initiate a Checkout Session? I'm only redirecting a user to a subscription checkout page via url.
what guide are you referring to implement Checkout? can you share the URL?
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.
can you share your account id? i'll take a look at how you're currently integrating
i need the livemode account id to view how you're currently integrating with us
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
did you post the livemode account id? i might have missed it
there's no live requests on that account though, the only requests that exist are in test mode
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?
i'd suggest you refer to https://stripe.com/docs/billing/quickstart to implement it
when you create the Checkout Session, you can pass in an existing customer id : https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer
you can create a Customer object using this API : https://stripe.com/docs/api/customers/create
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?
👋 taking over
It's recommend to create a customer beforehand
and no they are different Ids
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
No you are doing it incorrectly. You create a Checkout Session. After the customer authenticate and paid, it will generate a Subscription for you
Don't I need to create an item first? Otherwise, what is the user subscribing to?
the line_items that is
You can specify line_items on-the-fly. Have you checked this guide? https://stripe.com/docs/billing/subscriptions/build-subscriptions
I think you can also specify the Price properties on-the-fly but it's recommended to create the Price first
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
Do you see the creation call succeed? https://dashboard.stripe.com/test/logs
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
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'
}
So this is not working
if (session.url) res.redirect(303, session.url)
Not sure why but can you put it in proper brackets?
No it's not working
If you log out session.url will you see the value above?
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?
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
do you see the same if replace with the Session Url above?
But just not redirecting?
it's not redirecting as well