programster / stripe-wrapper
A wrapper around the stipe/stripe-php SDK in order to make life easier.
Requires
- php: ^8.2
- ext-curl: *
- programster/collections: ^3.0
- stripe/stripe-php: ^v19.4.0
Requires (Dev)
- phpstan/phpstan: ^2.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-16 17:40:43 UTC
README
Contents
- About
- Requirements
- Installation
- Quick start
- Examples
- Checkout sessions
- Customers
- Subscriptions
- Responses
- Listing
- Exceptions
- Upgrading
- Testing
- Design principles
- License
About
A wrapper around the stripe/stripe-php package, to make it easier to use Stripe without having to read its documentation. Instead of building arrays of parameters, you fill in constructors whose parameters are typed and documented, and your IDE shows you the options as you type. Values with a fixed set of options, such as currencies, countries and statuses, are enums, so they can't be misspelt.
What comes back is typed too: each method returns readonly models, such as a Customer or a Subscription, with a
getter for each field, and the list methods return a collection of everything that matches, so there are no pages to
handle (see Responses).
Requirements
PHP 8.2, 8.3, 8.4 or 8.5, with the curl extension.
Installation
composer require programster/stripe-wrapper
Quick start
This creates a checkout session for a one-off payment, and sends the customer to Stripe's payment page:
<?php require_once(__DIR__ . '/vendor/autoload.php'); $client = new StripeClient('sk_test_...'); $flow = new HostedFlow(successUrl: "https://example.com/success"); $shirt = PriceDataForSinglePayment::createUsingInlineProduct( currency: Currency::GBP, unitAmount: 2000, productData: new ProductData( name: "T-shirt", description: "A designer t-shirt." ) ); $items = new SinglePaymentLineItemsCollection( SinglePaymentLineItem::createUsingInlinePrice( priceData: $shirt, quantity: 1, adjustableQuantityConfig: new AdjustableQuantityConfig(1, 100) ) ); $checkoutSession = $client->createHostedCheckoutSessionForSinglePayment( flow: $flow, items: $items, ); # Redirect the user to the Stripe payment page. http_response_code(303); header('Location: ' . $checkoutSession->getUrl());
Every class used above is in the Programster\Stripe namespace, e.g. Programster\Stripe\StripeClient and
Programster\Stripe\Enums\Currency. See Examples for common tasks from start to finish, and
Checkout sessions for subscriptions, embedded checkouts, existing customers and the other options.
Design principles
- Mistakes are caught where they're made. Options with a fixed set of values are enums, a parameter that takes one of several kinds of thing (such as an existing price, or one created inline) takes an object with a static creator for each, and values Stripe would always reject (such as a negative price, a product's ID where a price's is needed, or a minimum that's more than the maximum) throw an exception when the object is created, rather than when the request reaches Stripe.
- Each client uses its own key. Requests go through the client they were made with, so an application with several
Stripe accounts can't send one account's request with another's key. The key is also kept out of
var_dump(),print_r()and stack traces. - Tested against Stripe itself. As well as offline tests on every supported version of PHP, live tests check that Stripe's test mode accepts what the package sends (see Testing).
License
MIT. See LICENSE.