trendspider/stripe-legacy
Composer 安装命令:
composer require trendspider/stripe-legacy
包简介
Stripe PHP Library
README 文档
README
You can sign up for a Stripe account at https://stripe.com.
Requirements
PHP 5.3.3 and later.
Composer
You can install the bindings via Composer. Run the following command:
composer require stripe/stripe-php
To use the bindings, use Composer's autoload:
require_once('vendor/autoload.php');
Manual Installation
If you do not wish to use Composer, you can download the latest release. Then, to use the bindings, include the init.php file.
require_once('/path/to/stripe-php/init.php');
Dependencies
The bindings require the following extension in order to work properly:
If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.
Getting Started
Simple usage looks like:
\Stripe_Legacy\Stripe::setApiKey('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $charge = \Stripe_Legacy\Charge::create(array('amount' => 2000, 'currency' => 'usd', 'source' => 'tok_189fqt2eZvKYlo2CTGBeg6Uq' )); echo $charge;
Documentation
Please see https://stripe.com/docs/api for up-to-date documentation.
Legacy Version Support
If you are using PHP 5.2, you can download v1.18.0 (zip, tar.gz) from our releases page. This version will continue to work with new versions of the Stripe API for all common uses.
This legacy version may be included via require_once("/path/to/stripe-php/lib/Stripe.php");, and used like:
Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249'); $charge = Stripe_Charge::create(array('source' => 'tok_XXXXXXXX', 'amount' => 2000, 'currency' => 'usd')); echo $charge;
Custom Request Timeouts
NOTE: We do not recommend decreasing the timeout for non-read-only calls (e.g. charge creation), since even if you locally timeout, the request on Stripe's side can still complete. If you are decreasing timeouts on these calls, make sure to use idempotency tokens to avoid executing the same transaction twice as a result of timeout retry logic.
To modify request timeouts (connect or total, in seconds) you'll need to tell the API client to use a CurlClient other than its default. You'll set the timeouts in that CurlClient.
// set up your tweaked Curl client $curl = new \Stripe_Legacy\HttpClient\CurlClient(); $curl->setTimeout(10); // default is \Stripe_Legacy\HttpClient\CurlClient::DEFAULT_TIMEOUT $curl->setConnectTimeout(5); // default is \Stripe_Legacy\HttpClient\CurlClient::DEFAULT_CONNECT_TIMEOUT echo $curl->getTimeout(); // 10 echo $curl->getConnectTimeout(); // 5 // tell Stripe to use the tweaked client \Stripe_Legacy\ApiRequestor::setHttpClient($curl); // use the Stripe API client as you normally would
Custom cURL Options (e.g. proxies)
Need to set a proxy for your requests? Pass in the requisite CURLOPT_* array to the CurlClient constructor, using the same syntax as curl_stopt_array(). This will set the default cURL options for each HTTP request made by the SDK, though many more common options (e.g. timeouts; see above on how to set those) will be overridden by the client even if set here.
// set up your tweaked Curl client $curl = new \Stripe_Legacy\HttpClient\CurlClient(array(CURLOPT_PROXY => 'proxy.local:80')); // tell Stripe to use the tweaked client \Stripe_Legacy\ApiRequestor::setHttpClient($curl);
Alternately, a callable can be passed to the CurlClient constructor that returns the above array based on request inputs. See testDefaultOptions() in tests/CurlClientTest.php for an example of this behavior. Note that the callable is called at the beginning of every API request, before the request is sent.
Configuring a Logger
The library does minimal logging, but it can be configured
with a PSR-3 compatible logger so that messages
end up there instead of error_log:
\Stripe_Legacy\Stripe::setLogger($logger);
Accessing response data
You can access the data from the last API response on any object via getLastResponse().
$charge = \Stripe_Legacy\Charge::create(array('amount' => 2000, 'currency' => 'usd', 'source' => 'tok_visa')); echo $charge->getLastResponse()->headers['Request-Id'];
SSL / TLS compatibility issues
Stripe's API now requires that all connections use TLS 1.2. Some systems (most notably some older CentOS and RHEL versions) are capable of using TLS 1.2 but will use TLS 1.0 or 1.1 by default. In this case, you'd get an invalid_request_error with the following error message: "Stripe no longer supports API requests made with TLS 1.0. Please initiate HTTPS connections with TLS 1.2 or later. You can learn more about this at https://stripe.com/blog/upgrading-tls.".
The recommended course of action is to upgrade your cURL and OpenSSL packages so that TLS 1.2 is used by default, but if that is not possible, you might be able to solve the issue by setting the CURLOPT_SSLVERSION option to either CURL_SSLVERSION_TLSv1 or CURL_SSLVERSION_TLSv1_2:
$curl = new \Stripe_Legacy\HttpClient\CurlClient(array(CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1)); \Stripe_Legacy\ApiRequestor::setHttpClient($curl);
Development
Install dependencies:
composer install
Tests
Install dependencies as mentioned above (which will resolve PHPUnit), then you can run the test suite:
./vendor/bin/phpunit
Or to run an individual test file:
./vendor/bin/phpunit tests/UtilTest.php
Attention plugin developers
Are you writing a plugin that integrates Stripe and embeds our library? Then please use the setAppInfo function to identify your plugin. For example:
\Stripe_Legacy\Stripe::setAppInfo("MyAwesomePlugin", "1.2.34", "https://myawesomeplugin.info");
The method should be called once, before any request is sent to the API. The second and third parameters are optional.
SSL / TLS configuration option
See the "SSL / TLS compatibility issues" paragraph above for full context. If you want to ensure that your plugin can be used on all systems, you should add a configuration option to let your users choose between different values for CURLOPT_SSLVERSION: none (default), CURL_SSLVERSION_TLSv1 and CURL_SSLVERSION_TLSv1_2.
trendspider/stripe-legacy 适用场景与选型建议
trendspider/stripe-legacy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.08k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「stripe」 「payment processing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 trendspider/stripe-legacy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 trendspider/stripe-legacy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 trendspider/stripe-legacy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Flexible payment integration for Laravel, lunarphp, supporting multiple payment providers.
A PSR-7 compatible library for making CRUD API endpoints
Rich payment solutions for Laravel framework. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more
A simple Symfony bundle for Stripe API.
Configuration-driven, multi-gateway payment orchestration for Laravel. Drivers expose primitives; flows compose them.
统计信息
- 总下载量: 11.08k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-05-04