Skip to content

Commit c4a9094

Browse files
committed
Refactor SubscriptionBuilder and ManagesSubscriptions to use string for plan parameter instead of Model
1 parent 6021757 commit c4a9094

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/Classes/SubscriptionBuilder.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Veeqtoh\Cashier\Classes;
66

77
use Carbon\Carbon;
8-
use Illuminate\Database\Eloquent\Model;
98
use Veeqtoh\Cashier\Exceptions\FailedToCreateSubscription;
109
use Veeqtoh\Cashier\Models\Subscription;
1110
use Veeqtoh\Cashier\Services\PaystackService;
@@ -37,12 +36,12 @@ class SubscriptionBuilder
3736
* Create a new subscription builder instance.
3837
*
3938
* @param mixed $owner The model that is subscribing.
40-
* @param Model $plan The model instance of the plan being subscribed to.
39+
* @param string $plan The name of the plan being subscribed to.
4140
* @param string $name The name of the subscription.
4241
*
4342
* @return void
4443
*/
45-
public function __construct(protected mixed $owner, protected Model $plan, protected string $name)
44+
public function __construct(protected mixed $owner, protected string $plan, protected string $name)
4645
{
4746
//
4847
}
@@ -82,7 +81,7 @@ public function add(array $options = []): Subscription
8281
'name' => $this->name,
8382
'paystack_id' => $options['id'],
8483
'paystack_code' => $options['subscription_code'],
85-
'paystack_plan' => $this->plan->plan_code,
84+
'paystack_plan' => $this->plan,
8685
'quantity' => 1,
8786
'trial_ends_at' => $trialEndsAt,
8887
'ends_at' => null,
@@ -92,13 +91,13 @@ public function add(array $options = []): Subscription
9291
/**
9392
* Charge for a Paystack subscription.
9493
*/
95-
public function charge(array $options = []): mixed
94+
public function charge(int $amount, array $options = []): mixed
9695
{
9796
$options = array_merge([
98-
'plan' => $this->plan->plan_code
97+
'plan' => $this->plan
9998
], $options);
10099

101-
return $this->owner->charge($this->plan->price, $options);
100+
return $this->owner->charge($amount, $options);
102101
}
103102

104103
/**
@@ -137,7 +136,7 @@ protected function getSubscriptionPayload(array $customer, array $options = []):
137136

138137
return [
139138
'customer' => $customer['customer_code'], // Customer email or code
140-
'plan' => $this->plan->plan_code,
139+
'plan' => $this->plan,
141140
'start_date' => $startDate->format('c'),
142141
];
143142
}

src/Concerns/ManagesSubscriptions.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Veeqtoh\Cashier\Concerns;
66

77
use Carbon\Carbon;
8-
use Illuminate\Database\Eloquent\Model;
98
use Illuminate\Database\Eloquent\Relations\HasMany;
109
use Unicodeveloper\Paystack\Facades\Paystack;
1110
use Veeqtoh\Cashier\Classes\SubscriptionBuilder;
@@ -18,7 +17,7 @@ trait ManagesSubscriptions
1817
/**
1918
* Begin creating a new subscription.
2019
*/
21-
public function newSubscription(Model $plan, string $subscription = 'default'): SubscriptionBuilder
20+
public function newSubscription(string $plan, string $subscription = 'default'): SubscriptionBuilder
2221
{
2322
return new SubscriptionBuilder($this, $plan, $subscription);
2423
}

0 commit comments

Comments
 (0)