PayPal REST API获取总金额

Rya*_*edy 3 php json paypal

我正在使用PayPal rest-api-sdk-php最新版本.在创建付款和执行付款以及获取所有相关数据方面,一切都运行良好,但已决定我希望通过paypal支付的总金额.它返回一个JSON对象,例如下面的例子

"transactions": [
    {
        "amount": {
            "total": "20.00",
            "currency": "GBP",
            "details": {
                "subtotal": "17.50",
                "tax": "1.30",
                "shipping": "1.20"
            }
        },
        "description": "Payment description",
        "invoice_number": "55e30dbd55cea",
        "item_list": {
            "items": [
                {
                    "name": "Ground Coffee 40 oz",
                    "price": "7.50",
                    "currency": "GBP",
                    "quantity": "1",
                    "description": "Ground Coffee 40 oz",
                    "tax": "0.30"
                },
                {
                    "name": "Granola bars",
                    "price": "2.00",
                    "currency": "USD",
                    "quantity": "5",
                    "description": "Granola Bars with Peanuts",
                    "tax": "0.20"
                }
            ]
        },
    }
],
Run Code Online (Sandbox Code Playgroud)

我试过调用$ payment-> transactions-> amount-> total但是得到了一个错误.只是想知道是否有人可以解决问题.谢谢

man*_*niL 6

"transactions"是一个数组,因此您需要遍历它.如果您想要第一笔总金额,请尝试$ payment-> transactions [0] - > amount-> total;