Search code examples
phpgoogle-app-enginebraintreephp-5.5

Braintree PHP client library, and Google App Engine CURLOPT_CAINFO not implemented


I'm deploying an app to Google App Engine standard environment, PHP 5.5, but I'm encountering the following issue when making any request through the Braintree PHP library:

PHP Fatal error:  Uncaught exception 'google\appengine\runtime\CurlLiteOptionNotSupportedException' with message     'Option 10065 is not supported by this curl implementation.' in /base/php_experiment_runtime/sdk/google/appengine/runtime/CurlLite.php:487
Stack trace:
#0 /base/php_experiment_runtime/sdk/google/appengine/runtime/CurlLite.php(215): google\appengine\runtime\CurlLite->setOption(10065, '/base/data/home...')
#1 /base/php_experiment_runtime/sdk/google/appengine/runtime/CurlLiteStub.php(1325): google\appengine\runtime\CurlLite->setOptionsArray(Array)
#2 /base/php_experiment_runtime/sdk/google/appengine/runtime/CurlLiteStub.php(1319): curl_setopt_array(Object(google\appengine\runtime\CurlLite), Array)
#3 /base/data/home/apps/s~enoronbackend/20170630t135950.402337515471573447/vendor/braintree/braintree_php/lib/Braintree/Http.php(135): curl_setopt(Object(google\appengine\runtime\CurlLite), 10065, '/base/data/home...')
#4 /base/data/home/apps/s~enoronbackend/20170630t135950.402337515471573447/vendor/braintree/braintree_php/li in /base/php_experiment_runtime/sdk/google/appengine/runtime/CurlLite.php on line 487

I did set up the library specifying no gzip responses, as indicated here.

Braintree\Configuration::environment('production');
Braintree\Configuration::merchantId('XXX');
Braintree\Configuration::publicKey('XXX');
Braintree\Configuration::privateKey('XXX');
Braintree\Configuration::acceptGzipEncoding(false);

It appears however that the problem is caused by line 133 in Braintree\Http:

curl_setopt($curl, CURLOPT_CAINFO, $this->getCaFile());

The cUrl lite implementation provided by GAE does not support CURLOPT_CAINFO. I did try to use CURLOPT_CAPATH instead, as suggested in the PHP documentation on cUrl, but then I got an Authorization error from Braintree.

Also commenting out the line where CURLOPT_CAINFO is results in an Authorization error.


Solution

  • In case anyone's interested, it turns out the solution was very simple, using the full cUrl PHP library instead of the lite one provided by GAE. To do so you need to edit the php.ini file:

    Instead of

    google_app_engine.enable_curl_lite = “1”
    

    use

    extension = "curl.so"