psr18-adapter / stripe-php
Requires
- php: >=7.1
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- stripe/stripe-php: >=v2.1.3
Requires (Dev)
- nyholm/psr7: ^1.3
- php-http/mock-client: ^1.4
- phpunit/phpunit: >=5.7
This package is auto-updated.
Last update: 2024-11-29 06:41:20 UTC
README
Install
Via Composer
composer require psr18-adapter/stripe-php
Usage
stripe-php
library uses singleton for setting the http client, so you will have to call it at some point
before you start calling Stripe itself, like so
\Stripe\ApiRequestor::setHttpClient( new \Psr18Adapter\Stripe\StripePsr18Client($psr18Client, $psr7UriFactory, $psr7RequestFactory) );
How to set up for dependency injection containers
Singletons like ApiRequestor cannot really be configured for dependency injection containers like
symfony/dependency-injection
without writing extra layer as well. This is why I'm shipping such layer within
this package too, in case you are also finding that you need to write such layer, but don't really want to.
It's used like following, if you use YAML and symfony/dependency-injection
services: Stripe\StripeClient: factory: ['Psr18Adapter\Stripe\StripeClientAccessor', 'access'] arguments: - !service class: Stripe\StripeClient arguments: $config: api_key: '%stripe_secret_key%' - !service class: Psr18Adapter\Stripe\StripePsr18Client autowire: true
This should be a replacement of definition of Stripe\StripeClient
service itself.
Advantage of this approach is that
it ensures http client is set in singleton before retrieving \Stripe\StripeClient
service. This means you can be
confident any time StripeClient is fetched from container, it's already configured with your PSR-18 HTTP client.
Licensing
MIT license. Please see License File for more information.