fix: Catch stripe errors (#1714)
This commit is contained in:
@@ -138,12 +138,35 @@ class SubscriptionsController extends Controller
|
||||
|
||||
$plan = InstanceHelper::getPlanInformationFromConfig($request->input('plan'));
|
||||
|
||||
auth()->user()->account->newSubscription($plan['name'], $plan['id'])
|
||||
->create($stripeToken, [
|
||||
'email' => auth()->user()->email,
|
||||
]);
|
||||
try {
|
||||
auth()->user()->account->newSubscription($plan['name'], $plan['id'])
|
||||
->create($stripeToken, [
|
||||
'email' => auth()->user()->email,
|
||||
]);
|
||||
|
||||
return redirect()->route('settings.subscriptions.upgrade.success');
|
||||
return redirect()->route('settings.subscriptions.upgrade.success');
|
||||
} catch (\Stripe\Error\Card $e) {
|
||||
// Since it's a decline, \Stripe\Error\Card will be caught
|
||||
$body = $e->getJsonBody();
|
||||
$err = $body['error'];
|
||||
$message = trans('settings.stripe_error_card', ['message' => $err['message']]);
|
||||
} catch (\Stripe\Error\RateLimit $e) {
|
||||
// Too many requests made to the API too quickly
|
||||
$message = trans('settings.stripe_error_rate_limit');
|
||||
} catch (\Stripe\Error\Authentication $e) {
|
||||
// Authentication with Stripe's API failed
|
||||
// (maybe you changed API keys recently)
|
||||
$message = trans('settings.stripe_error_authentication');
|
||||
} catch (\Stripe\Error\ApiConnection $e) {
|
||||
// Network communication with Stripe failed
|
||||
$message = trans('settings.stripe_error_api_connection_error');
|
||||
} catch (\Stripe\Error\Base $e) {
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
return back()
|
||||
->withInput()
|
||||
->withErrors($message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user