Skip to content

Commit 6021757

Browse files
committed
Merge remote-tracking branch 'origin/master' into laravel-12-support
2 parents 78126ce + 87340dc commit 6021757

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/Classes/SubscriptionBuilder.php

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

77
use Carbon\Carbon;
8+
use Illuminate\Database\Eloquent\Model;
89
use Veeqtoh\Cashier\Exceptions\FailedToCreateSubscription;
910
use Veeqtoh\Cashier\Models\Subscription;
1011
use Veeqtoh\Cashier\Services\PaystackService;
@@ -36,12 +37,12 @@ class SubscriptionBuilder
3637
* Create a new subscription builder instance.
3738
*
3839
* @param mixed $owner The model that is subscribing.
39-
* @param string $plan The name of the plan being subscribed to.
40+
* @param Model $plan The model instance of the plan being subscribed to.
4041
* @param string $name The name of the subscription.
4142
*
4243
* @return void
4344
*/
44-
public function __construct(protected mixed $owner, protected string $plan, protected string $name)
45+
public function __construct(protected mixed $owner, protected Model $plan, protected string $name)
4546
{
4647
//
4748
}
@@ -81,7 +82,7 @@ public function add(array $options = []): Subscription
8182
'name' => $this->name,
8283
'paystack_id' => $options['id'],
8384
'paystack_code' => $options['subscription_code'],
84-
'paystack_plan' => $this->plan,
85+
'paystack_plan' => $this->plan->plan_code,
8586
'quantity' => 1,
8687
'trial_ends_at' => $trialEndsAt,
8788
'ends_at' => null,
@@ -94,10 +95,10 @@ public function add(array $options = []): Subscription
9495
public function charge(array $options = []): mixed
9596
{
9697
$options = array_merge([
97-
'plan' => $this->plan
98+
'plan' => $this->plan->plan_code
9899
], $options);
99100

100-
return $this->owner->charge(100, $options);
101+
return $this->owner->charge($this->plan->price, $options);
101102
}
102103

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

137138
return [
138139
'customer' => $customer['customer_code'], // Customer email or code
139-
'plan' => $this->plan,
140+
'plan' => $this->plan->plan_code,
140141
'start_date' => $startDate->format('c'),
141142
];
142143
}

src/Concerns/ManagesSubscriptions.php

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

77
use Carbon\Carbon;
8+
use Illuminate\Database\Eloquent\Model;
89
use Illuminate\Database\Eloquent\Relations\HasMany;
910
use Unicodeveloper\Paystack\Facades\Paystack;
1011
use Veeqtoh\Cashier\Classes\SubscriptionBuilder;
@@ -17,7 +18,7 @@ trait ManagesSubscriptions
1718
/**
1819
* Begin creating a new subscription.
1920
*/
20-
public function newSubscription(string $plan, string $subscription = 'default'): SubscriptionBuilder
21+
public function newSubscription(Model $plan, string $subscription = 'default'): SubscriptionBuilder
2122
{
2223
return new SubscriptionBuilder($this, $plan, $subscription);
2324
}

0 commit comments

Comments
 (0)