/** * Delete a card. * * @return Card */ public function delete() { $this->info(); $this->local_card->delete(); $this->gateway->apiDelay(); $this->local_card = null; return $this; }
/** * Update a subscription. * * @param array $properties * * @return Subscription */ public function update(array $properties = array()) { $this->info(); if (!empty($properties['plan'])) { $this->local_subscription->plan_id = Models\Plan::where('key', $properties['plan'])->first()->id; } if (!empty($properties['quantity'])) { $this->local_subscription->quantity = $properties['quantity']; } if (!empty($properties['trial_ends_at'])) { $trial_ends_at = date('Y-m-d H:i:s', strtotime((string) $properties['trial_ends_at'])); if (strtotime($properties['trial_ends_at']) <= time()) { if ($this->local_subscription->trial_ends_at && strtotime((string) $this->local_subscription->trial_ends_at) > time()) { $this->local_subscription->trial_ends_at = date('Y-m-d H:i:s'); } } else { $this->local_subscription->trial_ends_at = $trial_ends_at; } } if (!empty($properties['coupon'])) { $this->local_subscription->coupon_id = $properties['coupon']; } if (!empty($properties['card_token'])) { $card_id = $this->gateway->customer($this->local_customer)->card()->create($properties['card_token'])->id(); $this->local_subscription->card_id = Models\Card::find($card_id)->id; } else { if (!empty($properties['card'])) { $this->local_subscription->card_id = Models\Card::find($properties['card'])->id; } } $this->local_subscription->cancel_at = null; $this->local_subscription->save(); $this->gateway->apiDelay(); $this->local_subscription = null; return $this; }
/** * Create a new charge. * * @param int $amount * @param array $properties * * @return Charge */ public function create($amount, array $properties = array()) { $card_id = empty($properties['card']) ? null : $properties['card']; if (!empty($properties['card_token'])) { $card_id = $this->gateway->customer($this->local_customer)->card()->create($properties['card_token'])->id(); } if (!$card_id) { $card_id = $this->local_customer->cards->first()->id; } $this->local_charge = Models\Charge::create(array('customer_id' => $this->local_customer->id, 'amount' => $amount, 'card_id' => Models\Card::find($card_id)->id, 'description' => Arr::get($properties, 'description'), 'paid' => false, 'captured' => false, 'refunded' => false)); $this->gateway->apiDelay(); $this->id = $this->local_charge->id; if (Arr::get($properties, 'capture', true)) { $this->local_charge->capture(); } return $this; }