FLUX-SE / SyliusPayumStripePlugin

Sylius Payum Stripe gateway plugin (with SCA support)
MIT License
56 stars 25 forks source link

[Stripe Checkout Session] Order discounts #26

Closed ramundomario closed 3 years ago

ramundomario commented 3 years ago

Hi @Prometee, maybe this isn't an issue for Sylius because maybe it works differently, sorry! I opened this issue to discuss this issue (coreshop/PayumStripeBundle#6) we came across with Stripe Checkout. In our case, in CoreShop, we have cart price rules (for example vouchers) which reduce the price of the order (but not of a product). This use case is currently not managed and it doesn't seem possible currently with Stripe Checkout (unless workaround), do you also have this problem?

Thanks for a feedback Regards

Prometee commented 3 years ago

Hi @ramundomario,

There is two ways of handling what you need :

  1. the first is to simply provide only one line item with quantity equal to 1 and price equal to the total of your order, that's how it's done in the library : https://github.com/FLUX-SE/PayumStripe/blob/master/src/Action/StripeCheckoutSession/ConvertPaymentAction.php#L38-L41
  2. the second is to handle all possible objects in the LineItemsProvider. Sylius don't have any other types available so it will only be an OrderItem
ramundomario commented 3 years ago

At the moment we are already using the second way as it's done in this Sylius package since also in CoreShop there is only an OrderItem which matches to a line_item.

Maybe I didn't explain myself well, I try to do it with an example:

The first way could be a valid workaround (since you have a single line_item of the order total amount) with the con you don't see OrderItems in checkout page.

Thanks a lot for your feedback and hope I was clear 😉

Prometee commented 3 years ago

Sylius is using adjustments on OrderItemUnits, OrderItem or on the Order. But by default only on OrtemItemUnits is used. This allow each OrderItemUnit to be aware of every promotions, adjustments, shipping adjustments and taxes adjustments, so when we ask for a total on an OrderItem all adjustments have already been distributed over each sub OrderItemUnits and we get the exact total we need for each item.

ramundomario commented 3 years ago

Thanks a lot @Prometee for the quick overview of Sylius I would be interested, if possibile, in @dpfaffenbauer thoughts :wink:

dpfaffenbauer commented 3 years ago

CoreShop uses a similar approach to Sylius, but a bit different. CoreShop has Adjustments on Order and OrderItem. Order Adjustment are directly reflected in the total price, whereas OrderItem Adjustment are not always. Due to how CoreShop handles discounts -> they get calculated per item, but are not directly reflected in the item price. You could just do $item->getTotal() -> $item->getAdjustmentsTotal() to get the real order-item price.

I don't exactly understand what the real problem here is? Does Stripe calculate the Total Payment based on line_items?

Prometee commented 3 years ago

@dpfaffenbauer yes it does calculate the total based on line_items

ramundomario commented 3 years ago

Thanks a lot for your support @Prometee, we will continue in our repo

markbennett1973 commented 3 years ago

This may be a bit late, but on a non-Sylius project I had a similar problem, and was advised by Stripe support that the best way to handle discounts was using Stripe coupons. We manage all the discount codes ourselves on the website, so when a customer uses one of our discount codes, when we create the order on Stripe, we first create a Stripe coupon object with max_redemptions set to 1, for the value of the total discount we want to apply. We then add the order to Stripe, adding that Stripe coupon code. It's a bit fiddly, but works well. and provides a very good user experience - the Stripe hosted payment page and confirmation email list all the order items at the correct value, and shows the correct amount of discount and correct total order value.

Manasmd commented 12 months ago

@Prometee Is there any way to apply the discounts? when we using coupons it seems to apply the discounts just fine but with Gift cards it's not working.

Prometee commented 12 months ago

@Manasmd on my own project I made a Promotion action for this : image The screenshot is showing the custom promotion action needed to link the promotion to a Stripe coupon, it will be different for each currencies you have, in my case I have 2 currencies each attached on 2 channels.

Manasmd commented 12 months ago

@Prometee thanks for your swift response! So the only was is to add a "stripe coupon" in the stripe dashboard for each "GiftCard" we create in sylius?

Since we have limited access to stripe dashboard, would it be possible to amend the total in sylius.order.pre_payment event?

Prometee commented 11 months ago

@Manasmd It's up to you, I choose to sync promo with Stripe coupon but you can also change the total amount (via decorating the Providers available in this plugin for example).