php - 交易金额详细信息(小计、税金、运费)必须加起来达到指定的总金额 - PayPal PHP SDK

标签 php paypal transactions

出于某种原因,当我尝试使用 SDK 授权 PayPal 付款时,我的日志中不断出现以下错误:

ERROR: Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment. {"name":"VALIDATION_ERROR","details":[{"field":"transactions[0].amount","issue":"Transaction amount details (subtotal, tax, shipping) must add up to specified amount total"}],"message":"Invalid request - see details"

我的交易金额似乎加起来没问题,所以我不知道为什么 PayPal 会抛出错误,这是我的交易金额:

'transactions' => [
                0 => PayPal\Api\Transaction#5
                (
                    [PayPal\Common\PayPalModel:_propMap] => [
                        'amount' => PayPal\Api\Amount#6
                        (
                            [PayPal\Common\PayPalModel:_propMap] => [
                                'currency' => 'GBP'
                                'total' => '675.00'
                                'details' => PayPal\Api\Details#7
                                (
                                    [PayPal\Common\PayPalModel:_propMap] => [
                                        'fee' => '75.00'
                                        'subtotal' => '600.00'
                                    ]
                                )
                            ]
                        )
                        'item_list' => PayPal\Api\ItemList#8
                        (
                            [PayPal\Common\PayPalModel:_propMap] => [
                                'items' => [
                                    0 => PayPal\Api\Item#9
                                    (
                                        [PayPal\Common\PayPalModel:_propMap] => [
                                            'name' => 'Day 1: 30-12-2017'
                                            'currency' => 'GBP'
                                            'quantity' => 1
                                            'price' => '300.00'
                                        ]
                                    )
                                    1 => PayPal\Api\Item#10
                                    (
                                        [PayPal\Common\PayPalModel:_propMap] => [
                                            'name' => 'Day 2: 27-01-2018'
                                            'currency' => 'GBP'
                                            'quantity' => 1
                                            'price' => '300.00'
                                        ]
                                    )
                                ]
                            ]
                        )

这可能与 number_format 有关吗?功能?我正在使用该函数来确保所有值都与其小数位一致:$grandTotal = number_format($data['job']['grandTotalAmount'], 2, '.', '');

最佳答案

我遇到了这个问题。在我的例子中,解决方案是正确的总计和小计计算:

subtotal 必须是 Price * Quantity

Total 必须是 Tax + shipping + subtotal

不要只是硬编码这些字段。

希望对你有帮助

关于php - 交易金额详细信息(小计、税金、运费)必须加起来达到指定的总金额 - PayPal PHP SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48061785/

相关文章:

transactions - 迁移应用程序以使用 Guice - 如何将事务注入(inject)现有对象?

php - 从具有不同 IP 的专用服务器发送电子邮件

php - 如何在php中格式化打印输出

php - Magento 2.2 Paypal 付款方式选项未显示在结帐中

ruby-on-rails - 具有 Paypal 权限和 Paypal Express Checkout 的 Rails

php - 给定多个连接时,Mysql 事务的原子性如何?

transactions - Yii2 中带有回调的数据库事务

php - Symfony 复选框列出了 Twig 渲染

PHP 5.3.6 段错误(在 apache w/mod_php 和 nginx w/fpm 中)

java - 将 ArrayList 转换为数组 PayPalItem 时出错