Search code examples
laravelstripe-paymentsomnipay

Laravel Omnipay/Stripe unable to send request on linux


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();

Solution

  • 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();