Skip to content

Commit

Permalink
Merge pull request #1 from otnansirk/feat/subscriptions
Browse files Browse the repository at this point in the history
Feat/subscriptions
  • Loading branch information
otnansirk committed Feb 16, 2024
2 parents 6bde2b2 + 45eba7c commit f8c8a72
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/Traits/PayPalAPI/Subscriptions/Helpers.php
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 Down

0 comments on commit f8c8a72

Please sign in to comment.