Skip to content

Commit 9199acf

Browse files
committed
improve error handling
1 parent a482e41 commit 9199acf

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

src/Console/Commands/CreateStripeEndpoints.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ public function handle()
4343
Stripe\Stripe::setApiKey(config('services.stripe.secret'));
4444

4545
$this->info('Creating endpoints ...');
46-
$this->createEndpoints();
46+
47+
try {
48+
$this->createEndpoints();
49+
} catch (\Stripe\Error\InvalidRequest $e) {
50+
$this->error($e->getMessage());
51+
}
4752

4853
$this->info('Finished');
4954
}

src/Console/Commands/CreateStripePlans.php

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ protected function createProduct()
7070
$id = $this->getProductId();
7171

7272
try {
73-
Stripe\Product::retrieve($id);
74-
75-
$this->line('Stripe product ' . $id . ' already exists');
76-
} catch (\Exception $e) {
7773
Stripe\Product::create([
7874
'id' => $id,
7975
'name' => Spark::$details['product'],
@@ -83,6 +79,8 @@ protected function createProduct()
8379
]);
8480

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

8886
}
@@ -99,9 +97,7 @@ protected function createStripePlans($plans)
9997
continue;
10098
}
10199

102-
if ($this->planExists($plan)) {
103-
$this->line('Stripe plan ' . $plan->id . ' already exists');
104-
} else {
100+
try {
105101
Stripe\Plan::create([
106102
'id' => $plan->id,
107103
'nickname' => $plan->name,
@@ -115,24 +111,9 @@ protected function createStripePlans($plans)
115111
]);
116112

117113
$this->info('Stripe plan created: ' . $plan->id);
114+
} catch (\Stripe\Error\InvalidRequest $e) {
115+
$this->line('Stripe plan ' . $plan->id . ' already exists');
118116
}
119117
}
120118
}
121-
122-
/**
123-
* Check if a plan already exists
124-
*
125-
* @param $plan
126-
* @return bool
127-
*/
128-
private function planExists($plan)
129-
{
130-
try {
131-
Stripe\Plan::retrieve($plan->id);
132-
return true;
133-
} catch (\Exception $e) {
134-
}
135-
136-
return false;
137-
}
138119
}

0 commit comments

Comments
 (0)