How to add a negative line item or an equivalent of a discount in Stripe new checkout?

Viewed 698

I have my own shop engine and I use Stripe new checkout for payments, where a customer would be redirected and make payments at checkout.stripe.com.

When there's a discount in an order, I want to be able to simply add a negative line item into an order instead of having to create a discount at Stripe and then apply it to an order. This is because in my shop engine I may apply a discount to shipping, or to a whole order, or to certain products within an order, and it may be difficult to reflect that at Stripe as a discount because discounts at Stripe aren't this flexible. Also I'd have to have my discounts and the ones at Stripe at sync -- more work.

Therefore, I'd simply calculate it and add a negative line, a one with a negative "amount", item on my side.

However, it's not allowed to add a negative line item. What'd be a solution?

1 Answers

You are correct that Checkout line_items must have a positive amount value.

My recommendation would be to instead re-calculate your cart items/total based on any discounts before creating the Checkout session.

Related