dominservice / laravel-stripe
Laravel integration for Stripe.
Requires
- php: ^8.1|^8,2|^8.3
- ext-json: *
- dominservice/data_locale_parser: ^2.0
- illuminate/console: ^10.0|^11.0|^12.0|13.0
- illuminate/contracts: ^10.0|^11.0|^12.0|13.0
- illuminate/database: ^10.0|^11.0|^12.0|13.0
- illuminate/http: ^10.0|^11.0|^12.0|13.0
- illuminate/queue: ^10.0|^11.0|^12.0|13.0
- illuminate/routing: ^10.0|^11.0|^12.0|13.0
- illuminate/support: ^10.0|^11.0|^12.0|13.0
- psr/log: ^3.0
- stripe/stripe-php: ^13.10
README
Stripe integration for laravel 10+ on PHP 8.1+
Installation
composer require dominservice/laravel-stripe
Add your stripe credentials in .env:
STRIPE_KEY=pk_live_XxxXXxXXX
STRIPE_SECRET=sk_live_XxxXXxXXX
STRIPE_WEBHOOK_CHECKOUT=whsec_XxxXXxXXX
Publish config:
php artisan vendor:publish --tag=stripe
Publish migrations:
php artisan vendor:publish --tag=stripe-migrations
Configuration
In the configuration file you can change the list of allowed currencies. Check if your currency is on this list, and if it is not there, add it, otherwise you will not be able to use this package.
Also check if your User model is the same as the model specified in the config/stripe.php file
Usage
Routing
You must attach middleware stripe.verify:{name} to routes that have a reference to payments webhook so that the paths are secured.
Route::group(['middleware' => ['stripe.verify:checkout'], 'namespace' => '\App\Http\Controllers'], function () { Route::get('/webhook/payments', 'WebhookController@payments'); (...)
{name} indicates which webhook key should be used. In the above example, it is checkout.
This means that config("stripe.webhooks.signing_secrets.checkout") will be used to verify webhook.
For direct Checkout Session line_items.price_data payloads, the package also accepts uppercase currency codes declared in config/stripe.php and normalizes them to Stripe's expected lowercase format before the request is sent.
Stripe Connect
The package supports the base repositories required for Stripe Connect onboarding:
accounts()accountLinks()loginLinks()
Typical platform flow:
use Dominservice\LaraStripe\Client as StripeClient; $stripe = new StripeClient(); $account = $stripe->accounts() ->setType('express') ->setCountry('PL') ->setEmail($expert->email) ->setCapabilities([ 'transfers' => ['requested' => true], ]) ->create($expert); $onboarding = $stripe->accountLinks() ->setAccount($account->id) ->setRefreshUrl(route('expert.billing.refresh')) ->setReturnUrl(route('expert.billing.return')) ->setType('account_onboarding') ->create(); $loginLink = $stripe->loginLinks()->create($account->id);
For marketplace split payments handled on the platform account, create Checkout Sessions with:
payment_intent_data.application_fee_amountpayment_intent_data.transfer_data.destination
This allows the platform to collect its fee and transfer the remaining amount to the connected expert account.
Code
use Dominservice\LaraStripe\Client as StripeClient; (...) $stripe = (new StripeClient()); // Create product with price $product = \App\Models\Product::find(1); $productStripe = $stripe->products() ->setName($product->name) ->setActive(true) ->setExtendPricesCurrency('pln') ->setExtendPricesUnitAmount((float)$amount) ->setExtendPricesBillingScheme('per_unit') ->setExtendPricesRecurring(['interval' => 'month']) ->create($product); // Create customer $customer = $stripe->customers() ->setName($user->name) ->setEmail($user->email) ->setPhone($user->phone) ->setAddress([ 'country' => 'PL', 'city' => 'Warszawa', 'postal_code' => '00-000', 'line1' => 'ul. kopernika 1/2', ]) ->create($user); // Checkout session $session = $stripe->checkoutSessions() ->setSuccessUrl(route('payment.afterTransaction', $order->ulid) . '?session_id={CHECKOUT_SESSION_ID}') ->setCancelUrl(route('payment.canceled', $order->ulid)) ->setMode('subscription') ->setClientReferenceId($order->ulid) ->setCustomer($customer->id) ->setLineItems([ [ 'price' => $productStripe->default_price->id, 'quantity' => 1, ] ]) ->create();
To be continued... ;)
This repo is not finished