项目作者: ExpDev07

项目描述 :
💲 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.
高级语言: PHP
项目地址: git://github.com/ExpDev07/laravel-cashier-stripe-connect.git
创建时间: 2020-12-01T18:38:10Z
项目社区:https://github.com/ExpDev07/laravel-cashier-stripe-connect

开源协议:MIT License

下载



laravel-cashier-stripe-connect


Total Downloads
Latest Stable Version
License

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.



Buy Me a Coffee at ko-fi.com

💲 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.

Installation

  1. Enable Stripe Connect in your dashboard settings.
  2. Install Cashier: composer require laravel/cashier.
  3. Install package: composer require expdev07/laravel-cashier-stripe-connect.
  4. Run migrations: php artisan migrate.
  5. Configure Stripe keys for Cashier: Cashier Docs.

Note: the package will not work as intended if you do not install Laravel’s official Cashier package first.

Use

The library builds on the official Cashier library, so getting up and started is a breeze.

Setup model

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.

  1. namespace App\Models;
  2. use Illuminate\Foundation\Auth\User as Authenticatable;
  3. use ExpDev07\CashierConnect\Contracts\StripeAccount;
  4. use Laravel\Cashier\Billable as CashierBillable;
  5. use ExpDev07\CashierConnect\Billable as ConnectBillable;
  6. class User extends Authenticatable implements StripeAccount
  7. {
  8. use CashierBillable;
  9. use ConnectBillable;
  10. ///
  11. }

Create controller

Create a controller to manage on-boarding process. The example below registers an Express account for the user.

  1. namespace App\Http\Controllers;
  2. use App\Http\Controllers\Controller;
  3. use App\Models\User;
  4. use Illuminate\Http\RedirectResponse;
  5. use Illuminate\Http\Request;
  6. use URL;
  7. class StripeController extends Controller
  8. {
  9. /**
  10. * Creates an onboarding link and redirects the user there.
  11. *
  12. * @param Request $request
  13. * @return RedirectResponse
  14. */
  15. public function board(Request $request): RedirectResponse
  16. {
  17. return $this->handleBoardingRedirect($request->user());
  18. }
  19. /**
  20. * Handles returning from completing the onboarding process.
  21. *
  22. * @param Request $request
  23. * @return RedirectResponse
  24. */
  25. public function returning(Request $request): RedirectResponse
  26. {
  27. return $this->handleBoardingRedirect($request->user());
  28. }
  29. /**
  30. * Handles refreshing of onboarding process.
  31. *
  32. * @param Request $request
  33. * @return RedirectResponse
  34. */
  35. public function refresh(Request $request): RedirectResponse
  36. {
  37. return $this->handleBoardingRedirect($request->user());
  38. }
  39. /**
  40. * Handles the redirection logic of Stripe onboarding for the given user. Will
  41. * create account and redirect user to onboarding process or redirect to account
  42. * dashboard if they have already completed the process.
  43. *
  44. * @param User $user
  45. * @return RedirectResponse
  46. */
  47. private function handleBoardingRedirect(User $user): RedirectResponse
  48. {
  49. // Redirect to dashboard if onboarding is already completed.
  50. if ($user->hasStripeAccountId() && $user->hasCompletedOnboarding()) {
  51. return $user->redirectToAccountDashboard();
  52. }
  53. // Delete account if already exists and create new express account with
  54. // weekly payouts.
  55. $user->deleteAndCreateStripeAccount('express', [
  56. 'settings' => [
  57. 'payouts' => [
  58. 'schedule' => [
  59. 'interval' => 'weekly',
  60. 'weekly_anchor' => 'friday',
  61. ]
  62. ]
  63. ]
  64. ]);
  65. // Redirect to Stripe account onboarding, with return and refresh url, otherwise.
  66. return $user->redirectToAccountOnboarding(
  67. URL::to('/api/stripe/return?api_token=' . $user->api_token),
  68. URL::to('/api/stripe/refresh?api_token=' . $user->api_token)
  69. );
  70. }
  71. }

Example

  1. // Get user. This user has added the Billable trait and implements StripeAccount.
  2. $user = User::query()->find(1);
  3. // Transfer 10 USD to the user.
  4. $user->transferToStripeAccount(1000);
  5. // Payout 5 dollars to the user's bank account, which will arrive in 1 week.
  6. $user->payoutStripeAccount(500, Date::now()->addWeek());

License

Please refer to LICENSE.md for this project’s license.

Contributors

This list only contains some of the most notable contributors. For the full list, refer to GitHub’s contributors graph.

  • ExpDev07 (Marius) - creator and maintainer.
  • Haytam Bakouane (hbakouane) - contributor.

Thanks to

Taylor Otwell for his amazing framework and all the contributors of Cashier.