Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Oct 15, 2019
1 parent a482e41 commit 9199acf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
7 changes: 6 additions & 1 deletion src/Console/Commands/CreateStripeEndpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ public function handle()
Stripe\Stripe::setApiKey(config('services.stripe.secret'));

$this->info('Creating endpoints ...');
$this->createEndpoints();

try {
$this->createEndpoints();
} catch (\Stripe\Error\InvalidRequest $e) {
$this->error($e->getMessage());
}

$this->info('Finished');
}
Expand Down
29 changes: 5 additions & 24 deletions src/Console/Commands/CreateStripePlans.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ protected function createProduct()
$id = $this->getProductId();

try {
Stripe\Product::retrieve($id);

$this->line('Stripe product ' . $id . ' already exists');
} catch (\Exception $e) {
Stripe\Product::create([
'id' => $id,
'name' => Spark::$details['product'],
Expand All @@ -83,6 +79,8 @@ protected function createProduct()
]);

$this->info('Stripe product created: ' . $id);
} catch (\Stripe\Error\InvalidRequest $e) {
$this->line('Stripe product ' . $id . ' already exists');
}

}
Expand All @@ -99,9 +97,7 @@ protected function createStripePlans($plans)
continue;
}

if ($this->planExists($plan)) {
$this->line('Stripe plan ' . $plan->id . ' already exists');
} else {
try {
Stripe\Plan::create([
'id' => $plan->id,
'nickname' => $plan->name,
Expand All @@ -115,24 +111,9 @@ protected function createStripePlans($plans)
]);

$this->info('Stripe plan created: ' . $plan->id);
} catch (\Stripe\Error\InvalidRequest $e) {
$this->line('Stripe plan ' . $plan->id . ' already exists');
}
}
}

/**
* Check if a plan already exists
*
* @param $plan
* @return bool
*/
private function planExists($plan)
{
try {
Stripe\Plan::retrieve($plan->id);
return true;
} catch (\Exception $e) {
}

return false;
}
}

0 comments on commit 9199acf

Please # to comment.