All Projects → stripe → Stripe Php

stripe / Stripe Php

Licence: mit
PHP library for the Stripe API.

Programming Languages

PHP
23972 projects - #3 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to Stripe Php

Stripe Ruby
Ruby library for the Stripe API.
Stars: ✭ 1,634 (-45.73%)
Mutual labels:  stripe, stripe-sdk
limestone-accounts
Boilerplate Rails 5.2 multitenant SaaS application with webpack and Docker integration. Billing is scoped to accounts.
Stars: ✭ 97 (-96.78%)
Mutual labels:  stripe
halfstaff
🇺🇸 Is the US flag at half-staff?
Stars: ✭ 22 (-99.27%)
Mutual labels:  stripe
stripe-update-card
💳 Expose a page that let your customers update their payment information on Stripe.
Stars: ✭ 16 (-99.47%)
Mutual labels:  stripe
stripe-scala
Scala library for the Stripe API
Stars: ✭ 33 (-98.9%)
Mutual labels:  stripe
laravel-saas
📧 💵 Email activation, two-factor authentication, subscription billing, team billing, API token authentication, admin user impersonation and more.
Stars: ✭ 19 (-99.37%)
Mutual labels:  stripe
Penny-Seed
PennySeed is an alternative crowdfunding platform where the funding goal is divided by the number of pledgers
Stars: ✭ 18 (-99.4%)
Mutual labels:  stripe
Nest-Js-Boiler-Plate
Nest Js Boilerplate with JWT authentication, CRUD functions and payment gateways.
Stars: ✭ 14 (-99.54%)
Mutual labels:  stripe
ember-stripe-elements
A simple Ember wrapper for Stripe Elements.
Stars: ✭ 64 (-97.87%)
Mutual labels:  stripe
AWS Stripe-SaaS-quickstart
🛍️ 🚀 AWS Software as a Service App with subscriptions using Stripe Quickstart
Stars: ✭ 30 (-99%)
Mutual labels:  stripe
Flask-Stripe-MySQL-Bootstrapped
Flask template with microservices architecture. Fully integrated with Stripe 🚀
Stars: ✭ 124 (-95.88%)
Mutual labels:  stripe
flask-stripe-checkout
Setting up Stripe Checkout with Flask
Stars: ✭ 29 (-99.04%)
Mutual labels:  stripe
nestjs-stripe
Provides an injectable Stripe client to nestjs modules
Stars: ✭ 126 (-95.82%)
Mutual labels:  stripe
procesa-pagos-con-laravel
Código fuente resultado del curso "Procesa pagos con Laravel y las mejores plataformas de pagos"
Stars: ✭ 38 (-98.74%)
Mutual labels:  stripe
DwinaTech-Shop
E-commerce application. created for education and learning
Stars: ✭ 35 (-98.84%)
Mutual labels:  stripe
flask-vue-stripe
Stripe payments with Vue and Flask
Stars: ✭ 28 (-99.07%)
Mutual labels:  stripe
PayumYiiExtension
Rich payment solutions for Yii framework. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more
Stars: ✭ 13 (-99.57%)
Mutual labels:  stripe
ember-credit-card
"make your credit card form dreamy in one line of code"
Stars: ✭ 89 (-97.04%)
Mutual labels:  stripe
Stripe
A comprehensive PHP Library for the Stripe.
Stars: ✭ 256 (-91.5%)
Mutual labels:  stripe
django ecommerce
Scalable Django E-Commerce, perfect to start one new online shop project.
Stars: ✭ 25 (-99.17%)
Mutual labels:  stripe

Stripe PHP bindings

Build Status Latest Stable Version Total Downloads License

The Stripe PHP library provides convenient access to the Stripe API from applications written in the PHP language. It includes a pre-defined set of classes for API resources that initialize themselves dynamically from API responses which makes it compatible with a wide range of versions of the Stripe API.

Requirements

PHP 5.6.0 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 extensions in order to work properly:

  • curl, although you can use your own non-cURL client if you prefer
  • json
  • mbstring (Multibyte String)

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 = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2');
$customer = $stripe->customers->create([
    'description' => 'example customer',
    'email' => '[email protected]',
    'payment_method' => 'pm_card_visa',
]);
echo $customer;

Client/service patterns vs legacy patterns

You can continue to use the legacy integration patterns used prior to version 7.33.0. Review the migration guide for the backwards-compatible client/services pattern changes.

Documentation

See the PHP API docs.

See video demonstrations covering how to use the library.

Legacy Version Support

PHP 5.4 & 5.5

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. Otherwise, you can still use Stripe by downloading stripe-php v6.43.1 (zip, tar.gz) from our releases page. 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.

PHP 5.3

If you are using PHP 5.3, you should upgrade your environment as this version has been past end of life since August 2014. Otherwise, you can download v5.9.2 (zip, tar.gz) from our releases page. This version will continue to work with new versions of the Stripe API for all common uses.

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\HttpClient\CurlClient();
$curl->setTimeout(10); // default is \Stripe\HttpClient\CurlClient::DEFAULT_TIMEOUT
$curl->setConnectTimeout(5); // default is \Stripe\HttpClient\CurlClient::DEFAULT_CONNECT_TIMEOUT

echo $curl->getTimeout(); // 10
echo $curl->getConnectTimeout(); // 5

// tell Stripe to use the tweaked client
\Stripe\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\HttpClient\CurlClient([CURLOPT_PROXY => 'proxy.local:80']);
// tell Stripe to use the tweaked client
\Stripe\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\Stripe::setLogger($logger);

Accessing response data

You can access the data from the last API response on any object via getLastResponse().

$customer = $stripe->customers->create([
    'description' => 'example customer',
]);
echo $customer->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\HttpClient\CurlClient([CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1]);
\Stripe\ApiRequestor::setHttpClient($curl);

Per-request Configuration

For apps that need to use multiple keys during the lifetime of a process, like one that uses Stripe Connect, it's also possible to set a per-request key and/or account:

$customers = $stripe->customers->all([],[
    'api_key' => 'sk_test_...',
    'stripe_account' => 'acct_...'
]);

$stripe->customers->retrieve('cus_123456789', [], [
    'api_key' => 'sk_test_...',
    'stripe_account' => 'acct_...'
]);

Configuring CA Bundles

By default, the library will use its own internal bundle of known CA certificates, but it's possible to configure your own:

\Stripe\Stripe::setCABundlePath("path/to/ca/bundle");

Configuring Automatic Retries

The library can be configured to automatically retry requests that fail due to an intermittent network problem:

\Stripe\Stripe::setMaxNetworkRetries(2);

Idempotency keys are added to requests to guarantee that retries are safe.

Request latency telemetry

By default, the library sends request latency telemetry to Stripe. These numbers help Stripe improve the overall latency of its API for all users.

You can disable this behavior if you prefer:

\Stripe\Stripe::setEnableTelemetry(false);

Development

Get Composer. For example, on Mac OS:

brew install composer

Install dependencies:

composer install

The test suite depends on stripe-mock, so make sure to fetch and run it from a background terminal (stripe-mock's README also contains instructions for installing via Homebrew and other methods):

go get -u github.com/stripe/stripe-mock
stripe-mock

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/Stripe/UtilTest.php

Update bundled CA certificates from the Mozilla cURL release:

./update_certs.php

The library uses PHP CS Fixer for code formatting. Code must be formatted before PRs are submitted, otherwise CI will fail. Run the formatter with:

./vendor/bin/php-cs-fixer fix -v .

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\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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].