| Total Complexity | 8 |
| Total Lines | 167 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | trait BillingPlans |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Create a new billing plan. |
||
| 9 | * |
||
| 10 | * @param array $data |
||
| 11 | * |
||
| 12 | * @throws \Throwable |
||
| 13 | * |
||
| 14 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 15 | * |
||
| 16 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_create |
||
| 17 | */ |
||
| 18 | public function createPlan(array $data) |
||
| 19 | { |
||
| 20 | $this->apiEndPoint = 'v1/billing/plans'; |
||
|
1 ignored issue
–
show
|
|||
| 21 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
|
1 ignored issue
–
show
|
|||
| 22 | |||
| 23 | $this->options['json'] = $data; |
||
|
1 ignored issue
–
show
|
|||
| 24 | |||
| 25 | $this->verb = 'post'; |
||
|
1 ignored issue
–
show
|
|||
| 26 | |||
| 27 | return $this->doPayPalRequest(); |
||
|
1 ignored issue
–
show
|
|||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * List all billing plans. |
||
| 32 | * |
||
| 33 | * @param int $page |
||
| 34 | * @param int $size |
||
| 35 | * @param bool $totals |
||
| 36 | * @param array $fields |
||
| 37 | * |
||
| 38 | * @throws \Throwable |
||
| 39 | * |
||
| 40 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 41 | * |
||
| 42 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_list |
||
| 43 | */ |
||
| 44 | public function listPlans($page = 1, $size = 20, $totals = true, array $fields = []) |
||
| 45 | { |
||
| 46 | $fields_list = collect($fields); |
||
| 47 | |||
| 48 | $fields = ''; |
||
| 49 | if ($fields_list->count() > 0) { |
||
| 50 | $fields = "&fields={$fields_list->implode(',')}"; |
||
| 51 | } |
||
| 52 | |||
| 53 | $this->apiEndPoint = "v1/billing/plans?page={$page}&page_size={$size}&total_required={$totals}{$fields}"; |
||
|
1 ignored issue
–
show
|
|||
| 54 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
|
1 ignored issue
–
show
|
|||
| 55 | |||
| 56 | $this->verb = 'get'; |
||
|
1 ignored issue
–
show
|
|||
| 57 | |||
| 58 | return $this->doPayPalRequest(); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Update an existing billing plan. |
||
| 63 | * |
||
| 64 | * @param string $plan_id |
||
| 65 | * @param array $data |
||
| 66 | * |
||
| 67 | * @throws \Throwable |
||
| 68 | * |
||
| 69 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 70 | * |
||
| 71 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_update |
||
| 72 | */ |
||
| 73 | public function updatePlan($plan_id, array $data) |
||
| 74 | { |
||
| 75 | $this->apiEndPoint = "v1/billing/plans/{$plan_id}"; |
||
|
1 ignored issue
–
show
|
|||
| 76 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
|
1 ignored issue
–
show
|
|||
| 77 | |||
| 78 | $this->options['json'] = $data; |
||
|
1 ignored issue
–
show
|
|||
| 79 | |||
| 80 | $this->verb = 'patch'; |
||
|
1 ignored issue
–
show
|
|||
| 81 | |||
| 82 | return $this->doPayPalRequest(); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Show details for an existing billing plan. |
||
| 87 | * |
||
| 88 | * @param string $plan_id |
||
| 89 | * |
||
| 90 | * @throws \Throwable |
||
| 91 | * |
||
| 92 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 93 | * |
||
| 94 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_get |
||
| 95 | */ |
||
| 96 | public function showPlanDetails($plan_id) |
||
| 97 | { |
||
| 98 | $this->apiEndPoint = "v1/billing/plans/{$plan_id}"; |
||
|
1 ignored issue
–
show
|
|||
| 99 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
|
1 ignored issue
–
show
|
|||
| 100 | |||
| 101 | $this->verb = 'get'; |
||
|
1 ignored issue
–
show
|
|||
| 102 | |||
| 103 | return $this->doPayPalRequest(); |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Activate an existing billing plan. |
||
| 108 | * |
||
| 109 | * @param string $plan_id |
||
| 110 | * |
||
| 111 | * @throws \Throwable |
||
| 112 | * |
||
| 113 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 114 | * |
||
| 115 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_activate |
||
| 116 | */ |
||
| 117 | public function activatePlan($plan_id) |
||
| 118 | { |
||
| 119 | $this->apiEndPoint = "v1/billing/plans/{$plan_id}/activate"; |
||
|
1 ignored issue
–
show
|
|||
| 120 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
|
1 ignored issue
–
show
|
|||
| 121 | |||
| 122 | $this->verb = 'post'; |
||
|
1 ignored issue
–
show
|
|||
| 123 | |||
| 124 | return $this->doPayPalRequest(); |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Deactivate an existing billing plan. |
||
| 129 | * |
||
| 130 | * @param string $plan_id |
||
| 131 | * |
||
| 132 | * @throws \Throwable |
||
| 133 | * |
||
| 134 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 135 | * |
||
| 136 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_deactivate |
||
| 137 | */ |
||
| 138 | public function deactivatePlan($plan_id) |
||
| 139 | { |
||
| 140 | $this->apiEndPoint = "v1/billing/plans/{$plan_id}/deactivate"; |
||
|
1 ignored issue
–
show
|
|||
| 141 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
|
1 ignored issue
–
show
|
|||
| 142 | |||
| 143 | $this->verb = 'post'; |
||
|
1 ignored issue
–
show
|
|||
| 144 | |||
| 145 | return $this->doPayPalRequest(); |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Update pricing for an existing billing plan. |
||
| 150 | * |
||
| 151 | * @param string $plan_id |
||
| 152 | * @param array $pricing |
||
| 153 | * |
||
| 154 | * @throws \Throwable |
||
| 155 | * |
||
| 156 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 157 | * |
||
| 158 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_update-pricing-schemes |
||
| 159 | */ |
||
| 160 | public function updatePlanPricing($plan_id, array $pricing) |
||
| 172 | } |
||
| 173 | } |
||
| 174 |