thephpleague / omnipay-common

Core components for the Omnipay PHP payment processing library
MIT License
329 stars 242 forks source link

passing headers #211

Open lorvent opened 5 years ago

lorvent commented 5 years ago

Hello all, I am using a payment gateway which requires sending auth details over headers.

so i am using this code now

$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(),['headers'=> $headers, 'body' => json_encode($data)]);

        return $this->response = new PurchaseResponse($this, json_decode((string) $httpResponse->getBody(), true));

but it always says Authentication credentials were not provided

i tried passing headers as 3rd parameter...still no luck.

can anyone help me fixing this please?

PS: i tried looking guzzle 6 docs but still no luck.

thanks.

judgej commented 5 years ago

The HTTP client has changed for Omnipay 3.0, if you are using the latest code. It would look more like this:

$this->httpClient->request(
    'POST',
    $this->getEndpoint(),
    $headers,
    json_encode($data)
);

Related question here https://github.com/thephpleague/omnipay/issues/565

lorvent commented 5 years ago

Thanks for the quick response and yes, i am using omnipay 3.x

i tried changing to above format but still it says Authentication credentials were not provided

i just hard coded them into $headers.

judgej commented 5 years ago

Have you dumped your headers to see what is in them? What they should contain will depend on the gateway, but for a simple bearer token it may look something like this:

[
    'Authorization' => 'Bearer 687a78bBDBE6e84E&fbb4356fEDb',
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
]
lorvent commented 5 years ago

How can i dump?

Actually i have no clue how to debug it.... that way should have fixed it easily.

i am using laravel, if that helps.

i am trying for instamojo and their api is at https://docs.instamojo.com/docs/create-a-request

and my $headers looks like this

$headers =
            ['X-Api-Key' => '3d1c00axxxx',
            'X-Auth-Token' => '496e9dxxxx'
        ];

thanks.

judgej commented 5 years ago

Those headers are probably okay (I haven't looked at the docs for the details, but the structure looks fine), but do make sure you have other required headers in there too. If you are sending JSON, then you need a header to tell the gateway that you are sending JSON as the content type. Some gateways don't care if you do or not, but some gateways are very fussy.

lorvent commented 5 years ago

I have tried sending following headers but still no use.

'Content-Type' => 'application/json',
    'Accept' => 'application/json',

can you tell me, how to debug or see full request info somewhere? including headers.

thanks.

pradeep-sawant2501 commented 4 years ago

Finally instamojo omnipay 2.0 package run on omnipay 3.1.. few headers and createRequest modified based on 3.1 version. 2 files to change from package. Anyone need help msg here..

vemulaharshith commented 3 years ago

I am trying to integrate instamojo from a month but not able to do please help me. Can you share me the github package @pradeep-sawant2501