Question:
I’m working on a project currently. and I’m making use of stripe, the stripe.checkout.session.create function works perfectly.but the only issue i have is it receives only unit price.
but i want a field where i can pass only total Price, cause in my code , if the users applys a discount to a product , it deducts it from the product total price meanwhile the unit price for each product is stable.
My question is basically is there a field where i can pass total price.
Answer:
Short answer is that you can’t. You need to use theline_items
parameter and either pass a Price object ID (price_xxx
) or use ad-hoc pricing with the price_data
parameter. Checkout will then compute the total from all line items, factoring in any discounts that you provide.You have a couple of options to achieve the behaviour you want:
- Re-calculate the
price_data.unit_amount
value to reflect the discount applied by your customers. - Utilise Stripe coupons to apply to the Checkout Session which will take care of the dedication for you.
If you have better answer, please add a comment about this, thank you!