This commit is contained in:
Benjamin Beganović 2021-04-21 16:36:08 +02:00
parent 81f4f3999d
commit bdc564092e
5 changed files with 52 additions and 12 deletions

View File

@ -12,6 +12,7 @@
namespace App\Http\Controllers;
use App\Factory\CompanyGatewayFactory;
use App\Http\Requests\StripeConnect\InitializeStripeConnectRequest;
use App\Models\CompanyGateway;
use App\PaymentDrivers\Stripe\Connect\Account;
@ -27,25 +28,33 @@ class StripeConnectController extends BaseController
*/
public function initialize(InitializeStripeConnectRequest $request, string $token)
{
// $request->getTokenContent();
// Should we check if company has set country in the ap? Otherwise this will fail.
$data = [
'type' => 'standard',
'email' => 'user@example.com',
'country' => 'US',
'email' => $request->getContact()->email,
'country' => $request->getCompany()->country()->iso_3166_2,
];
$account = Account::create($data);
$link = Account::link($account->id);
$link = Account::link($account->id, $token);
// Store account->id into company_gateways.
// $company_gateway = CompanyGatewayFactory::create($request->getCompany()->id, $request->getContact()->client->user->id);
//
// $company_gateway->fill([
// 'gateway_key' => 'provide-valid-stripe-key-here',
// 'fees_and_limits' => [],
// 'config' => encrypt(json_encode(['account_id' => $account->id]))
// ]);
//
// $company_gateway->save();
return redirect($link['url']);
}
public function completed()
{
dd(request()->all());
return render('gateways.stripe.connect.completed');
}
}

View File

@ -12,6 +12,8 @@
namespace App\Http\Requests\StripeConnect;
use App\Models\ClientContact;
use App\Models\Company;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Cache;
@ -46,10 +48,24 @@ class InitializeStripeConnectRequest extends FormRequest
*/
public function getTokenContent()
{
$data = Cache::get($this->input('token'));
$data = Cache::get($this->token);
abort_if(!$data, 404);
abort_if(!array_key_exists('user_id', $data), 404);
abort_if(!array_key_exists('company_key', $data), 404);
return $data;
}
public function getContact()
{
return ClientContact::findOrFail($this->getTokenContent()['user_id']);
}
public function getCompany()
{
return Company::where('company_key', $this->getTokenContent()['company_key'])->firstOrFail();
}
}

View File

@ -33,7 +33,7 @@ class Account
/**
* @throws \Stripe\Exception\ApiErrorException
*/
public static function link(string $account_id): \Stripe\AccountLink
public static function link(string $account_id, string $token): \Stripe\AccountLink
{
$stripe = new \Stripe\StripeClient(
config('ninja.ninja_stripe_key')
@ -41,8 +41,8 @@ class Account
return $stripe->accountLinks->create([
'account' => $account_id,
'refresh_url' => 'http://ninja.test:8000/stripe_connect/reauth',
'return_url' => 'http://ninja.test:8000/stripe_connect/return',
'refresh_url' => route('stripe_connect.initialization', $token),
'return_url' => route('stripe_connect.return'),
'type' => 'account_onboarding',
]);
}

View File

@ -0,0 +1,13 @@
@extends('portal.ninja2020.layout.clean')
@section('meta_title', ctrans('texts.success'))
@section('body')
<div class="flex flex-col justify-center items-center mt-10">
<div class="mb-4">
<svg height="60" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" x="0" y="0" viewBox="0 0 468 222.5" xml:space="preserve"><style>.st0{fill-rule:evenodd;clip-rule:evenodd;fill:#635bff}</style><path class="st0" d="M414 113.4c0-25.6-12.4-45.8-36.1-45.8-23.8 0-38.2 20.2-38.2 45.6 0 30.1 17 45.3 41.4 45.3 11.9 0 20.9-2.7 27.7-6.5v-20c-6.8 3.4-14.6 5.5-24.5 5.5-9.7 0-18.3-3.4-19.4-15.2h48.9c0-1.3.2-6.5.2-8.9zm-49.4-9.5c0-11.3 6.9-16 13.2-16 6.1 0 12.6 4.7 12.6 16h-25.8zM301.1 67.6c-9.8 0-16.1 4.6-19.6 7.8l-1.3-6.2h-22v116.6l25-5.3.1-28.3c3.6 2.6 8.9 6.3 17.7 6.3 17.9 0 34.2-14.4 34.2-46.1-.1-29-16.6-44.8-34.1-44.8zm-6 68.9c-5.9 0-9.4-2.1-11.8-4.7l-.1-37.1c2.6-2.9 6.2-4.9 11.9-4.9 9.1 0 15.4 10.2 15.4 23.3 0 13.4-6.2 23.4-15.4 23.4zM223.8 61.7l25.1-5.4V36l-25.1 5.3zM223.8 69.3h25.1v87.5h-25.1zM196.9 76.7l-1.6-7.4h-21.6v87.5h25V97.5c5.9-7.7 15.9-6.3 19-5.2v-23c-3.2-1.2-14.9-3.4-20.8 7.4zM146.9 47.6l-24.4 5.2-.1 80.1c0 14.8 11.1 25.7 25.9 25.7 8.2 0 14.2-1.5 17.5-3.3V135c-3.2 1.3-19 5.9-19-8.9V90.6h19V69.3h-19l.1-21.7zM79.3 94.7c0-3.9 3.2-5.4 8.5-5.4 7.6 0 17.2 2.3 24.8 6.4V72.2c-8.3-3.3-16.5-4.6-24.8-4.6C67.5 67.6 54 78.2 54 95.9c0 27.6 38 23.2 38 35.1 0 4.6-4 6.1-9.6 6.1-8.3 0-18.9-3.4-27.3-8v23.8c9.3 4 18.7 5.7 27.3 5.7 20.8 0 35.1-10.3 35.1-28.2-.1-29.8-38.2-24.5-38.2-35.7z"/></svg>
</div>
<p>Connection with Stripe has been successfully completed.</p>
<span>Click <a class="font-semibold hover:underline" href="{{ url('/#/settings/company_gateways') }}">here</a> to continue.</span>
</div>
@endsection

View File

@ -192,7 +192,9 @@ Route::get('token_hash_router', 'OneTimeTokenController@router');
Route::get('webcron', 'WebCronController@index');
Route::get('stripe_connect/{token}', 'StripeConnectController@initialize')->name('stripe_connect.initialization');
Route::get('stripe_connect/completed', 'StripeConnectController@completed')->name('stripe_connect.return');
Route::group(['middleware' => ['api_db', 'locale']], function () {
Route::get('stripe_connect/completed', 'StripeConnectController@completed')->name('stripe_connect.return');
Route::get('stripe_connect/{token}', 'StripeConnectController@initialize')->name('stripe_connect.initialization');
});
Route::fallback('BaseController@notFound');