@@ -273,7 +273,7 @@ |
||
| 273 | 273 | /** |
| 274 | 274 | * Gets the native customer response. |
| 275 | 275 | * |
| 276 | - * @return Braintree_Customer |
|
| 276 | + * @return null|Braintree_Customer |
|
| 277 | 277 | */ |
| 278 | 278 | public function getNativeResponse() |
| 279 | 279 | { |
@@ -8,276 +8,276 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Customer implements CustomerInterface |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The gateway instance. |
|
| 13 | - * |
|
| 14 | - * @var Gateway |
|
| 15 | - */ |
|
| 16 | - protected $gateway; |
|
| 11 | + /** |
|
| 12 | + * The gateway instance. |
|
| 13 | + * |
|
| 14 | + * @var Gateway |
|
| 15 | + */ |
|
| 16 | + protected $gateway; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Primary identifier. |
|
| 20 | - * |
|
| 21 | - * @var mixed |
|
| 22 | - */ |
|
| 23 | - protected $id; |
|
| 18 | + /** |
|
| 19 | + * Primary identifier. |
|
| 20 | + * |
|
| 21 | + * @var mixed |
|
| 22 | + */ |
|
| 23 | + protected $id; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Braintree customer object. |
|
| 27 | - * |
|
| 28 | - * @var Braintree_Customer |
|
| 29 | - */ |
|
| 30 | - protected $braintree_customer; |
|
| 25 | + /** |
|
| 26 | + * Braintree customer object. |
|
| 27 | + * |
|
| 28 | + * @var Braintree_Customer |
|
| 29 | + */ |
|
| 30 | + protected $braintree_customer; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Create a new Braintree customer instance. |
|
| 34 | - * |
|
| 35 | - * @param Gateway $gateway |
|
| 36 | - * @param mixed $id |
|
| 37 | - * |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public function __construct(Gateway $gateway, $id = null) |
|
| 41 | - { |
|
| 42 | - $this->gateway = $gateway; |
|
| 32 | + /** |
|
| 33 | + * Create a new Braintree customer instance. |
|
| 34 | + * |
|
| 35 | + * @param Gateway $gateway |
|
| 36 | + * @param mixed $id |
|
| 37 | + * |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public function __construct(Gateway $gateway, $id = null) |
|
| 41 | + { |
|
| 42 | + $this->gateway = $gateway; |
|
| 43 | 43 | |
| 44 | - if ($id instanceof Braintree_Customer) { |
|
| 45 | - $this->braintree_customer = $id; |
|
| 46 | - $this->id = $this->braintree_customer->id; |
|
| 47 | - } |
|
| 48 | - else if (null !== $id) { |
|
| 49 | - $this->id = $id; |
|
| 50 | - } |
|
| 51 | - } |
|
| 44 | + if ($id instanceof Braintree_Customer) { |
|
| 45 | + $this->braintree_customer = $id; |
|
| 46 | + $this->id = $this->braintree_customer->id; |
|
| 47 | + } |
|
| 48 | + else if (null !== $id) { |
|
| 49 | + $this->id = $id; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Gets the id of this instance. |
|
| 55 | - * |
|
| 56 | - * @return mixed |
|
| 57 | - */ |
|
| 58 | - public function id() |
|
| 59 | - { |
|
| 60 | - return $this->id; |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * Gets the id of this instance. |
|
| 55 | + * |
|
| 56 | + * @return mixed |
|
| 57 | + */ |
|
| 58 | + public function id() |
|
| 59 | + { |
|
| 60 | + return $this->id; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Gets info for a customer. |
|
| 65 | - * |
|
| 66 | - * @return array|null |
|
| 67 | - */ |
|
| 68 | - public function info() |
|
| 69 | - { |
|
| 70 | - if (!$this->id) { |
|
| 71 | - return null; |
|
| 72 | - } |
|
| 63 | + /** |
|
| 64 | + * Gets info for a customer. |
|
| 65 | + * |
|
| 66 | + * @return array|null |
|
| 67 | + */ |
|
| 68 | + public function info() |
|
| 69 | + { |
|
| 70 | + if (!$this->id) { |
|
| 71 | + return null; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - if (!$this->braintree_customer) { |
|
| 75 | - $this->braintree_customer = Braintree_Customer::find($this->id); |
|
| 76 | - } |
|
| 74 | + if (!$this->braintree_customer) { |
|
| 75 | + $this->braintree_customer = Braintree_Customer::find($this->id); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - if (!$this->braintree_customer) { |
|
| 79 | - return null; |
|
| 80 | - } |
|
| 78 | + if (!$this->braintree_customer) { |
|
| 79 | + return null; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - return array( |
|
| 83 | - 'id' => $this->id, |
|
| 84 | - 'description' => null, |
|
| 85 | - 'email' => $this->braintree_customer->email, |
|
| 86 | - 'created_at' => date('Y-m-d H:i:s', $this->braintree_customer->createdAt->getTimestamp()), |
|
| 87 | - 'discounts' => array(), // Customer-specific discounts not supported. |
|
| 88 | - ); |
|
| 89 | - } |
|
| 82 | + return array( |
|
| 83 | + 'id' => $this->id, |
|
| 84 | + 'description' => null, |
|
| 85 | + 'email' => $this->braintree_customer->email, |
|
| 86 | + 'created_at' => date('Y-m-d H:i:s', $this->braintree_customer->createdAt->getTimestamp()), |
|
| 87 | + 'discounts' => array(), // Customer-specific discounts not supported. |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Create a new customer. |
|
| 93 | - * |
|
| 94 | - * @param array $properties |
|
| 95 | - * |
|
| 96 | - * @return Customer |
|
| 97 | - */ |
|
| 98 | - public function create(array $properties = array()) |
|
| 99 | - { |
|
| 100 | - $this->braintree_customer = Braintree_Customer::create(array( |
|
| 101 | - 'email' => Arr::get($properties, 'email'), |
|
| 102 | - ))->customer; |
|
| 91 | + /** |
|
| 92 | + * Create a new customer. |
|
| 93 | + * |
|
| 94 | + * @param array $properties |
|
| 95 | + * |
|
| 96 | + * @return Customer |
|
| 97 | + */ |
|
| 98 | + public function create(array $properties = array()) |
|
| 99 | + { |
|
| 100 | + $this->braintree_customer = Braintree_Customer::create(array( |
|
| 101 | + 'email' => Arr::get($properties, 'email'), |
|
| 102 | + ))->customer; |
|
| 103 | 103 | |
| 104 | - $this->id = $this->braintree_customer->id; |
|
| 104 | + $this->id = $this->braintree_customer->id; |
|
| 105 | 105 | |
| 106 | - return $this; |
|
| 107 | - } |
|
| 106 | + return $this; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Update a customer. |
|
| 111 | - * |
|
| 112 | - * @param array $properties |
|
| 113 | - * |
|
| 114 | - * @return Customer |
|
| 115 | - */ |
|
| 116 | - public function update(array $properties = array()) |
|
| 117 | - { |
|
| 118 | - $props = array(); |
|
| 119 | - if (!empty($properties['email'])) { |
|
| 120 | - $props['email'] = $properties['email']; |
|
| 121 | - } |
|
| 109 | + /** |
|
| 110 | + * Update a customer. |
|
| 111 | + * |
|
| 112 | + * @param array $properties |
|
| 113 | + * |
|
| 114 | + * @return Customer |
|
| 115 | + */ |
|
| 116 | + public function update(array $properties = array()) |
|
| 117 | + { |
|
| 118 | + $props = array(); |
|
| 119 | + if (!empty($properties['email'])) { |
|
| 120 | + $props['email'] = $properties['email']; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - Braintree_Customer::update($this->id, $props); |
|
| 124 | - $this->braintree_customer = null; |
|
| 123 | + Braintree_Customer::update($this->id, $props); |
|
| 124 | + $this->braintree_customer = null; |
|
| 125 | 125 | |
| 126 | - return $this; |
|
| 127 | - } |
|
| 126 | + return $this; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Delete a customer. |
|
| 131 | - * |
|
| 132 | - * @return Customer |
|
| 133 | - */ |
|
| 134 | - public function delete() |
|
| 135 | - { |
|
| 136 | - Braintree_Customer::delete($this->id); |
|
| 137 | - $this->braintree_customer = null; |
|
| 138 | - return $this; |
|
| 139 | - } |
|
| 129 | + /** |
|
| 130 | + * Delete a customer. |
|
| 131 | + * |
|
| 132 | + * @return Customer |
|
| 133 | + */ |
|
| 134 | + public function delete() |
|
| 135 | + { |
|
| 136 | + Braintree_Customer::delete($this->id); |
|
| 137 | + $this->braintree_customer = null; |
|
| 138 | + return $this; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Gets all subscriptions for a customer. |
|
| 143 | - * |
|
| 144 | - * @return array |
|
| 145 | - */ |
|
| 146 | - public function subscriptions() |
|
| 147 | - { |
|
| 148 | - $this->info(); |
|
| 141 | + /** |
|
| 142 | + * Gets all subscriptions for a customer. |
|
| 143 | + * |
|
| 144 | + * @return array |
|
| 145 | + */ |
|
| 146 | + public function subscriptions() |
|
| 147 | + { |
|
| 148 | + $this->info(); |
|
| 149 | 149 | |
| 150 | - if (!$this->braintree_customer) { |
|
| 151 | - return array(); |
|
| 152 | - } |
|
| 150 | + if (!$this->braintree_customer) { |
|
| 151 | + return array(); |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - $subscriptions_array = array(); |
|
| 155 | - foreach ($this->braintree_customer->creditCards as $card) { |
|
| 156 | - foreach ($card->subscriptions as $subscription) { |
|
| 157 | - $subscriptions_array[] = $this->gateway->subscription($subscription, $this); |
|
| 158 | - } |
|
| 159 | - } |
|
| 154 | + $subscriptions_array = array(); |
|
| 155 | + foreach ($this->braintree_customer->creditCards as $card) { |
|
| 156 | + foreach ($card->subscriptions as $subscription) { |
|
| 157 | + $subscriptions_array[] = $this->gateway->subscription($subscription, $this); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - return $subscriptions_array; |
|
| 162 | - } |
|
| 161 | + return $subscriptions_array; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Gets all credit cards for a customer. |
|
| 166 | - * |
|
| 167 | - * @return array |
|
| 168 | - */ |
|
| 169 | - public function cards() |
|
| 170 | - { |
|
| 171 | - $this->info(); |
|
| 164 | + /** |
|
| 165 | + * Gets all credit cards for a customer. |
|
| 166 | + * |
|
| 167 | + * @return array |
|
| 168 | + */ |
|
| 169 | + public function cards() |
|
| 170 | + { |
|
| 171 | + $this->info(); |
|
| 172 | 172 | |
| 173 | - if (!$this->braintree_customer) { |
|
| 174 | - return array(); |
|
| 175 | - } |
|
| 173 | + if (!$this->braintree_customer) { |
|
| 174 | + return array(); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - $cards = $this->braintree_customer->creditCards; |
|
| 177 | + $cards = $this->braintree_customer->creditCards; |
|
| 178 | 178 | |
| 179 | - $cards_array = array(); |
|
| 180 | - foreach ($cards as $card) { |
|
| 181 | - $cards_array[] = $this->card($card); |
|
| 182 | - } |
|
| 179 | + $cards_array = array(); |
|
| 180 | + foreach ($cards as $card) { |
|
| 181 | + $cards_array[] = $this->card($card); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - return $cards_array; |
|
| 185 | - } |
|
| 184 | + return $cards_array; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * Fetch a customer card instance. |
|
| 189 | - * |
|
| 190 | - * @param mixed $id |
|
| 191 | - * |
|
| 192 | - * @return Card |
|
| 193 | - */ |
|
| 194 | - public function card($id = null) |
|
| 195 | - { |
|
| 196 | - return new Card($this->gateway, $id); |
|
| 197 | - } |
|
| 187 | + /** |
|
| 188 | + * Fetch a customer card instance. |
|
| 189 | + * |
|
| 190 | + * @param mixed $id |
|
| 191 | + * |
|
| 192 | + * @return Card |
|
| 193 | + */ |
|
| 194 | + public function card($id = null) |
|
| 195 | + { |
|
| 196 | + return new Card($this->gateway, $id); |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * Gets all invoices for a customer. |
|
| 201 | - * |
|
| 202 | - * @return array |
|
| 203 | - */ |
|
| 204 | - public function invoices() |
|
| 205 | - { |
|
| 206 | - if (!$this->id) { |
|
| 207 | - return array(); |
|
| 208 | - } |
|
| 199 | + /** |
|
| 200 | + * Gets all invoices for a customer. |
|
| 201 | + * |
|
| 202 | + * @return array |
|
| 203 | + */ |
|
| 204 | + public function invoices() |
|
| 205 | + { |
|
| 206 | + if (!$this->id) { |
|
| 207 | + return array(); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - $invoices = Braintree_Transaction::search(array( |
|
| 211 | - Braintree_TransactionSearch::customerId()->is($this->id), |
|
| 212 | - )); |
|
| 210 | + $invoices = Braintree_Transaction::search(array( |
|
| 211 | + Braintree_TransactionSearch::customerId()->is($this->id), |
|
| 212 | + )); |
|
| 213 | 213 | |
| 214 | - $invoices_array = array(); |
|
| 215 | - foreach ($invoices as $invoice) { |
|
| 216 | - if (empty($invoice->subscriptionId)) { |
|
| 217 | - continue; |
|
| 218 | - } |
|
| 214 | + $invoices_array = array(); |
|
| 215 | + foreach ($invoices as $invoice) { |
|
| 216 | + if (empty($invoice->subscriptionId)) { |
|
| 217 | + continue; |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - $invoices_array[] = $this->invoice($invoice); |
|
| 221 | - } |
|
| 220 | + $invoices_array[] = $this->invoice($invoice); |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - return $invoices_array; |
|
| 224 | - } |
|
| 223 | + return $invoices_array; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Fetch an invoice instance. |
|
| 228 | - * |
|
| 229 | - * @param mixed $id |
|
| 230 | - * |
|
| 231 | - * @return Invoice |
|
| 232 | - */ |
|
| 233 | - public function invoice($id = null) |
|
| 234 | - { |
|
| 235 | - return new Invoice($this->gateway, $this->getNativeResponse(), $id); |
|
| 236 | - } |
|
| 226 | + /** |
|
| 227 | + * Fetch an invoice instance. |
|
| 228 | + * |
|
| 229 | + * @param mixed $id |
|
| 230 | + * |
|
| 231 | + * @return Invoice |
|
| 232 | + */ |
|
| 233 | + public function invoice($id = null) |
|
| 234 | + { |
|
| 235 | + return new Invoice($this->gateway, $this->getNativeResponse(), $id); |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * Gets all charges for a customer. |
|
| 240 | - * |
|
| 241 | - * @return array |
|
| 242 | - */ |
|
| 243 | - public function charges() |
|
| 244 | - { |
|
| 245 | - if (!$this->id) { |
|
| 246 | - return array(); |
|
| 247 | - } |
|
| 238 | + /** |
|
| 239 | + * Gets all charges for a customer. |
|
| 240 | + * |
|
| 241 | + * @return array |
|
| 242 | + */ |
|
| 243 | + public function charges() |
|
| 244 | + { |
|
| 245 | + if (!$this->id) { |
|
| 246 | + return array(); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - $charges = Braintree_Transaction::search(array( |
|
| 250 | - Braintree_TransactionSearch::customerId()->is($this->id), |
|
| 251 | - )); |
|
| 249 | + $charges = Braintree_Transaction::search(array( |
|
| 250 | + Braintree_TransactionSearch::customerId()->is($this->id), |
|
| 251 | + )); |
|
| 252 | 252 | |
| 253 | - $charges_array = array(); |
|
| 254 | - foreach ($charges as $charge) { |
|
| 255 | - $charges_array[] = $this->charge($charge); |
|
| 256 | - } |
|
| 253 | + $charges_array = array(); |
|
| 254 | + foreach ($charges as $charge) { |
|
| 255 | + $charges_array[] = $this->charge($charge); |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - return $charges_array; |
|
| 259 | - } |
|
| 258 | + return $charges_array; |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * Fetch an charge instance. |
|
| 263 | - * |
|
| 264 | - * @param mixed $id |
|
| 265 | - * |
|
| 266 | - * @return Charge |
|
| 267 | - */ |
|
| 268 | - public function charge($id = null) |
|
| 269 | - { |
|
| 270 | - return new Charge($this->gateway, $this->getNativeResponse(), $id); |
|
| 271 | - } |
|
| 261 | + /** |
|
| 262 | + * Fetch an charge instance. |
|
| 263 | + * |
|
| 264 | + * @param mixed $id |
|
| 265 | + * |
|
| 266 | + * @return Charge |
|
| 267 | + */ |
|
| 268 | + public function charge($id = null) |
|
| 269 | + { |
|
| 270 | + return new Charge($this->gateway, $this->getNativeResponse(), $id); |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * Gets the native customer response. |
|
| 275 | - * |
|
| 276 | - * @return Braintree_Customer |
|
| 277 | - */ |
|
| 278 | - public function getNativeResponse() |
|
| 279 | - { |
|
| 280 | - $this->info(); |
|
| 281 | - return $this->braintree_customer; |
|
| 282 | - } |
|
| 273 | + /** |
|
| 274 | + * Gets the native customer response. |
|
| 275 | + * |
|
| 276 | + * @return Braintree_Customer |
|
| 277 | + */ |
|
| 278 | + public function getNativeResponse() |
|
| 279 | + { |
|
| 280 | + $this->info(); |
|
| 281 | + return $this->braintree_customer; |
|
| 282 | + } |
|
| 283 | 283 | } |
@@ -44,8 +44,7 @@ |
||
| 44 | 44 | if ($id instanceof Braintree_Customer) { |
| 45 | 45 | $this->braintree_customer = $id; |
| 46 | 46 | $this->id = $this->braintree_customer->id; |
| 47 | - } |
|
| 48 | - else if (null !== $id) { |
|
| 47 | + } else if (null !== $id) { |
|
| 49 | 48 | $this->id = $id; |
| 50 | 49 | } |
| 51 | 50 | } |
@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php namespace Mmanos\Billing\Gateways\Braintree; |
| 2 | 2 | |
| 3 | 3 | use Mmanos\Billing\Gateways\InvoiceInterface; |
| 4 | -use Illuminate\Support\Arr; |
|
| 5 | 4 | use Braintree_Customer; |
| 6 | 5 | use Braintree_Transaction; |
| 7 | 6 | |
@@ -7,150 +7,150 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Invoice implements InvoiceInterface |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * The gateway instance. |
|
| 12 | - * |
|
| 13 | - * @var Gateway |
|
| 14 | - */ |
|
| 15 | - protected $gateway; |
|
| 10 | + /** |
|
| 11 | + * The gateway instance. |
|
| 12 | + * |
|
| 13 | + * @var Gateway |
|
| 14 | + */ |
|
| 15 | + protected $gateway; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Braintree customer object. |
|
| 19 | - * |
|
| 20 | - * @var Braintree_Customer |
|
| 21 | - */ |
|
| 22 | - protected $braintree_customer; |
|
| 17 | + /** |
|
| 18 | + * Braintree customer object. |
|
| 19 | + * |
|
| 20 | + * @var Braintree_Customer |
|
| 21 | + */ |
|
| 22 | + protected $braintree_customer; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Primary identifier. |
|
| 26 | - * |
|
| 27 | - * @var mixed |
|
| 28 | - */ |
|
| 29 | - protected $id; |
|
| 24 | + /** |
|
| 25 | + * Primary identifier. |
|
| 26 | + * |
|
| 27 | + * @var mixed |
|
| 28 | + */ |
|
| 29 | + protected $id; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Braintree invoice object. |
|
| 33 | - * |
|
| 34 | - * @var Braintree_Transaction |
|
| 35 | - */ |
|
| 36 | - protected $braintree_invoice; |
|
| 31 | + /** |
|
| 32 | + * Braintree invoice object. |
|
| 33 | + * |
|
| 34 | + * @var Braintree_Transaction |
|
| 35 | + */ |
|
| 36 | + protected $braintree_invoice; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Create a new Braintree invoice instance. |
|
| 40 | - * |
|
| 41 | - * @param Gateway $gateway |
|
| 42 | - * @param Braintree_Customer $customer |
|
| 43 | - * @param mixed $id |
|
| 44 | - * |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - public function __construct(Gateway $gateway, Braintree_Customer $customer = null, $id = null) |
|
| 48 | - { |
|
| 49 | - $this->gateway = $gateway; |
|
| 50 | - $this->braintree_customer = $customer; |
|
| 38 | + /** |
|
| 39 | + * Create a new Braintree invoice instance. |
|
| 40 | + * |
|
| 41 | + * @param Gateway $gateway |
|
| 42 | + * @param Braintree_Customer $customer |
|
| 43 | + * @param mixed $id |
|
| 44 | + * |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + public function __construct(Gateway $gateway, Braintree_Customer $customer = null, $id = null) |
|
| 48 | + { |
|
| 49 | + $this->gateway = $gateway; |
|
| 50 | + $this->braintree_customer = $customer; |
|
| 51 | 51 | |
| 52 | - if ($id instanceof Braintree_Transaction) { |
|
| 53 | - $this->braintree_invoice = $id; |
|
| 54 | - $this->id = $this->braintree_invoice->id; |
|
| 55 | - } |
|
| 56 | - else if (null !== $id) { |
|
| 57 | - $this->id = $id; |
|
| 58 | - } |
|
| 59 | - } |
|
| 52 | + if ($id instanceof Braintree_Transaction) { |
|
| 53 | + $this->braintree_invoice = $id; |
|
| 54 | + $this->id = $this->braintree_invoice->id; |
|
| 55 | + } |
|
| 56 | + else if (null !== $id) { |
|
| 57 | + $this->id = $id; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Gets the id of this instance. |
|
| 63 | - * |
|
| 64 | - * @return mixed |
|
| 65 | - */ |
|
| 66 | - public function id() |
|
| 67 | - { |
|
| 68 | - return $this->id; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Gets the id of this instance. |
|
| 63 | + * |
|
| 64 | + * @return mixed |
|
| 65 | + */ |
|
| 66 | + public function id() |
|
| 67 | + { |
|
| 68 | + return $this->id; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Gets info for an invoice. |
|
| 73 | - * |
|
| 74 | - * @return array|null |
|
| 75 | - */ |
|
| 76 | - public function info() |
|
| 77 | - { |
|
| 78 | - if (!$this->id || !$this->braintree_customer) { |
|
| 79 | - return null; |
|
| 80 | - } |
|
| 71 | + /** |
|
| 72 | + * Gets info for an invoice. |
|
| 73 | + * |
|
| 74 | + * @return array|null |
|
| 75 | + */ |
|
| 76 | + public function info() |
|
| 77 | + { |
|
| 78 | + if (!$this->id || !$this->braintree_customer) { |
|
| 79 | + return null; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - if (!$this->braintree_invoice) { |
|
| 83 | - $this->braintree_invoice = Braintree_Transaction::find($this->id); |
|
| 82 | + if (!$this->braintree_invoice) { |
|
| 83 | + $this->braintree_invoice = Braintree_Transaction::find($this->id); |
|
| 84 | 84 | |
| 85 | - if ($this->braintree_invoice->customer && $this->braintree_customer->id != $this->braintree_invoice->customer['id']) { |
|
| 86 | - return $this->braintree_invoice = null; |
|
| 87 | - } |
|
| 88 | - } |
|
| 85 | + if ($this->braintree_invoice->customer && $this->braintree_customer->id != $this->braintree_invoice->customer['id']) { |
|
| 86 | + return $this->braintree_invoice = null; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - if (!$this->braintree_invoice) { |
|
| 91 | - return null; |
|
| 92 | - } |
|
| 90 | + if (!$this->braintree_invoice) { |
|
| 91 | + return null; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - $discounts = array(); |
|
| 95 | - $total_off = 0; |
|
| 96 | - foreach ($this->braintree_invoice->discounts as $discount) { |
|
| 97 | - $discounts[] = array( |
|
| 98 | - 'coupon' => $discount->id, |
|
| 99 | - 'amount_off' => ((float) $discount->amount * 100), |
|
| 100 | - 'percent_off' => null, |
|
| 101 | - 'started_at' => null, |
|
| 102 | - 'ends_at' => null, |
|
| 103 | - ); |
|
| 104 | - $total_off += ((float) $discount->amount * 100); |
|
| 105 | - } |
|
| 94 | + $discounts = array(); |
|
| 95 | + $total_off = 0; |
|
| 96 | + foreach ($this->braintree_invoice->discounts as $discount) { |
|
| 97 | + $discounts[] = array( |
|
| 98 | + 'coupon' => $discount->id, |
|
| 99 | + 'amount_off' => ((float) $discount->amount * 100), |
|
| 100 | + 'percent_off' => null, |
|
| 101 | + 'started_at' => null, |
|
| 102 | + 'ends_at' => null, |
|
| 103 | + ); |
|
| 104 | + $total_off += ((float) $discount->amount * 100); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - $period_started_at = null; |
|
| 108 | - $period_ends_at = null; |
|
| 109 | - if ($this->braintree_invoice->subscriptionDetails) { |
|
| 110 | - if ($this->braintree_invoice->subscriptionDetails->billingPeriodStartDate) { |
|
| 111 | - $period_started_at = date('Y-m-d H:i:s', $this->braintree_invoice->subscriptionDetails->billingPeriodStartDate->getTimestamp()); |
|
| 112 | - } |
|
| 113 | - if ($this->braintree_invoice->subscriptionDetails->billingPeriodEndDate) { |
|
| 114 | - $period_ends_at = date('Y-m-d H:i:s', $this->braintree_invoice->subscriptionDetails->billingPeriodEndDate->getTimestamp()); |
|
| 115 | - } |
|
| 116 | - } |
|
| 107 | + $period_started_at = null; |
|
| 108 | + $period_ends_at = null; |
|
| 109 | + if ($this->braintree_invoice->subscriptionDetails) { |
|
| 110 | + if ($this->braintree_invoice->subscriptionDetails->billingPeriodStartDate) { |
|
| 111 | + $period_started_at = date('Y-m-d H:i:s', $this->braintree_invoice->subscriptionDetails->billingPeriodStartDate->getTimestamp()); |
|
| 112 | + } |
|
| 113 | + if ($this->braintree_invoice->subscriptionDetails->billingPeriodEndDate) { |
|
| 114 | + $period_ends_at = date('Y-m-d H:i:s', $this->braintree_invoice->subscriptionDetails->billingPeriodEndDate->getTimestamp()); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - $items = array(array( |
|
| 119 | - 'id' => $this->braintree_invoice->subscriptionId ?: 1, |
|
| 120 | - 'amount' => ((float) $this->braintree_invoice->amount * 100) + $total_off, |
|
| 121 | - 'period_start' => $period_started_at, |
|
| 122 | - 'period_end' => $period_ends_at, |
|
| 123 | - 'description' => null, |
|
| 124 | - 'subscription_id' => $this->braintree_invoice->subscriptionId, |
|
| 125 | - 'quantity' => 1, |
|
| 126 | - )); |
|
| 118 | + $items = array(array( |
|
| 119 | + 'id' => $this->braintree_invoice->subscriptionId ?: 1, |
|
| 120 | + 'amount' => ((float) $this->braintree_invoice->amount * 100) + $total_off, |
|
| 121 | + 'period_start' => $period_started_at, |
|
| 122 | + 'period_end' => $period_ends_at, |
|
| 123 | + 'description' => null, |
|
| 124 | + 'subscription_id' => $this->braintree_invoice->subscriptionId, |
|
| 125 | + 'quantity' => 1, |
|
| 126 | + )); |
|
| 127 | 127 | |
| 128 | - $paid = in_array($this->braintree_invoice->status, array('submitted_for_settlement', 'settled', 'settling')); |
|
| 129 | - $closed = $paid || in_array($this->braintree_invoice->status, array('voided')); |
|
| 128 | + $paid = in_array($this->braintree_invoice->status, array('submitted_for_settlement', 'settled', 'settling')); |
|
| 129 | + $closed = $paid || in_array($this->braintree_invoice->status, array('voided')); |
|
| 130 | 130 | |
| 131 | - return array( |
|
| 132 | - 'id' => $this->id, |
|
| 133 | - 'date' => date('Y-m-d H:i:s', $this->braintree_invoice->createdAt->getTimestamp()), |
|
| 134 | - 'total' => ((float) $this->braintree_invoice->amount * 100), |
|
| 135 | - 'subtotal' => ((float) $this->braintree_invoice->amount * 100) + $total_off, |
|
| 136 | - 'amount' => ((float) $this->braintree_invoice->amount * 100), |
|
| 137 | - 'starting_balance' => null, |
|
| 138 | - 'ending_balance' => null, |
|
| 139 | - 'closed' => $closed, |
|
| 140 | - 'paid' => $paid, |
|
| 141 | - 'discounts' => $discounts, |
|
| 142 | - 'items' => $items, |
|
| 143 | - ); |
|
| 144 | - } |
|
| 131 | + return array( |
|
| 132 | + 'id' => $this->id, |
|
| 133 | + 'date' => date('Y-m-d H:i:s', $this->braintree_invoice->createdAt->getTimestamp()), |
|
| 134 | + 'total' => ((float) $this->braintree_invoice->amount * 100), |
|
| 135 | + 'subtotal' => ((float) $this->braintree_invoice->amount * 100) + $total_off, |
|
| 136 | + 'amount' => ((float) $this->braintree_invoice->amount * 100), |
|
| 137 | + 'starting_balance' => null, |
|
| 138 | + 'ending_balance' => null, |
|
| 139 | + 'closed' => $closed, |
|
| 140 | + 'paid' => $paid, |
|
| 141 | + 'discounts' => $discounts, |
|
| 142 | + 'items' => $items, |
|
| 143 | + ); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Gets the native invoice response. |
|
| 148 | - * |
|
| 149 | - * @return Braintree_Transaction |
|
| 150 | - */ |
|
| 151 | - public function getNativeResponse() |
|
| 152 | - { |
|
| 153 | - $this->info(); |
|
| 154 | - return $this->braintree_invoice; |
|
| 155 | - } |
|
| 146 | + /** |
|
| 147 | + * Gets the native invoice response. |
|
| 148 | + * |
|
| 149 | + * @return Braintree_Transaction |
|
| 150 | + */ |
|
| 151 | + public function getNativeResponse() |
|
| 152 | + { |
|
| 153 | + $this->info(); |
|
| 154 | + return $this->braintree_invoice; |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -52,8 +52,7 @@ |
||
| 52 | 52 | if ($id instanceof Braintree_Transaction) { |
| 53 | 53 | $this->braintree_invoice = $id; |
| 54 | 54 | $this->id = $this->braintree_invoice->id; |
| 55 | - } |
|
| 56 | - else if (null !== $id) { |
|
| 55 | + } else if (null !== $id) { |
|
| 57 | 56 | $this->id = $id; |
| 58 | 57 | } |
| 59 | 58 | } |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | /** |
| 44 | 44 | * Fetch a customer instance. |
| 45 | 45 | * |
| 46 | - * @param mixed $id |
|
| 46 | + * @param Models\Customer $id |
|
| 47 | 47 | * |
| 48 | 48 | * @return Customer |
| 49 | 49 | */ |
@@ -8,100 +8,100 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Gateway implements GatewayInterface |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * Array of gateway connection/configuration properties. |
|
| 13 | - * |
|
| 14 | - * @var array |
|
| 15 | - */ |
|
| 16 | - protected $connection; |
|
| 11 | + /** |
|
| 12 | + * Array of gateway connection/configuration properties. |
|
| 13 | + * |
|
| 14 | + * @var array |
|
| 15 | + */ |
|
| 16 | + protected $connection; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Create a new Local gateway instance. |
|
| 20 | - * |
|
| 21 | - * @return void |
|
| 22 | - */ |
|
| 23 | - public function __construct($connection = null) |
|
| 24 | - { |
|
| 25 | - if (null === $connection) { |
|
| 26 | - $connection = Config::get('laravel-billing::gateways.local'); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Create a new Local gateway instance. |
|
| 20 | + * |
|
| 21 | + * @return void |
|
| 22 | + */ |
|
| 23 | + public function __construct($connection = null) |
|
| 24 | + { |
|
| 25 | + if (null === $connection) { |
|
| 26 | + $connection = Config::get('laravel-billing::gateways.local'); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - $this->connection = $connection; |
|
| 29 | + $this->connection = $connection; |
|
| 30 | 30 | |
| 31 | - Config::set('database.connections.billinglocal', Arr::get($connection, 'database')); |
|
| 31 | + Config::set('database.connections.billinglocal', Arr::get($connection, 'database')); |
|
| 32 | 32 | |
| 33 | - $path = Arr::get($connection, 'database.database'); |
|
| 34 | - if (!file_exists($path) && is_dir(dirname($path))) { |
|
| 35 | - touch($path); |
|
| 36 | - } |
|
| 33 | + $path = Arr::get($connection, 'database.database'); |
|
| 34 | + if (!file_exists($path) && is_dir(dirname($path))) { |
|
| 35 | + touch($path); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - if (!Schema::connection('billinglocal')->hasTable('customers')) { |
|
| 39 | - include_once 'Models/migration.php'; |
|
| 40 | - } |
|
| 41 | - } |
|
| 38 | + if (!Schema::connection('billinglocal')->hasTable('customers')) { |
|
| 39 | + include_once 'Models/migration.php'; |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Fetch a customer instance. |
|
| 45 | - * |
|
| 46 | - * @param mixed $id |
|
| 47 | - * |
|
| 48 | - * @return Customer |
|
| 49 | - */ |
|
| 50 | - public function customer($id = null) |
|
| 51 | - { |
|
| 52 | - return new Customer($this, $id); |
|
| 53 | - } |
|
| 43 | + /** |
|
| 44 | + * Fetch a customer instance. |
|
| 45 | + * |
|
| 46 | + * @param mixed $id |
|
| 47 | + * |
|
| 48 | + * @return Customer |
|
| 49 | + */ |
|
| 50 | + public function customer($id = null) |
|
| 51 | + { |
|
| 52 | + return new Customer($this, $id); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Fetch a subscription instance. |
|
| 57 | - * |
|
| 58 | - * @param mixed $id |
|
| 59 | - * @param Customer $customer |
|
| 60 | - * |
|
| 61 | - * @return Subscription |
|
| 62 | - */ |
|
| 63 | - public function subscription($id = null, CustomerInterface $customer = null) |
|
| 64 | - { |
|
| 65 | - if ($customer) { |
|
| 66 | - $customer = $customer->getNativeResponse(); |
|
| 67 | - } |
|
| 55 | + /** |
|
| 56 | + * Fetch a subscription instance. |
|
| 57 | + * |
|
| 58 | + * @param mixed $id |
|
| 59 | + * @param Customer $customer |
|
| 60 | + * |
|
| 61 | + * @return Subscription |
|
| 62 | + */ |
|
| 63 | + public function subscription($id = null, CustomerInterface $customer = null) |
|
| 64 | + { |
|
| 65 | + if ($customer) { |
|
| 66 | + $customer = $customer->getNativeResponse(); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - return new Subscription($this, $customer, $id); |
|
| 70 | - } |
|
| 69 | + return new Subscription($this, $customer, $id); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Fetch a charge instance. |
|
| 74 | - * |
|
| 75 | - * @param mixed $id |
|
| 76 | - * @param CustomerInterface $customer |
|
| 77 | - * |
|
| 78 | - * @return Charge |
|
| 79 | - */ |
|
| 80 | - public function charge($id = null, CustomerInterface $customer = null) |
|
| 81 | - { |
|
| 82 | - if ($customer) { |
|
| 83 | - $customer = $customer->getNativeResponse(); |
|
| 84 | - } |
|
| 72 | + /** |
|
| 73 | + * Fetch a charge instance. |
|
| 74 | + * |
|
| 75 | + * @param mixed $id |
|
| 76 | + * @param CustomerInterface $customer |
|
| 77 | + * |
|
| 78 | + * @return Charge |
|
| 79 | + */ |
|
| 80 | + public function charge($id = null, CustomerInterface $customer = null) |
|
| 81 | + { |
|
| 82 | + if ($customer) { |
|
| 83 | + $customer = $customer->getNativeResponse(); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - return new Charge($this, $customer, $id); |
|
| 87 | - } |
|
| 86 | + return new Charge($this, $customer, $id); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Simulate an API delay. |
|
| 91 | - * |
|
| 92 | - * @return void |
|
| 93 | - */ |
|
| 94 | - public function apiDelay() |
|
| 95 | - { |
|
| 96 | - $delay = Config::get('laravel-billing::gateways.local.api_delay_ms'); |
|
| 97 | - if (empty($delay)) { |
|
| 98 | - return; |
|
| 99 | - } |
|
| 89 | + /** |
|
| 90 | + * Simulate an API delay. |
|
| 91 | + * |
|
| 92 | + * @return void |
|
| 93 | + */ |
|
| 94 | + public function apiDelay() |
|
| 95 | + { |
|
| 96 | + $delay = Config::get('laravel-billing::gateways.local.api_delay_ms'); |
|
| 97 | + if (empty($delay)) { |
|
| 98 | + return; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - $ms = $delay * 1000; |
|
| 102 | - $threshold = $ms * .5; |
|
| 103 | - $sleep = rand($ms-$threshold, $ms+$threshold); |
|
| 101 | + $ms = $delay * 1000; |
|
| 102 | + $threshold = $ms * .5; |
|
| 103 | + $sleep = rand($ms-$threshold, $ms+$threshold); |
|
| 104 | 104 | |
| 105 | - usleep($sleep); |
|
| 106 | - } |
|
| 105 | + usleep($sleep); |
|
| 106 | + } |
|
| 107 | 107 | } |
@@ -100,7 +100,7 @@ |
||
| 100 | 100 | |
| 101 | 101 | $ms = $delay * 1000; |
| 102 | 102 | $threshold = $ms * .5; |
| 103 | - $sleep = rand($ms-$threshold, $ms+$threshold); |
|
| 103 | + $sleep = rand($ms - $threshold, $ms + $threshold); |
|
| 104 | 104 | |
| 105 | 105 | usleep($sleep); |
| 106 | 106 | } |
@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php namespace Mmanos\Billing\Gateways\Local; |
| 2 | 2 | |
| 3 | 3 | use Mmanos\Billing\Gateways\InvoiceInterface; |
| 4 | -use Illuminate\Support\Arr; |
|
| 5 | 4 | |
| 6 | 5 | class Invoice implements InvoiceInterface |
| 7 | 6 | { |
@@ -5,154 +5,154 @@ |
||
| 5 | 5 | |
| 6 | 6 | class Invoice implements InvoiceInterface |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * The gateway instance. |
|
| 10 | - * |
|
| 11 | - * @var Gateway |
|
| 12 | - */ |
|
| 13 | - protected $gateway; |
|
| 8 | + /** |
|
| 9 | + * The gateway instance. |
|
| 10 | + * |
|
| 11 | + * @var Gateway |
|
| 12 | + */ |
|
| 13 | + protected $gateway; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Local customer object. |
|
| 17 | - * |
|
| 18 | - * @var Models\Customer |
|
| 19 | - */ |
|
| 20 | - protected $local_customer; |
|
| 15 | + /** |
|
| 16 | + * Local customer object. |
|
| 17 | + * |
|
| 18 | + * @var Models\Customer |
|
| 19 | + */ |
|
| 20 | + protected $local_customer; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Primary identifier. |
|
| 24 | - * |
|
| 25 | - * @var mixed |
|
| 26 | - */ |
|
| 27 | - protected $id; |
|
| 22 | + /** |
|
| 23 | + * Primary identifier. |
|
| 24 | + * |
|
| 25 | + * @var mixed |
|
| 26 | + */ |
|
| 27 | + protected $id; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Local invoice object. |
|
| 31 | - * |
|
| 32 | - * @var Models\Invoice |
|
| 33 | - */ |
|
| 34 | - protected $local_invoice; |
|
| 29 | + /** |
|
| 30 | + * Local invoice object. |
|
| 31 | + * |
|
| 32 | + * @var Models\Invoice |
|
| 33 | + */ |
|
| 34 | + protected $local_invoice; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Create a new Local invoice instance. |
|
| 38 | - * |
|
| 39 | - * @param Gateway $gateway |
|
| 40 | - * @param Models\Customer $customer |
|
| 41 | - * @param mixed $id |
|
| 42 | - * |
|
| 43 | - * @return void |
|
| 44 | - */ |
|
| 45 | - public function __construct(Gateway $gateway, Models\Customer $customer = null, $id = null) |
|
| 46 | - { |
|
| 47 | - $this->gateway = $gateway; |
|
| 48 | - $this->local_customer = $customer; |
|
| 36 | + /** |
|
| 37 | + * Create a new Local invoice instance. |
|
| 38 | + * |
|
| 39 | + * @param Gateway $gateway |
|
| 40 | + * @param Models\Customer $customer |
|
| 41 | + * @param mixed $id |
|
| 42 | + * |
|
| 43 | + * @return void |
|
| 44 | + */ |
|
| 45 | + public function __construct(Gateway $gateway, Models\Customer $customer = null, $id = null) |
|
| 46 | + { |
|
| 47 | + $this->gateway = $gateway; |
|
| 48 | + $this->local_customer = $customer; |
|
| 49 | 49 | |
| 50 | - if ($id instanceof Models\Invoice) { |
|
| 51 | - $this->local_invoice = $id; |
|
| 52 | - $this->id = $this->local_invoice->id; |
|
| 53 | - } |
|
| 54 | - else if (null !== $id) { |
|
| 55 | - $this->id = $id; |
|
| 56 | - } |
|
| 57 | - } |
|
| 50 | + if ($id instanceof Models\Invoice) { |
|
| 51 | + $this->local_invoice = $id; |
|
| 52 | + $this->id = $this->local_invoice->id; |
|
| 53 | + } |
|
| 54 | + else if (null !== $id) { |
|
| 55 | + $this->id = $id; |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Gets the id of this instance. |
|
| 61 | - * |
|
| 62 | - * @return mixed |
|
| 63 | - */ |
|
| 64 | - public function id() |
|
| 65 | - { |
|
| 66 | - return $this->id; |
|
| 67 | - } |
|
| 59 | + /** |
|
| 60 | + * Gets the id of this instance. |
|
| 61 | + * |
|
| 62 | + * @return mixed |
|
| 63 | + */ |
|
| 64 | + public function id() |
|
| 65 | + { |
|
| 66 | + return $this->id; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Gets info for an invoice. |
|
| 71 | - * |
|
| 72 | - * @return array|null |
|
| 73 | - */ |
|
| 74 | - public function info() |
|
| 75 | - { |
|
| 76 | - if (!$this->id || !$this->local_customer) { |
|
| 77 | - return null; |
|
| 78 | - } |
|
| 69 | + /** |
|
| 70 | + * Gets info for an invoice. |
|
| 71 | + * |
|
| 72 | + * @return array|null |
|
| 73 | + */ |
|
| 74 | + public function info() |
|
| 75 | + { |
|
| 76 | + if (!$this->id || !$this->local_customer) { |
|
| 77 | + return null; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - if (!$this->local_invoice) { |
|
| 81 | - $this->local_invoice = $this->local_customer->invoices()->where('id', $this->id)->first(); |
|
| 82 | - $this->gateway->apiDelay(); |
|
| 83 | - } |
|
| 80 | + if (!$this->local_invoice) { |
|
| 81 | + $this->local_invoice = $this->local_customer->invoices()->where('id', $this->id)->first(); |
|
| 82 | + $this->gateway->apiDelay(); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - if (!$this->local_invoice) { |
|
| 86 | - return null; |
|
| 87 | - } |
|
| 85 | + if (!$this->local_invoice) { |
|
| 86 | + return null; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - $discounts = array(); |
|
| 90 | - if ($this->local_invoice->coupon) { |
|
| 91 | - $started_at = $this->local_invoice->subscription |
|
| 92 | - ? $this->local_invoice->subscription->created_at |
|
| 93 | - : $this->local_invoice->customer->created_at; |
|
| 89 | + $discounts = array(); |
|
| 90 | + if ($this->local_invoice->coupon) { |
|
| 91 | + $started_at = $this->local_invoice->subscription |
|
| 92 | + ? $this->local_invoice->subscription->created_at |
|
| 93 | + : $this->local_invoice->customer->created_at; |
|
| 94 | 94 | |
| 95 | - $ends_at = null; |
|
| 96 | - if ($this->local_invoice->coupon->duration_in_months) { |
|
| 97 | - if ($this->local_invoice->subscription) { |
|
| 98 | - $ends_at = $this->local_invoice->subscription->created_at->copy()->addMonths( |
|
| 99 | - $this->local_invoice->coupon->duration_in_months |
|
| 100 | - ); |
|
| 101 | - } |
|
| 102 | - else { |
|
| 103 | - $ends_at = $this->local_invoice->customer->created_at->copy()->addMonths( |
|
| 104 | - $this->local_invoice->coupon->duration_in_months |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - } |
|
| 95 | + $ends_at = null; |
|
| 96 | + if ($this->local_invoice->coupon->duration_in_months) { |
|
| 97 | + if ($this->local_invoice->subscription) { |
|
| 98 | + $ends_at = $this->local_invoice->subscription->created_at->copy()->addMonths( |
|
| 99 | + $this->local_invoice->coupon->duration_in_months |
|
| 100 | + ); |
|
| 101 | + } |
|
| 102 | + else { |
|
| 103 | + $ends_at = $this->local_invoice->customer->created_at->copy()->addMonths( |
|
| 104 | + $this->local_invoice->coupon->duration_in_months |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - $discounts[] = array( |
|
| 110 | - 'coupon' => $this->local_invoice->coupon->code, |
|
| 111 | - 'amount_off' => $this->local_invoice->coupon->amount_off, |
|
| 112 | - 'percent_off' => $this->local_invoice->coupon->percent_off, |
|
| 113 | - 'started_at' => (string) $started_at, |
|
| 114 | - 'ends_at' => $ends_at ? (string) $ends_at : null, |
|
| 115 | - ); |
|
| 116 | - } |
|
| 109 | + $discounts[] = array( |
|
| 110 | + 'coupon' => $this->local_invoice->coupon->code, |
|
| 111 | + 'amount_off' => $this->local_invoice->coupon->amount_off, |
|
| 112 | + 'percent_off' => $this->local_invoice->coupon->percent_off, |
|
| 113 | + 'started_at' => (string) $started_at, |
|
| 114 | + 'ends_at' => $ends_at ? (string) $ends_at : null, |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - $items = array(); |
|
| 119 | - foreach ($this->local_invoice->items as $line) { |
|
| 120 | - $item = array( |
|
| 121 | - 'id' => $line->id, |
|
| 122 | - 'amount' => $line->amount, |
|
| 123 | - 'period_start' => $line->period_started_at ? (string) $line->period_started_at : null, |
|
| 124 | - 'period_end' => $line->period_ends_at ? (string) $line->period_ends_at : null, |
|
| 125 | - 'description' => $line->description, |
|
| 126 | - 'subscription_id' => $line->subscription_id, |
|
| 127 | - 'quantity' => $line->quantity, |
|
| 128 | - ); |
|
| 118 | + $items = array(); |
|
| 119 | + foreach ($this->local_invoice->items as $line) { |
|
| 120 | + $item = array( |
|
| 121 | + 'id' => $line->id, |
|
| 122 | + 'amount' => $line->amount, |
|
| 123 | + 'period_start' => $line->period_started_at ? (string) $line->period_started_at : null, |
|
| 124 | + 'period_end' => $line->period_ends_at ? (string) $line->period_ends_at : null, |
|
| 125 | + 'description' => $line->description, |
|
| 126 | + 'subscription_id' => $line->subscription_id, |
|
| 127 | + 'quantity' => $line->quantity, |
|
| 128 | + ); |
|
| 129 | 129 | |
| 130 | - $items[] = $item; |
|
| 131 | - } |
|
| 130 | + $items[] = $item; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - return array( |
|
| 134 | - 'id' => $this->id, |
|
| 135 | - 'date' => (string) $this->local_invoice->period_started_at, |
|
| 136 | - 'total' => $this->local_invoice->subtotal, |
|
| 137 | - 'subtotal' => $this->local_invoice->subtotal, |
|
| 138 | - 'amount' => $this->local_invoice->amount, |
|
| 139 | - 'starting_balance' => 0, |
|
| 140 | - 'ending_balance' => 0, |
|
| 141 | - 'closed' => $this->local_invoice->closed, |
|
| 142 | - 'paid' => $this->local_invoice->paid, |
|
| 143 | - 'discounts' => $discounts, |
|
| 144 | - 'items' => $items, |
|
| 145 | - ); |
|
| 146 | - } |
|
| 133 | + return array( |
|
| 134 | + 'id' => $this->id, |
|
| 135 | + 'date' => (string) $this->local_invoice->period_started_at, |
|
| 136 | + 'total' => $this->local_invoice->subtotal, |
|
| 137 | + 'subtotal' => $this->local_invoice->subtotal, |
|
| 138 | + 'amount' => $this->local_invoice->amount, |
|
| 139 | + 'starting_balance' => 0, |
|
| 140 | + 'ending_balance' => 0, |
|
| 141 | + 'closed' => $this->local_invoice->closed, |
|
| 142 | + 'paid' => $this->local_invoice->paid, |
|
| 143 | + 'discounts' => $discounts, |
|
| 144 | + 'items' => $items, |
|
| 145 | + ); |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Gets the native invoice response. |
|
| 150 | - * |
|
| 151 | - * @return Models\Invoice |
|
| 152 | - */ |
|
| 153 | - public function getNativeResponse() |
|
| 154 | - { |
|
| 155 | - $this->info(); |
|
| 156 | - return $this->local_invoice; |
|
| 157 | - } |
|
| 148 | + /** |
|
| 149 | + * Gets the native invoice response. |
|
| 150 | + * |
|
| 151 | + * @return Models\Invoice |
|
| 152 | + */ |
|
| 153 | + public function getNativeResponse() |
|
| 154 | + { |
|
| 155 | + $this->info(); |
|
| 156 | + return $this->local_invoice; |
|
| 157 | + } |
|
| 158 | 158 | } |
@@ -50,8 +50,7 @@ discard block |
||
| 50 | 50 | if ($id instanceof Models\Invoice) { |
| 51 | 51 | $this->local_invoice = $id; |
| 52 | 52 | $this->id = $this->local_invoice->id; |
| 53 | - } |
|
| 54 | - else if (null !== $id) { |
|
| 53 | + } else if (null !== $id) { |
|
| 55 | 54 | $this->id = $id; |
| 56 | 55 | } |
| 57 | 56 | } |
@@ -98,8 +97,7 @@ discard block |
||
| 98 | 97 | $ends_at = $this->local_invoice->subscription->created_at->copy()->addMonths( |
| 99 | 98 | $this->local_invoice->coupon->duration_in_months |
| 100 | 99 | ); |
| 101 | - } |
|
| 102 | - else { |
|
| 100 | + } else { |
|
| 103 | 101 | $ends_at = $this->local_invoice->customer->created_at->copy()->addMonths( |
| 104 | 102 | $this->local_invoice->coupon->duration_in_months |
| 105 | 103 | ); |
@@ -2,7 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | use Illuminate\Database\Eloquent\Model; |
| 4 | 4 | use Illuminate\Database\Eloquent\SoftDeletingTrait; |
| 5 | -use Carbon\Carbon; |
|
| 6 | 5 | |
| 7 | 6 | class Subscription extends Model |
| 8 | 7 | { |
@@ -6,124 +6,124 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Subscription extends Model |
| 8 | 8 | { |
| 9 | - use SoftDeletingTrait; |
|
| 10 | - protected $connection = 'billinglocal'; |
|
| 11 | - protected $guarded = array('id'); |
|
| 12 | - protected $appends = array('period_started_at', 'period_ends_at'); |
|
| 13 | - protected $dates = array('period_started_at', 'period_ends_at', 'trial_ends_at', 'cancel_at'); |
|
| 9 | + use SoftDeletingTrait; |
|
| 10 | + protected $connection = 'billinglocal'; |
|
| 11 | + protected $guarded = array('id'); |
|
| 12 | + protected $appends = array('period_started_at', 'period_ends_at'); |
|
| 13 | + protected $dates = array('period_started_at', 'period_ends_at', 'trial_ends_at', 'cancel_at'); |
|
| 14 | 14 | |
| 15 | - public function customer() |
|
| 16 | - { |
|
| 17 | - return $this->belongsTo('Mmanos\Billing\Gateways\Local\Models\Customer')->withTrashed(); |
|
| 18 | - } |
|
| 15 | + public function customer() |
|
| 16 | + { |
|
| 17 | + return $this->belongsTo('Mmanos\Billing\Gateways\Local\Models\Customer')->withTrashed(); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - public function plan() |
|
| 21 | - { |
|
| 22 | - return $this->belongsTo('Mmanos\Billing\Gateways\Local\Models\Plan')->withTrashed(); |
|
| 23 | - } |
|
| 20 | + public function plan() |
|
| 21 | + { |
|
| 22 | + return $this->belongsTo('Mmanos\Billing\Gateways\Local\Models\Plan')->withTrashed(); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - public function card() |
|
| 26 | - { |
|
| 27 | - return $this->belongsTo('Mmanos\Billing\Gateways\Local\Models\Card'); |
|
| 28 | - } |
|
| 25 | + public function card() |
|
| 26 | + { |
|
| 27 | + return $this->belongsTo('Mmanos\Billing\Gateways\Local\Models\Card'); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function coupon() |
|
| 31 | - { |
|
| 32 | - return $this->belongsTo('Mmanos\Billing\Gateways\Local\Models\Coupon')->withTrashed(); |
|
| 33 | - } |
|
| 30 | + public function coupon() |
|
| 31 | + { |
|
| 32 | + return $this->belongsTo('Mmanos\Billing\Gateways\Local\Models\Coupon')->withTrashed(); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function getPeriodStartedAtAttribute($value) |
|
| 36 | - { |
|
| 37 | - if ($this->trial_ends_at && $this->trial_ends_at->timestamp > time()) { |
|
| 38 | - return $this->created_at; |
|
| 39 | - } |
|
| 35 | + public function getPeriodStartedAtAttribute($value) |
|
| 36 | + { |
|
| 37 | + if ($this->trial_ends_at && $this->trial_ends_at->timestamp > time()) { |
|
| 38 | + return $this->created_at; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - $first_started = $this->trial_ends_at ? $this->trial_ends_at : $this->created_at; |
|
| 42 | - $period_started = $first_started->copy(); |
|
| 43 | - while (!$period_started->isFuture()) { |
|
| 44 | - $this->plan->addInterval($period_started); |
|
| 45 | - } |
|
| 41 | + $first_started = $this->trial_ends_at ? $this->trial_ends_at : $this->created_at; |
|
| 42 | + $period_started = $first_started->copy(); |
|
| 43 | + while (!$period_started->isFuture()) { |
|
| 44 | + $this->plan->addInterval($period_started); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return $period_started; |
|
| 48 | - } |
|
| 47 | + return $period_started; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function getPeriodEndsAtAttribute($value) |
|
| 51 | - { |
|
| 52 | - if ($this->trial_ends_at && $this->trial_ends_at->timestamp > time()) { |
|
| 53 | - return $this->trial_ends_at; |
|
| 54 | - } |
|
| 50 | + public function getPeriodEndsAtAttribute($value) |
|
| 51 | + { |
|
| 52 | + if ($this->trial_ends_at && $this->trial_ends_at->timestamp > time()) { |
|
| 53 | + return $this->trial_ends_at; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $this->plan->addInterval($this->period_started_at->copy()); |
|
| 57 | - } |
|
| 56 | + return $this->plan->addInterval($this->period_started_at->copy()); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function gracePeriodEnded() |
|
| 60 | - { |
|
| 61 | - if (!$this->cancel_at) { |
|
| 62 | - return false; |
|
| 63 | - } |
|
| 59 | + public function gracePeriodEnded() |
|
| 60 | + { |
|
| 61 | + if (!$this->cancel_at) { |
|
| 62 | + return false; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - if ($this->cancel_at->timestamp > time()) { |
|
| 66 | - return false; |
|
| 67 | - } |
|
| 65 | + if ($this->cancel_at->timestamp > time()) { |
|
| 66 | + return false; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $this->delete(); |
|
| 69 | + $this->delete(); |
|
| 70 | 70 | |
| 71 | - return true; |
|
| 72 | - } |
|
| 71 | + return true; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - public function process() |
|
| 75 | - { |
|
| 76 | - if ($this->cancel_at || $this->trashed()) { |
|
| 77 | - return; |
|
| 78 | - } |
|
| 74 | + public function process() |
|
| 75 | + { |
|
| 76 | + if ($this->cancel_at || $this->trashed()) { |
|
| 77 | + return; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - $first_started = $this->trial_ends_at ? $this->trial_ends_at : $this->created_at; |
|
| 81 | - $period_started = $first_started->copy(); |
|
| 80 | + $first_started = $this->trial_ends_at ? $this->trial_ends_at : $this->created_at; |
|
| 81 | + $period_started = $first_started->copy(); |
|
| 82 | 82 | |
| 83 | - $oldest_invoice = $this->customer->invoices() |
|
| 84 | - ->where('subscription_id', $this->id) |
|
| 85 | - ->orderBy('period_started_at', 'DESC') |
|
| 86 | - ->first(); |
|
| 83 | + $oldest_invoice = $this->customer->invoices() |
|
| 84 | + ->where('subscription_id', $this->id) |
|
| 85 | + ->orderBy('period_started_at', 'DESC') |
|
| 86 | + ->first(); |
|
| 87 | 87 | |
| 88 | - $oldest_at = $oldest_invoice |
|
| 89 | - ? $oldest_invoice->period_started_at |
|
| 90 | - : $period_started->copy()->subDay(); |
|
| 88 | + $oldest_at = $oldest_invoice |
|
| 89 | + ? $oldest_invoice->period_started_at |
|
| 90 | + : $period_started->copy()->subDay(); |
|
| 91 | 91 | |
| 92 | - while (!$period_started->isFuture()) { |
|
| 93 | - if ($period_started->gt($oldest_at)) { |
|
| 94 | - $this->createInvoice( |
|
| 95 | - $period_started, |
|
| 96 | - !$this->customer->cards->isEmpty() |
|
| 97 | - ); |
|
| 98 | - } |
|
| 92 | + while (!$period_started->isFuture()) { |
|
| 93 | + if ($period_started->gt($oldest_at)) { |
|
| 94 | + $this->createInvoice( |
|
| 95 | + $period_started, |
|
| 96 | + !$this->customer->cards->isEmpty() |
|
| 97 | + ); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - $this->plan->addInterval($period_started); |
|
| 101 | - } |
|
| 102 | - } |
|
| 100 | + $this->plan->addInterval($period_started); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - public function createInvoice($period_started, $paid = true) |
|
| 105 | - { |
|
| 106 | - $period_end = $this->plan->addInterval($period_started->copy()); |
|
| 104 | + public function createInvoice($period_started, $paid = true) |
|
| 105 | + { |
|
| 106 | + $period_end = $this->plan->addInterval($period_started->copy()); |
|
| 107 | 107 | |
| 108 | - $invoice = Invoice::create(array( |
|
| 109 | - 'customer_id' => $this->customer->id, |
|
| 110 | - 'subscription_id' => $this->id, |
|
| 111 | - 'closed' => 0, |
|
| 112 | - 'paid' => (int) $paid, |
|
| 113 | - 'coupon_id' => $this->coupon_id, |
|
| 114 | - 'period_started_at' => $period_started, |
|
| 115 | - 'period_ends_at' => $period_end, |
|
| 116 | - )); |
|
| 108 | + $invoice = Invoice::create(array( |
|
| 109 | + 'customer_id' => $this->customer->id, |
|
| 110 | + 'subscription_id' => $this->id, |
|
| 111 | + 'closed' => 0, |
|
| 112 | + 'paid' => (int) $paid, |
|
| 113 | + 'coupon_id' => $this->coupon_id, |
|
| 114 | + 'period_started_at' => $period_started, |
|
| 115 | + 'period_ends_at' => $period_end, |
|
| 116 | + )); |
|
| 117 | 117 | |
| 118 | - Invoice\Item::create(array( |
|
| 119 | - 'invoice_id' => $invoice->id, |
|
| 120 | - 'subscription_id' => $this->id, |
|
| 121 | - 'description' => null, |
|
| 122 | - 'amount' => $this->plan->amount, |
|
| 123 | - 'period_started_at' => $period_started, |
|
| 124 | - 'period_ends_at' => $period_end, |
|
| 125 | - )); |
|
| 118 | + Invoice\Item::create(array( |
|
| 119 | + 'invoice_id' => $invoice->id, |
|
| 120 | + 'subscription_id' => $this->id, |
|
| 121 | + 'description' => null, |
|
| 122 | + 'amount' => $this->plan->amount, |
|
| 123 | + 'period_started_at' => $period_started, |
|
| 124 | + 'period_ends_at' => $period_end, |
|
| 125 | + )); |
|
| 126 | 126 | |
| 127 | - return $invoice; |
|
| 128 | - } |
|
| 127 | + return $invoice; |
|
| 128 | + } |
|
| 129 | 129 | } |
@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php namespace Mmanos\Billing\Gateways\Stripe; |
| 2 | 2 | |
| 3 | 3 | use Mmanos\Billing\Gateways\CardInterface; |
| 4 | -use Illuminate\Support\Arr; |
|
| 5 | 4 | use Stripe_Customer; |
| 6 | 5 | use Stripe_Card; |
| 7 | 6 | |
@@ -7,186 +7,186 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Card implements CardInterface |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * The gateway instance. |
|
| 12 | - * |
|
| 13 | - * @var Gateway |
|
| 14 | - */ |
|
| 15 | - protected $gateway; |
|
| 10 | + /** |
|
| 11 | + * The gateway instance. |
|
| 12 | + * |
|
| 13 | + * @var Gateway |
|
| 14 | + */ |
|
| 15 | + protected $gateway; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Stripe customer object. |
|
| 19 | - * |
|
| 20 | - * @var Stripe_Customer |
|
| 21 | - */ |
|
| 22 | - protected $stripe_customer; |
|
| 17 | + /** |
|
| 18 | + * Stripe customer object. |
|
| 19 | + * |
|
| 20 | + * @var Stripe_Customer |
|
| 21 | + */ |
|
| 22 | + protected $stripe_customer; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Primary identifier. |
|
| 26 | - * |
|
| 27 | - * @var mixed |
|
| 28 | - */ |
|
| 29 | - protected $id; |
|
| 24 | + /** |
|
| 25 | + * Primary identifier. |
|
| 26 | + * |
|
| 27 | + * @var mixed |
|
| 28 | + */ |
|
| 29 | + protected $id; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Stripe card object. |
|
| 33 | - * |
|
| 34 | - * @var Stripe_Card |
|
| 35 | - */ |
|
| 36 | - protected $stripe_card; |
|
| 31 | + /** |
|
| 32 | + * Stripe card object. |
|
| 33 | + * |
|
| 34 | + * @var Stripe_Card |
|
| 35 | + */ |
|
| 36 | + protected $stripe_card; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Create a new Stripe card instance. |
|
| 40 | - * |
|
| 41 | - * @param Gateway $gateway |
|
| 42 | - * @param Stripe_Customer $customer |
|
| 43 | - * @param mixed $id |
|
| 44 | - * |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - public function __construct(Gateway $gateway, Stripe_Customer $customer = null, $id = null) |
|
| 48 | - { |
|
| 49 | - $this->gateway = $gateway; |
|
| 50 | - $this->stripe_customer = $customer; |
|
| 38 | + /** |
|
| 39 | + * Create a new Stripe card instance. |
|
| 40 | + * |
|
| 41 | + * @param Gateway $gateway |
|
| 42 | + * @param Stripe_Customer $customer |
|
| 43 | + * @param mixed $id |
|
| 44 | + * |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + public function __construct(Gateway $gateway, Stripe_Customer $customer = null, $id = null) |
|
| 48 | + { |
|
| 49 | + $this->gateway = $gateway; |
|
| 50 | + $this->stripe_customer = $customer; |
|
| 51 | 51 | |
| 52 | - if ($id instanceof Stripe_Card) { |
|
| 53 | - $this->stripe_card = $id; |
|
| 54 | - $this->id = $this->stripe_card->id; |
|
| 55 | - } |
|
| 56 | - else if (null !== $id) { |
|
| 57 | - $this->id = $id; |
|
| 58 | - } |
|
| 59 | - } |
|
| 52 | + if ($id instanceof Stripe_Card) { |
|
| 53 | + $this->stripe_card = $id; |
|
| 54 | + $this->id = $this->stripe_card->id; |
|
| 55 | + } |
|
| 56 | + else if (null !== $id) { |
|
| 57 | + $this->id = $id; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Gets the id of this instance. |
|
| 63 | - * |
|
| 64 | - * @return mixed |
|
| 65 | - */ |
|
| 66 | - public function id() |
|
| 67 | - { |
|
| 68 | - return $this->id; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Gets the id of this instance. |
|
| 63 | + * |
|
| 64 | + * @return mixed |
|
| 65 | + */ |
|
| 66 | + public function id() |
|
| 67 | + { |
|
| 68 | + return $this->id; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Gets info for a card. |
|
| 73 | - * |
|
| 74 | - * @return array|null |
|
| 75 | - */ |
|
| 76 | - public function info() |
|
| 77 | - { |
|
| 78 | - if (!$this->id || !$this->stripe_customer) { |
|
| 79 | - return null; |
|
| 80 | - } |
|
| 71 | + /** |
|
| 72 | + * Gets info for a card. |
|
| 73 | + * |
|
| 74 | + * @return array|null |
|
| 75 | + */ |
|
| 76 | + public function info() |
|
| 77 | + { |
|
| 78 | + if (!$this->id || !$this->stripe_customer) { |
|
| 79 | + return null; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - if (!$this->stripe_card) { |
|
| 83 | - $this->stripe_card = $this->stripe_customer->cards->retrieve($this->id); |
|
| 84 | - } |
|
| 82 | + if (!$this->stripe_card) { |
|
| 83 | + $this->stripe_card = $this->stripe_customer->cards->retrieve($this->id); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - if (!$this->stripe_card) { |
|
| 87 | - return null; |
|
| 88 | - } |
|
| 86 | + if (!$this->stripe_card) { |
|
| 87 | + return null; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - return array( |
|
| 91 | - 'id' => $this->id, |
|
| 92 | - 'last4' => $this->stripe_card->last4, |
|
| 93 | - 'brand' => $this->stripe_card->brand, |
|
| 94 | - 'exp_month' => $this->stripe_card->exp_month, |
|
| 95 | - 'exp_year' => $this->stripe_card->exp_year, |
|
| 96 | - 'name' => $this->stripe_card->name, |
|
| 97 | - 'address_line1' => $this->stripe_card->address_line1, |
|
| 98 | - 'address_line2' => $this->stripe_card->address_line2, |
|
| 99 | - 'address_city' => $this->stripe_card->address_city, |
|
| 100 | - 'address_state' => $this->stripe_card->address_state, |
|
| 101 | - 'address_zip' => $this->stripe_card->address_zip, |
|
| 102 | - 'address_country' => $this->stripe_card->address_country, |
|
| 103 | - ); |
|
| 104 | - } |
|
| 90 | + return array( |
|
| 91 | + 'id' => $this->id, |
|
| 92 | + 'last4' => $this->stripe_card->last4, |
|
| 93 | + 'brand' => $this->stripe_card->brand, |
|
| 94 | + 'exp_month' => $this->stripe_card->exp_month, |
|
| 95 | + 'exp_year' => $this->stripe_card->exp_year, |
|
| 96 | + 'name' => $this->stripe_card->name, |
|
| 97 | + 'address_line1' => $this->stripe_card->address_line1, |
|
| 98 | + 'address_line2' => $this->stripe_card->address_line2, |
|
| 99 | + 'address_city' => $this->stripe_card->address_city, |
|
| 100 | + 'address_state' => $this->stripe_card->address_state, |
|
| 101 | + 'address_zip' => $this->stripe_card->address_zip, |
|
| 102 | + 'address_country' => $this->stripe_card->address_country, |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Create a new card. |
|
| 108 | - * |
|
| 109 | - * @param string $card_token |
|
| 110 | - * |
|
| 111 | - * @return Card |
|
| 112 | - */ |
|
| 113 | - public function create($card_token) |
|
| 114 | - { |
|
| 115 | - $stripe_card = $this->stripe_customer->cards->create(array( |
|
| 116 | - 'card' => $card_token, |
|
| 117 | - )); |
|
| 106 | + /** |
|
| 107 | + * Create a new card. |
|
| 108 | + * |
|
| 109 | + * @param string $card_token |
|
| 110 | + * |
|
| 111 | + * @return Card |
|
| 112 | + */ |
|
| 113 | + public function create($card_token) |
|
| 114 | + { |
|
| 115 | + $stripe_card = $this->stripe_customer->cards->create(array( |
|
| 116 | + 'card' => $card_token, |
|
| 117 | + )); |
|
| 118 | 118 | |
| 119 | - $this->id = $stripe_card->id; |
|
| 119 | + $this->id = $stripe_card->id; |
|
| 120 | 120 | |
| 121 | - return $this; |
|
| 122 | - } |
|
| 121 | + return $this; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Update a card. |
|
| 126 | - * |
|
| 127 | - * @param array $properties |
|
| 128 | - * |
|
| 129 | - * @return Card |
|
| 130 | - */ |
|
| 131 | - public function update(array $properties = array()) |
|
| 132 | - { |
|
| 133 | - $this->info(); |
|
| 124 | + /** |
|
| 125 | + * Update a card. |
|
| 126 | + * |
|
| 127 | + * @param array $properties |
|
| 128 | + * |
|
| 129 | + * @return Card |
|
| 130 | + */ |
|
| 131 | + public function update(array $properties = array()) |
|
| 132 | + { |
|
| 133 | + $this->info(); |
|
| 134 | 134 | |
| 135 | - if (!empty($properties['name'])) { |
|
| 136 | - $this->stripe_card->name = $properties['name']; |
|
| 137 | - } |
|
| 138 | - if (!empty($properties['exp_month'])) { |
|
| 139 | - $this->stripe_card->exp_month = $properties['exp_month']; |
|
| 140 | - } |
|
| 141 | - if (!empty($properties['exp_year'])) { |
|
| 142 | - $this->stripe_card->exp_year = $properties['exp_year']; |
|
| 143 | - } |
|
| 144 | - if (!empty($properties['address_line1'])) { |
|
| 145 | - $this->stripe_card->address_line1 = $properties['address_line1']; |
|
| 146 | - } |
|
| 147 | - if (!empty($properties['address_line2'])) { |
|
| 148 | - $this->stripe_card->address_line2 = $properties['address_line2']; |
|
| 149 | - } |
|
| 150 | - if (!empty($properties['address_city'])) { |
|
| 151 | - $this->stripe_card->address_city = $properties['address_city']; |
|
| 152 | - } |
|
| 153 | - if (!empty($properties['address_state'])) { |
|
| 154 | - $this->stripe_card->address_state = $properties['address_state']; |
|
| 155 | - } |
|
| 156 | - if (!empty($properties['address_zip'])) { |
|
| 157 | - $this->stripe_card->address_zip = $properties['address_zip']; |
|
| 158 | - } |
|
| 159 | - if (!empty($properties['address_country'])) { |
|
| 160 | - $this->stripe_card->address_country = $properties['address_country']; |
|
| 161 | - } |
|
| 135 | + if (!empty($properties['name'])) { |
|
| 136 | + $this->stripe_card->name = $properties['name']; |
|
| 137 | + } |
|
| 138 | + if (!empty($properties['exp_month'])) { |
|
| 139 | + $this->stripe_card->exp_month = $properties['exp_month']; |
|
| 140 | + } |
|
| 141 | + if (!empty($properties['exp_year'])) { |
|
| 142 | + $this->stripe_card->exp_year = $properties['exp_year']; |
|
| 143 | + } |
|
| 144 | + if (!empty($properties['address_line1'])) { |
|
| 145 | + $this->stripe_card->address_line1 = $properties['address_line1']; |
|
| 146 | + } |
|
| 147 | + if (!empty($properties['address_line2'])) { |
|
| 148 | + $this->stripe_card->address_line2 = $properties['address_line2']; |
|
| 149 | + } |
|
| 150 | + if (!empty($properties['address_city'])) { |
|
| 151 | + $this->stripe_card->address_city = $properties['address_city']; |
|
| 152 | + } |
|
| 153 | + if (!empty($properties['address_state'])) { |
|
| 154 | + $this->stripe_card->address_state = $properties['address_state']; |
|
| 155 | + } |
|
| 156 | + if (!empty($properties['address_zip'])) { |
|
| 157 | + $this->stripe_card->address_zip = $properties['address_zip']; |
|
| 158 | + } |
|
| 159 | + if (!empty($properties['address_country'])) { |
|
| 160 | + $this->stripe_card->address_country = $properties['address_country']; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - $this->stripe_card->save(); |
|
| 164 | - $this->stripe_card = null; |
|
| 163 | + $this->stripe_card->save(); |
|
| 164 | + $this->stripe_card = null; |
|
| 165 | 165 | |
| 166 | - return $this; |
|
| 167 | - } |
|
| 166 | + return $this; |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Delete a card. |
|
| 171 | - * |
|
| 172 | - * @return Card |
|
| 173 | - */ |
|
| 174 | - public function delete() |
|
| 175 | - { |
|
| 176 | - $this->info(); |
|
| 177 | - $this->stripe_card->delete(); |
|
| 178 | - $this->stripe_card = null; |
|
| 179 | - return $this; |
|
| 180 | - } |
|
| 169 | + /** |
|
| 170 | + * Delete a card. |
|
| 171 | + * |
|
| 172 | + * @return Card |
|
| 173 | + */ |
|
| 174 | + public function delete() |
|
| 175 | + { |
|
| 176 | + $this->info(); |
|
| 177 | + $this->stripe_card->delete(); |
|
| 178 | + $this->stripe_card = null; |
|
| 179 | + return $this; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Gets the native card response. |
|
| 184 | - * |
|
| 185 | - * @return Stripe_Card |
|
| 186 | - */ |
|
| 187 | - public function getNativeResponse() |
|
| 188 | - { |
|
| 189 | - $this->info(); |
|
| 190 | - return $this->stripe_card; |
|
| 191 | - } |
|
| 182 | + /** |
|
| 183 | + * Gets the native card response. |
|
| 184 | + * |
|
| 185 | + * @return Stripe_Card |
|
| 186 | + */ |
|
| 187 | + public function getNativeResponse() |
|
| 188 | + { |
|
| 189 | + $this->info(); |
|
| 190 | + return $this->stripe_card; |
|
| 191 | + } |
|
| 192 | 192 | } |
@@ -52,8 +52,7 @@ |
||
| 52 | 52 | if ($id instanceof Stripe_Card) { |
| 53 | 53 | $this->stripe_card = $id; |
| 54 | 54 | $this->id = $this->stripe_card->id; |
| 55 | - } |
|
| 56 | - else if (null !== $id) { |
|
| 55 | + } else if (null !== $id) { |
|
| 57 | 56 | $this->id = $id; |
| 58 | 57 | } |
| 59 | 58 | } |
@@ -300,7 +300,7 @@ |
||
| 300 | 300 | /** |
| 301 | 301 | * Gets the native customer response. |
| 302 | 302 | * |
| 303 | - * @return Stripe_Customer |
|
| 303 | + * @return null|Stripe_Customer |
|
| 304 | 304 | */ |
| 305 | 305 | public function getNativeResponse() |
| 306 | 306 | { |
@@ -8,303 +8,303 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Customer implements CustomerInterface |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The gateway instance. |
|
| 13 | - * |
|
| 14 | - * @var Gateway |
|
| 15 | - */ |
|
| 16 | - protected $gateway; |
|
| 11 | + /** |
|
| 12 | + * The gateway instance. |
|
| 13 | + * |
|
| 14 | + * @var Gateway |
|
| 15 | + */ |
|
| 16 | + protected $gateway; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Primary identifier. |
|
| 20 | - * |
|
| 21 | - * @var mixed |
|
| 22 | - */ |
|
| 23 | - protected $id; |
|
| 18 | + /** |
|
| 19 | + * Primary identifier. |
|
| 20 | + * |
|
| 21 | + * @var mixed |
|
| 22 | + */ |
|
| 23 | + protected $id; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Stripe customer object. |
|
| 27 | - * |
|
| 28 | - * @var Stripe_Customer |
|
| 29 | - */ |
|
| 30 | - protected $stripe_customer; |
|
| 25 | + /** |
|
| 26 | + * Stripe customer object. |
|
| 27 | + * |
|
| 28 | + * @var Stripe_Customer |
|
| 29 | + */ |
|
| 30 | + protected $stripe_customer; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Create a new Stripe customer instance. |
|
| 34 | - * |
|
| 35 | - * @param Gateway $gateway |
|
| 36 | - * @param mixed $id |
|
| 37 | - * |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public function __construct(Gateway $gateway, $id = null) |
|
| 41 | - { |
|
| 42 | - $this->gateway = $gateway; |
|
| 32 | + /** |
|
| 33 | + * Create a new Stripe customer instance. |
|
| 34 | + * |
|
| 35 | + * @param Gateway $gateway |
|
| 36 | + * @param mixed $id |
|
| 37 | + * |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public function __construct(Gateway $gateway, $id = null) |
|
| 41 | + { |
|
| 42 | + $this->gateway = $gateway; |
|
| 43 | 43 | |
| 44 | - if ($id instanceof Stripe_Customer) { |
|
| 45 | - $this->stripe_customer = $id; |
|
| 46 | - $this->id = $this->stripe_customer->id; |
|
| 47 | - } |
|
| 48 | - else if (null !== $id) { |
|
| 49 | - $this->id = $id; |
|
| 50 | - } |
|
| 51 | - } |
|
| 44 | + if ($id instanceof Stripe_Customer) { |
|
| 45 | + $this->stripe_customer = $id; |
|
| 46 | + $this->id = $this->stripe_customer->id; |
|
| 47 | + } |
|
| 48 | + else if (null !== $id) { |
|
| 49 | + $this->id = $id; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Gets the id of this instance. |
|
| 55 | - * |
|
| 56 | - * @return mixed |
|
| 57 | - */ |
|
| 58 | - public function id() |
|
| 59 | - { |
|
| 60 | - return $this->id; |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * Gets the id of this instance. |
|
| 55 | + * |
|
| 56 | + * @return mixed |
|
| 57 | + */ |
|
| 58 | + public function id() |
|
| 59 | + { |
|
| 60 | + return $this->id; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Gets info for a customer. |
|
| 65 | - * |
|
| 66 | - * @return array|null |
|
| 67 | - */ |
|
| 68 | - public function info() |
|
| 69 | - { |
|
| 70 | - if (!$this->id) { |
|
| 71 | - return null; |
|
| 72 | - } |
|
| 63 | + /** |
|
| 64 | + * Gets info for a customer. |
|
| 65 | + * |
|
| 66 | + * @return array|null |
|
| 67 | + */ |
|
| 68 | + public function info() |
|
| 69 | + { |
|
| 70 | + if (!$this->id) { |
|
| 71 | + return null; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - if (!$this->stripe_customer) { |
|
| 75 | - $this->stripe_customer = Stripe_Customer::retrieve($this->id); |
|
| 76 | - } |
|
| 74 | + if (!$this->stripe_customer) { |
|
| 75 | + $this->stripe_customer = Stripe_Customer::retrieve($this->id); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - if (!$this->stripe_customer || property_exists($this->stripe_customer, 'deleted')) { |
|
| 79 | - return null; |
|
| 80 | - } |
|
| 78 | + if (!$this->stripe_customer || property_exists($this->stripe_customer, 'deleted')) { |
|
| 79 | + return null; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - $discounts = array(); |
|
| 83 | - if ($this->stripe_customer->discount) { |
|
| 84 | - $discounts[] = array( |
|
| 85 | - 'coupon' => $this->stripe_customer->discount->coupon->id, |
|
| 86 | - 'amount_off' => $this->stripe_customer->discount->coupon->amount_off, |
|
| 87 | - 'percent_off' => $this->stripe_customer->discount->coupon->percent_off, |
|
| 88 | - 'started_at' => date('Y-m-d H:i:s', $this->stripe_customer->discount->start), |
|
| 89 | - 'ends_at' => $this->stripe_customer->discount->end ? date('Y-m-d H:i:s', $this->stripe_customer->discount->end) : null, |
|
| 90 | - ); |
|
| 91 | - } |
|
| 82 | + $discounts = array(); |
|
| 83 | + if ($this->stripe_customer->discount) { |
|
| 84 | + $discounts[] = array( |
|
| 85 | + 'coupon' => $this->stripe_customer->discount->coupon->id, |
|
| 86 | + 'amount_off' => $this->stripe_customer->discount->coupon->amount_off, |
|
| 87 | + 'percent_off' => $this->stripe_customer->discount->coupon->percent_off, |
|
| 88 | + 'started_at' => date('Y-m-d H:i:s', $this->stripe_customer->discount->start), |
|
| 89 | + 'ends_at' => $this->stripe_customer->discount->end ? date('Y-m-d H:i:s', $this->stripe_customer->discount->end) : null, |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return array( |
|
| 94 | - 'id' => $this->id, |
|
| 95 | - 'description' => $this->stripe_customer->description, |
|
| 96 | - 'email' => $this->stripe_customer->email, |
|
| 97 | - 'created_at' => date('Y-m-d H:i:s', $this->stripe_customer->created), |
|
| 98 | - 'discounts' => $discounts, |
|
| 99 | - ); |
|
| 100 | - } |
|
| 93 | + return array( |
|
| 94 | + 'id' => $this->id, |
|
| 95 | + 'description' => $this->stripe_customer->description, |
|
| 96 | + 'email' => $this->stripe_customer->email, |
|
| 97 | + 'created_at' => date('Y-m-d H:i:s', $this->stripe_customer->created), |
|
| 98 | + 'discounts' => $discounts, |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Create a new customer. |
|
| 104 | - * |
|
| 105 | - * @param array $properties |
|
| 106 | - * |
|
| 107 | - * @return Customer |
|
| 108 | - */ |
|
| 109 | - public function create(array $properties = array()) |
|
| 110 | - { |
|
| 111 | - $stripe_customer = Stripe_Customer::create(array( |
|
| 112 | - 'description' => Arr::get($properties, 'description') ? Arr::get($properties, 'description') : null, |
|
| 113 | - 'email' => Arr::get($properties, 'email') ? Arr::get($properties, 'email') : null, |
|
| 114 | - 'coupon' => Arr::get($properties, 'coupon') ? Arr::get($properties, 'coupon') : null, |
|
| 115 | - 'card' => Arr::get($properties, 'card_token') ? Arr::get($properties, 'card_token') : null, |
|
| 116 | - )); |
|
| 102 | + /** |
|
| 103 | + * Create a new customer. |
|
| 104 | + * |
|
| 105 | + * @param array $properties |
|
| 106 | + * |
|
| 107 | + * @return Customer |
|
| 108 | + */ |
|
| 109 | + public function create(array $properties = array()) |
|
| 110 | + { |
|
| 111 | + $stripe_customer = Stripe_Customer::create(array( |
|
| 112 | + 'description' => Arr::get($properties, 'description') ? Arr::get($properties, 'description') : null, |
|
| 113 | + 'email' => Arr::get($properties, 'email') ? Arr::get($properties, 'email') : null, |
|
| 114 | + 'coupon' => Arr::get($properties, 'coupon') ? Arr::get($properties, 'coupon') : null, |
|
| 115 | + 'card' => Arr::get($properties, 'card_token') ? Arr::get($properties, 'card_token') : null, |
|
| 116 | + )); |
|
| 117 | 117 | |
| 118 | - $this->id = $stripe_customer->id; |
|
| 118 | + $this->id = $stripe_customer->id; |
|
| 119 | 119 | |
| 120 | - return $this; |
|
| 121 | - } |
|
| 120 | + return $this; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Update a customer. |
|
| 125 | - * |
|
| 126 | - * @param array $properties |
|
| 127 | - * |
|
| 128 | - * @return Customer |
|
| 129 | - */ |
|
| 130 | - public function update(array $properties = array()) |
|
| 131 | - { |
|
| 132 | - $this->info(); |
|
| 123 | + /** |
|
| 124 | + * Update a customer. |
|
| 125 | + * |
|
| 126 | + * @param array $properties |
|
| 127 | + * |
|
| 128 | + * @return Customer |
|
| 129 | + */ |
|
| 130 | + public function update(array $properties = array()) |
|
| 131 | + { |
|
| 132 | + $this->info(); |
|
| 133 | 133 | |
| 134 | - if (!empty($properties['description'])) { |
|
| 135 | - $this->stripe_customer->description = $properties['description']; |
|
| 136 | - } |
|
| 137 | - if (!empty($properties['email'])) { |
|
| 138 | - $this->stripe_customer->email = $properties['email']; |
|
| 139 | - } |
|
| 140 | - if (!empty($properties['coupon'])) { |
|
| 141 | - $this->stripe_customer->coupon = $properties['coupon']; |
|
| 142 | - } |
|
| 143 | - if (!empty($properties['card_token'])) { |
|
| 144 | - $this->stripe_customer->card = $properties['card_token']; |
|
| 145 | - } |
|
| 134 | + if (!empty($properties['description'])) { |
|
| 135 | + $this->stripe_customer->description = $properties['description']; |
|
| 136 | + } |
|
| 137 | + if (!empty($properties['email'])) { |
|
| 138 | + $this->stripe_customer->email = $properties['email']; |
|
| 139 | + } |
|
| 140 | + if (!empty($properties['coupon'])) { |
|
| 141 | + $this->stripe_customer->coupon = $properties['coupon']; |
|
| 142 | + } |
|
| 143 | + if (!empty($properties['card_token'])) { |
|
| 144 | + $this->stripe_customer->card = $properties['card_token']; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - $this->stripe_customer->save(); |
|
| 148 | - $this->stripe_customer = null; |
|
| 147 | + $this->stripe_customer->save(); |
|
| 148 | + $this->stripe_customer = null; |
|
| 149 | 149 | |
| 150 | - return $this; |
|
| 151 | - } |
|
| 150 | + return $this; |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Delete a customer. |
|
| 155 | - * |
|
| 156 | - * @return Customer |
|
| 157 | - */ |
|
| 158 | - public function delete() |
|
| 159 | - { |
|
| 160 | - $this->info(); |
|
| 161 | - $this->stripe_customer->delete(); |
|
| 162 | - $this->stripe_customer = null; |
|
| 163 | - return $this; |
|
| 164 | - } |
|
| 153 | + /** |
|
| 154 | + * Delete a customer. |
|
| 155 | + * |
|
| 156 | + * @return Customer |
|
| 157 | + */ |
|
| 158 | + public function delete() |
|
| 159 | + { |
|
| 160 | + $this->info(); |
|
| 161 | + $this->stripe_customer->delete(); |
|
| 162 | + $this->stripe_customer = null; |
|
| 163 | + return $this; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Gets all subscriptions for a customer. |
|
| 168 | - * |
|
| 169 | - * @return array |
|
| 170 | - */ |
|
| 171 | - public function subscriptions() |
|
| 172 | - { |
|
| 173 | - $this->info(); |
|
| 166 | + /** |
|
| 167 | + * Gets all subscriptions for a customer. |
|
| 168 | + * |
|
| 169 | + * @return array |
|
| 170 | + */ |
|
| 171 | + public function subscriptions() |
|
| 172 | + { |
|
| 173 | + $this->info(); |
|
| 174 | 174 | |
| 175 | - if (!$this->stripe_customer) { |
|
| 176 | - return array(); |
|
| 177 | - } |
|
| 175 | + if (!$this->stripe_customer) { |
|
| 176 | + return array(); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - $subscriptions = $this->stripe_customer->subscriptions->all(); |
|
| 179 | + $subscriptions = $this->stripe_customer->subscriptions->all(); |
|
| 180 | 180 | |
| 181 | - $subscriptions_array = array(); |
|
| 182 | - foreach ($subscriptions->data as $subscription) { |
|
| 183 | - $subscriptions_array[] = $this->gateway->subscription($subscription, $this); |
|
| 184 | - } |
|
| 181 | + $subscriptions_array = array(); |
|
| 182 | + foreach ($subscriptions->data as $subscription) { |
|
| 183 | + $subscriptions_array[] = $this->gateway->subscription($subscription, $this); |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - return $subscriptions_array; |
|
| 187 | - } |
|
| 186 | + return $subscriptions_array; |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * Gets all credit cards for a customer. |
|
| 191 | - * |
|
| 192 | - * @return array |
|
| 193 | - */ |
|
| 194 | - public function cards() |
|
| 195 | - { |
|
| 196 | - $this->info(); |
|
| 189 | + /** |
|
| 190 | + * Gets all credit cards for a customer. |
|
| 191 | + * |
|
| 192 | + * @return array |
|
| 193 | + */ |
|
| 194 | + public function cards() |
|
| 195 | + { |
|
| 196 | + $this->info(); |
|
| 197 | 197 | |
| 198 | - if (!$this->stripe_customer) { |
|
| 199 | - return array(); |
|
| 200 | - } |
|
| 198 | + if (!$this->stripe_customer) { |
|
| 199 | + return array(); |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - $cards = $this->stripe_customer->cards->all(); |
|
| 202 | + $cards = $this->stripe_customer->cards->all(); |
|
| 203 | 203 | |
| 204 | - $cards_array = array(); |
|
| 205 | - foreach ($cards->data as $card) { |
|
| 206 | - $cards_array[] = $this->card($card); |
|
| 207 | - } |
|
| 204 | + $cards_array = array(); |
|
| 205 | + foreach ($cards->data as $card) { |
|
| 206 | + $cards_array[] = $this->card($card); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - return $cards_array; |
|
| 210 | - } |
|
| 209 | + return $cards_array; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * Fetch a customer card instance. |
|
| 214 | - * |
|
| 215 | - * @param mixed $id |
|
| 216 | - * |
|
| 217 | - * @return Card |
|
| 218 | - */ |
|
| 219 | - public function card($id = null) |
|
| 220 | - { |
|
| 221 | - return new Card($this->gateway, $this->getNativeResponse(), $id); |
|
| 222 | - } |
|
| 212 | + /** |
|
| 213 | + * Fetch a customer card instance. |
|
| 214 | + * |
|
| 215 | + * @param mixed $id |
|
| 216 | + * |
|
| 217 | + * @return Card |
|
| 218 | + */ |
|
| 219 | + public function card($id = null) |
|
| 220 | + { |
|
| 221 | + return new Card($this->gateway, $this->getNativeResponse(), $id); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - /** |
|
| 225 | - * Gets all invoices for a customer. |
|
| 226 | - * |
|
| 227 | - * @return array |
|
| 228 | - */ |
|
| 229 | - public function invoices() |
|
| 230 | - { |
|
| 231 | - $this->info(); |
|
| 224 | + /** |
|
| 225 | + * Gets all invoices for a customer. |
|
| 226 | + * |
|
| 227 | + * @return array |
|
| 228 | + */ |
|
| 229 | + public function invoices() |
|
| 230 | + { |
|
| 231 | + $this->info(); |
|
| 232 | 232 | |
| 233 | - if (!$this->stripe_customer) { |
|
| 234 | - return array(); |
|
| 235 | - } |
|
| 233 | + if (!$this->stripe_customer) { |
|
| 234 | + return array(); |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - $invoices = Stripe_Invoice::all(array( |
|
| 238 | - 'customer' => $this->id, |
|
| 239 | - 'limit' => 100, |
|
| 240 | - )); |
|
| 237 | + $invoices = Stripe_Invoice::all(array( |
|
| 238 | + 'customer' => $this->id, |
|
| 239 | + 'limit' => 100, |
|
| 240 | + )); |
|
| 241 | 241 | |
| 242 | - $invoices_array = array(); |
|
| 243 | - foreach ($invoices->data as $invoice) { |
|
| 244 | - $invoices_array[] = $this->invoice($invoice); |
|
| 245 | - } |
|
| 242 | + $invoices_array = array(); |
|
| 243 | + foreach ($invoices->data as $invoice) { |
|
| 244 | + $invoices_array[] = $this->invoice($invoice); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - return $invoices_array; |
|
| 248 | - } |
|
| 247 | + return $invoices_array; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * Fetch an invoice instance. |
|
| 252 | - * |
|
| 253 | - * @param mixed $id |
|
| 254 | - * |
|
| 255 | - * @return Invoice |
|
| 256 | - */ |
|
| 257 | - public function invoice($id = null) |
|
| 258 | - { |
|
| 259 | - return new Invoice($this->gateway, $this->getNativeResponse(), $id); |
|
| 260 | - } |
|
| 250 | + /** |
|
| 251 | + * Fetch an invoice instance. |
|
| 252 | + * |
|
| 253 | + * @param mixed $id |
|
| 254 | + * |
|
| 255 | + * @return Invoice |
|
| 256 | + */ |
|
| 257 | + public function invoice($id = null) |
|
| 258 | + { |
|
| 259 | + return new Invoice($this->gateway, $this->getNativeResponse(), $id); |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * Gets all charges for a customer. |
|
| 264 | - * |
|
| 265 | - * @return array |
|
| 266 | - */ |
|
| 267 | - public function charges() |
|
| 268 | - { |
|
| 269 | - $this->info(); |
|
| 262 | + /** |
|
| 263 | + * Gets all charges for a customer. |
|
| 264 | + * |
|
| 265 | + * @return array |
|
| 266 | + */ |
|
| 267 | + public function charges() |
|
| 268 | + { |
|
| 269 | + $this->info(); |
|
| 270 | 270 | |
| 271 | - if (!$this->stripe_customer) { |
|
| 272 | - return array(); |
|
| 273 | - } |
|
| 271 | + if (!$this->stripe_customer) { |
|
| 272 | + return array(); |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - $charges = Stripe_Charge::all(array( |
|
| 276 | - 'customer' => $this->id, |
|
| 277 | - 'limit' => 100, |
|
| 278 | - )); |
|
| 275 | + $charges = Stripe_Charge::all(array( |
|
| 276 | + 'customer' => $this->id, |
|
| 277 | + 'limit' => 100, |
|
| 278 | + )); |
|
| 279 | 279 | |
| 280 | - $charges_array = array(); |
|
| 281 | - foreach ($charges->data as $charge) { |
|
| 282 | - $charges_array[] = $this->charge($charge); |
|
| 283 | - } |
|
| 280 | + $charges_array = array(); |
|
| 281 | + foreach ($charges->data as $charge) { |
|
| 282 | + $charges_array[] = $this->charge($charge); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - return $charges_array; |
|
| 286 | - } |
|
| 285 | + return $charges_array; |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - /** |
|
| 289 | - * Fetch a charge instance. |
|
| 290 | - * |
|
| 291 | - * @param mixed $id |
|
| 292 | - * |
|
| 293 | - * @return Charge |
|
| 294 | - */ |
|
| 295 | - public function charge($id = null) |
|
| 296 | - { |
|
| 297 | - return new Charge($this->gateway, $this->getNativeResponse(), $id); |
|
| 298 | - } |
|
| 288 | + /** |
|
| 289 | + * Fetch a charge instance. |
|
| 290 | + * |
|
| 291 | + * @param mixed $id |
|
| 292 | + * |
|
| 293 | + * @return Charge |
|
| 294 | + */ |
|
| 295 | + public function charge($id = null) |
|
| 296 | + { |
|
| 297 | + return new Charge($this->gateway, $this->getNativeResponse(), $id); |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - /** |
|
| 301 | - * Gets the native customer response. |
|
| 302 | - * |
|
| 303 | - * @return Stripe_Customer |
|
| 304 | - */ |
|
| 305 | - public function getNativeResponse() |
|
| 306 | - { |
|
| 307 | - $this->info(); |
|
| 308 | - return $this->stripe_customer; |
|
| 309 | - } |
|
| 300 | + /** |
|
| 301 | + * Gets the native customer response. |
|
| 302 | + * |
|
| 303 | + * @return Stripe_Customer |
|
| 304 | + */ |
|
| 305 | + public function getNativeResponse() |
|
| 306 | + { |
|
| 307 | + $this->info(); |
|
| 308 | + return $this->stripe_customer; |
|
| 309 | + } |
|
| 310 | 310 | } |
@@ -44,8 +44,7 @@ |
||
| 44 | 44 | if ($id instanceof Stripe_Customer) { |
| 45 | 45 | $this->stripe_customer = $id; |
| 46 | 46 | $this->id = $this->stripe_customer->id; |
| 47 | - } |
|
| 48 | - else if (null !== $id) { |
|
| 47 | + } else if (null !== $id) { |
|
| 49 | 48 | $this->id = $id; |
| 50 | 49 | } |
| 51 | 50 | } |
@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php namespace Mmanos\Billing\Gateways\Stripe; |
| 2 | 2 | |
| 3 | 3 | use Mmanos\Billing\Gateways\InvoiceInterface; |
| 4 | -use Illuminate\Support\Arr; |
|
| 5 | 4 | use Stripe_Customer; |
| 6 | 5 | use Stripe_Invoice; |
| 7 | 6 | |
@@ -7,146 +7,146 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Invoice implements InvoiceInterface |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * The gateway instance. |
|
| 12 | - * |
|
| 13 | - * @var Gateway |
|
| 14 | - */ |
|
| 15 | - protected $gateway; |
|
| 10 | + /** |
|
| 11 | + * The gateway instance. |
|
| 12 | + * |
|
| 13 | + * @var Gateway |
|
| 14 | + */ |
|
| 15 | + protected $gateway; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Stripe customer object. |
|
| 19 | - * |
|
| 20 | - * @var Stripe_Customer |
|
| 21 | - */ |
|
| 22 | - protected $stripe_customer; |
|
| 17 | + /** |
|
| 18 | + * Stripe customer object. |
|
| 19 | + * |
|
| 20 | + * @var Stripe_Customer |
|
| 21 | + */ |
|
| 22 | + protected $stripe_customer; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Primary identifier. |
|
| 26 | - * |
|
| 27 | - * @var mixed |
|
| 28 | - */ |
|
| 29 | - protected $id; |
|
| 24 | + /** |
|
| 25 | + * Primary identifier. |
|
| 26 | + * |
|
| 27 | + * @var mixed |
|
| 28 | + */ |
|
| 29 | + protected $id; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Stripe invoice object. |
|
| 33 | - * |
|
| 34 | - * @var Stripe_Invoice |
|
| 35 | - */ |
|
| 36 | - protected $stripe_invoice; |
|
| 31 | + /** |
|
| 32 | + * Stripe invoice object. |
|
| 33 | + * |
|
| 34 | + * @var Stripe_Invoice |
|
| 35 | + */ |
|
| 36 | + protected $stripe_invoice; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Create a new Stripe invoice instance. |
|
| 40 | - * |
|
| 41 | - * @param Gateway $gateway |
|
| 42 | - * @param Stripe_Customer $customer |
|
| 43 | - * @param mixed $id |
|
| 44 | - * |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - public function __construct(Gateway $gateway, Stripe_Customer $customer = null, $id = null) |
|
| 48 | - { |
|
| 49 | - $this->gateway = $gateway; |
|
| 50 | - $this->stripe_customer = $customer; |
|
| 38 | + /** |
|
| 39 | + * Create a new Stripe invoice instance. |
|
| 40 | + * |
|
| 41 | + * @param Gateway $gateway |
|
| 42 | + * @param Stripe_Customer $customer |
|
| 43 | + * @param mixed $id |
|
| 44 | + * |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + public function __construct(Gateway $gateway, Stripe_Customer $customer = null, $id = null) |
|
| 48 | + { |
|
| 49 | + $this->gateway = $gateway; |
|
| 50 | + $this->stripe_customer = $customer; |
|
| 51 | 51 | |
| 52 | - if ($id instanceof Stripe_Invoice) { |
|
| 53 | - $this->stripe_invoice = $id; |
|
| 54 | - $this->id = $this->stripe_invoice->id; |
|
| 55 | - } |
|
| 56 | - else if (null !== $id) { |
|
| 57 | - $this->id = $id; |
|
| 58 | - } |
|
| 59 | - } |
|
| 52 | + if ($id instanceof Stripe_Invoice) { |
|
| 53 | + $this->stripe_invoice = $id; |
|
| 54 | + $this->id = $this->stripe_invoice->id; |
|
| 55 | + } |
|
| 56 | + else if (null !== $id) { |
|
| 57 | + $this->id = $id; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Gets the id of this instance. |
|
| 63 | - * |
|
| 64 | - * @return mixed |
|
| 65 | - */ |
|
| 66 | - public function id() |
|
| 67 | - { |
|
| 68 | - return $this->id; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Gets the id of this instance. |
|
| 63 | + * |
|
| 64 | + * @return mixed |
|
| 65 | + */ |
|
| 66 | + public function id() |
|
| 67 | + { |
|
| 68 | + return $this->id; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Gets info for an invoice. |
|
| 73 | - * |
|
| 74 | - * @return array|null |
|
| 75 | - */ |
|
| 76 | - public function info() |
|
| 77 | - { |
|
| 78 | - if (!$this->id || !$this->stripe_customer) { |
|
| 79 | - return null; |
|
| 80 | - } |
|
| 71 | + /** |
|
| 72 | + * Gets info for an invoice. |
|
| 73 | + * |
|
| 74 | + * @return array|null |
|
| 75 | + */ |
|
| 76 | + public function info() |
|
| 77 | + { |
|
| 78 | + if (!$this->id || !$this->stripe_customer) { |
|
| 79 | + return null; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - if (!$this->stripe_invoice) { |
|
| 83 | - $this->stripe_invoice = Stripe_Invoice::retrieve($this->id); |
|
| 82 | + if (!$this->stripe_invoice) { |
|
| 83 | + $this->stripe_invoice = Stripe_Invoice::retrieve($this->id); |
|
| 84 | 84 | |
| 85 | - if ($this->stripe_customer->id != $this->stripe_invoice->customer) { |
|
| 86 | - return $this->stripe_invoice = null; |
|
| 87 | - } |
|
| 88 | - } |
|
| 85 | + if ($this->stripe_customer->id != $this->stripe_invoice->customer) { |
|
| 86 | + return $this->stripe_invoice = null; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - if (!$this->stripe_invoice) { |
|
| 91 | - return null; |
|
| 92 | - } |
|
| 90 | + if (!$this->stripe_invoice) { |
|
| 91 | + return null; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - $discounts = array(); |
|
| 95 | - if ($this->stripe_invoice->discount) { |
|
| 96 | - $discounts[] = array( |
|
| 97 | - 'coupon' => $this->stripe_invoice->discount->coupon->id, |
|
| 98 | - 'amount_off' => $this->stripe_invoice->discount->coupon->amount_off, |
|
| 99 | - 'percent_off' => $this->stripe_invoice->discount->coupon->percent_off, |
|
| 100 | - 'started_at' => date('Y-m-d H:i:s', $this->stripe_invoice->discount->start), |
|
| 101 | - 'ends_at' => $this->stripe_invoice->discount->end ? date('Y-m-d H:i:s', $this->stripe_invoice->discount->end) : null, |
|
| 102 | - ); |
|
| 103 | - } |
|
| 94 | + $discounts = array(); |
|
| 95 | + if ($this->stripe_invoice->discount) { |
|
| 96 | + $discounts[] = array( |
|
| 97 | + 'coupon' => $this->stripe_invoice->discount->coupon->id, |
|
| 98 | + 'amount_off' => $this->stripe_invoice->discount->coupon->amount_off, |
|
| 99 | + 'percent_off' => $this->stripe_invoice->discount->coupon->percent_off, |
|
| 100 | + 'started_at' => date('Y-m-d H:i:s', $this->stripe_invoice->discount->start), |
|
| 101 | + 'ends_at' => $this->stripe_invoice->discount->end ? date('Y-m-d H:i:s', $this->stripe_invoice->discount->end) : null, |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - $items = array(); |
|
| 106 | - foreach ($this->stripe_invoice->lines->data as $line) { |
|
| 107 | - $item = array( |
|
| 108 | - 'id' => $line->id, |
|
| 109 | - 'amount' => $line->amount, |
|
| 110 | - 'period_start' => null, |
|
| 111 | - 'period_end' => null, |
|
| 112 | - 'description' => $line->description, |
|
| 113 | - 'subscription_id' => ('subscription' == $line->type) ? $line->id : $line->subscription, |
|
| 114 | - 'quantity' => $line->quantity, |
|
| 115 | - ); |
|
| 105 | + $items = array(); |
|
| 106 | + foreach ($this->stripe_invoice->lines->data as $line) { |
|
| 107 | + $item = array( |
|
| 108 | + 'id' => $line->id, |
|
| 109 | + 'amount' => $line->amount, |
|
| 110 | + 'period_start' => null, |
|
| 111 | + 'period_end' => null, |
|
| 112 | + 'description' => $line->description, |
|
| 113 | + 'subscription_id' => ('subscription' == $line->type) ? $line->id : $line->subscription, |
|
| 114 | + 'quantity' => $line->quantity, |
|
| 115 | + ); |
|
| 116 | 116 | |
| 117 | - if ($line->period && $line->period->start) { |
|
| 118 | - $item['period_start'] = date('Y-m-d H:i:s', $line->period->start); |
|
| 119 | - } |
|
| 120 | - if ($line->period && $line->period->end) { |
|
| 121 | - $item['period_end'] = date('Y-m-d H:i:s', $line->period->end); |
|
| 122 | - } |
|
| 117 | + if ($line->period && $line->period->start) { |
|
| 118 | + $item['period_start'] = date('Y-m-d H:i:s', $line->period->start); |
|
| 119 | + } |
|
| 120 | + if ($line->period && $line->period->end) { |
|
| 121 | + $item['period_end'] = date('Y-m-d H:i:s', $line->period->end); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - $items[] = $item; |
|
| 125 | - } |
|
| 124 | + $items[] = $item; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - return array( |
|
| 128 | - 'id' => $this->id, |
|
| 129 | - 'date' => date('Y-m-d H:i:s', $this->stripe_invoice->date), |
|
| 130 | - 'total' => $this->stripe_invoice->total, |
|
| 131 | - 'subtotal' => $this->stripe_invoice->subtotal, |
|
| 132 | - 'amount' => $this->stripe_invoice->amount_due, |
|
| 133 | - 'starting_balance' => $this->stripe_invoice->starting_balance, |
|
| 134 | - 'ending_balance' => $this->stripe_invoice->ending_balance, |
|
| 135 | - 'closed' => $this->stripe_invoice->closed, |
|
| 136 | - 'paid' => $this->stripe_invoice->paid, |
|
| 137 | - 'discounts' => $discounts, |
|
| 138 | - 'items' => $items, |
|
| 139 | - ); |
|
| 140 | - } |
|
| 127 | + return array( |
|
| 128 | + 'id' => $this->id, |
|
| 129 | + 'date' => date('Y-m-d H:i:s', $this->stripe_invoice->date), |
|
| 130 | + 'total' => $this->stripe_invoice->total, |
|
| 131 | + 'subtotal' => $this->stripe_invoice->subtotal, |
|
| 132 | + 'amount' => $this->stripe_invoice->amount_due, |
|
| 133 | + 'starting_balance' => $this->stripe_invoice->starting_balance, |
|
| 134 | + 'ending_balance' => $this->stripe_invoice->ending_balance, |
|
| 135 | + 'closed' => $this->stripe_invoice->closed, |
|
| 136 | + 'paid' => $this->stripe_invoice->paid, |
|
| 137 | + 'discounts' => $discounts, |
|
| 138 | + 'items' => $items, |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Gets the native invoice response. |
|
| 144 | - * |
|
| 145 | - * @return Stripe_Invoice |
|
| 146 | - */ |
|
| 147 | - public function getNativeResponse() |
|
| 148 | - { |
|
| 149 | - $this->info(); |
|
| 150 | - return $this->stripe_invoice; |
|
| 151 | - } |
|
| 142 | + /** |
|
| 143 | + * Gets the native invoice response. |
|
| 144 | + * |
|
| 145 | + * @return Stripe_Invoice |
|
| 146 | + */ |
|
| 147 | + public function getNativeResponse() |
|
| 148 | + { |
|
| 149 | + $this->info(); |
|
| 150 | + return $this->stripe_invoice; |
|
| 151 | + } |
|
| 152 | 152 | } |
@@ -52,8 +52,7 @@ |
||
| 52 | 52 | if ($id instanceof Stripe_Invoice) { |
| 53 | 53 | $this->stripe_invoice = $id; |
| 54 | 54 | $this->id = $this->stripe_invoice->id; |
| 55 | - } |
|
| 56 | - else if (null !== $id) { |
|
| 55 | + } else if (null !== $id) { |
|
| 57 | 56 | $this->id = $id; |
| 58 | 57 | } |
| 59 | 58 | } |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | /** |
| 9 | 9 | * Return the gateway subscription object for this model. |
| 10 | 10 | * |
| 11 | - * @return Mmanos\Billing\Gateways\SubscriptionInterface |
|
| 11 | + * @return null|Gateways\SubscriptionInterface |
|
| 12 | 12 | */ |
| 13 | 13 | public function gatewaySubscription() |
| 14 | 14 | { |
@@ -5,467 +5,467 @@ |
||
| 5 | 5 | |
| 6 | 6 | trait SubscriptionBillableTrait |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Return the gateway subscription object for this model. |
|
| 10 | - * |
|
| 11 | - * @return Mmanos\Billing\Gateways\SubscriptionInterface |
|
| 12 | - */ |
|
| 13 | - public function gatewaySubscription() |
|
| 14 | - { |
|
| 15 | - if (!$this->everSubscribed()) { |
|
| 16 | - return null; |
|
| 17 | - } |
|
| 8 | + /** |
|
| 9 | + * Return the gateway subscription object for this model. |
|
| 10 | + * |
|
| 11 | + * @return Mmanos\Billing\Gateways\SubscriptionInterface |
|
| 12 | + */ |
|
| 13 | + public function gatewaySubscription() |
|
| 14 | + { |
|
| 15 | + if (!$this->everSubscribed()) { |
|
| 16 | + return null; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - if ($customer = $this->customer()) { |
|
| 20 | - $customer = $customer->gatewayCustomer(); |
|
| 21 | - } |
|
| 19 | + if ($customer = $this->customer()) { |
|
| 20 | + $customer = $customer->gatewayCustomer(); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - return Billing::subscription($this->billing_subscription, $customer); |
|
| 24 | - } |
|
| 23 | + return Billing::subscription($this->billing_subscription, $customer); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Return the subscription billing helper object. |
|
| 28 | - * |
|
| 29 | - * @param mixed $plan |
|
| 30 | - * |
|
| 31 | - * @return SubscriptionBillableTrait\Subscription |
|
| 32 | - */ |
|
| 33 | - public function subscription($plan = null) |
|
| 34 | - { |
|
| 35 | - return new SubscriptionBillableTrait\Subscription($this, $this->gatewaySubscription(), $plan); |
|
| 36 | - } |
|
| 26 | + /** |
|
| 27 | + * Return the subscription billing helper object. |
|
| 28 | + * |
|
| 29 | + * @param mixed $plan |
|
| 30 | + * |
|
| 31 | + * @return SubscriptionBillableTrait\Subscription |
|
| 32 | + */ |
|
| 33 | + public function subscription($plan = null) |
|
| 34 | + { |
|
| 35 | + return new SubscriptionBillableTrait\Subscription($this, $this->gatewaySubscription(), $plan); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Determine if the entity is within their trial period. |
|
| 40 | - * |
|
| 41 | - * @return bool |
|
| 42 | - */ |
|
| 43 | - public function onTrial() |
|
| 44 | - { |
|
| 45 | - if ($this->billing_trial_ends_at) { |
|
| 46 | - return time() < strtotime($this->billing_trial_ends_at); |
|
| 47 | - } |
|
| 38 | + /** |
|
| 39 | + * Determine if the entity is within their trial period. |
|
| 40 | + * |
|
| 41 | + * @return bool |
|
| 42 | + */ |
|
| 43 | + public function onTrial() |
|
| 44 | + { |
|
| 45 | + if ($this->billing_trial_ends_at) { |
|
| 46 | + return time() < strtotime($this->billing_trial_ends_at); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return false; |
|
| 50 | - } |
|
| 49 | + return false; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Determine if the entity is on grace period after cancellation. |
|
| 54 | - * |
|
| 55 | - * @return bool |
|
| 56 | - */ |
|
| 57 | - public function onGracePeriod() |
|
| 58 | - { |
|
| 59 | - if ($this->billing_subscription_ends_at) { |
|
| 60 | - return time() < strtotime($this->billing_subscription_ends_at); |
|
| 61 | - } |
|
| 52 | + /** |
|
| 53 | + * Determine if the entity is on grace period after cancellation. |
|
| 54 | + * |
|
| 55 | + * @return bool |
|
| 56 | + */ |
|
| 57 | + public function onGracePeriod() |
|
| 58 | + { |
|
| 59 | + if ($this->billing_subscription_ends_at) { |
|
| 60 | + return time() < strtotime($this->billing_subscription_ends_at); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return false; |
|
| 64 | - } |
|
| 63 | + return false; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Determine if the entity has an active subscription. |
|
| 68 | - * |
|
| 69 | - * @return bool |
|
| 70 | - */ |
|
| 71 | - public function subscribed() |
|
| 72 | - { |
|
| 73 | - if ($this->billing_free) { |
|
| 74 | - if (!$this->billing_subscription_ends_at |
|
| 75 | - || time() < strtotime($this->billing_subscription_ends_at) |
|
| 76 | - ) { |
|
| 77 | - return true; |
|
| 78 | - } |
|
| 79 | - } |
|
| 66 | + /** |
|
| 67 | + * Determine if the entity has an active subscription. |
|
| 68 | + * |
|
| 69 | + * @return bool |
|
| 70 | + */ |
|
| 71 | + public function subscribed() |
|
| 72 | + { |
|
| 73 | + if ($this->billing_free) { |
|
| 74 | + if (!$this->billing_subscription_ends_at |
|
| 75 | + || time() < strtotime($this->billing_subscription_ends_at) |
|
| 76 | + ) { |
|
| 77 | + return true; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - if (!isset($this->cardUpFront) || $this->cardUpFront) { |
|
| 82 | - return $this->billingIsActive() || $this->onGracePeriod(); |
|
| 83 | - } |
|
| 81 | + if (!isset($this->cardUpFront) || $this->cardUpFront) { |
|
| 82 | + return $this->billingIsActive() || $this->onGracePeriod(); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - return $this->billingIsActive() || $this->onGracePeriod() || $this->onTrial(); |
|
| 86 | - } |
|
| 85 | + return $this->billingIsActive() || $this->onGracePeriod() || $this->onTrial(); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Determine if the entity's trial has expired. |
|
| 90 | - * |
|
| 91 | - * @return bool |
|
| 92 | - */ |
|
| 93 | - public function expired() |
|
| 94 | - { |
|
| 95 | - return !$this->subscribed() && $this->billing_trial_ends_at && strtotime($this->billing_trial_ends_at) <= time(); |
|
| 96 | - } |
|
| 88 | + /** |
|
| 89 | + * Determine if the entity's trial has expired. |
|
| 90 | + * |
|
| 91 | + * @return bool |
|
| 92 | + */ |
|
| 93 | + public function expired() |
|
| 94 | + { |
|
| 95 | + return !$this->subscribed() && $this->billing_trial_ends_at && strtotime($this->billing_trial_ends_at) <= time(); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Determine if the entity had a subscription which is no longer active. |
|
| 100 | - * |
|
| 101 | - * @return bool |
|
| 102 | - */ |
|
| 103 | - public function canceled() |
|
| 104 | - { |
|
| 105 | - return $this->everSubscribed() && !$this->billingIsActive(); |
|
| 106 | - } |
|
| 98 | + /** |
|
| 99 | + * Determine if the entity had a subscription which is no longer active. |
|
| 100 | + * |
|
| 101 | + * @return bool |
|
| 102 | + */ |
|
| 103 | + public function canceled() |
|
| 104 | + { |
|
| 105 | + return $this->everSubscribed() && !$this->billingIsActive(); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Deteremine if the user has ever been subscribed. |
|
| 110 | - * |
|
| 111 | - * @return bool |
|
| 112 | - */ |
|
| 113 | - public function everSubscribed() |
|
| 114 | - { |
|
| 115 | - return !empty($this->billing_subscription); |
|
| 116 | - } |
|
| 108 | + /** |
|
| 109 | + * Deteremine if the user has ever been subscribed. |
|
| 110 | + * |
|
| 111 | + * @return bool |
|
| 112 | + */ |
|
| 113 | + public function everSubscribed() |
|
| 114 | + { |
|
| 115 | + return !empty($this->billing_subscription); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Determine if the entity has a current subscription. |
|
| 120 | - * |
|
| 121 | - * @return bool |
|
| 122 | - */ |
|
| 123 | - public function billingIsActive() |
|
| 124 | - { |
|
| 125 | - return $this->billing_active; |
|
| 126 | - } |
|
| 118 | + /** |
|
| 119 | + * Determine if the entity has a current subscription. |
|
| 120 | + * |
|
| 121 | + * @return bool |
|
| 122 | + */ |
|
| 123 | + public function billingIsActive() |
|
| 124 | + { |
|
| 125 | + return $this->billing_active; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * Whether or not this model requires a credit card up front. |
|
| 130 | - * |
|
| 131 | - * @return bool |
|
| 132 | - */ |
|
| 133 | - public function requiresCardUpFront() |
|
| 134 | - { |
|
| 135 | - if (!isset($this->cardUpFront) || $this->cardUpFront) { |
|
| 136 | - return true; |
|
| 137 | - } |
|
| 128 | + /** |
|
| 129 | + * Whether or not this model requires a credit card up front. |
|
| 130 | + * |
|
| 131 | + * @return bool |
|
| 132 | + */ |
|
| 133 | + public function requiresCardUpFront() |
|
| 134 | + { |
|
| 135 | + if (!isset($this->cardUpFront) || $this->cardUpFront) { |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - return false; |
|
| 140 | - } |
|
| 139 | + return false; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Return the Eloquent model acting as the billing customer for this model. |
|
| 144 | - * The customer model can be defined in one of the following ways: |
|
| 145 | - * - A 'customermodel' relationship on this model. |
|
| 146 | - * - A 'customermodel' method on this model that returns a valid Eloquent model. |
|
| 147 | - * |
|
| 148 | - * @return \Illuminate\Database\Eloquent\Model |
|
| 149 | - */ |
|
| 150 | - public function customer() |
|
| 151 | - { |
|
| 152 | - // Note: Laravel throws a LogicException if a customer method exists but |
|
| 153 | - // doesn't return a valid relationship. |
|
| 154 | - try { |
|
| 155 | - if ($customer = $this->customermodel) { |
|
| 156 | - return $customer; |
|
| 157 | - } |
|
| 158 | - } catch (LogicException $e) {} |
|
| 142 | + /** |
|
| 143 | + * Return the Eloquent model acting as the billing customer for this model. |
|
| 144 | + * The customer model can be defined in one of the following ways: |
|
| 145 | + * - A 'customermodel' relationship on this model. |
|
| 146 | + * - A 'customermodel' method on this model that returns a valid Eloquent model. |
|
| 147 | + * |
|
| 148 | + * @return \Illuminate\Database\Eloquent\Model |
|
| 149 | + */ |
|
| 150 | + public function customer() |
|
| 151 | + { |
|
| 152 | + // Note: Laravel throws a LogicException if a customer method exists but |
|
| 153 | + // doesn't return a valid relationship. |
|
| 154 | + try { |
|
| 155 | + if ($customer = $this->customermodel) { |
|
| 156 | + return $customer; |
|
| 157 | + } |
|
| 158 | + } catch (LogicException $e) {} |
|
| 159 | 159 | |
| 160 | - if (method_exists($this, 'customermodel')) { |
|
| 161 | - return $this->customermodel(); |
|
| 162 | - } |
|
| 160 | + if (method_exists($this, 'customermodel')) { |
|
| 161 | + return $this->customermodel(); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - // Check for customer/subscription on the same model. |
|
| 165 | - if (method_exists($this, 'gatewayCustomer')) { |
|
| 166 | - return $this; |
|
| 167 | - } |
|
| 164 | + // Check for customer/subscription on the same model. |
|
| 165 | + if (method_exists($this, 'gatewayCustomer')) { |
|
| 166 | + return $this; |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - return null; |
|
| 170 | - } |
|
| 169 | + return null; |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Getter for billing_subscription_discounts property. |
|
| 174 | - * |
|
| 175 | - * @param string $value |
|
| 176 | - * |
|
| 177 | - * @return array |
|
| 178 | - */ |
|
| 179 | - public function getBillingSubscriptionDiscountsAttribute($value) |
|
| 180 | - { |
|
| 181 | - return $value ? json_decode($value, true) : array(); |
|
| 182 | - } |
|
| 172 | + /** |
|
| 173 | + * Getter for billing_subscription_discounts property. |
|
| 174 | + * |
|
| 175 | + * @param string $value |
|
| 176 | + * |
|
| 177 | + * @return array |
|
| 178 | + */ |
|
| 179 | + public function getBillingSubscriptionDiscountsAttribute($value) |
|
| 180 | + { |
|
| 181 | + return $value ? json_decode($value, true) : array(); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * Setter for billing_subscription_discounts property. |
|
| 186 | - * |
|
| 187 | - * @param array $value |
|
| 188 | - * |
|
| 189 | - * @return void |
|
| 190 | - */ |
|
| 191 | - public function setBillingSubscriptionDiscountsAttribute($value) |
|
| 192 | - { |
|
| 193 | - $this->attributes['billing_subscription_discounts'] = empty($value) ? null : json_encode($value); |
|
| 194 | - } |
|
| 184 | + /** |
|
| 185 | + * Setter for billing_subscription_discounts property. |
|
| 186 | + * |
|
| 187 | + * @param array $value |
|
| 188 | + * |
|
| 189 | + * @return void |
|
| 190 | + */ |
|
| 191 | + public function setBillingSubscriptionDiscountsAttribute($value) |
|
| 192 | + { |
|
| 193 | + $this->attributes['billing_subscription_discounts'] = empty($value) ? null : json_encode($value); |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Register a billingActivated model event with the dispatcher. |
|
| 198 | - * |
|
| 199 | - * @param \Closure|string $callback |
|
| 200 | - * |
|
| 201 | - * @return void |
|
| 202 | - */ |
|
| 203 | - public static function billingActivated($callback) |
|
| 204 | - { |
|
| 205 | - static::listenForSubscriptionEvents(); |
|
| 206 | - static::registerModelEvent('billingActivated', $callback); |
|
| 207 | - } |
|
| 196 | + /** |
|
| 197 | + * Register a billingActivated model event with the dispatcher. |
|
| 198 | + * |
|
| 199 | + * @param \Closure|string $callback |
|
| 200 | + * |
|
| 201 | + * @return void |
|
| 202 | + */ |
|
| 203 | + public static function billingActivated($callback) |
|
| 204 | + { |
|
| 205 | + static::listenForSubscriptionEvents(); |
|
| 206 | + static::registerModelEvent('billingActivated', $callback); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Register a billingCanceled model event with the dispatcher. |
|
| 211 | - * |
|
| 212 | - * @param \Closure|string $callback |
|
| 213 | - * |
|
| 214 | - * @return void |
|
| 215 | - */ |
|
| 216 | - public static function billingCanceled($callback) |
|
| 217 | - { |
|
| 218 | - static::listenForSubscriptionEvents(); |
|
| 219 | - static::registerModelEvent('billingCanceled', $callback); |
|
| 220 | - } |
|
| 209 | + /** |
|
| 210 | + * Register a billingCanceled model event with the dispatcher. |
|
| 211 | + * |
|
| 212 | + * @param \Closure|string $callback |
|
| 213 | + * |
|
| 214 | + * @return void |
|
| 215 | + */ |
|
| 216 | + public static function billingCanceled($callback) |
|
| 217 | + { |
|
| 218 | + static::listenForSubscriptionEvents(); |
|
| 219 | + static::registerModelEvent('billingCanceled', $callback); |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * Register a planSwapped model event with the dispatcher. |
|
| 224 | - * |
|
| 225 | - * @param \Closure|string $callback |
|
| 226 | - * |
|
| 227 | - * @return void |
|
| 228 | - */ |
|
| 229 | - public static function planSwapped($callback) |
|
| 230 | - { |
|
| 231 | - static::listenForSubscriptionEvents(); |
|
| 232 | - static::registerModelEvent('planSwapped', $callback); |
|
| 233 | - } |
|
| 222 | + /** |
|
| 223 | + * Register a planSwapped model event with the dispatcher. |
|
| 224 | + * |
|
| 225 | + * @param \Closure|string $callback |
|
| 226 | + * |
|
| 227 | + * @return void |
|
| 228 | + */ |
|
| 229 | + public static function planSwapped($callback) |
|
| 230 | + { |
|
| 231 | + static::listenForSubscriptionEvents(); |
|
| 232 | + static::registerModelEvent('planSwapped', $callback); |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - /** |
|
| 236 | - * Register a planChanged model event with the dispatcher. |
|
| 237 | - * |
|
| 238 | - * @param \Closure|string $callback |
|
| 239 | - * |
|
| 240 | - * @return void |
|
| 241 | - */ |
|
| 242 | - public static function planChanged($callback) |
|
| 243 | - { |
|
| 244 | - static::listenForSubscriptionEvents(); |
|
| 245 | - static::registerModelEvent('planChanged', $callback); |
|
| 246 | - } |
|
| 235 | + /** |
|
| 236 | + * Register a planChanged model event with the dispatcher. |
|
| 237 | + * |
|
| 238 | + * @param \Closure|string $callback |
|
| 239 | + * |
|
| 240 | + * @return void |
|
| 241 | + */ |
|
| 242 | + public static function planChanged($callback) |
|
| 243 | + { |
|
| 244 | + static::listenForSubscriptionEvents(); |
|
| 245 | + static::registerModelEvent('planChanged', $callback); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * Register a subscriptionIncremented model event with the dispatcher. |
|
| 250 | - * |
|
| 251 | - * @param \Closure|string $callback |
|
| 252 | - * |
|
| 253 | - * @return void |
|
| 254 | - */ |
|
| 255 | - public static function subscriptionIncremented($callback) |
|
| 256 | - { |
|
| 257 | - static::listenForSubscriptionEvents(); |
|
| 258 | - static::registerModelEvent('subscriptionIncremented', $callback); |
|
| 259 | - } |
|
| 248 | + /** |
|
| 249 | + * Register a subscriptionIncremented model event with the dispatcher. |
|
| 250 | + * |
|
| 251 | + * @param \Closure|string $callback |
|
| 252 | + * |
|
| 253 | + * @return void |
|
| 254 | + */ |
|
| 255 | + public static function subscriptionIncremented($callback) |
|
| 256 | + { |
|
| 257 | + static::listenForSubscriptionEvents(); |
|
| 258 | + static::registerModelEvent('subscriptionIncremented', $callback); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * Register a subscriptionDecremented model event with the dispatcher. |
|
| 263 | - * |
|
| 264 | - * @param \Closure|string $callback |
|
| 265 | - * |
|
| 266 | - * @return void |
|
| 267 | - */ |
|
| 268 | - public static function subscriptionDecremented($callback) |
|
| 269 | - { |
|
| 270 | - static::listenForSubscriptionEvents(); |
|
| 271 | - static::registerModelEvent('subscriptionDecremented', $callback); |
|
| 272 | - } |
|
| 261 | + /** |
|
| 262 | + * Register a subscriptionDecremented model event with the dispatcher. |
|
| 263 | + * |
|
| 264 | + * @param \Closure|string $callback |
|
| 265 | + * |
|
| 266 | + * @return void |
|
| 267 | + */ |
|
| 268 | + public static function subscriptionDecremented($callback) |
|
| 269 | + { |
|
| 270 | + static::listenForSubscriptionEvents(); |
|
| 271 | + static::registerModelEvent('subscriptionDecremented', $callback); |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * Register a billingResumed model event with the dispatcher. |
|
| 276 | - * |
|
| 277 | - * @param \Closure|string $callback |
|
| 278 | - * |
|
| 279 | - * @return void |
|
| 280 | - */ |
|
| 281 | - public static function billingResumed($callback) |
|
| 282 | - { |
|
| 283 | - static::listenForSubscriptionEvents(); |
|
| 284 | - static::registerModelEvent('billingResumed', $callback); |
|
| 285 | - } |
|
| 274 | + /** |
|
| 275 | + * Register a billingResumed model event with the dispatcher. |
|
| 276 | + * |
|
| 277 | + * @param \Closure|string $callback |
|
| 278 | + * |
|
| 279 | + * @return void |
|
| 280 | + */ |
|
| 281 | + public static function billingResumed($callback) |
|
| 282 | + { |
|
| 283 | + static::listenForSubscriptionEvents(); |
|
| 284 | + static::registerModelEvent('billingResumed', $callback); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - /** |
|
| 288 | - * Register a trialExtended model event with the dispatcher. |
|
| 289 | - * |
|
| 290 | - * @param \Closure|string $callback |
|
| 291 | - * |
|
| 292 | - * @return void |
|
| 293 | - */ |
|
| 294 | - public static function trialExtended($callback) |
|
| 295 | - { |
|
| 296 | - static::listenForSubscriptionEvents(); |
|
| 297 | - static::registerModelEvent('trialExtended', $callback); |
|
| 298 | - } |
|
| 287 | + /** |
|
| 288 | + * Register a trialExtended model event with the dispatcher. |
|
| 289 | + * |
|
| 290 | + * @param \Closure|string $callback |
|
| 291 | + * |
|
| 292 | + * @return void |
|
| 293 | + */ |
|
| 294 | + public static function trialExtended($callback) |
|
| 295 | + { |
|
| 296 | + static::listenForSubscriptionEvents(); |
|
| 297 | + static::registerModelEvent('trialExtended', $callback); |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - /** |
|
| 301 | - * Register a trialChanged model event with the dispatcher. |
|
| 302 | - * |
|
| 303 | - * @param \Closure|string $callback |
|
| 304 | - * |
|
| 305 | - * @return void |
|
| 306 | - */ |
|
| 307 | - public static function trialChanged($callback) |
|
| 308 | - { |
|
| 309 | - static::listenForSubscriptionEvents(); |
|
| 310 | - static::registerModelEvent('trialChanged', $callback); |
|
| 311 | - } |
|
| 300 | + /** |
|
| 301 | + * Register a trialChanged model event with the dispatcher. |
|
| 302 | + * |
|
| 303 | + * @param \Closure|string $callback |
|
| 304 | + * |
|
| 305 | + * @return void |
|
| 306 | + */ |
|
| 307 | + public static function trialChanged($callback) |
|
| 308 | + { |
|
| 309 | + static::listenForSubscriptionEvents(); |
|
| 310 | + static::registerModelEvent('trialChanged', $callback); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - /** |
|
| 314 | - * Register a trialWillEnd model event with the dispatcher. |
|
| 315 | - * Triggered via webhook. |
|
| 316 | - * |
|
| 317 | - * @param \Closure|string $callback |
|
| 318 | - * |
|
| 319 | - * @return void |
|
| 320 | - */ |
|
| 321 | - public static function trialWillEnd($callback) |
|
| 322 | - { |
|
| 323 | - static::registerModelEvent('trialWillEnd', $callback); |
|
| 324 | - } |
|
| 313 | + /** |
|
| 314 | + * Register a trialWillEnd model event with the dispatcher. |
|
| 315 | + * Triggered via webhook. |
|
| 316 | + * |
|
| 317 | + * @param \Closure|string $callback |
|
| 318 | + * |
|
| 319 | + * @return void |
|
| 320 | + */ |
|
| 321 | + public static function trialWillEnd($callback) |
|
| 322 | + { |
|
| 323 | + static::registerModelEvent('trialWillEnd', $callback); |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - /** |
|
| 327 | - * Register a subscriptionDiscountAdded model event with the dispatcher. |
|
| 328 | - * |
|
| 329 | - * @param \Closure|string $callback |
|
| 330 | - * |
|
| 331 | - * @return void |
|
| 332 | - */ |
|
| 333 | - public static function subscriptionDiscountAdded($callback) |
|
| 334 | - { |
|
| 335 | - static::listenForSubscriptionEvents(); |
|
| 336 | - static::registerModelEvent('subscriptionDiscountAdded', $callback); |
|
| 337 | - } |
|
| 326 | + /** |
|
| 327 | + * Register a subscriptionDiscountAdded model event with the dispatcher. |
|
| 328 | + * |
|
| 329 | + * @param \Closure|string $callback |
|
| 330 | + * |
|
| 331 | + * @return void |
|
| 332 | + */ |
|
| 333 | + public static function subscriptionDiscountAdded($callback) |
|
| 334 | + { |
|
| 335 | + static::listenForSubscriptionEvents(); |
|
| 336 | + static::registerModelEvent('subscriptionDiscountAdded', $callback); |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - /** |
|
| 340 | - * Register a subscriptionDiscountRemoved model event with the dispatcher. |
|
| 341 | - * |
|
| 342 | - * @param \Closure|string $callback |
|
| 343 | - * |
|
| 344 | - * @return void |
|
| 345 | - */ |
|
| 346 | - public static function subscriptionDiscountRemoved($callback) |
|
| 347 | - { |
|
| 348 | - static::listenForSubscriptionEvents(); |
|
| 349 | - static::registerModelEvent('subscriptionDiscountRemoved', $callback); |
|
| 350 | - } |
|
| 339 | + /** |
|
| 340 | + * Register a subscriptionDiscountRemoved model event with the dispatcher. |
|
| 341 | + * |
|
| 342 | + * @param \Closure|string $callback |
|
| 343 | + * |
|
| 344 | + * @return void |
|
| 345 | + */ |
|
| 346 | + public static function subscriptionDiscountRemoved($callback) |
|
| 347 | + { |
|
| 348 | + static::listenForSubscriptionEvents(); |
|
| 349 | + static::registerModelEvent('subscriptionDiscountRemoved', $callback); |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - /** |
|
| 353 | - * Register a subscriptionDiscountUpdated model event with the dispatcher. |
|
| 354 | - * |
|
| 355 | - * @param \Closure|string $callback |
|
| 356 | - * |
|
| 357 | - * @return void |
|
| 358 | - */ |
|
| 359 | - public static function subscriptionDiscountUpdated($callback) |
|
| 360 | - { |
|
| 361 | - static::listenForSubscriptionEvents(); |
|
| 362 | - static::registerModelEvent('subscriptionDiscountUpdated', $callback); |
|
| 363 | - } |
|
| 352 | + /** |
|
| 353 | + * Register a subscriptionDiscountUpdated model event with the dispatcher. |
|
| 354 | + * |
|
| 355 | + * @param \Closure|string $callback |
|
| 356 | + * |
|
| 357 | + * @return void |
|
| 358 | + */ |
|
| 359 | + public static function subscriptionDiscountUpdated($callback) |
|
| 360 | + { |
|
| 361 | + static::listenForSubscriptionEvents(); |
|
| 362 | + static::registerModelEvent('subscriptionDiscountUpdated', $callback); |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | - /** |
|
| 366 | - * Register a subscriptionDiscountChanged model event with the dispatcher. |
|
| 367 | - * |
|
| 368 | - * @param \Closure|string $callback |
|
| 369 | - * |
|
| 370 | - * @return void |
|
| 371 | - */ |
|
| 372 | - public static function subscriptionDiscountChanged($callback) |
|
| 373 | - { |
|
| 374 | - static::listenForSubscriptionEvents(); |
|
| 375 | - static::registerModelEvent('subscriptionDiscountChanged', $callback); |
|
| 376 | - } |
|
| 365 | + /** |
|
| 366 | + * Register a subscriptionDiscountChanged model event with the dispatcher. |
|
| 367 | + * |
|
| 368 | + * @param \Closure|string $callback |
|
| 369 | + * |
|
| 370 | + * @return void |
|
| 371 | + */ |
|
| 372 | + public static function subscriptionDiscountChanged($callback) |
|
| 373 | + { |
|
| 374 | + static::listenForSubscriptionEvents(); |
|
| 375 | + static::registerModelEvent('subscriptionDiscountChanged', $callback); |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | - /** |
|
| 379 | - * Fire the given event for the model. |
|
| 380 | - * |
|
| 381 | - * @param string $event |
|
| 382 | - * |
|
| 383 | - * @return mixed |
|
| 384 | - */ |
|
| 385 | - public function fireSubscriptionEvent($event) |
|
| 386 | - { |
|
| 387 | - if ( ! isset(static::$dispatcher)) return true; |
|
| 378 | + /** |
|
| 379 | + * Fire the given event for the model. |
|
| 380 | + * |
|
| 381 | + * @param string $event |
|
| 382 | + * |
|
| 383 | + * @return mixed |
|
| 384 | + */ |
|
| 385 | + public function fireSubscriptionEvent($event) |
|
| 386 | + { |
|
| 387 | + if ( ! isset(static::$dispatcher)) return true; |
|
| 388 | 388 | |
| 389 | - // We will append the names of the class to the event to distinguish it from |
|
| 390 | - // other model events that are fired, allowing us to listen on each model |
|
| 391 | - // event set individually instead of catching event for all the models. |
|
| 392 | - $event = "eloquent.{$event}: ".get_class($this); |
|
| 389 | + // We will append the names of the class to the event to distinguish it from |
|
| 390 | + // other model events that are fired, allowing us to listen on each model |
|
| 391 | + // event set individually instead of catching event for all the models. |
|
| 392 | + $event = "eloquent.{$event}: ".get_class($this); |
|
| 393 | 393 | |
| 394 | - $args = array_merge(array($this), array_slice(func_get_args(), 1)); |
|
| 394 | + $args = array_merge(array($this), array_slice(func_get_args(), 1)); |
|
| 395 | 395 | |
| 396 | - return static::$dispatcher->fire($event, $args); |
|
| 397 | - } |
|
| 396 | + return static::$dispatcher->fire($event, $args); |
|
| 397 | + } |
|
| 398 | 398 | |
| 399 | - /** |
|
| 400 | - * Register listeners for model change events so we can trigger our own |
|
| 401 | - * custom events. |
|
| 402 | - * |
|
| 403 | - * @return void |
|
| 404 | - */ |
|
| 405 | - protected static function listenForSubscriptionEvents() |
|
| 406 | - { |
|
| 407 | - static $listening_for_subscription_events; |
|
| 408 | - if ($listening_for_subscription_events) { |
|
| 409 | - return; |
|
| 410 | - } |
|
| 399 | + /** |
|
| 400 | + * Register listeners for model change events so we can trigger our own |
|
| 401 | + * custom events. |
|
| 402 | + * |
|
| 403 | + * @return void |
|
| 404 | + */ |
|
| 405 | + protected static function listenForSubscriptionEvents() |
|
| 406 | + { |
|
| 407 | + static $listening_for_subscription_events; |
|
| 408 | + if ($listening_for_subscription_events) { |
|
| 409 | + return; |
|
| 410 | + } |
|
| 411 | 411 | |
| 412 | - static::saved(function ($model) { |
|
| 413 | - $original = $model->getOriginal(); |
|
| 412 | + static::saved(function ($model) { |
|
| 413 | + $original = $model->getOriginal(); |
|
| 414 | 414 | |
| 415 | - if ($model->isDirty('billing_active')) { |
|
| 416 | - if (empty($original['billing_active']) && !empty($model->billing_active)) { |
|
| 417 | - $model->fireSubscriptionEvent('billingActivated'); |
|
| 415 | + if ($model->isDirty('billing_active')) { |
|
| 416 | + if (empty($original['billing_active']) && !empty($model->billing_active)) { |
|
| 417 | + $model->fireSubscriptionEvent('billingActivated'); |
|
| 418 | 418 | |
| 419 | - if ($model->isDirty('billing_subscription_ends_at')) { |
|
| 420 | - if (empty($model->billing_subscription_ends_at) && !empty($original['billing_subscription_ends_at'])) { |
|
| 421 | - $model->fireSubscriptionEvent('billingResumed'); |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - else if (empty($model->billing_active) && !empty($original['billing_active'])) { |
|
| 426 | - $model->fireSubscriptionEvent('billingCanceled'); |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - if ($model->isDirty('billing_plan')) { |
|
| 430 | - if (!empty($original['billing_plan']) && !empty($model->billing_plan)) { |
|
| 431 | - $model->fireSubscriptionEvent('planSwapped'); |
|
| 432 | - } |
|
| 433 | - if (!empty($model->billing_plan)) { |
|
| 434 | - $model->fireSubscriptionEvent('planChanged'); |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - if ($model->isDirty('billing_quantity')) { |
|
| 438 | - if ($model->billing_quantity > 0 && $model->getOriginal('billing_quantity') > 0) { |
|
| 439 | - if ($model->billing_quantity > $model->getOriginal('billing_quantity')) { |
|
| 440 | - $model->fireSubscriptionEvent('subscriptionIncremented'); |
|
| 441 | - } |
|
| 442 | - else { |
|
| 443 | - $model->fireSubscriptionEvent('subscriptionDecremented'); |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - if ($model->isDirty('billing_trial_ends_at')) { |
|
| 448 | - if (!empty($model->billing_trial_ends_at) && !empty($original['billing_trial_ends_at'])) { |
|
| 449 | - if (strtotime($model->billing_trial_ends_at) > strtotime($model->getOriginal('billing_trial_ends_at'))) { |
|
| 450 | - $model->fireSubscriptionEvent('trialExtended'); |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - $model->fireSubscriptionEvent('trialChanged'); |
|
| 454 | - } |
|
| 455 | - if ($model->isDirty('billing_subscription_discounts')) { |
|
| 456 | - if (count($model->billing_subscription_discounts) > count(json_decode($model->getOriginal('billing_subscription_discounts'), true))) { |
|
| 457 | - $model->fireSubscriptionEvent('subscriptionDiscountAdded'); |
|
| 458 | - } |
|
| 459 | - else if (count($model->billing_subscription_discounts) < count(json_decode($model->getOriginal('billing_subscription_discounts'), true))) { |
|
| 460 | - $model->fireSubscriptionEvent('subscriptionDiscountRemoved'); |
|
| 461 | - } |
|
| 462 | - else if (!empty($model->billing_subscription_discounts)) { |
|
| 463 | - $model->fireSubscriptionEvent('subscriptionDiscountUpdated'); |
|
| 464 | - } |
|
| 465 | - $model->fireSubscriptionEvent('subscriptionDiscountChanged'); |
|
| 466 | - } |
|
| 467 | - }); |
|
| 419 | + if ($model->isDirty('billing_subscription_ends_at')) { |
|
| 420 | + if (empty($model->billing_subscription_ends_at) && !empty($original['billing_subscription_ends_at'])) { |
|
| 421 | + $model->fireSubscriptionEvent('billingResumed'); |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + else if (empty($model->billing_active) && !empty($original['billing_active'])) { |
|
| 426 | + $model->fireSubscriptionEvent('billingCanceled'); |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + if ($model->isDirty('billing_plan')) { |
|
| 430 | + if (!empty($original['billing_plan']) && !empty($model->billing_plan)) { |
|
| 431 | + $model->fireSubscriptionEvent('planSwapped'); |
|
| 432 | + } |
|
| 433 | + if (!empty($model->billing_plan)) { |
|
| 434 | + $model->fireSubscriptionEvent('planChanged'); |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + if ($model->isDirty('billing_quantity')) { |
|
| 438 | + if ($model->billing_quantity > 0 && $model->getOriginal('billing_quantity') > 0) { |
|
| 439 | + if ($model->billing_quantity > $model->getOriginal('billing_quantity')) { |
|
| 440 | + $model->fireSubscriptionEvent('subscriptionIncremented'); |
|
| 441 | + } |
|
| 442 | + else { |
|
| 443 | + $model->fireSubscriptionEvent('subscriptionDecremented'); |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + if ($model->isDirty('billing_trial_ends_at')) { |
|
| 448 | + if (!empty($model->billing_trial_ends_at) && !empty($original['billing_trial_ends_at'])) { |
|
| 449 | + if (strtotime($model->billing_trial_ends_at) > strtotime($model->getOriginal('billing_trial_ends_at'))) { |
|
| 450 | + $model->fireSubscriptionEvent('trialExtended'); |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + $model->fireSubscriptionEvent('trialChanged'); |
|
| 454 | + } |
|
| 455 | + if ($model->isDirty('billing_subscription_discounts')) { |
|
| 456 | + if (count($model->billing_subscription_discounts) > count(json_decode($model->getOriginal('billing_subscription_discounts'), true))) { |
|
| 457 | + $model->fireSubscriptionEvent('subscriptionDiscountAdded'); |
|
| 458 | + } |
|
| 459 | + else if (count($model->billing_subscription_discounts) < count(json_decode($model->getOriginal('billing_subscription_discounts'), true))) { |
|
| 460 | + $model->fireSubscriptionEvent('subscriptionDiscountRemoved'); |
|
| 461 | + } |
|
| 462 | + else if (!empty($model->billing_subscription_discounts)) { |
|
| 463 | + $model->fireSubscriptionEvent('subscriptionDiscountUpdated'); |
|
| 464 | + } |
|
| 465 | + $model->fireSubscriptionEvent('subscriptionDiscountChanged'); |
|
| 466 | + } |
|
| 467 | + }); |
|
| 468 | 468 | |
| 469 | - $listening_for_subscription_events = true; |
|
| 470 | - } |
|
| 469 | + $listening_for_subscription_events = true; |
|
| 470 | + } |
|
| 471 | 471 | } |
@@ -384,7 +384,9 @@ discard block |
||
| 384 | 384 | */ |
| 385 | 385 | public function fireSubscriptionEvent($event) |
| 386 | 386 | { |
| 387 | - if ( ! isset(static::$dispatcher)) return true; |
|
| 387 | + if ( ! isset(static::$dispatcher)) { |
|
| 388 | + return true; |
|
| 389 | + } |
|
| 388 | 390 | |
| 389 | 391 | // We will append the names of the class to the event to distinguish it from |
| 390 | 392 | // other model events that are fired, allowing us to listen on each model |
@@ -421,8 +423,7 @@ discard block |
||
| 421 | 423 | $model->fireSubscriptionEvent('billingResumed'); |
| 422 | 424 | } |
| 423 | 425 | } |
| 424 | - } |
|
| 425 | - else if (empty($model->billing_active) && !empty($original['billing_active'])) { |
|
| 426 | + } else if (empty($model->billing_active) && !empty($original['billing_active'])) { |
|
| 426 | 427 | $model->fireSubscriptionEvent('billingCanceled'); |
| 427 | 428 | } |
| 428 | 429 | } |
@@ -438,8 +439,7 @@ discard block |
||
| 438 | 439 | if ($model->billing_quantity > 0 && $model->getOriginal('billing_quantity') > 0) { |
| 439 | 440 | if ($model->billing_quantity > $model->getOriginal('billing_quantity')) { |
| 440 | 441 | $model->fireSubscriptionEvent('subscriptionIncremented'); |
| 441 | - } |
|
| 442 | - else { |
|
| 442 | + } else { |
|
| 443 | 443 | $model->fireSubscriptionEvent('subscriptionDecremented'); |
| 444 | 444 | } |
| 445 | 445 | } |
@@ -455,11 +455,9 @@ discard block |
||
| 455 | 455 | if ($model->isDirty('billing_subscription_discounts')) { |
| 456 | 456 | if (count($model->billing_subscription_discounts) > count(json_decode($model->getOriginal('billing_subscription_discounts'), true))) { |
| 457 | 457 | $model->fireSubscriptionEvent('subscriptionDiscountAdded'); |
| 458 | - } |
|
| 459 | - else if (count($model->billing_subscription_discounts) < count(json_decode($model->getOriginal('billing_subscription_discounts'), true))) { |
|
| 458 | + } else if (count($model->billing_subscription_discounts) < count(json_decode($model->getOriginal('billing_subscription_discounts'), true))) { |
|
| 460 | 459 | $model->fireSubscriptionEvent('subscriptionDiscountRemoved'); |
| 461 | - } |
|
| 462 | - else if (!empty($model->billing_subscription_discounts)) { |
|
| 460 | + } else if (!empty($model->billing_subscription_discounts)) { |
|
| 463 | 461 | $model->fireSubscriptionEvent('subscriptionDiscountUpdated'); |
| 464 | 462 | } |
| 465 | 463 | $model->fireSubscriptionEvent('subscriptionDiscountChanged'); |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | */ |
| 385 | 385 | public function fireSubscriptionEvent($event) |
| 386 | 386 | { |
| 387 | - if ( ! isset(static::$dispatcher)) return true; |
|
| 387 | + if (!isset(static::$dispatcher)) return true; |
|
| 388 | 388 | |
| 389 | 389 | // We will append the names of the class to the event to distinguish it from |
| 390 | 390 | // other model events that are fired, allowing us to listen on each model |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | return; |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - static::saved(function ($model) { |
|
| 412 | + static::saved(function($model) { |
|
| 413 | 413 | $original = $model->getOriginal(); |
| 414 | 414 | |
| 415 | 415 | if ($model->isDirty('billing_active')) { |