woocommerce / woocommerce-gateway-paypal-express-checkout

58 stars 65 forks source link

Refunds not possible if using 3 decimals (or more) #815

Open danielvonmitschke opened 3 years ago

danielvonmitschke commented 3 years ago

If you set the store to use 3 (or more) decimals, then refunds are rejected by PayPal. Please make sure to proper round refund amounts before sending them to PayPal.

I think it should be done here: https://github.com/woocommerce/woocommerce-gateway-paypal-express-checkout/blob/49cead0f46e31fd2fdc9d7e2e40b841ab179dd14/includes/class-wc-gateway-ppec-refund.php#L28

Similar to here: https://github.com/woocommerce/woocommerce-gateway-paypal-express-checkout/blob/49cead0f46e31fd2fdc9d7e2e40b841ab179dd14/includes/class-wc-gateway-ppec-client.php#L475

Here is an example request an response (it does not like the 1.000 amount):

[02-Oct-2020 13:09:58 UTC] WC_Gateway_PPEC_Client::_request: remote request to https://api-3t.paypal.com/nvp with params: Array
(
    [TRANSACTIONID] => XXXXX
    [REFUNDTYPE] => Full
    [AMT] => 1.000
    [CURRENCYCODE] => EUR
    [NOTE] => 
    [METHOD] => RefundTransaction
    [VERSION] => 120.0
    [USER] => info_api1.xxx.com
    [PWD] => xxx
    [SIGNATURE] => AfyTwa31ACemqv.8WJ5qwV7OS7BJAM8PR0p0xkp8uPp4VugYHJRy5A8t
)

[02-Oct-2020 13:09:58 UTC] WC_Gateway_PPEC_Client::_process_response: acknowleged response body: Array
(
    [TIMESTAMP] => 2020-10-02T13:09:58Z
    [CORRELATIONID] => XXXX
    [ACK] => Failure
    [VERSION] => 120.0
    [BUILD] => 54906389
    [L_ERRORCODE0] => 10004
    [L_SHORTMESSAGE0] => Transaction refused because of an invalid argument. See additional error messages for details.
    [L_LONGMESSAGE0] => The partial refund amount is not valid
    [L_SEVERITYCODE0] => Error
    [REFUNDSTATUS] => None
    [PENDINGREASON] => None
)