diff --git a/config/cashier.php b/config/cashier.php index f2883c5b..48350041 100644 --- a/config/cashier.php +++ b/config/cashier.php @@ -46,19 +46,6 @@ 'tolerance' => env('STRIPE_WEBHOOK_TOLERANCE', 300), ], - /* - |-------------------------------------------------------------------------- - | Cashier Model - |-------------------------------------------------------------------------- - | - | This is the model in your application that implements the Billable trait - | provided by Cashier. It will serve as the primary model you use while - | interacting with Cashier related methods, subscriptions, and so on. - | - */ - - 'model' => env('CASHIER_MODEL', class_exists(App\Models\User::class) ? App\Models\User::class : App\User::class), - /* |-------------------------------------------------------------------------- | Currency diff --git a/database/factories/SubscriptionFactory.php b/database/factories/SubscriptionFactory.php index adefdafd..28b2e92a 100644 --- a/database/factories/SubscriptionFactory.php +++ b/database/factories/SubscriptionFactory.php @@ -5,6 +5,7 @@ use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; +use Laravel\Cashier\Cashier; use Laravel\Cashier\Subscription; use Stripe\Subscription as StripeSubscription; @@ -24,7 +25,7 @@ class SubscriptionFactory extends Factory */ public function definition() { - $model = config('cashier.model'); + $model = Cashier::$customerModel; return [ (new $model)->getForeignKey() => ($model)::factory(), diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5df111f0..54762eee 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -19,7 +19,6 @@ - diff --git a/src/Cashier.php b/src/Cashier.php index 75c45d71..9852443e 100644 --- a/src/Cashier.php +++ b/src/Cashier.php @@ -52,6 +52,13 @@ class Cashier */ public static $deactivatePastDue = true; + /** + * The default customer model class name. + * + * @var string + */ + public static $customerModel = 'App\\Models\\User'; + /** * The subscription model class name. * @@ -67,7 +74,7 @@ class Cashier public static $subscriptionItemModel = SubscriptionItem::class; /** - * Get the customer instance by Stripe ID. + * Get the customer instance by its Stripe ID. * * @param string $stripeId * @return \Laravel\Cashier\Billable|null @@ -78,9 +85,7 @@ public static function findBillable($stripeId) return; } - $model = config('cashier.model'); - - return (new $model)->where('stripe_id', $stripeId)->first(); + return (new static::$customerModel)->where('stripe_id', $stripeId)->first(); } /** @@ -168,6 +173,17 @@ public static function keepPastDueSubscriptionsActive() return new static; } + /** + * Set the customer model class name. + * + * @param string $customerModel + * @return void + */ + public static function useCustomerModel($customerModel) + { + static::$customerModel = $customerModel; + } + /** * Set the subscription model class name. * diff --git a/src/Concerns/ManagesCustomer.php b/src/Concerns/ManagesCustomer.php index 59594a6c..cc0fde49 100644 --- a/src/Concerns/ManagesCustomer.php +++ b/src/Concerns/ManagesCustomer.php @@ -217,7 +217,7 @@ public function reverseChargeApplies() } /** - * Get the default Stripe API options for the current Billable model. + * Get the default Stripe API options for the current customer model. * * @param array $options * @return array diff --git a/src/Subscription.php b/src/Subscription.php index 0102fca6..26c9fedc 100644 --- a/src/Subscription.php +++ b/src/Subscription.php @@ -82,7 +82,7 @@ public function user() */ public function owner() { - $model = config('cashier.model'); + $model = Cashier::$customerModel; return $this->belongsTo($model, (new $model)->getForeignKey()); } diff --git a/tests/Feature/LoggerTest.php b/tests/Feature/LoggerTest.php index f12b775d..e545a951 100644 --- a/tests/Feature/LoggerTest.php +++ b/tests/Feature/LoggerTest.php @@ -83,6 +83,8 @@ public function test_it_uses_a_configured_logger() protected function getEnvironmentSetUp($app) { + parent::getEnvironmentSetUp($app); + $app['config']->set('cashier.logger', $this->channel); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index bcfbed63..91137d01 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,11 +2,18 @@ namespace Laravel\Cashier\Tests; +use Laravel\Cashier\Cashier; use Laravel\Cashier\CashierServiceProvider; +use Laravel\Cashier\Tests\Fixtures\User; use Orchestra\Testbench\TestCase as OrchestraTestCase; abstract class TestCase extends OrchestraTestCase { + protected function getEnvironmentSetUp($app) + { + Cashier::useCustomerModel(User::class); + } + protected function getPackageProviders($app) { return [CashierServiceProvider::class];