diff --git a/app/Http/Controllers/StripeConnectController.php b/app/Http/Controllers/StripeConnectController.php index 055748b8c02f..59e5458cae72 100644 --- a/app/Http/Controllers/StripeConnectController.php +++ b/app/Http/Controllers/StripeConnectController.php @@ -12,9 +12,11 @@ namespace App\Http\Controllers; +use App\DataMapper\FeesAndLimits; use App\Factory\CompanyGatewayFactory; use App\Http\Requests\StripeConnect\InitializeStripeConnectRequest; use App\Libraries\MultiDB; +use App\Models\Client; use App\Models\CompanyGateway; use App\PaymentDrivers\Stripe\Connect\Account; use Stripe\Exception\ApiErrorException; @@ -70,8 +72,28 @@ class StripeConnectController extends BaseController 'config' => encrypt(json_encode(['account_id' => $account->id])) ]); + /* Set Credit Card To Enabled */ + $gateway_types = $company_gateway->driver(new Client)->gatewayTypes(); + + $fees_and_limits = new \stdClass; + $fees_and_limits->{$gateway_types[0]} = new FeesAndLimits; + + $company_gateway->fees_and_limits = $fees_and_limits; $company_gateway->save(); + /* Link account if existing account exists */ + if($account_id = $this->checkAccountAlreadyLinkToEmail($company_gateway, $request->getContact()->email)) { + + $config = json_decode(decrypt($company_gateway->config)); + + $config->account_id = $account_id; + $company_gateway->config = encrypt(json_encode($config)); + $company_gateway->save(); + + return render('gateways.stripe.connect.existing'); + } + + return redirect($link['url']); } @@ -79,4 +101,22 @@ class StripeConnectController extends BaseController { return render('gateways.stripe.connect.completed'); } + + + private function checkAccountAlreadyLinkToEmail($company_gateway, $email) + { + $client = Client::first() ? Client::first() : new Client; + + //Pull the list of Stripe Accounts and see if we match + $accounts = $company_gateway->driver($client)->getAllConnectedAccounts()->data; + + foreach($accounts as $account) + { + if($account['email'] == $email) + return $account['id']; + } + + return false; + + } } diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 7fc8ec6ea423..cafe46f220bf 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -1263,7 +1263,7 @@ class Import implements ShouldQueue if(Ninja::isHosted() && $modified['gateway_key'] == 'd14dd26a37cecc30fdd65700bfb55b23'){ $modified['gateway_key'] = 'd14dd26a47cecc30fdd65700bfb67b34'; - $modified['fees_and_limits'] = []; + $modified['fees_and_limits'] = '{}'; } $company_gateway = CompanyGateway::create($modified); diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 61418d9ddc83..2fdb5f27e5a3 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -30,6 +30,7 @@ use App\PaymentDrivers\Stripe\Utilities; use App\Utils\Traits\MakesHash; use Exception; use Illuminate\Support\Carbon; +use Stripe\Account; use Stripe\Customer; use Stripe\Exception\ApiErrorException; use Stripe\PaymentIntent; @@ -482,7 +483,14 @@ class StripePaymentDriver extends BaseDriver } catch (ApiErrorException | Exception $e) { return $this->processInternallyFailedPayment($this, $e); - + } } + + public function getAllConnectedAccounts() + { + $this->init(); + + return Account::all(); + } }