| Total Complexity | 11 |
| Total Lines | 218 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | trait Subscriptions |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Create a new subscription. |
||
| 11 | * |
||
| 12 | * @param array $data |
||
| 13 | * |
||
| 14 | * @throws \Throwable |
||
| 15 | * |
||
| 16 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 17 | * |
||
| 18 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create |
||
| 19 | */ |
||
| 20 | public function createSubscription(array $data) |
||
| 21 | { |
||
| 22 | $this->apiEndPoint = 'v1/billing/subscriptions'; |
||
|
1 ignored issue
–
show
|
|||
| 23 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
|
1 ignored issue
–
show
|
|||
| 24 | |||
| 25 | $this->options['json'] = $data; |
||
|
1 ignored issue
–
show
|
|||
| 26 | |||
| 27 | $this->verb = 'post'; |
||
|
1 ignored issue
–
show
|
|||
| 28 | |||
| 29 | return $this->doPayPalRequest(); |
||
|
1 ignored issue
–
show
|
|||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Update an existing billing plan. |
||
| 34 | * |
||
| 35 | * @param string $subscription_id |
||
| 36 | * @param array $data |
||
| 37 | * |
||
| 38 | * @throws \Throwable |
||
| 39 | * |
||
| 40 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 41 | * |
||
| 42 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_patch |
||
| 43 | */ |
||
| 44 | public function updateSubscription($subscription_id, array $data) |
||
| 45 | { |
||
| 46 | $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}"; |
||
|
1 ignored issue
–
show
|
|||
| 47 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
|
1 ignored issue
–
show
|
|||
| 48 | |||
| 49 | $this->options['json'] = $data; |
||
|
1 ignored issue
–
show
|
|||
| 50 | |||
| 51 | $this->verb = 'patch'; |
||
|
1 ignored issue
–
show
|
|||
| 52 | |||
| 53 | return $this->doPayPalRequest(); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Show details for an existing subscription. |
||
| 58 | * |
||
| 59 | * @param string $subscription_id |
||
| 60 | * |
||
| 61 | * @throws \Throwable |
||
| 62 | * |
||
| 63 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 64 | * |
||
| 65 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get |
||
| 66 | */ |
||
| 67 | public function showSubscriptionDetails($subscription_id) |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Activate an existing subscription. |
||
| 79 | * |
||
| 80 | * @param string $subscription_id |
||
| 81 | * |
||
| 82 | * @throws \Throwable |
||
| 83 | * |
||
| 84 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 85 | * |
||
| 86 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_activate |
||
| 87 | */ |
||
| 88 | public function activateSubscription($subscription_id) |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Cancel an existing subscription. |
||
| 100 | * |
||
| 101 | * @param string $subscription_id |
||
| 102 | * |
||
| 103 | * @throws \Throwable |
||
| 104 | * |
||
| 105 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 106 | * |
||
| 107 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel |
||
| 108 | */ |
||
| 109 | public function cancelSubscription($subscription_id) |
||
| 110 | { |
||
| 111 | $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/cancel"; |
||
|
1 ignored issue
–
show
|
|||
| 112 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
|
1 ignored issue
–
show
|
|||
| 113 | |||
| 114 | $this->verb = 'post'; |
||
|
1 ignored issue
–
show
|
|||
| 115 | |||
| 116 | return $this->doPayPalRequest(); |
||
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Suspend an existing subscription. |
||
| 121 | * |
||
| 122 | * @param string $subscription_id |
||
| 123 | * |
||
| 124 | * @throws \Throwable |
||
| 125 | * |
||
| 126 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 127 | * |
||
| 128 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_suspend |
||
| 129 | */ |
||
| 130 | public function suspendSubscription($subscription_id) |
||
| 131 | { |
||
| 132 | $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/suspend"; |
||
|
1 ignored issue
–
show
|
|||
| 133 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
|
1 ignored issue
–
show
|
|||
| 134 | |||
| 135 | $this->verb = 'post'; |
||
|
1 ignored issue
–
show
|
|||
| 136 | |||
| 137 | return $this->doPayPalRequest(); |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Capture payment for an existing subscription. |
||
| 142 | * |
||
| 143 | * @param string $subscription_id |
||
| 144 | * @param string $note |
||
| 145 | * @param float $amount |
||
| 146 | * |
||
| 147 | * @throws \Throwable |
||
| 148 | * |
||
| 149 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 150 | * |
||
| 151 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_capture |
||
| 152 | */ |
||
| 153 | public function captureSubscriptionPayment($subscription_id, $note, $amount) |
||
| 154 | { |
||
| 155 | $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/capture"; |
||
|
1 ignored issue
–
show
|
|||
| 156 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
|
1 ignored issue
–
show
|
|||
| 157 | |||
| 158 | $this->options['json'] = [ |
||
|
1 ignored issue
–
show
|
|||
| 159 | "note" => $note, |
||
| 160 | "capture_type" => "OUTSTANDING_BALANCE", |
||
| 161 | "amount" => [ |
||
| 162 | "currency" => $this->currency, |
||
| 163 | "value" => "{$amount}", |
||
| 164 | ], |
||
| 165 | ]; |
||
| 166 | |||
| 167 | $this->verb = 'post'; |
||
|
1 ignored issue
–
show
|
|||
| 168 | |||
| 169 | return $this->doPayPalRequest(); |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Revise quantity, product or service for an existing subscription. |
||
| 174 | * |
||
| 175 | * @param string $subscription_id |
||
| 176 | * @param array $items |
||
| 177 | * |
||
| 178 | * @throws \Throwable |
||
| 179 | * |
||
| 180 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 181 | * |
||
| 182 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_revise |
||
| 183 | */ |
||
| 184 | public function reviseSubscription($subscription_id, array $items) |
||
| 194 | } |
||
| 195 | |||
| 196 | /** |
||
| 197 | * List transactions for an existing subscription. |
||
| 198 | * |
||
| 199 | * @param string $subscription_id |
||
| 200 | * @param string $start_date |
||
| 201 | * @param string $end_date |
||
| 202 | * |
||
| 203 | * @throws \Throwable |
||
| 204 | * |
||
| 205 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 206 | * |
||
| 207 | * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions |
||
| 208 | */ |
||
| 209 | public function listSubscriptionTransactions($subscription_id, $start_date = "", $end_date = "") |
||
| 225 | } |
||
| 226 | } |
||
| 227 |