【问题标题】:paypal php sdk issues with float while going to livepaypal php sdk 在上线时出现浮动问题
【发布时间】:2023-04-09 05:50:02
【问题描述】:

我正在使用 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,问题也是一样的。 有人可以帮帮我吗?

【问题讨论】:

    标签: php paypal woocommerce


    【解决方案1】:

    我的猜测是您传递的值不符合贝宝要求的格式。很可能是由不同的区域设置或其他原因引起的小数分隔符。

    【讨论】:

    • 那么,为什么它在 sanbox 上工作?目前,它在返回 intval($myprice) 时有效,但交易金额与客户在网站上购买的金额不同,这是我真正的问题。为什么它在沙盒上工作?是sdk的问题吗?
    猜你喜欢
    • 2015-04-10
    • 1970-01-01
    • 2014-08-29
    • 2011-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    相关资源
    最近更新 更多