['required'], 'last_name' => ['required'], 'email' => ['required', 'email'], 'company_name' => ['required'], 'country' => ['required'], 'ach' => ['sometimes'], 'wepay_payment_tos_agree' => ['accepted'], ]; public function mount() { $user = User::find($this->user_id); $this->company = Company::where('company_key', $this->company_key)->firstOrFail(); $this->fill([ 'wepay_payment_tos_agree' => '', 'ach' => '', 'country' => 'US', 'user' => $user, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'email' => $user->email, 'company_name' => $this->company->present()->name(), 'saved' => ctrans('texts.confirm'), 'terms' => ''.ctrans('texts.terms_of_service').'', 'privacy_policy' => ''.ctrans('texts.privacy_policy').'', ]); } public function render() { return render('gateways.wepay.signup.wepay-signup'); } public function submit() { //need to create or get a new WePay CompanyGateway $data = $this->validate($this->rules); $this->saved = ctrans('texts.processing'); $wepay_driver = new WePayPaymentDriver(new CompanyGateway, null, null); $wepay_driver->init(); $user_details = [ 'client_id' => config('ninja.wepay.client_id'), 'client_secret' => config('ninja.wepay.client_secret'), 'email' => $data['email'], 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'original_ip' => request()->ip(), 'original_device' => request()->server('HTTP_USER_AGENT'), 'tos_acceptance_time' => time(), 'redirect_uri' => route('wepay.process_signup'), 'scope' => 'manage_accounts,collect_payments,view_user,preapprove_payments,send_money', ]; $wepay_user = $wepay_driver->request('user/register/', $user_details); $access_token = $wepay_user->access_token; $access_token_expires = $wepay_user->expires_in ? (time() + $wepay_user->expires_in) : null; $wepay = new WePay($access_token); $account_details = [ 'name' => $data['company_name'], 'description' => ctrans('texts.wepay_account_description'), 'theme_object' => json_decode('{"name":"Invoice Ninja","primary_color":"0b4d78","secondary_color":"0b4d78","background_color":"f8f8f8","button_color":"33b753"}'), 'callback_uri' => $accountGateway->getWebhookUrl(), 'rbits' => $this->company->present()->rBits, 'country' => $data['country'], ]; if ($data['country'] == 'CA') { $account_details['currencies'] = ['CAD']; $account_details['country_options'] = ['debit_opt_in' => boolval($data['debit_cards'])]; } elseif ($data['country'] == 'GB') { $account_details['currencies'] = ['GBP']; } $wepay_account = $wepay->request('account/create/', $account_details); try { $wepay->request('user/send_confirmation/', []); $confirmation_required = true; } catch (\WePayException $ex) { if ($ex->getMessage() == 'This access_token is already approved.') { $confirmation_required = false; } else { throw $ex; } } } }