Skip to content

Commit

Permalink
use getApp() instead of $this->app in models
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared King committed Jun 4, 2016
1 parent 2175947 commit 3eafbce
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/Models/BillableModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ abstract public function stripeCustomerData();

protected function preCreateHook()
{
if (isset($this->not_charged) && !$this->app['user']->isAdmin()) {
if (isset($this->not_charged) && !$this->getApp()['user']->isAdmin()) {
unset($this->not_charged);
}

Expand All @@ -101,7 +101,7 @@ protected function preCreateHook()

protected function preSetHook(&$data)
{
if (isset($data['not_charged']) && !$this->app['user']->isAdmin()) {
if (isset($data['not_charged']) && !$this->getApp()['user']->isAdmin()) {
unset($data['not_charged']);
}

Expand All @@ -119,16 +119,18 @@ protected function preSetHook(&$data)
*/
public function stripeCustomer()
{
$apiKey = $this->app['config']->get('stripe.secret');
$app = $this->getApp();

$apiKey = $app['config']->get('stripe.secret');

// attempt to retreive the customer on stripe
try {
if ($custId = $this->stripe_customer) {
return Customer::retrieve($custId, $apiKey);
}
} catch (StripeError $e) {
$this->app['logger']->debug($e);
$this->app['errors']->push([
$app['logger']->debug($e);
$app['errors']->push([
'error' => 'stripe_error',
'message' => $e->getMessage(), ]);

Expand All @@ -139,7 +141,7 @@ public function stripeCustomer()
try {
// This is necessary because save() on stripe objects does
// not accept an API key or save one from the retrieve() request
Stripe::setApiKey($this->app['config']->get('stripe.secret'));
Stripe::setApiKey($app['config']->get('stripe.secret'));

$customer = Customer::create($this->stripeCustomerData(), $apiKey);

Expand All @@ -150,8 +152,8 @@ public function stripeCustomer()

return $customer;
} catch (StripeError $e) {
$this->app['logger']->debug($e);
$this->app['errors']->push([
$app['logger']->debug($e);
$app['errors']->push([
'error' => 'stripe_error',
'message' => $e->getMessage(), ]);
}
Expand All @@ -170,6 +172,8 @@ public function stripeCustomer()
*/
public function setDefaultCard($token)
{
$app = $this->getApp();

$customer = $this->stripeCustomer();

if (!$customer || empty($token)) {
Expand All @@ -178,16 +182,16 @@ public function setDefaultCard($token)

// This is necessary because save() on stripe objects does
// not accept an API key or save one from the retrieve() request
Stripe::setApiKey($this->app['config']->get('stripe.secret'));
Stripe::setApiKey($app['config']->get('stripe.secret'));

try {
$customer->source = $token;
$customer->save();

return true;
} catch (StripeError $e) {
$this->app['logger']->debug($e);
$this->app['errors']->push([
$app['logger']->debug($e);
$app['errors']->push([
'error' => 'stripe_error',
'message' => $e->getMessage(), ]);

Expand All @@ -208,7 +212,7 @@ public function subscription($plan = false)
$plan = $this->plan;
}

return new BillingSubscription($this, $plan, $this->app);
return new BillingSubscription($this, $plan, $this->getApp());
}

/**
Expand Down

0 comments on commit 3eafbce

Please sign in to comment.