Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add billing_plan_id and product_id after creating recurring subscriptions #617

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions src/Traits/PayPalAPI/Subscriptions/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -286,7 +288,7 @@ protected function addPlanBillingCycle(string $interval_unit, int $interval_coun
}

return [
'frequency' => [
'frequency' => [
'interval_unit' => $interval_unit,
'interval_count' => $interval_count,
],
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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,
],
];

Expand All @@ -475,4 +477,4 @@ public function addTaxes(float $percentage)

return $this;
}
}
}
otnansirk marked this conversation as resolved.
Show resolved Hide resolved