We Pay Account Signup

This commit is contained in:
David Bomba 2021-06-11 17:39:51 +10:00
parent e3da3c35be
commit b111483ef1
7 changed files with 71 additions and 8 deletions

View File

@ -44,10 +44,10 @@ class WePayController extends BaseController
// $data['user_id'] = $this->encodePrimaryKey($hash['user_id']);
// $data['company_key'] = $hash['company_key'];
/* Mock Data - in production we will be passed the correct company*/
$user = User::first();
$data['user_id'] = $user->id;
$data['company_key'] = $user->account->companies()->first()->company_key;
$data['company'] = $user->account->companies()->first();
$wepay_driver = new WePayPaymentDriver(new CompanyGateway, null, null);
@ -59,4 +59,9 @@ class WePayController extends BaseController
{
}
public function finished()
{
return render('gateways.wepay.signup.finished');
}
}

View File

@ -12,9 +12,12 @@
namespace App\Http\Livewire;
use App\DataMapper\FeesAndLimits;
use App\Factory\CompanyGatewayFactory;
use App\Libraries\MultiDB;
use App\Models\Company;
use App\Models\CompanyGateway;
use App\Models\GatewayType;
use App\Models\User;
use App\PaymentDrivers\WePayPaymentDriver;
use Illuminate\Support\Facades\Hash;
@ -54,8 +57,10 @@ class WepaySignup extends Component
public function mount()
{
MultiDB::setDb($this->company->db);
$user = User::find($this->user_id);
$this->company = Company::where('company_key', $this->company_key)->firstOrFail();
$this->company = Company::where('company_key', $this->company->company_key)->first();
$this->fill([
'wepay_payment_tos_agree' => '',
@ -87,6 +92,11 @@ class WepaySignup extends Component
->firstOrNew();
if(!$cg->id) {
$fees_and_limits = new \stdClass;
$fees_and_limits->{GatewayType::CREDIT_CARD} = new FeesAndLimits;
$fees_and_limits->{GatewayType::BANK_TRANSFER} = new FeesAndLimits;
$cg = CompanyGatewayFactory::create($this->company->id, $this->user->id);
$cg->gateway_key = '8fdeed552015b3c7b44ed6c8ebd9e992';
$cg->require_cvv = false;
@ -94,7 +104,9 @@ class WepaySignup extends Component
$cg->require_shipping_address = false;
$cg->update_details = false;
$cg->config = encrypt(config('ninja.testvars.checkout'));
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
$this->saved = ctrans('texts.processing');
@ -139,7 +151,7 @@ class WepaySignup extends Component
} elseif ($data['country'] == 'GB') {
$account_details['currencies'] = ['GBP'];
}
$wepay_account = $wepay->request('account/create/', $account_details);
try {
@ -149,8 +161,11 @@ class WepaySignup extends Component
if ($ex->getMessage() == 'This access_token is already approved.') {
$confirmation_required = false;
} else {
throw $ex;
request()->session()->flash('message', $ex->getMessage());
}
nlog("failed in try catch ");
nlog($ex->getMessage());
}
$config = [
@ -166,6 +181,20 @@ class WepaySignup extends Component
$cg->setConfig($config);
$cg->save();
if ($confirmation_required) {
request()->session()->flash('message', trans('texts.created_wepay_confirmation_required'));
} else {
$update_uri = $wepay->request('/account/get_update_uri', [
'account_id' => $wepay_account->account_id,
'redirect_uri' => config('ninja.app_url'),
]);
return redirect($update_uri->uri);
}
return redirect()->to('/wepay/finished');
}
}

View File

@ -95,6 +95,10 @@ class Gateway extends StaticModel
case 39:
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true]]; //Checkout
break;
case 49:
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true],
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true]]; //WePay
break;
default:
return [];
break;

View File

@ -28,7 +28,7 @@ class Setup
{
/*
'user_id',
'company_key',
'company',
*/
return render('gateways.wepay.signup.index', $data);

View File

@ -0,0 +1,24 @@
@extends('portal.ninja2020.layout.clean', ['custom_body_class' => 'bg-gray-50'])
@section('meta_title', ctrans('texts.sign_up_with_wepay'))
@section('body')
<div class="flex flex-col justify-center items-center mt-10">
<img src="{{ asset('images/wepay.svg') }}" alt="We Pay">
</div>
<div class="flex flex-col justify-center items-center mt-10">
<h1>Wepay setup complete:</h1>
</div>
<div class="flex flex-col justify-center items-center mt-10">
@if(isset($message))
{{ $message ?? '' }}
@endif
</div>
</div>
@endsection
@push('footer')
<script>
</script>
@endpush

View File

@ -6,7 +6,7 @@
<img src="{{ asset('images/wepay.svg') }}" alt="We Pay">
</div>
@livewire('wepay-signup', ['user_id' => $user_id, 'company_key' => $company_key])
@livewire('wepay-signup', ['user_id' => $user_id, 'company' => $company])
@endsection
@push('footer')

View File

@ -21,7 +21,8 @@ Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm
Route::post('password/reset', 'Auth\ResetPasswordController@reset')->name('password.update');
Route::get('wepay/signup/{token}', 'WePayController@signup')->name('wepay.signup');
Route::get('wepay/processSignup', 'WePayController@processSignup')->name('wepay.process_signup');
Route::post('wepay/process_signup', 'WePayController@processSignup')->name('wepay.process_signup');
Route::get('wepay/finished', 'WePayController@finished')->name('wepay.finished');
/*
* Social authentication