Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal REST API get total amount

Tags:

json

php

paypal

I'm using PayPal rest-api-sdk-php the latest version. Everything is working fine in terms of creating the payment and executing the payment and getting all the relevant data back but have decided I want the total amount paid via paypal. It returns a JSON object back, example below

"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"
                }
            ]
        },
    }
],

I have tried calling $payment->transactions->amount->total but get an error. Just wondered if someone can shed some light. Thanks

like image 236
Ryan Kennedy Avatar asked Feb 21 '26 07:02

Ryan Kennedy


1 Answers

"transactions" is an array, so you need to iterate through it. If you want the first total amount, try $payment->transactions[0]->amount->total;

like image 123
manniL Avatar answered Feb 22 '26 19:02

manniL