diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index 13556fdc5d..e57cc00007 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -44,8 +44,12 @@ class PaymentMethodController extends Controller { $gateway = auth()->user()->client->getCreditCardGateway(); - return $gateway->driver(auth()->user()->client)->authorizeView(GatewayType::CREDIT_CARD); + $data['gateway'] = $gateway; + return $gateway + ->driver(auth()->user()->client) + ->setPaymentMethod(GatewayType::BANK_TRANSFER) + ->authorizeView($data); } /** @@ -57,9 +61,11 @@ class PaymentMethodController extends Controller public function store(Request $request) { $gateway = auth()->user()->client->getCreditCardGateway(); - - return $gateway->driver(auth()->user()->client)->authorizeResponseView($request->all()); + return $gateway + ->driver(auth()->user()->client) + ->setPaymentMethod(GatewayType::BANK_TRANSFER) + ->authorizeResponse($request); } /** @@ -104,7 +110,7 @@ class PaymentMethodController extends Controller return $gateway ->driver(auth()->user()->client) - ->setPaymentMethod('App\\PaymentDrivers\\Stripe\\ACH') + ->setPaymentMethod(GatewayType::BANK_TRANSFER) ->verificationView($payment_method); } @@ -114,7 +120,7 @@ class PaymentMethodController extends Controller return $gateway ->driver(auth()->user()->client) - ->setPaymentMethod('App\\PaymentDrivers\\Stripe\\ACH') + ->setPaymentMethod(GatewayType::BANK_TRANSFER) ->processVerification($payment_method); } diff --git a/app/Http/Controllers/Traits/VerifiesUserEmail.php b/app/Http/Controllers/Traits/VerifiesUserEmail.php index 889d4dea5c..5e34fc587e 100644 --- a/app/Http/Controllers/Traits/VerifiesUserEmail.php +++ b/app/Http/Controllers/Traits/VerifiesUserEmail.php @@ -15,6 +15,7 @@ namespace App\Http\Controllers\Traits; use App\Models\User; use App\Utils\Traits\UserSessionAttributes; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Hash; /** * Class VerifiesUserEmail @@ -30,20 +31,49 @@ trait VerifiesUserEmail */ public function confirm() { - if ($user = User::whereRaw("BINARY `confirmation_code`= ?", request()->route('confirmation_code'))->first()) { - $user->email_verified_at = now(); - $user->confirmation_code = null; - $user->save(); + $user = User::where('confirmation_code', request()->confirmation_code)->first(); + + // if ($user = User::whereRaw("BINARY `confirmation_code`= ?", request()->input('confirmation_code'))->first()) { - return $this->render('auth.confirmed', [ - 'root' => 'themes', - 'message' => ctrans('texts.security_confirmation'), - ]); + if (!$user) { + return $this->render('auth.confirmed', ['root' => 'themes', 'message' => ctrans('texts.wrong_confirmation')]); } + if (is_null($user->password) || empty($user->password)) { + return $this->render('auth.confirmation_with_password', ['root' => 'themes']); + } + + $user->email_verified_at = now(); + $user->confirmation_code = null; + $user->save(); + return $this->render('auth.confirmed', [ 'root' => 'themes', - 'message' => ctrans('texts.wrong_confirmation'), + 'message' => ctrans('texts.security_confirmation'), + ]); + } + + public function confirmWithPassword() + { + $user = User::where('confirmation_code', request()->confirmation_code)->first(); + + if (!$user) { + return $this->render('auth.confirmed', ['root' => 'themes', 'message' => ctrans('texts.wrong_confirmation')]); + } + + request()->validate([ + 'password' => ['required', 'min:6', 'confirmed'], + ]); + + $user->password = Hash::make(request()->password); + + $user->email_verified_at = now(); + $user->confirmation_code = null; + $user->save(); + + return $this->render('auth.confirmed', [ + 'root' => 'themes', + 'message' => ctrans('texts.security_confirmation'), ]); } } diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index cff4ceda3e..3e329e14ba 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -172,7 +172,7 @@ class StripePaymentDriver extends BasePaymentDriver * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function authorizeCreditCardResponse($request) + public function authorizeResponse($request) { return $this->payment_method->authorizeResponse($request); } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 74905738a8..d06eaaf5a9 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -3223,7 +3223,8 @@ return [ 'month_invalid' => 'Provided month is not valid.', 'year_invalid' => 'Provided year is not valid.', - 'if_you_need_help' => 'If you need help you can either post to our', - + 'if_you_need_help' => 'If you need help you can either post to our', 'reversed' => 'Reversed', + 'update_password_on_confirm' => 'After updating password, your account will be confirmed.', + 'bank_account_not_linked' => 'To pay with bank account, first you have to add it as payment method.', ]; diff --git a/resources/views/portal/ninja2020/gateways/stripe/ach/pay.blade.php b/resources/views/portal/ninja2020/gateways/stripe/ach/pay.blade.php index 46182a54c5..d4ffdf84a2 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/ach/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/ach/pay.blade.php @@ -2,18 +2,20 @@ @section('meta_title', ctrans('texts.ach')) @section('body') -
- @csrf - @foreach($invoices as $invoice) - - @endforeach - - - - - - -
+ @if($token) +
+ @csrf + @foreach($invoices as $invoice) + + @endforeach + + + + + + +
+ @endif
@@ -29,27 +31,36 @@

-
-
- {{ ctrans('texts.payment_type') }} -
-
- {{ ctrans('texts.ach') }} ({{ ctrans('texts.bank_transfer') }}) (****{{ $token->meta->last4 }}) -
-
-
-
- {{ ctrans('texts.amount') }} -
-
- {{ App\Utils\Number::formatMoney($amount, $client) }} -
-
-
- -
+ @if($token) +
+
+ {{ ctrans('texts.payment_type') }} +
+
+ {{ ctrans('texts.ach') }} ({{ ctrans('texts.bank_transfer') }}) (****{{ $token->meta->last4 }}) +
+
+
+
+ {{ ctrans('texts.amount') }} +
+
+ {{ App\Utils\Number::formatMoney($amount, $client) }} +
+
+
+ +
+ @else +
+
+ {{ ctrans('texts.bank_account_not_linked') }} + {{ ctrans('texts.add_payment_method') }} +
+
+ @endif
diff --git a/resources/views/themes/ninja2020/auth/confirmation_with_password.blade.php b/resources/views/themes/ninja2020/auth/confirmation_with_password.blade.php new file mode 100644 index 0000000000..227b382464 --- /dev/null +++ b/resources/views/themes/ninja2020/auth/confirmation_with_password.blade.php @@ -0,0 +1,43 @@ +@extends('portal.ninja2020.layout.clean') +@section('meta_title', ctrans('texts.set_password')) + +@section('body') +
+
+
+ Invoice Ninja logo +

{{ ctrans('texts.set_password') }}

+ {{ ctrans('texts.update_password_on_confirm') }} + +
+ @csrf +
+ + + @error('password') +
+ {{ $message }} +
+ @enderror +
+
+ + + @error('password_confirmation') +
+ {{ $message }} +
+ @enderror +
+
+ +
+
+
+
+
+@endsection diff --git a/resources/views/themes/ninja2020/auth/passwords/reset.blade.php b/resources/views/themes/ninja2020/auth/passwords/reset.blade.php index deaa68e6e9..f59686661e 100644 --- a/resources/views/themes/ninja2020/auth/passwords/reset.blade.php +++ b/resources/views/themes/ninja2020/auth/passwords/reset.blade.php @@ -38,7 +38,7 @@ @enderror
- + diff --git a/routes/web.php b/routes/web.php index 08e26b71c1..b50df7e6e9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -30,4 +30,5 @@ Route::post('password/reset', 'Auth\ResetPasswordController@reset')->name('passw */ Route::group(['middleware' => ['url_db']], function () { Route::get('/user/confirm/{confirmation_code}', 'UserController@confirm'); + Route::post('/user/confirm/{confirmation_code}', 'UserController@confirmWithPassword'); }); \ No newline at end of file