Skip to content

Commit 3ed5989

Browse files
committed
fix: switch from app load to command init
1 parent 7133955 commit 3ed5989

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/Stripe.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ public function __construct($billingSettings = [])
6161
$this->config = $billingSettings;
6262
$this->provider = new StripeClient($config);
6363

64+
if (storage()->exists(StoragePath('billing/stripe.json'))) {
65+
$provider = storage()->read(StoragePath('billing/stripe.json'));
66+
$provider = json_decode($provider, true);
67+
68+
$this->product = $provider['product'];
69+
$this->tiers = $provider['tiers'];
70+
}
71+
}
72+
73+
/**
74+
* @inheritDoc
75+
*/
76+
public function initialize(): bool
77+
{
6478
if (storage()->exists(StoragePath('billing/stripe.json'))) {
6579
$provider = storage()->read(StoragePath('billing/stripe.json'));
6680
$provider = json_decode($provider, true);
@@ -73,13 +87,20 @@ public function __construct($billingSettings = [])
7387
]);
7488

7589
$this->product = $stripeProduct->id;
76-
$this->initTiers($billingSettings['tiers']);
90+
}
7791

78-
storage()->createFile(StoragePath('billing/stripe.json'), json_encode([
79-
'product' => $this->product,
80-
'tiers' => $this->tiers,
81-
]), ['recursive' => true]);
92+
try {
93+
$this->initTiers($this->config['tiers']);
94+
} catch (\Throwable $th) {
95+
return false;
8296
}
97+
98+
storage()->createFile(StoragePath('billing/stripe.json'), json_encode([
99+
'product' => $this->product,
100+
'tiers' => $this->tiers,
101+
]), ['recursive' => true]);
102+
103+
return true;
83104
}
84105

85106
protected function initTiers(array $tierSettings)

0 commit comments

Comments
 (0)