#warryshooter_05765
1 messages ยท Page 1 of 1 (latest)
Yes
you can use https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer_creation always
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
this way you always have a customer object instead of a Guest Customer
try {
const customer = await stripe.customers.search({
query: 'email:\''+userEmail+'\'',
});
if (customer.data.length > 0) {
const customerId = customer.data[0].id;
const allSubscriptions = await stripe.subscriptions.list({ customer: customerId });
const activeSubscriptions = allSubscriptions.data.filter(sub => sub.status === 'active' || sub.status === 'trialing');
if (activeSubscriptions.length > 0) {
const portalSession = await stripe.billingPortal.sessions.create({
customer: customerId,
return_url: baseURL, // URL de
});
console.log('Redirecting to billing portal for customer: ' + userEmail);
res.redirect(portalSession.url);
} else {
const checkoutSession = await stripe.checkout.sessions.create({
payment_method_types: ['card', 'paypal'],
line_items: [{
price: stripeDetails.price_id,
quantity: 1,
}],
automatic_tax: {
enabled: true,
},
customer: customerId,
mode: 'subscription',
allow_promotion_codes: true,
success_url: `${baseURL}success`,
cancel_url: `${baseURL}`,
});
console.log('Redirecting to checkout for customer: ' + userEmail);
res.redirect(checkoutSession.url);
}
} else {
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card','paypal'],
line_items: [{
price: stripeDetails.price_id,
quantity: 1,
}],
automatic_tax: {
enabled: true,
},
mode: 'subscription',
customer_email: userEmail,
allow_promotion_codes:true,
success_url: `${baseURL}success`,
cancel_url: `${baseURL}`
});
console.log('No customer found with this email.');
res.redirect(session.url);
}
}``` It looks like this
So yeah I'm always using "checkout"
except if the user already has a pending sub
yes
payment_method_types: ['card','paypal'],
line_items: [{
price: stripeDetails.price_id,
quantity: 1,
}],
automatic_tax: {
enabled: true,
},
mode: 'subscription',
customer_email: userEmail,
allow_promotion_codes:true,
success_url: `${baseURL}success`,
cancel_url: `${baseURL}`
customer_creation: 'always'
okok thanks a lot for your help
sure let me know if you need any more help
it won't be an issue for current customers, or ppl with already an account right?