Paypal API invalid request on Orders capture

adgower
Contributor
Contributor

Using Laravel HTTP client

Http::withToken($response->json()['access_token'])->post('https://api.sandbox.paypal.com/v2/checkout/orders/'.$request->token.'/capture');

returns:

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

I have the required parameters not sure what else I am missing. Any tips?

 

Login to Me Too
1 REPLY 1

dreadkopp
Contributor
Contributor

Since i ran into the same issue recently and stumbled upon this thread:

When using the HTTP Facade, the ::post() method will pass an empty array as payload. which is by definition invalid (since present but not according to specs).

 

As a workaround you can use the underlying ::send() method

something like this:

public function captureOrder(string $token): bool
{
    return Http::withToken($this->getAuthToken())
            ->contentType('application/json')
            ->send('POST',$this->baseUrl.'/v2/checkout/orders/'.$token.'/capture')
            ->created();
}

 

i know to OP might not need this info anymore but it might help someone 🙂

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.