/** * Execute the console command. * * @return void */ public function fire() { if ('local' != Config::get('laravel-billing::default')) { return $this->error('Not configured to use the "local" driver.'); } // Init gateway. Facades\Billing::customer(); $key = $this->ask('What is the plan ID (eg. basic or pro)?'); $amount = $this->ask('What is the plan Amount (in cents)?'); $interval = $this->ask('What is the plan Interval (eg. monthly or yearly)?'); $trial_period_days = $this->ask('How many days of trial do you want to give (press enter for none)?'); $plan = Gateways\Local\Models\Plan::create(array('key' => $key, 'name' => ucwords($key), 'amount' => $amount, 'interval' => $interval, 'trial_period_days' => $trial_period_days)); $this->info('Plan created successfully: ' . $plan->id); }
/** * 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; }