Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-stripe/vendor/stripe/stripe-php/README.md
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
# Stripe PHP bindings
2
+
3
+
[](https://github.com/stripe/stripe-php/actions?query=branch%3Amaster)
4
+
[](https://packagist.org/packages/stripe/stripe-php)
5
+
[](https://packagist.org/packages/stripe/stripe-php)
6
+
[](https://packagist.org/packages/stripe/stripe-php)
7
+
8
+
The Stripe PHP library provides convenient access to the Stripe API from
9
+
applications written in the PHP language. It includes a pre-defined set of
10
+
classes for API resources that initialize themselves dynamically from API
11
+
responses which makes it compatible with a wide range of versions of the Stripe
12
+
API.
13
+
14
+
## Requirements
15
+
16
+
PHP 5.6.0 and later.
17
+
18
+
## Composer
19
+
20
+
You can install the bindings via [Composer](http://getcomposer.org/). Run the following command:
21
+
22
+
```bash
23
+
composer require stripe/stripe-php
24
+
```
25
+
26
+
To use the bindings, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
27
+
28
+
```php
29
+
require_once 'vendor/autoload.php';
30
+
```
31
+
32
+
## Manual Installation
33
+
34
+
If you do not wish to use Composer, you can download the [latest release](https://github.com/stripe/stripe-php/releases). Then, to use the bindings, include the `init.php` file.
35
+
36
+
```php
37
+
require_once '/path/to/stripe-php/init.php';
38
+
```
39
+
40
+
## Dependencies
41
+
42
+
The bindings require the following extensions in order to work properly:
43
+
44
+
- [`curl`](https://secure.php.net/manual/en/book.curl.php), although you can use your own non-cURL client if you prefer
45
+
- [`json`](https://secure.php.net/manual/en/book.json.php)
46
+
- [`mbstring`](https://secure.php.net/manual/en/book.mbstring.php) (Multibyte String)
47
+
48
+
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.
49
+
50
+
## Getting Started
51
+
52
+
Simple usage looks like:
53
+
54
+
```php
55
+
$stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2');
56
+
$customer = $stripe->customers->create([
57
+
'description' => 'example customer',
58
+
'email' => 'email@example.com',
59
+
'payment_method' => 'pm_card_visa',
60
+
]);
61
+
echo $customer;
62
+
```
63
+
64
+
### Client/service patterns vs legacy patterns
65
+
66
+
You can continue to use the legacy integration patterns used prior to version [7.33.0](https://github.com/stripe/stripe-php/blob/master/CHANGELOG.md#7330---2020-05-14). Review the [migration guide](https://github.com/stripe/stripe-php/wiki/Migration-to-StripeClient-and-services-in-7.33.0) for the backwards-compatible client/services pattern changes.
67
+
68
+
## Documentation
69
+
70
+
See the [PHP API docs](https://stripe.com/docs/api/?lang=php#intro).
71
+
72
+
## Legacy Version Support
73
+
74
+
### PHP 5.4 & 5.5
75
+
76
+
If you are using PHP 5.4 or 5.5, you should consider upgrading your environment as those versions have been past end of life since September 2015 and July 2016 respectively.
77
+
Otherwise, you can still use Stripe by downloading stripe-php v6.43.1 ([zip](https://github.com/stripe/stripe-php/archive/v6.43.1.zip), [tar.gz](https://github.com/stripe/stripe-php/archive/6.43.1.tar.gz)) from our [releases page](https://github.com/stripe/stripe-php/releases). This version will work but might not support recent features we added since the version was released and upgrading PHP is the best course of action.
78
+
79
+
### PHP 5.3
80
+
81
+
If you are using PHP 5.3, you should upgrade your environment as this version has been past end of life since August 2014.
82
+
Otherwise, you can download v5.9.2 ([zip](https://github.com/stripe/stripe-php/archive/v5.9.2.zip), [tar.gz](https://github.com/stripe/stripe-php/archive/v5.9.2.tar.gz)) from our [releases page](https://github.com/stripe/stripe-php/releases). This version will continue to work with new versions of the Stripe API for all common uses.
83
+
84
+
## Custom Request Timeouts
85
+
86
+
> **Note**
87
+
> 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](https://stripe.com/docs/api/?lang=php#idempotent_requests) to avoid executing the same transaction twice as a result of timeout retry logic.
88
+
89
+
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.
90
+
91
+
```php
92
+
// set up your tweaked Curl client
93
+
$curl = new \Stripe\HttpClient\CurlClient();
94
+
$curl->setTimeout(10); // default is \Stripe\HttpClient\CurlClient::DEFAULT_TIMEOUT
95
+
$curl->setConnectTimeout(5); // default is \Stripe\HttpClient\CurlClient::DEFAULT_CONNECT_TIMEOUT
96
+
97
+
echo $curl->getTimeout(); // 10
98
+
echo $curl->getConnectTimeout(); // 5
99
+
100
+
// tell Stripe to use the tweaked client
101
+
\Stripe\ApiRequestor::setHttpClient($curl);
102
+
103
+
// use the Stripe API client as you normally would
104
+
```
105
+
106
+
## Custom cURL Options (e.g. proxies)
107
+
108
+
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.
109
+
110
+
```php
111
+
// set up your tweaked Curl client
112
+
$curl = new \Stripe\HttpClient\CurlClient([CURLOPT_PROXY => 'proxy.local:80']);
113
+
// tell Stripe to use the tweaked client
114
+
\Stripe\ApiRequestor::setHttpClient($curl);
115
+
```
116
+
117
+
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.
118
+
119
+
### Configuring a Logger
120
+
121
+
The library does minimal logging, but it can be configured
122
+
with a [`PSR-3` compatible logger][psr3] so that messages
123
+
end up there instead of `error_log`:
124
+
125
+
```php
126
+
\Stripe\Stripe::setLogger($logger);
127
+
```
128
+
129
+
### Accessing response data
130
+
131
+
You can access the data from the last API response on any object via `getLastResponse()`.
132
+
133
+
```php
134
+
$customer = $stripe->customers->create([
135
+
'description' => 'example customer',
136
+
]);
137
+
echo $customer->getLastResponse()->headers['Request-Id'];
138
+
```
139
+
140
+
### SSL / TLS compatibility issues
141
+
142
+
Stripe's API now requires that [all connections use TLS 1.2](https://stripe.com/blog/upgrading-tls). 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](https://stripe.com/blog/upgrading-tls).".
143
+
144
+
The recommended course of action is to [upgrade your cURL and OpenSSL packages](https://support.stripe.com/questions/how-do-i-upgrade-my-stripe-integration-from-tls-1-0-to-tls-1-2#php) 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`:
145
+
146
+
```php
147
+
$curl = new \Stripe\HttpClient\CurlClient([CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1]);
148
+
\Stripe\ApiRequestor::setHttpClient($curl);
149
+
```
150
+
151
+
### Per-request Configuration
152
+
153
+
For apps that need to use multiple keys during the lifetime of a process, like
154
+
one that uses [Stripe Connect][connect], it's also possible to set a
155
+
per-request key and/or account:
156
+
157
+
```php
158
+
$customers = $stripe->customers->all([],[
159
+
'api_key' => 'sk_test_...',
160
+
'stripe_account' => 'acct_...'
161
+
]);
162
+
163
+
$stripe->customers->retrieve('cus_123456789', [], [
164
+
'api_key' => 'sk_test_...',
165
+
'stripe_account' => 'acct_...'
166
+
]);
167
+
```
168
+
169
+
### Configuring CA Bundles
170
+
171
+
By default, the library will use its own internal bundle of known CA
172
+
certificates, but it's possible to configure your own:
173
+
174
+
```php
175
+
\Stripe\Stripe::setCABundlePath("path/to/ca/bundle");
176
+
```
177
+
178
+
### Configuring Automatic Retries
179
+
180
+
The library can be configured to automatically retry requests that fail due to
181
+
an intermittent network problem:
182
+
183
+
```php
184
+
\Stripe\Stripe::setMaxNetworkRetries(2);
185
+
```
186
+
187
+
[Idempotency keys][idempotency-keys] are added to requests to guarantee that
188
+
retries are safe.
189
+
190
+
### Telemetry
191
+
192
+
By default, the library sends telemetry to Stripe regarding request latency and feature usage. These
193
+
numbers help Stripe improve the overall latency of its API for all users, and
194
+
improve popular features.
195
+
196
+
You can disable this behavior if you prefer:
197
+
198
+
```php
199
+
\Stripe\Stripe::setEnableTelemetry(false);
200
+
```
201
+
202
+
### Public Preview SDKs
203
+
204
+
Stripe has features in the [public preview phase](https://docs.stripe.com/release-phases) that can be accessed via versions of this package that have the `-beta.X` suffix like `12.2.0-beta.2`.
205
+
We would love for you to try these as we incrementally release new features and improve them based on your feedback.
206
+
207
+
The public preview SDKs are a different version of the same package as the stable SDKs. These versions are appended with `-beta.X` such as `15.0.0-beta.1`. To install, pick the latest version with the `beta` suffix by reviewing the [releases page](https://github.com/stripe/stripe-dotnet/releases/) and then use it in the `composer require` command:
208
+
209
+
```bash
210
+
composer require stripe/stripe-php:v<replace-with-the-version-of-your-choice>
211
+
```
212
+
213
+
> **Note**
214
+
> There can be breaking changes between two versions of the public preview SDKs without a bump in the major version. Therefore we recommend pinning the package version to a specific version in your composer.json file. This way you can install the same version each time without breaking changes unless you are intentionally looking for the latest version of the public preview SDK.
215
+
216
+
Some preview features require a name and version to be set in the `Stripe-Version` header like `feature_beta=v3`. If the preview feature you are interested in has this requirement, use the function `addBetaVersion` (available only in the public preview SDKs):
217
+
218
+
```php
219
+
Stripe::addBetaVersion("feature_beta", "v3");
220
+
```
221
+
### Private Preview SDKs
222
+
223
+
Stripe has features in the [private preview phase](https://docs.stripe.com/release-phases) that can be accessed via versions of this package that have the `-alpha.X` suffix like `12.2.0-alpha.2`. These are invite-only features. Once invited, you can install the private preview SDKs by following the same instructions as for the [public preview SDKs](https://github.com/stripe/stripe-php?tab=readme-ov-file#public-preview-sdks) above and replacing the term `beta` with `alpha`.
224
+
225
+
### Custom requests
226
+
227
+
If you would like to send a request to an undocumented API (for example you are in a private beta), or if you prefer to bypass the method definitions in the library and specify your request details directly, you can use the `rawRequest` method on the StripeClient.
228
+
229
+
```php
230
+
$stripe = new \Stripe\StripeClient('sk_test_xyz');
231
+
$response = $stripe->rawRequest('post', '/v1/beta_endpoint', [
232
+
"caveat": "emptor"
233
+
], [
234
+
"stripe_version" => "2022-11_15",
235
+
]);
236
+
// $response->body is a string, you can call $stripe->deserialize to get a \Stripe\StripeObject.
237
+
$obj = $stripe->deserialize($response->body);
238
+
239
+
// For GET requests, the params argument must be null, and you should write the query string explicitly.
240
+
$get_response = $stripe->rawRequest('get', '/v1/beta_endpoint?caveat=emptor', null, [
241
+
"stripe_version" => "2022-11_15",
242
+
]);
243
+
```
244
+
245
+
## Support
246
+
247
+
New features and bug fixes are released on the latest major version of the Stripe PHP library. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.
248
+
249
+
## Development
250
+
251
+
[Contribution guidelines for this project](CONTRIBUTING.md)
252
+
253
+
We use [just](https://github.com/casey/just) for conveniently running development tasks. You can use them directly, or copy the commands out of the `justfile`. To our help docs, run `just`.
254
+
255
+
To get started, install [Composer][composer]. For example, on Mac OS:
256
+
257
+
```bash
258
+
brew install composer
259
+
```
260
+
261
+
Install dependencies:
262
+
263
+
```bash
264
+
just install
265
+
# or: composer install
266
+
```
267
+
268
+
The test suite depends on [stripe-mock], so make sure to fetch and run it from a
269
+
background terminal ([stripe-mock's README][stripe-mock] also contains
270
+
instructions for installing via Homebrew and other methods):
271
+
272
+
```bash
273
+
go install github.com/stripe/stripe-mock@latest
274
+
stripe-mock
275
+
```
276
+
277
+
Install dependencies as mentioned above (which will resolve [PHPUnit](http://packagist.org/packages/phpunit/phpunit)), then you can run the test suite:
278
+
279
+
```bash
280
+
just test
281
+
# or: ./vendor/bin/phpunit
282
+
```
283
+
284
+
Or to run an individual test file:
285
+
286
+
```bash
287
+
just test tests/Stripe/UtilTest.php
288
+
# or: ./vendor/bin/phpunit tests/Stripe/UtilTest.php
289
+
```
290
+
291
+
Update bundled CA certificates from the [Mozilla cURL release][curl]:
292
+
293
+
```bash
294
+
./update_certs.php
295
+
```
296
+
297
+
The library uses [PHP CS Fixer][php-cs-fixer] for code formatting. Code must be formatted before PRs are submitted, otherwise CI will fail. Run the formatter with:
298
+
299
+
```bash
300
+
just format
301
+
# or: ./vendor/bin/php-cs-fixer fix -v .
302
+
```
303
+
304
+
## Attention plugin developers
305
+
306
+
Are you writing a plugin that integrates Stripe and embeds our library? Then please use the `setAppInfo` function to identify your plugin. For example:
307
+
308
+
```php
309
+
\Stripe\Stripe::setAppInfo("MyAwesomePlugin", "1.2.34", "https://myawesomeplugin.info");
310
+
```
311
+
312
+
The method should be called once, before any request is sent to the API. The second and third parameters are optional.
313
+
314
+
### SSL / TLS configuration option
315
+
316
+
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`.
317
+
318
+
[composer]: https://getcomposer.org/
319
+
[connect]: https://stripe.com/connect
320
+
[curl]: http://curl.haxx.se/docs/caextract.html
321
+
[idempotency-keys]: https://stripe.com/docs/api/?lang=php#idempotent_requests
322
+
[php-cs-fixer]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
323
+
[psr3]: http://www.php-fig.org/psr/psr-3/
324
+
[stripe-mock]: https://github.com/stripe/stripe-mock
325
+