Stripe PHP

repository·master·Indexed 26 days ago

https://github.com/stripe/stripe-php

PHP bindings for the Stripe API providing an object-oriented way to interact with Stripe services. Features include the StripeClient for modern API interaction, support for PSR-3 logging, automatic network retries, and auto-paging iterators for resource collections. Supports PHP 7.2.0 and later, with legacy versions available for PHP 5.3, 5.4, and 5.5.

Tokens
5.9K
Snippets
16
Records
78
Agent score
87%

What's inside stripe-php

  1. Install Public Preview SDKs

    master

    Public preview features are available in versions with a -beta.X suffix. You can install them via Composer by specifying the version. It is recommended to pin the version in your composer.json to avoid breaking changes between preview releases.

    If a preview feature requires a specific Stripe-Version header (e.g., feature_beta=v3), use Stripe::addBetaVersion().

    composer require stripe/stripe-php:v<replace-with-the-version-of-your-choice>
    Stripe::addBetaVersion("feature_beta", "v3");
  2. Add a new example to the repository

    master

    To contribute a new example to the stripe-php repository, follow these steps:

    1. Clone ExampleTemplate.php to create your new file.
    2. Implement your example logic.
    3. Fill out the file comment block, ensuring you include a description and the key steps being demonstrated.
    4. Run the script using php your_example.php to verify it works.
  3. Configure Stripe PHP requirements and dependencies

    master

    PHP Version Requirements

    • Current: PHP 7.2.0 and later.
    • Note: Support for PHP 7.2 and 7.3 is being phased out; it is recommended to upgrade to a newer runtime.

    Required PHP Extensions

    If installing manually, ensure the following extensions are enabled:

    • curl (or provide a custom non-cURL client)
    • json
    • mbstring (Multibyte String)
  4. Get started with StripeClient

    master

    The modern way to interact with the Stripe API is by instantiating a \[Stripe\]StripeClient with your secret key. This follows the client/service pattern introduced in version 7.33.0.

    $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2');
    $customer = $stripe->customers->create([
        'description' => 'example customer',
        'email' => 'email@example.com',
        'payment_method' => 'pm_card_visa',
    ]);
    echo $customer;
  5. Configure automatic network retries

    master

    To automatically retry requests that fail due to intermittent network problems, use \Stripe\Stripe::setMaxNetworkRetries(int $count). The library uses idempotency keys to ensure these retries are safe.

    \Stripe\Stripe::setMaxNetworkRetries(2);