/** * Return the gateway customer object for this user. * * @return Mmanos\Billing\Gateways\CustomerInterface */ public function gatewayCustomer() { if (!$this->readyForBilling()) { return null; } return Billing::customer($this->billing_id); }
/** * Return the gateway client token * * @return Mmanos\Billing\Gateways\CustomerInterface */ public function clientToken($default = false) { $billing = null; if ($this->readyForBilling()) { $billing = $this->billing_id; } return \Mmanos\Billing\Facades\Billing::customer($billing)->clientToken($default); }
/** * Return the gateway subscription object for this model. * * @return Mmanos\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); }
/** * 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(); } }
/** * 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 = \Mmanos\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('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); }
/** * 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); }
/** * Create this subscription in the billing gateway. * * @param array $properties * * @return Subscription */ public function create(array $properties = array()) { if ($this->is_free || $this->canLocalTrial()) { return $this->storeLocal(array('quantity' => Arr::get($properties, 'quantity', 1))); } if ($this->model->billingIsActive()) { return $this; } if ($customer = $this->model->customer()) { if (!$customer->readyForBilling()) { if ($this->card_token) { $customer->billing()->withCardToken($this->card_token)->create($properties); if (!empty($customer->billing_cards)) { $this->card_token = null; } } else { $customer->billing()->create($properties); } } else { if ($this->card_token) { $this->card = $customer->creditcards()->create($this->card_token)->id; $this->card_token = null; } } } $this->subscription = Billing::subscription(null, $customer ? $customer->gatewayCustomer() : null)->create($this->plan, array_merge($properties, array('trial_ends_at' => $this->skip_trial ? date('Y-m-d H:i:s') : $this->model->billing_trial_ends_at, 'coupon' => $this->coupon, 'quantity' => Arr::get($properties, 'quantity', 1), 'card_token' => $this->card_token, 'card' => $this->card))); $this->model->billing_subscription_ends_at = null; $this->model->save(); $this->refresh(); return $this; }
/** * 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; }
/** * 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 = \Mmanos\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); }