#cornonthecob
1 messages · Page 1 of 1 (latest)
I'd recommend checking your code why a new Checkout Session is created every time when customer clicks return back. Creating a new Checkout Session is controlled by your integration
if (product_id == "price_1NbgQJGJK35igdoBqjOdeQWR"):
stripe.InvoiceItem.create(
customer=stripe_customer_id,
amount=19900,
currency="nzd",
description="Early bird subscription"
)
session = stripe.checkout.Session.create(
customer=stripe_customer_id,
line_items=[{
'price': product_id,
'quantity': 1,
}],
mode='subscription',
success_url='https://www.ostudy.org/user/stripe/success',
cancel_url='https://www.ostudy.org/user/stripe/cancel',
subscription_data={
"trial_settings": {"end_behavior": {"missing_payment_method": "cancel"}},
"trial_end": int(earlybird_trial_end_date.timestamp()),
},
payment_method_collection="if_required",
)
if (product_id == "price_1NzFD9GJK35igdoB6IyeAgw8"):
stripe.InvoiceItem.create(
customer=stripe_customer_id,
amount=29900,
currency="nzd",
description="standard subscription"
)
session = stripe.checkout.Session.create(
customer=stripe_customer_id,
line_items=[{
'price': product_id,
'quantity': 1,
}],
mode='subscription',
success_url='https://www.ostudy.org/user/stripe/success',
cancel_url='https://www.ostudy.org/user/stripe/cancel',
payment_method_collection="if_required",
)
isnt that what i want though? It should be a new checkout session each time a user clicks on a product to create a session
it seems to add a line item every time
Can you share an example Checkout Session (cs_xxx) that new item has been added to a Checkout Session? Checkout Session doesn't support update feature, so it's not possible to add a line item on the existing Checkout Session
this is the current live one
every time I click on it it continues to add another line item
Thanks for sharing! Taking a look now
every time I click on it it continues to add another line item
Which button do you click exactly?
on the frontend i have a button which calls the fetch to my backend
// handle early bird subscription
const handleEarlyBirdSubscription = async () => {
const jwtToken = Cookies.get("access_token_cookie");
setIsSubscribingToEarlyBird(true);
const price = 199;
const response = await fetch(
`${process.env.BASEURL}/flask/user/create-checkout-session`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${jwtToken}`,
},
credentials: "include",
body: JSON.stringify({ price }),
}
);
const session = await response.json();
const stripe = await stripePromise;
const result = await stripe.redirectToCheckout({
sessionId: session.sessionId,
});
if (result.error) {
console.error(result.error.message);
}
};
// handle standard subscription
const handleStandardSubscription = async () => {
const jwtToken = Cookies.get("access_token_cookie");
setIsSubscribingToStandard(true);
const price = 299;
const response = await fetch(
`${process.env.BASEURL}/flask/user/create-checkout-session`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${jwtToken}`,
},
credentials: "include",
body: JSON.stringify({ price }),
}
);
const session = await response.json();
const stripe = await stripePromise;
const result = await stripe.redirectToCheckout({
sessionId: session.sessionId,
});
if (result.error) {
console.error(result.error.message);
}
};
This is indeed strange! We are still looking into it
From the log history of the customer cus_Onx9nszzeS5eHu https://dashboard.stripe.com/logs?object=cus_Onx9nszzeS5eHu, your server added invoice items every time before creating a Checkout Session
oh i see...the reason I have this is because I want there to be an initial payment at the start of the subscription and then a free trial before the recurring payments happen
maybe i need to include the invoice inside of the checkout session?
Even so, the behaviour doesn't seem right that the Checkout Session picks up those invoice line items
Can I suggest you writing to Support https://support.stripe.com/contact with the Checkout Session ID, so that we can double check if this is indeed an expected behaviour?
okay. So before that how am i able to have an initial payment in a subscription? I want there to be an initial payment of $199 and then a free trial period until feburary 9th and then recurring payments after this
This can be done with adding one-time price in the line_items of the Checkout Session
how would this work? would I need to create another product that is a one-time payment and then include this in the line items?
yes, you're right!
okayt that seesm to have worked now
so now in the checkout session there are two line items one for the initial payment awnd then one for the subscription
is there some way to add a description of what they're getting for the overall checkout session? Currently they are seeing one description for each line item i would prefer if there was one big desciprtion for the whole checkout
I'm afraid having an overall description on a Checkout Session is not supported