我正在使用 paypal rest api 为 woocommerce 编写自定义 paypal 网关。 我几乎完成了,在使用沙盒帐户进行测试时一切正常。但是切换到 Live 后,我得到了很多错误“货币金额必须是非负数” 这是我得到的:
PayPal\Core\PayPalHttpConnection : ERROR: Got Http response code 400 when accessing https://api.paypal.com/v1/payments/payment. {"name":"VALIDATION_ERROR","details":[{"field":"transactions[0].item_list.items[0].price","issue":"Currency amount must be non-negative number, contain exactly 2 decimal places separated by '.' (JPY contains 0 decimal places), optional thousands separator ',', limited to 7 digits before the decimal point and currency which is a valid ISO Currency Code"},{"field":"transactions[0].amount.details.subtotal","issue":"Currency amount must be non-negative number, contain exactly 2 decimal places separated by '.' (JPY contains 0 decimal places), optional thousands separator ',', limited to 7 digits before the decimal point and currency which is a valid ISO Currency Code"},{"field":"transactions[0].amount.total","issue":"Currency amount must be non-negative number, contain exactly 2 decimal places separated by '.' (JPY contains 0 decimal places), optional thousands separator ',', limited to 7 digits before the decimal point and currency which is a valid ISO Currency Code"}],"message":"Invalid request - see details","information_link":"https://developer.paypal.com/docs/api/payments/#errors","debug_id":"dc60e0012af71"}
我觉得问题出在这里:
if ($dec == 0) $myprice = ceil($myprice);
else $myprice = round($myprice, $dec);}
$myprice = doubleval($myprice);
return $myprice ;
当我将 $myprice 的值更改为一个整数时,它工作正常,但它不起作用。即使使用 Number_format 问题也是一样的。 有人可以帮帮我吗?
最佳答案
我的猜测是您传递的值不符合 paypal 要求的格式。很可能是小数分隔符,由不同的区域设置或其他原因引起。
关于php - paypal php sdk 在上线时出现 float 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45960525/