Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Adgower's avatar
Level 14

Http Client & Paypal API invalid request

I can't capture this payment does anyone have any tips point me in the right direction? I think I'm missing something from the body of the request, but I have all the required, according to the API documentation. Was wondering if its a Http client issue?

Http::withToken($response->json()['access_token'])->post('https://api.sandbox.paypal.com/v2/checkout/orders/'.$request->token.'/capture');
{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"1ba98921ebb38","details":[{"field":"\/","location":"body","issue":"INVALID_SYNTAX","description":"MALFORMED_REQUEST_JSON"}],"links":[{"href":"https:\/\/developer.paypal.com\/docs\/api\/orders\/v2\/#error-INVALID_SYNTAX","rel":"information_link","encType":"application\/json"}]}
0 likes
3 replies
Adgower's avatar
Adgower
OP
Best Answer
Level 14

Had to add application_context (even though it says its not required...)

Http::withToken($response->json()['access_token'])->post('https://api.sandbox.paypal.com/v2/checkout/orders/'.$request->token.'/capture',[
            'application_context' => [
                'return_url' => route('invoices.index'),
                'cancel_url' => route('payments.cancel')
            ]
        ]);

https://developer.paypal.com/docs/api/orders/v2/#definition-order_capture_request.customized_x_unsupported_3218_order_application_context

4 likes
DavidBirkin's avatar

@Adgower This actually solved my problem! Thank you. The documentation to this day does not say these are required fields but when passing them everything works, even passing

 $payload = [
     'application_context' => [
            'return_url' => "",
            'cancel_url' => ""
        ]
    ];

with empty values worked fine, too!

Thanks David

1 like
roozmehr's avatar

I might be a little late to the party but i just faced this issue. The link works fine on postman(I don't have to pass application_context. in fact i do it with an empty body) but in laravel i'm forced to send application_context. does anyone have any idea why this is?

1 like

Please or to participate in this conversation.