thephpleague / omnipay

A framework agnostic, multi-gateway payment processing library for PHP 5.6+
http://omnipay.thephpleague.com/
MIT License
5.92k stars 929 forks source link

Send a POST request as application/x-www-form-urlencoded #565

Closed sheriffmarley closed 5 years ago

sheriffmarley commented 5 years ago

How are you supposed to do a request like:

 $client = new \GuzzleHttp\ClientClient();
            $response = $client->post($this->endpoint, [
                'form_params' => $data
            ]);

in omnipay?

I took a look in mostly every package for omnipay^3 but i just came up with this line of code.

$this->httpClient->request('POST', $this->endpoint, [], http_build_query($data))

it's not send as application/x-www-form-urlencoded .

I tried to pass it in the header parameter, but yeah that is obvious that it won't work.

So how can you send a post request with form_params

judgej commented 5 years ago

The third parameter is where you add the http request headers. Check out this example:

https://github.com/thephpleague/omnipay-sagepay/blob/master/src/Message/AbstractRequest.php#L200

The older Guzzle client just happened to do that for you behind the scenes, i.e. both the header and the http_build_query(). The new client does not; it's a bit more low-level. It means you need to understand more about the http messages, and less about the features and configuration of the client.

sheriffmarley commented 5 years ago

Thanks worked! :)