php - paypal php sdk 在上线时出现 float 问题

标签 php paypal woocommerce

我正在使用 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/

相关文章:

php - 类要求进入方法

php - 列名中的特殊字符

php - 插入在数据表复选框中选中的数据 codeigniter

php - 在mysql文件中加载数据在php脚本中不起作用

html - BIG Paypal 运费问题

ios - 使用 paypal 进行点对点/自适应支付

php - 在 Woocommerce Admin Orders 列表中添加可排序的自定义列

php - 用 Woocommerce 3 中的自定义文本替换产品零显示价格

python - 使用 python-paypalrestsdk 启动 Express Checkout 交易

php - 在 WooCommerce 中显示不包括产品类别的订单项目名称