Create Orders Api v2 doesn't show total without specifying items through PHP

Nimja
Contributor
Contributor

Very strange issue, if I do this request through PHP, using: 

 

 

 

$request = new \PayPalCheckoutSdk\Orders\OrdersCreateRequest();
$request->prefer('return=minimal');
$request->body = [
    "intent" => "CAPTURE",
    "purchase_units" => [
        [
            'description' => 'Example request',
            'soft_descriptor' => 'Example',
            'amount' => [
                "currency_code" => "USD",
                'value' => "3.00",
            ],
        ]
    ],
];

 

 

 

Like so: NOTICE: The total is NOT there!

  

Screenshot 2019-06-24 at 11.22.57 .png

 

However, if I do the same request in JavaScript, it goes as I expect:

 

 

 

return actions.order.create({
    purchase_units: [
        {
            description: "Example request.",
            amount: {
                currency_code: "USD",
                value: "3.00"
            }
        }
    ]
});

 

 

Notice; TOTAL is there, and clicking on it shows the description.

 

Screenshot 2019-06-24 at 11.27.10 .png

 

 

And if I specify the FULL message with items (but not nice) it also shows the amount.

 

 

 

$request = new \PayPalCheckoutSdk\Orders\OrdersCreateRequest();
$request->prefer('return=minimal');
$request->body = [
    "intent" => "CAPTURE",
    "purchase_units" => [
        [
            'description' => 'Example request',
            'soft_descriptor' => 'Example',
            'amount' => [
                "currency_code" => "USD,
                'value' => "3.00",
                'breakdown' => [
                    'item_total' => [
                        "currency_code" => "USD,
                        'value' => "3.00",
                    ],
                ],
            ],
            'items' => [
                [
                    'name' => "Item",
                    'description' => 'Example item',
                    'quantity' => 1,
                    'unit_amount' => [
                        "currency_code" => "USD,
                        'value' => "3.00",
                    ],
                ]
            ],
        ]
    ],
];

 

 

 

But the result is not very nice (notice the multiple lines basically saying the same):

NOTICE: Total is there, but also with (unnecessary) item details.

 

Screenshot 2019-06-24 at 11.24.50 .png 

 

I doubt this is intentional? Does anyone know why the total does NOT show with the minimal request?

 

 

 

 

Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

rahul-dighe
PayPal Employee
PayPal Employee

This issue has to do with whether the user_action = PAY_NOW or CONTINUE

 

when you use a clients SDK (Payments SDK)- it defaults it to PAY_NOW hence anytime you use it with a JS - it shows up as a PAY_NOW in which case the amount is shown.

 

if you use it through an SDK directly the default is 'CONTINUE' and as such for that we do not show an amount (when no items are present) - this is a bug that we hope to resolve. 

 

happy to answer any questions you guys may have but it's something we are looking to correct/improve.

Senior Product Manager - PayPal Checkout API Product

View solution in original post

Login to Me Too
3 REPLIES 3

Nimja
Contributor
Contributor

Doing some effort myself, I think I found out when and how this happens.

 

If I take the token from the JS request and use it in the standard url: https://www.sandbox.paypal.com/checkoutnow?token=XXXX

 

The same issue occurs for the minimal JS request. I wonder if this is only an issue on test or also on Live.

Login to Me Too
Solved

rahul-dighe
PayPal Employee
PayPal Employee

This issue has to do with whether the user_action = PAY_NOW or CONTINUE

 

when you use a clients SDK (Payments SDK)- it defaults it to PAY_NOW hence anytime you use it with a JS - it shows up as a PAY_NOW in which case the amount is shown.

 

if you use it through an SDK directly the default is 'CONTINUE' and as such for that we do not show an amount (when no items are present) - this is a bug that we hope to resolve. 

 

happy to answer any questions you guys may have but it's something we are looking to correct/improve.

Senior Product Manager - PayPal Checkout API Product
Login to Me Too

Nimja
Contributor
Contributor

Thank you very much, this is indeed what it was.

 

Example of functional request that will show the total:

 

$request = new \PayPalCheckoutSdk\Orders\OrdersCreateRequest();
$request->prefer('return=minimal');
$request->body = [
    "intent" => "CAPTURE",
    "purchase_units" => [
        [
            'description' => 'Example description',
            'soft_descriptor' => 'Soft description',
            'amount' => [
                "currency_code" => 'USD',
                'value' => '1.23',
            ],
        ]
    ],
    "application_context" => [
        "cancel_url" => "URL",
        "return_url" => "URL",
        "shipping_preference" => "NO_SHIPPING",
        "user_action" => "PAY_NOW",
    ],
];

 

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.