
Braintree 开发起步
基本流程
使用 Braintree SDK 在服务器生成令牌传给前端页面或客户端,客户端得到令牌后同样借助 SDK 渲染出 PayPal 按钮。
常见错误
Sandbox 账号错误
创建中国区的 Business Sandbox 账户会出现错误:
可以尝试创建 US 地区的 Business Sandbox 账户,同样能够用于测试。
SSL 版本错误
PHP 环境下出现如下 Exception:
Braintree\Exception\SSLCertificate: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version in Braintree\Http->_doUrlRequest()
Braintree\Exception\SSLCertificate: Protocol "https" not supported or disabled in libcurl in Braintree\Http->_doUrlRequest()
PHP SDK 通过 cURL 库和 Braintree 服务器交互,cURL 引用的 openssl 版本过低,或者 cURL 没有加入 ssl 支持时会造成此类问题。重新编译 cURL 并引用 1.0.2c 以上版本的 openssl 库可以解决此类问题。
MAMP 用户可以参考下面的方法解决问题:
# 确认 PHP 支持的 openssl 版本。
/Applications/MAMP/bin/php/php7.0.8/bin/php -r 'echo json_encode(curl_version(), JSON_PRETTY_PRINT);'
# 确认 cURL 的版本,从 https://curl.haxx.se/download/ 下载对应版本的源码。
/Applications/MAMP/Library/bin/curl-config --version
# 编译引用最新的 OpenSSL 库。
./configure --prefix=/Applications/MAMP/Library/ --with-ssl=/usr/local/Cellar/openssl/1.0.2o_1