55namespace Veeqtoh \Cashier \Classes ;
66
77use Carbon \Carbon ;
8+ use Illuminate \Database \Eloquent \Model ;
89use Veeqtoh \Cashier \Exceptions \FailedToCreateSubscription ;
910use Veeqtoh \Cashier \Models \Subscription ;
1011use 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 }
0 commit comments