conedevelopment / simplepay-gateway

OTP SimplePay bővítmény WooCommerce (WordPress) áruházak részére.
https://simplepay.conedevelopment.com
MIT License
57 stars 22 forks source link

Discounts ignored - customers charged full price #109

Closed ceo-tukan closed 1 year ago

ceo-tukan commented 1 year ago

Leírás

On line 122 you discard the negative amounts from the order, so clients with a discount (redeeming loyalty points for example) are charged for the full price. There is a discount field (line 41) that seems ignored as well. https://github.com/conedevelopment/simplepay-gateway/blob/master/src/Payloads/PaymentPayload.php#L122 Thanks for your help as we have the issue on 2 production sites now.

Reprodukáláshoz szükséges lépések

Client orders items, redeems loyalty points, the checkout page and the cart page show the right amounts, but with this method of payment they get charged the full amount thus ignoring the discount.

iamgergo commented 1 year ago

Hello,

Really sorry for the late answer here.

On line 122 you discard the negative amounts from the order, so clients with a discount

So, there is a limitation in the SimplePay API, it throws an error when receiving non positive prices, that's why we have to reject 0 and negative values.

About discounts: due to price/order total conflicts we experienced in the past, we pass the discount total as 0 and recalculate the product prices using the discount, and that's what we pass to the SimplePay API.

So negative fee, or discount will be ignored, the limitation is in the SimplePay API.

Tofandel commented 1 year ago

Well this is not closed, this is still an issue, and a big one, I understand the negative price limitation in the item line and why they are not in the items field but then they need to be added as discount somewhere

recalculate the product prices using the discount

I do not see what you are describing anywhere in the code, please have a look, this is exactly what is missing and what the PR does

Tofandel commented 1 year ago

Here is a screenshot, you can see the price total vs the price total sent to simple pay image image

If you want to test it yourself you can use https://wordpress.org/plugins/woo-add-custom-fee/

And add a -100 fee

ucsendre commented 1 year ago

Hello @Tofandel

I think you should try using coupons for what you are trying to achieve. Please take a look here how to do it: https://www.webtoffee.com/how-to-auto-apply-coupon-on-checkout-in-woocommerce/ I hope this will help you.

Best regards, Endre

iamgergo commented 1 year ago

@Tofandel Shortly: negative values are not accepted by the SimplePay API. As our last experience, not as a negative fee, discount or product price.

This works as it does, I wish not to add anything potencial breaking change at this phase.

The only way to fix it, is not to change the discount amount from zero to a real value (due to another limitation), but to apply the calculated value of the negative fee per product (eg.: price - abs(discount / number of products). We'll consider how to apply it (really).

I truly agree, this is not the way it should work, but SimplePay does not care (we told them, we asked them, they just don't care).

Thank you!

Tofandel commented 1 year ago

It would be unacceptable to ask us to change this for a calculation in the payment method that doesn't adheres to the woocommerce calculation and that can clearly be reasonably patched, other payment methods don't have this issue.

Users can redeem how many loyalty points they want as money off their orders, that means adding a negative item fee in the cart of the value of the redemption, a widely used paid loyalty plugin does it using a fee and not a coupon

The only way to fix it, is not to change the discount amount from zero to a real value (due to another limitation), but to apply the calculated value of the negative fee per product (eg.: price - abs(discount / number of products). We'll consider how to apply it (really).

Please clarify on the so called limitations you seem to have encountered because I have also tested and not seen any, in fact the api is more flexible than the documentation suggests, so I do not see why you would need to complicate the calculation

The documentation clearly describes the discount field on page 21 as a positive number that is removed from the order total, it doesn't need to be negative or spread across all items (but from my tests it accepts both positive and negative and takes the absolute value), but obviously it's wiser to stick to the documentation and send a positive one

Here is the simplepay payment after the patch which matches the order price image