diff --git a/app/Http/Controllers/CompanyGatewayController.php b/app/Http/Controllers/CompanyGatewayController.php index 6936bdc2b739..ef5edc80cae2 100644 --- a/app/Http/Controllers/CompanyGatewayController.php +++ b/app/Http/Controllers/CompanyGatewayController.php @@ -433,9 +433,14 @@ class CompanyGatewayController extends BaseController */ public function destroy(DestroyCompanyGatewayRequest $request, CompanyGateway $company_gateway) { + + $company_gateway->driver(new Client) + ->disconnect(); + $company_gateway->delete(); return $this->itemResponse($company_gateway->fresh()); + } /** diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 2ad64c1ae8c3..65705fc19c9d 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -631,4 +631,9 @@ class BaseDriver extends AbstractPaymentDriver return $types; } + + public function disconnect() + { + return true; + } } diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 12cd5a30e1a9..3124b6fbd7fb 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -547,4 +547,29 @@ class StripePaymentDriver extends BaseDriver { return (new Verify($this))->run(); } + + public function disconnect() + { + if(!$this->stripe_connect) + return true; + + if(!strlen($this->company_gateway->getConfigField('account_id')) > 1 ) + throw new StripeConnectFailure('Stripe Connect has not been configured'); + + Stripe::setApiKey(config('ninja.ninja_stripe_key')); + + try { + + \Stripe\OAuth::deauthorize([ + 'client_id' => config('ninja.ninja_stripe_client_id'), + 'stripe_user_id' => $this->company_gateway->getConfigField('account_id'), + ]); + + } + catch(\Exception $e){ + throw new StripeConnectFailure('Unable to disconnect Stripe Connect'); + } + + return response()->json(['message' => 'success'], 200); + } }