-1

currently I have integrated omnipay/stripe to my laravel project, it was ok on my local, but when I test it on server then it returned "Invalid request: unsupported Content-Type . If error persists and you need assistance, please contact [email protected]." when trying to send the request, please help.

$response = $gateway->purchase([
'amount' => $amount,
'currency' => $currency,
'token' => $token,
'confirm' => true,
'description' => auth()->user()->name
])->send();
2
  • please look at this link test github.com/vapor-community/stripe/issues/39 Feb 17, 2021 at 12:24
  • Hi @Arjunbhati , thanks for your reply but if it was the case, then I should also encounter the error on my local as well ? I'm new to laravel so have not much idea, or it have some way to make changes on local instead of the omnipay's library ? sorry for my broken english
    – Bernard.S
    Feb 17, 2021 at 12:35

2 Answers 2

0

The exact text of the error Content-Type . indicates the request has an empty Content-Type header (the value is included before the period). While I cannot explain why this is happening, something is interfering with the request.

You can try making basic curl calls (like the below) from your server to help isolate whether this is network-level interference or in the application stack.

curl --request POST \
  --url 'https://api.stripe.com/v1/customers' \
  -u sk_test_123: \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data 'description=test cust'

You can try with and without the explicit header to see if this make a difference.

3
  • Hi @Nolan i tried in my server with curl it seems ok to send the request, so might be the application layer has interfered the request ?
    – Bernard.S
    Feb 18, 2021 at 10:46
  • Yes, that would seem to be the case. Is this happening for all requests, or a subset? Are you trying to override any headers in any way?
    – Nolan H
    Feb 18, 2021 at 14:01
  • In my application I only integrate the purchase function, so I am not sure is it all request, do you know have any way to override the header in the Omnipay ? doesn't seems like they having the option for this...
    – Bernard.S
    Feb 18, 2021 at 14:46
0

Finally I found a workaround, I will post it here incase any future reference. I have consulted the Stripe's technical support and their respond gave me an idea.

The causes/issue found by Stripe's support: The request is being sent with an empty Content-Type header.

I have gone through the library and try to debug what the request header was being send out but found out actually in the log it was only the "Authorization" header as default, have no idea on how the Content-Type is added in, so based on their respond, I added in 'Content-Type' => 'application/x-www-form-urlencoded' to omnipay/stripe/src/Message/AbstractRequest.php at sendData($data). Of course you could also placed it in the more structured way than I did.

Surprisingly it works !

And they have also suggested one of the way you could try it as well, but I didn't.

$request = $gateway->purchase([
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
'amount' => $amount,
'currency' => $currency,
'token' => $token,
'confirm' => true,
'description' => auth()->user()->name
])->send();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.