This repository has been archived by the owner on Nov 9, 2021. It is now read-only.
generated from renoki-co/laravel-package-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added handler to prorate/not prorate swaps between plans
- Loading branch information
Showing
5 changed files
with
194 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace RenokiCo\BillingPortal\Traits; | ||
|
||
use Closure; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
trait ResolvesQuotas | ||
{ | ||
/** | ||
* The callback to sync quotas for an user. | ||
* | ||
* @var Closure|null | ||
*/ | ||
protected static $syncQuotasResolver; | ||
|
||
/** | ||
* Register a method that will run when the | ||
* subscription updates, in order to sync the quotas. | ||
* | ||
* @param \Closure $callback | ||
* @return void | ||
*/ | ||
public static function resolveQuotasSync(Closure $callback) | ||
{ | ||
static::$syncQuotasResolver = $callback; | ||
} | ||
|
||
/** | ||
* Run the syncing quotas callback. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $billable | ||
* @param \Illuminate\Database\Eloquent\Model $subscription | ||
* @return void | ||
*/ | ||
public static function syncQuotas(Model $billable, Model $subscription) | ||
{ | ||
if (static::$syncQuotasResolver) { | ||
$callback = static::$syncQuotasResolver; | ||
|
||
$callback($billable, $subscription); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace RenokiCo\BillingPortal\Traits; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use RenokiCo\CashierRegister\Plan; | ||
|
||
trait ResolvesStripeCheckout | ||
{ | ||
/** | ||
* The closure that will be called to get | ||
* the right Stripe Checkout parameters to call. | ||
* | ||
* @var null|Closure | ||
*/ | ||
protected static $stripeCheckoutOptions; | ||
|
||
/** | ||
* The closure that will be called to modify | ||
* the Stripe Checkout flow. | ||
* | ||
* @var null|Closure | ||
*/ | ||
protected static $stripeCheckoutResolver; | ||
|
||
/** | ||
* Set the Stripe Checkout options computator. | ||
* | ||
* @param \Closure $callback | ||
* @return void | ||
*/ | ||
public static function resolveStripeCheckoutOptions(Closure $callback) | ||
{ | ||
static::$stripeCheckoutOptions = $callback; | ||
} | ||
|
||
/** | ||
* Calculate the options for Stripe Checkout for | ||
* a specific Billable mode, plan and subscription name. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param mixed $billable | ||
* @param \RenokiCo\CashierRegister\Plan $plan | ||
* @param string $subscription | ||
* @return array | ||
*/ | ||
public static function getStripeCheckoutOptions(Request $request, $billable, Plan $plan, string $subscription): array | ||
{ | ||
$closure = static::$stripeCheckoutOptions; | ||
|
||
return $closure | ||
? $closure($request, $billable, $plan, $subscription) | ||
: []; | ||
} | ||
|
||
/** | ||
* Set the Stripe Checkout interceptor. | ||
* | ||
* @param \Closure $callback | ||
* @return void | ||
*/ | ||
public static function resolveStripeCheckout(Closure $callback) | ||
{ | ||
static::$stripeCheckoutResolver = $callback; | ||
} | ||
|
||
/** | ||
* Mutate the Stripe checkout for | ||
* a specific Billable mode, plan and subscription name. | ||
* | ||
* @param \Laravel\Cashier\SubscriptionBuilder $checkout | ||
* @param \Illuminate\Http\Request $request | ||
* @param mixed $billable | ||
* @param \RenokiCo\CashierRegister\Plan $plan | ||
* @param string $subscription | ||
* @return \Laravel\Cashier\SubscriptionBuilder | ||
*/ | ||
public static function mutateCheckout($checkout, Request $request, $billable, Plan $plan, string $subscription) | ||
{ | ||
$closure = static::$stripeCheckoutResolver; | ||
|
||
return $closure | ||
? $closure($checkout, $request, $billable, $plan, $subscription) | ||
: $checkout; | ||
} | ||
} |