Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passing headers #211

Open
lorvent opened this issue Jun 7, 2019 · 8 comments
Open

passing headers #211

lorvent opened this issue Jun 7, 2019 · 8 comments
Labels

Comments

@lorvent
Copy link

lorvent commented Jun 7, 2019

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
Copy link
Member

judgej commented Jun 7, 2019

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 thephpleague/omnipay#565

@judgej judgej added the question label Jun 7, 2019
@lorvent
Copy link
Author

lorvent commented Jun 7, 2019

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
Copy link
Member

judgej commented Jun 7, 2019

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
Copy link
Author

lorvent commented Jun 7, 2019

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
Copy link
Member

judgej commented Jun 7, 2019

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
Copy link
Author

lorvent commented Jun 7, 2019

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
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants