Update app/Livewire/Subscription/Index.php
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
@@ -50,29 +50,37 @@ class Index extends Component
|
|||||||
|
|
||||||
public function getStripeStatus()
|
public function getStripeStatus()
|
||||||
{
|
{
|
||||||
$subscription = currentTeam()->subscription;
|
try {
|
||||||
$stripe = new \Stripe\StripeClient(config('subscription.stripe_api_key'));
|
$subscription = currentTeam()->subscription;
|
||||||
$customer = $stripe->customers->retrieve(currentTeam()->subscription->stripe_customer_id);
|
$stripe = new \Stripe\StripeClient(config('subscription.stripe_api_key'));
|
||||||
if ($customer) {
|
$customer = $stripe->customers->retrieve(currentTeam()->subscription->stripe_customer_id);
|
||||||
$subscriptions = $stripe->subscriptions->all(['customer' => $customer->id]);
|
if ($customer) {
|
||||||
$currentTeam = currentTeam()->id ?? null;
|
$subscriptions = $stripe->subscriptions->all(['customer' => $customer->id]);
|
||||||
if (count($subscriptions->data) > 0 && $currentTeam) {
|
$currentTeam = currentTeam()->id ?? null;
|
||||||
$foundSubscription = collect($subscriptions->data)->firstWhere('metadata.team_id', $currentTeam);
|
if (count($subscriptions->data) > 0 && $currentTeam) {
|
||||||
if ($foundSubscription) {
|
$foundSubscription = collect($subscriptions->data)->firstWhere('metadata.team_id', $currentTeam);
|
||||||
$status = data_get($foundSubscription, 'status');
|
if ($foundSubscription) {
|
||||||
$subscription->update([
|
$status = data_get($foundSubscription, 'status');
|
||||||
'stripe_subscription_id' => $foundSubscription->id,
|
$subscription->update([
|
||||||
]);
|
'stripe_subscription_id' => $foundSubscription->id,
|
||||||
if ($status === 'unpaid') {
|
]);
|
||||||
$this->isUnpaid = true;
|
if ($status === 'unpaid') {
|
||||||
|
$this->isUnpaid = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (count($subscriptions->data) === 0) {
|
||||||
|
$this->isCancelled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (count($subscriptions->data) === 0) {
|
} catch (\Exception $e) {
|
||||||
$this->isCancelled = true;
|
// Log the error
|
||||||
}
|
logger()->error('Stripe API error: ' . $e->getMessage());
|
||||||
|
// Set a flag to show an error message to the user
|
||||||
|
$this->addError('stripe', 'Could not retrieve subscription information. Please try again later.');
|
||||||
|
} finally {
|
||||||
|
$this->loading = false;
|
||||||
}
|
}
|
||||||
$this->loading = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
|
|||||||
Reference in New Issue
Block a user