I set up Laravel Cashier and it fails to connect to Stripe.
I've isolated the bug to the point where this simple line fails:
$user = new User();
$user->subscription()->create('test');
The error is nondescript:
Stripe_ApiConnectionError
in vendor/stripe/stripe-php/lib/Stripe/ApiRequestor.php
Could not connect to Stripe (https://api.stripe.com). Please check your internet connection and try again. If this problem persists, you should check Stripe's service status at https://twitter.com/stripestatus. Reason was:
As you can see, $errstr
, used to display the reason, is null.
My research so far...
$errstr
can be null because of an unfixed PHP bug when the certificate check fails.
I found this StackOverflow question which mentions that it's because the CAPath is not specified.
This indeed seems to be the case in Homestead / Vagrant. I suspect something is wrong in the default VagrantBox config.
When I run this command from my Mac I get a return code 0
(working):
openssl s_client -connect api.stripe.com:443
When I run the same command from Homestead I get a return code 20
(unable to get local issuer certificate):
To make it work in Homestead, I have to manually specify the CAPath
like so:
openssl s_client -CApath /etc/ssl/certs/ -connect api.stripe.com:443
Then I get return code 0.
How can I fix this for good so my Cashier calls work?