Package Data | |
---|---|
Maintainer Username: | ExpDev07 |
Maintainer Contact: | mariusrich2@gmail.com (ExpDev07) |
Package Create Date: | 2020-12-01 |
Package Last Update: | 2022-11-01 |
Home Page: | https://github.com/ExpDev07/laravel-cashier-stripe-connect |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-02 03:10:08 |
Package Statistics | |
---|---|
Total Downloads: | 118,413 |
Monthly Downloads: | 370 |
Daily Downloads: | 4 |
Total Stars: | 61 |
Total Watchers: | 8 |
Total Forks: | 27 |
Total Open Issues: | 3 |
Newer Package Available
A more comprehensive package is now available, built upon this package so can be upgraded to from this package, it offers multi-model, multi-tenancy support, UUID support and the following features:
- Multi Model support - Previously only supported the User model, now any model can have the Connect Billable trait added to it and immediately inherit functionality.
- Tenancy for Laravel Support (Multi Tenant SaaS Plugin)
- Manage connected account onboarding
- Direct Charges
- Destination Charges
- Connected account customer management (Direct Customers)
- Connected account payment method management
- Connected account subscriptions ( Direct Subscriptions )
- Connected account product & price management
- Connect Webhook Support (On behalf of connected accounts)
- Connected Account Apple Pay Domain Registering
Click here to access the new package
As a result of the new package, this package will no longer be maintained.
💲 Adds Stripe Connect functionality to Laravel's main billing package, Cashier. Simply works as a drop-in on top of Cashier, with no extra configuration.
composer require laravel/cashier
.composer require expdev07/laravel-cashier-stripe-connect
.php artisan migrate
.Note: the package will not work as intended if you do not install Laravel's official Cashier package first.
The library builds on the official Cashier library, so getting up and started is a breeze.
Add the Billable
traits to your model. You can use them individually or together. You can also create your own Billable
trait and put them together there. In
addition, the model should also implement the StripeAccount
interface.
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use ExpDev07\CashierConnect\Contracts\StripeAccount;
use Laravel\Cashier\Billable as CashierBillable;
use ExpDev07\CashierConnect\Billable as ConnectBillable;
class User extends Authenticatable implements StripeAccount
{
use CashierBillable;
use ConnectBillable;
///
}
Create a controller to manage on-boarding process. The example below registers an Express account for the user.
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use URL;
class StripeController extends Controller
{
/**
* Creates an onboarding link and redirects the user there.
*
* @param Request $request
* @return RedirectResponse
*/
public function board(Request $request): RedirectResponse
{
return $this->handleBoardingRedirect($request->user());
}
/**
* Handles returning from completing the onboarding process.
*
* @param Request $request
* @return RedirectResponse
*/
public function returning(Request $request): RedirectResponse
{
return $this->handleBoardingRedirect($request->user());
}
/**
* Handles refreshing of onboarding process.
*
* @param Request $request
* @return RedirectResponse
*/
public function refresh(Request $request): RedirectResponse
{
return $this->handleBoardingRedirect($request->user());
}
/**
* Handles the redirection logic of Stripe onboarding for the given user. Will
* create account and redirect user to onboarding process or redirect to account
* dashboard if they have already completed the process.
*
* @param User $user
* @return RedirectResponse
*/
private function handleBoardingRedirect(User $user): RedirectResponse
{
// Redirect to dashboard if onboarding is already completed.
if ($user->hasStripeAccountId() && $user->hasCompletedOnboarding()) {
return $user->redirectToAccountDashboard();
}
// Delete account if already exists and create new express account with
// weekly payouts.
$user->deleteAndCreateStripeAccount('express', [
'settings' => [
'payouts' => [
'schedule' => [
'interval' => 'weekly',
'weekly_anchor' => 'friday',
]
]
]
]);
// Redirect to Stripe account onboarding, with return and refresh url, otherwise.
return $user->redirectToAccountOnboarding(
URL::to('/api/stripe/return?api_token=' . $user->api_token),
URL::to('/api/stripe/refresh?api_token=' . $user->api_token)
);
}
}
// Get user. This user has added the Billable trait and implements StripeAccount.
$user = User::query()->find(1);
// Transfer 10 USD to the user.
$user->transferToStripeAccount(1000);
// Payout 5 dollars to the user's bank account, which will arrive in 1 week.
$user->payoutStripeAccount(500, Date::now()->addWeek());
Please refer to LICENSE.md for this project's license.
This list only contains some of the most notable contributors. For the full list, refer to GitHub's contributors graph.
Taylor Otwell for his amazing framework and all the contributors of Cashier.