From cf4316b5ab5707d40eba291138eac3966aec2ce8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 9 Oct 2021 18:07:05 +1100 Subject: [PATCH] Allow disconnect from Stripe Connect --- app/Http/Controllers/StripeController.php | 14 ++++++++++++++ app/PaymentDrivers/StripePaymentDriver.php | 5 +++++ app/Utils/HtmlEngine.php | 3 +++ routes/api.php | 1 + 4 files changed, 23 insertions(+) diff --git a/app/Http/Controllers/StripeController.php b/app/Http/Controllers/StripeController.php index 61d412a1c2..1f303b7fc3 100644 --- a/app/Http/Controllers/StripeController.php +++ b/app/Http/Controllers/StripeController.php @@ -17,9 +17,11 @@ use App\Jobs\Util\StripeUpdatePaymentMethods; use App\Libraries\MultiDB; use App\Models\Client; use App\Models\CompanyGateway; +use App\Utils\Traits\MakesHash; class StripeController extends BaseController { + use MakesHash; private $stripe_keys = ['d14dd26a47cecc30fdd65700bfb67b34', 'd14dd26a37cecc30fdd65700bfb55b23']; @@ -75,4 +77,16 @@ class StripeController extends BaseController return response()->json(['message' => 'Unauthorized'], 403); } + + public function disconnect(string $company_gateway_id) + { + + $company_gateway = CompanyGateway::where('company_id', auth()->user()->company()->id) + ->where('id', $this->decodePrimaryKey($company_gateway_id)) + ->whereIn('gateway_key', $this->stripe_keys) + ->firstOrFail(); + + return $company_gateway->driver()->disconnect(); + + } } \ No newline at end of file diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 604a4a89c5..181bed60cb 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -636,6 +636,11 @@ class StripePaymentDriver extends BaseDriver 'stripe_user_id' => $this->company_gateway->getConfigField('account_id'), ]); + $config = $this->company_gateway->getConfig(); + $config->account_id = ""; + $this->company_gateway->setConfig($config); + $this->company_gateway->save(); + } catch(\Exception $e){ throw new StripeConnectFailure('Unable to disconnect Stripe Connect'); diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 03d8ffc1a2..de8cd66988 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -203,6 +203,7 @@ class HtmlEngine if ($this->entity->partial > 0) { $data['$balance_due'] = ['value' => Number::formatMoney($this->entity->partial, $this->client) ?: ' ', 'label' => ctrans('texts.partial_due')]; $data['$balance_due_raw'] = ['value' => $this->entity->partial, 'label' => ctrans('texts.partial_due')]; + $data['$amount_raw'] = ['value' => $this->entity->partial, 'label' => ctrans('texts.partial_due')]; $data['$due_date'] = ['value' => $this->translateDate($this->entity->partial_due_date, $this->client->date_format(), $this->client->locale()) ?: ' ', 'label' => ctrans('texts.'.$this->entity_string.'_due_date')]; } else { @@ -210,10 +211,12 @@ class HtmlEngine if($this->entity->status_id == 1){ $data['$balance_due'] = ['value' => Number::formatMoney($this->entity->amount, $this->client) ?: ' ', 'label' => ctrans('texts.balance_due')]; $data['$balance_due_raw'] = ['value' => $this->entity->amount, 'label' => ctrans('texts.balance_due')]; + $data['$amount_raw'] = ['value' => $this->entity->amount, 'label' => ctrans('texts.amount')]; } else{ $data['$balance_due'] = ['value' => Number::formatMoney($this->entity->balance, $this->client) ?: ' ', 'label' => ctrans('texts.balance_due')]; $data['$balance_due_raw'] = ['value' => $this->entity->balance, 'label' => ctrans('texts.balance_due')]; + $data['$amount_raw'] = ['value' => $this->entity->amount, 'label' => ctrans('texts.amount')]; } } diff --git a/routes/api.php b/routes/api.php index 8e230cf3bf..96e445e4a1 100644 --- a/routes/api.php +++ b/routes/api.php @@ -199,6 +199,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::post('stripe/import_customers', 'StripeController@import')->middleware('password_protected')->name('stripe.import'); Route::post('stripe/verify', 'StripeController@verify')->middleware('password_protected')->name('stripe.verify'); + Route::post('stripe/disconnect/{company_gateway_id}', 'StripeController@disconnect')->middleware('password_protected')->name('stripe.disconnect'); Route::resource('subscriptions', 'SubscriptionController'); Route::post('subscriptions/bulk', 'SubscriptionController@bulk')->name('subscriptions.bulk');