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

Fix: clients need to pay full price without discounts #108

Closed Tofandel closed 1 year ago

Tofandel commented 1 year ago

When paying for an order, discounts are ignored and the customer is asked to pay for the full price.. This is a huge issue as then customers need to get refunded

Fixes #109

iamgergo commented 1 year ago

Hi,

Thanks for the PR (and sorry for the late answer). The answer why we pass 0 discount: https://github.com/conedevelopment/simplepay-gateway/issues/109#issuecomment-1362585630

Tofandel commented 1 year ago

The item calculation doesn't work if you have negative fees which a lot of plugins use, if you look at https://github.com/conedevelopment/simplepay-gateway/blob/master/src/Payloads/PaymentPayload.php#L115 the negative fees are dropped, which is understandable because of the limitation of negative price to items

But then they are not used anywhere else to account for them

Right now this fix is doing the same operation but only for the negative values just adding all those negative fees up at the discount level which otherwise are completely dropped

I tested this PR and it's right now in production on 3 websites and completely fixes the issue, but it's hard patched and the next update of the plugin will obliterate this and the bug will come back, so we need to get this merged

iamgergo commented 1 year ago

So, are you sure negative discount values won't break anything here?

Tofandel commented 1 year ago

I tried both negative and positive in discount it does exactly the same, the simple pay api already takes the abs value, the doc does say discount should be positive so I abs it

image

And yes I'm sure it won't break anything

I added the commit with the abs value but because the PR is closed, it's not showing it

iamgergo commented 1 year ago

So I think, I misunderstood the complete thing here from the beginning. I don't know why, but I thought you are calculating the original discounts (not negative fees but for example coupons).

The limitation I was refering to was about that, and not the negative fees. So actually your code here makes sense.

My two questions:

Tofandel commented 1 year ago

are you sure line_items should be parsed here as well? Normal products should not have negative prices.

They should not but its in theory possible and this is just meant to complement the previous calculation so that all prices are taken into account no matter what, positives in 'items' and negatives all added up as discount

why are you casting the shipping total to float explicitly

Woocommerce is sending this values as string and not as a float so addition here is confusing (especially if you've been traumatised by js addition before 😂) and ide was complaining quite strongly about it, php is already casting it to float after some magic because of the addition, but better to be explicit