diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 68b70e84fb15..052a477c2da2 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -14,6 +14,7 @@ namespace App\Exceptions; use App\Exceptions\FilePermissionsFailure; use App\Exceptions\InternalPDFFailure; use App\Exceptions\PhantomPDFFailure; +use App\Exceptions\StripeConnectFailure; use App\Utils\Ninja; use Exception; use Illuminate\Auth\Access\AuthorizationException; @@ -197,6 +198,8 @@ class Handler extends ExceptionHandler return response()->json(['message' => $exception->getMessage()], 400); } elseif ($exception instanceof GenericPaymentDriverFailure) { return response()->json(['message' => $exception->getMessage()], 400); + } elseif ($exception instanceof StripeConnectFailure) { + return response()->json(['message' => $exception->getMessage()], 400); } return parent::render($request, $exception); diff --git a/app/Exceptions/StripeConnectFailure.php b/app/Exceptions/StripeConnectFailure.php new file mode 100644 index 000000000000..1aae9e57eabe --- /dev/null +++ b/app/Exceptions/StripeConnectFailure.php @@ -0,0 +1,10 @@ +stripe->init(); if($this->stripe->stripe_connect && strlen($this->stripe->company_gateway->getConfigField('account_id')) < 1) - return response()->json("Stripe Connect not authenticated", 400); + throw new StripeConnectFailure('Stripe Connect has not been configured'); $customers = Customer::all([], $this->stripe->stripe_connect_auth); diff --git a/app/PaymentDrivers/Stripe/ImportCustomers.php b/app/PaymentDrivers/Stripe/ImportCustomers.php index 0e5b95cc0e65..8377ba7c0fba 100644 --- a/app/PaymentDrivers/Stripe/ImportCustomers.php +++ b/app/PaymentDrivers/Stripe/ImportCustomers.php @@ -12,6 +12,7 @@ namespace App\PaymentDrivers\Stripe; +use App\Exceptions\StripeConnectFailure; use App\Factory\ClientContactFactory; use App\Factory\ClientFactory; use App\Factory\ClientGatewayTokenFactory; @@ -51,7 +52,7 @@ class ImportCustomers $this->update_payment_methods = new UpdatePaymentMethods($this->stripe); if(strlen($this->stripe->company_gateway->getConfigField('account_id')) < 1) - throw new \Exception('Stripe Connect has not been configured'); + throw new StripeConnectFailure('Stripe Connect has not been configured'); $customers = Customer::all([], $this->stripe->stripe_connect_auth); diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 547637de360e..f792ce495422 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -13,6 +13,7 @@ namespace App\PaymentDrivers; use App\Exceptions\PaymentFailed; +use App\Exceptions\StripeConnectFailure; use App\Factory\PaymentFactory; use App\Http\Requests\Payments\PaymentWebhookRequest; use App\Http\Requests\Request; @@ -90,7 +91,7 @@ class StripePaymentDriver extends BaseDriver if(strlen($this->company_gateway->getConfigField('account_id')) > 1) $this->stripe_connect_auth = ["stripe_account" => $this->company_gateway->getConfigField('account_id')]; else - throw new \Exception('Stripe Connect has not been configured'); + throw new StripeConnectFailure('Stripe Connect has not been configured'); } else {