/**
  * Resume a canceled subscription in the billing gateway.
  *
  * @param int $quantity
  * 
  * @return Subscription
  */
 public function resume($quantity = null)
 {
     if (null === $quantity) {
         $quantity = $this->model->billing_quantity;
     }
     if ($this->is_free || $this->canLocalTrial()) {
         return $this->storeLocal(array('quantity' => $quantity));
     }
     if (!$this->model->canceled()) {
         return $this;
     }
     if (($customer = $this->model->customer()) && $this->card_token) {
         $this->card = $customer->creditcards()->create($this->card_token)->id;
         $this->card_token = null;
     }
     $this->subscription = Billing::subscription($this->model->billing_subscription, $customer ? $customer->gatewayCustomer() : null);
     if ($this->subscription->info()) {
         $this->subscription->update(array('plan' => $this->plan, 'trial_ends_at' => $this->skip_trial ? date('Y-m-d H:i:s') : $this->model->billing_trial_ends_at, 'prorate' => false, 'quantity' => $quantity, 'card_token' => $this->card_token, 'source' => $this->card, 'billing_active' => 1));
     } else {
         $this->subscription = Billing::subscription(null, $customer ? $customer->gatewayCustomer() : null)->create($this->plan, array('trial_ends_at' => $this->skip_trial ? date('Y-m-d H:i:s') : $this->model->billing_trial_ends_at, 'quantity' => $quantity, 'card_token' => $this->card_token, 'card' => $this->card));
     }
     $this->refresh();
     return $this;
 }
 /**
  * Return the gateway subscription object for this model.
  *
  * @return LinkThrow\Billing\Gateways\SubscriptionInterface
  */
 public function gatewaySubscription()
 {
     if (!$this->everSubscribed()) {
         return null;
     }
     if ($customer = $this->customer()) {
         $customer = $customer->gatewayCustomer();
     }
     return Billing::subscription($this->billing_subscription, $customer);
 }
 /**
  * Return the gateway customer object for this user.
  *
  * @return LinkThrow\Billing\Gateways\CustomerInterface
  */
 public function gatewayCustomer()
 {
     if (!$this->readyForBilling()) {
         return null;
     }
     return Billing::customer($this->billing_id);
 }
 /**
  * Handle a Braintree webhook call.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function handleWebhook()
 {
     // Initialize Braintree gateway (config vars).
     Billing::customer();
     $payload = Braintree_WebhookNotification::parse(Input::get('bt_signature'), Input::get('bt_payload'));
     $method = 'handle' . studly_case(str_replace('.', '_', $payload->kind));
     if (method_exists($this, $method)) {
         return $this->{$method}($payload);
     } else {
         return $this->missingMethod();
     }
 }
Beispiel #5
0
 /**
  * Create this customer in the billing gateway.
  *
  * @param array $properties
  * 
  * @return Billing
  */
 public function create(array $properties = array())
 {
     if ($this->model->readyForBilling()) {
         return $this;
     }
     $this->customer = \LinkThrow\Billing\Facades\Billing::customer()->create(array_merge($properties, array('coupon' => $this->coupon, 'card_token' => $this->card_token)));
     $this->refresh();
     if ($this->with_subscriptions) {
         $this->createPendingSubscriptions();
     }
     return $this;
 }
 /**
  * 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);
 }
 /**
  * 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();
     $code = $this->ask('What is the coupon Code (eg. 20percentoff)?');
     $percent_off = $this->ask('What is the coupon Percent Off (enter for none)?');
     $amount_off = $this->ask('What is the coupon Amount Off (in cents) (enter for none)?');
     $duration_in_months = $this->ask('How many months should this coupon last (press enter for unlimited)?');
     $coupon = Gateways\Local\Models\Coupon::create(array('code' => $code, 'percent_off' => $percent_off ? $percent_off : null, 'amount_off' => $amount_off ? $amount_off : null, 'duration_in_months' => $duration_in_months ? $duration_in_months : null));
     $this->info('Coupon created successfully: ' . $coupon->id);
 }
Beispiel #8
0
 /**
  * Create this charge in the billing gateway.
  *
  * @param int   $amount
  * @param array $properties
  * 
  * @return Charge
  */
 public function create($amount, array $properties = array())
 {
     if (!$this->model->readyForBilling()) {
         if ($this->card_token) {
             $this->model->billing()->withCardToken($this->card_token)->create($properties);
             if (!empty($this->model->billing_cards)) {
                 $this->card_token = null;
             }
         } else {
             $this->model->billing()->create($properties);
         }
     }
     if ($this->card_token) {
         $this->card = $this->model->creditcards()->create($this->card_token)->id;
         $this->card_token = null;
     }
     $gateway_charge = \LinkThrow\Billing\Facades\Billing::charge(null, $this->model->gatewayCustomer())->create($amount, array_merge($properties, array('card_token' => $this->card_token, 'card' => $this->card)));
     return new Charge($this->model, $gateway_charge);
 }