From 8d566a38135e9227891f7d80b9abaebc97cbac9d Mon Sep 17 00:00:00 2001 From: k15 Date: Thu, 15 Feb 2024 11:26:29 +0700 Subject: [PATCH 1/2] fix : add billing_plan_id and product_id after creating recurring subscriptions --- .../PayPalAPI/Subscriptions/Helpers.php | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/Traits/PayPalAPI/Subscriptions/Helpers.php b/src/Traits/PayPalAPI/Subscriptions/Helpers.php index 8b65faa2..cd444235 100644 --- a/src/Traits/PayPalAPI/Subscriptions/Helpers.php +++ b/src/Traits/PayPalAPI/Subscriptions/Helpers.php @@ -93,7 +93,9 @@ public function setupSubscription(string $customer_name, string $customer_email, $body['taxes'] = $this->taxes; } - $subscription = $this->createSubscription($body); + $subscription = $this->createSubscription($body); + $subscription['billing_plan_id'] = $this->billing_plan['id']; + $subscription['product_id'] = $this->product['id']; unset($this->product); unset($this->billing_plan); @@ -139,7 +141,7 @@ public function addDailyPlan(string $name, string $description, float $price, in return $this; } - $plan_pricing = $this->addPlanBillingCycle('DAY', 1, $price, $total_cycles); + $plan_pricing = $this->addPlanBillingCycle('DAY', 1, $price, $total_cycles); $billing_cycles = empty($this->trial_pricing) ? [$plan_pricing] : collect([$this->trial_pricing, $plan_pricing])->filter()->toArray(); $this->addBillingPlan($name, $description, $billing_cycles); @@ -165,7 +167,7 @@ public function addWeeklyPlan(string $name, string $description, float $price, i return $this; } - $plan_pricing = $this->addPlanBillingCycle('WEEK', 1, $price, $total_cycles); + $plan_pricing = $this->addPlanBillingCycle('WEEK', 1, $price, $total_cycles); $billing_cycles = empty($this->trial_pricing) ? [$plan_pricing] : collect([$this->trial_pricing, $plan_pricing])->filter()->toArray(); $this->addBillingPlan($name, $description, $billing_cycles); @@ -191,7 +193,7 @@ public function addMonthlyPlan(string $name, string $description, float $price, return $this; } - $plan_pricing = $this->addPlanBillingCycle('MONTH', 1, $price, $total_cycles); + $plan_pricing = $this->addPlanBillingCycle('MONTH', 1, $price, $total_cycles); $billing_cycles = empty($this->trial_pricing) ? [$plan_pricing] : collect([$this->trial_pricing, $plan_pricing])->filter()->toArray(); $this->addBillingPlan($name, $description, $billing_cycles); @@ -217,7 +219,7 @@ public function addAnnualPlan(string $name, string $description, float $price, i return $this; } - $plan_pricing = $this->addPlanBillingCycle('YEAR', 1, $price, $total_cycles); + $plan_pricing = $this->addPlanBillingCycle('YEAR', 1, $price, $total_cycles); $billing_cycles = empty($this->trial_pricing) ? [$plan_pricing] : collect([$this->trial_pricing, $plan_pricing])->filter()->toArray(); $this->addBillingPlan($name, $description, $billing_cycles); @@ -248,10 +250,10 @@ public function addCustomPlan(string $name, string $description, float $price, s } if (!in_array($interval_unit, $billing_intervals)) { - throw new \RuntimeException('Billing intervals should either be '.implode(', ', $billing_intervals)); + throw new \RuntimeException('Billing intervals should either be ' . implode(', ', $billing_intervals)); } - $plan_pricing = $this->addPlanBillingCycle($interval_unit, $interval_count, $price, $total_cycles); + $plan_pricing = $this->addPlanBillingCycle($interval_unit, $interval_count, $price, $total_cycles); $billing_cycles = empty($this->trial_pricing) ? [$plan_pricing] : collect([$this->trial_pricing, $plan_pricing])->filter()->toArray(); $this->addBillingPlan($name, $description, $billing_cycles); @@ -286,7 +288,7 @@ protected function addPlanBillingCycle(string $interval_unit, int $interval_coun } return [ - 'frequency' => [ + 'frequency' => [ 'interval_unit' => $interval_unit, 'interval_count' => $interval_count, ], @@ -318,10 +320,10 @@ public function addProduct(string $name, string $description, string $type, stri $request_id = Str::random(); $this->product = $this->createProduct([ - 'name' => $name, - 'description' => $description, - 'type' => $type, - 'category' => $category, + 'name' => $name, + 'description' => $description, + 'type' => $type, + 'category' => $category, ], $request_id); return $this; @@ -413,7 +415,7 @@ public function addPaymentFailureThreshold(int $threshold): \Srmklive\PayPal\Ser */ public function addSetupFee(float $price): \Srmklive\PayPal\Services\PayPal { - $this->has_setup_fee = true; + $this->has_setup_fee = true; $this->payment_preferences = [ 'auto_bill_outstanding' => true, 'setup_fee' => [ @@ -443,16 +445,16 @@ public function addSetupFee(float $price): \Srmklive\PayPal\Services\PayPal public function addShippingAddress(string $full_name, string $address_line_1, string $address_line_2, string $admin_area_2, string $admin_area_1, string $postal_code, string $country_code): \Srmklive\PayPal\Services\PayPal { $this->shipping_address = [ - 'name' => [ + 'name' => [ 'full_name' => $full_name, ], 'address' => [ - 'address_line_1' => $address_line_1, - 'address_line_2' => $address_line_2, - 'admin_area_2' => $admin_area_2, - 'admin_area_1' => $admin_area_1, - 'postal_code' => $postal_code, - 'country_code' => $country_code, + 'address_line_1' => $address_line_1, + 'address_line_2' => $address_line_2, + 'admin_area_2' => $admin_area_2, + 'admin_area_1' => $admin_area_1, + 'postal_code' => $postal_code, + 'country_code' => $country_code, ], ]; @@ -475,4 +477,4 @@ public function addTaxes(float $percentage) return $this; } -} +} \ No newline at end of file From 45eba7c47054e182291ecba02ab6b66687e2f7e1 Mon Sep 17 00:00:00 2001 From: Kris Date: Thu, 15 Feb 2024 11:45:45 +0700 Subject: [PATCH 2/2] Update Helpers.php add white space end of file --- src/Traits/PayPalAPI/Subscriptions/Helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Traits/PayPalAPI/Subscriptions/Helpers.php b/src/Traits/PayPalAPI/Subscriptions/Helpers.php index cd444235..00d70752 100644 --- a/src/Traits/PayPalAPI/Subscriptions/Helpers.php +++ b/src/Traits/PayPalAPI/Subscriptions/Helpers.php @@ -477,4 +477,4 @@ public function addTaxes(float $percentage) return $this; } -} \ No newline at end of file +}