diff --git a/app/Events/Payment/Methods/MethodDeleted.php b/app/Events/Payment/Methods/MethodDeleted.php new file mode 100644 index 000000000000..b0dd9cce95cd --- /dev/null +++ b/app/Events/Payment/Methods/MethodDeleted.php @@ -0,0 +1,42 @@ +payment_method = $payment_method; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } +} diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index c9cc82dfa843..d0d409da841c 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -11,10 +11,12 @@ namespace App\Http\Controllers\ClientPortal; +use App\Events\Payment\Methods\MethodDeleted; use App\Http\Controllers\Controller; use App\Models\ClientGatewayToken; use App\Utils\Traits\MakesDates; use Illuminate\Http\Request; +use Illuminate\Http\Response; use Illuminate\Support\Facades\Log; use Yajra\DataTables\Facades\DataTables; use Yajra\DataTables\Html\Builder; @@ -36,37 +38,37 @@ class PaymentMethodController extends Controller if (request()->ajax()) { return DataTables::of($payment_methods)->addColumn('action', function ($payment_method) { - return ''.ctrans('texts.view').''; - }) - ->editColumn('gateway_type_id', function ($payment_method){ + return '' . ctrans('texts.view') . ''; + }) + ->editColumn('gateway_type_id', function ($payment_method) { return ctrans("texts.{$payment_method->gateway_type->alias}"); - })->editColumn('created_at', function ($payment_method){ + })->editColumn('created_at', function ($payment_method) { return $this->formatDateTimestamp($payment_method->created_at, auth()->user()->client->date_format()); - })->editColumn('is_default', function ($payment_method){ + })->editColumn('is_default', function ($payment_method) { return $payment_method->is_default ? ctrans('texts.default') : ''; })->editColumn('meta', function ($payment_method) { - if(isset($payment_method->meta->exp_month) && isset($payment_method->meta->exp_year)) + if (isset($payment_method->meta->exp_month) && isset($payment_method->meta->exp_year)) return "{$payment_method->meta->exp_month}/{$payment_method->meta->exp_year}"; else return ""; })->addColumn('last4', function ($payment_method) { - if(isset($payment_method->meta->last4)) + if (isset($payment_method->meta->last4)) return $payment_method->meta->last4; else return ""; })->addColumn('brand', function ($payment_method) { - if(isset($payment_method->meta->brand)) + if (isset($payment_method->meta->brand)) return $payment_method->meta->brand; else return ""; }) - ->rawColumns(['action', 'status_id','last4','brand']) + ->rawColumns(['action', 'status_id', 'last4', 'brand']) ->make(true); - + } $data['html'] = $builder; - + return view('portal.default.payment_methods.index', $data); } @@ -91,7 +93,7 @@ class PaymentMethodController extends Controller /** * Store a newly created resource in storage. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) @@ -105,18 +107,18 @@ class PaymentMethodController extends Controller /** * Display the specified resource. * - * @param int $id - * @return \Illuminate\Http\Response + * @param ClientGatewayToken $payment_method + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function show($id) + public function show(ClientGatewayToken $payment_method) { - // + return view('portal.default.payment_methods.show', compact('payment_method')); } /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) @@ -127,8 +129,8 @@ class PaymentMethodController extends Controller /** * Update the specified resource in storage. * - * @param \Illuminate\Http\Request $request - * @param int $id + * @param \Illuminate\Http\Request $request + * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) @@ -139,10 +141,19 @@ class PaymentMethodController extends Controller /** * Remove the specified resource from storage. * - * @return \Illuminate\Http\Response + * @param ClientGatewayToken $payment_method + * @return \Illuminate\Http\RedirectResponse */ - public function destroy() + public function destroy(ClientGatewayToken $payment_method) { + try { + event(new MethodDeleted($payment_method)); + $payment_method->delete(); + } catch (\Exception $e) { + Log::error(json_encode($e)); + return back(); + } + return redirect()->route('client.payment_methods.index'); } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index b1a7ca6b11d4..df52d9a9a90f 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1268,6 +1268,9 @@ $LANG = array( 'account_holder_name' => 'Account Holder Name', 'add_account' => 'Add Account', 'payment_methods' => 'Payment Methods', + 'delete_payment_method' => 'Delete Payment Method', + 'about_to_delete_payment_method' => 'You are about to delete the payment method.', + 'action_cant_be_reversed' => 'Action can\'t be reversed', 'complete_verification' => 'Complete Verification', 'verification_amount1' => 'Amount 1', 'verification_amount2' => 'Amount 2', @@ -3108,6 +3111,7 @@ $LANG = array( 'freq_indefinitely' => 'Indefinitely', 'next_send_date' => 'Next send date', 'cycles_remaining' => 'Cycles remaining', + 'i_understand_delete' => 'I understand, delete', ); return $LANG; diff --git a/resources/views/portal/default/payment_methods/show.blade.php b/resources/views/portal/default/payment_methods/show.blade.php new file mode 100644 index 000000000000..53c1b1e05d23 --- /dev/null +++ b/resources/views/portal/default/payment_methods/show.blade.php @@ -0,0 +1,67 @@ +@section('meta_title', __('texts.payment_methods')) +@extends('portal.default.layouts.master') + +@section('body') +
+
+
+
+
+
+ {{ ctrans("texts.{$payment_method->gateway_type->alias}") }} +
+
+

+ {{ ctrans('texts.payment_type') }}: + {{ $payment_method->gateway_type->name }} +

+

+ {{ ctrans('texts.type') }}: + {{ ucfirst($payment_method->meta->brand) }} +

+ +

+ {{ ctrans('texts.card_number') }}: + **** **** **** {{ ucfirst($payment_method->meta->last4) }} +

+ + @isset($payment_method->meta->exp_month) +

+ {{ ctrans('texts.expires') }}: + {{ "{$payment_method->meta->exp_month}/{$payment_method->meta->exp_year}" }} +

+ @endisset + +

+ {{ ctrans('texts.date_created') }}: + {{ date(auth()->user()->client->date_format(), $payment_method->created_at) }} +

+

+ {{ ctrans('texts.default') }}: + {{ $payment_method->is_default ? ctrans('texts.yes') : ctrans('texts.no') }} +

+
+
+
+
+
+
+ {{ ctrans("texts.delete_payment_method") }} +
+
+

+ {{ ctrans('texts.about_to_delete_payment_method') }} + {{ ctrans('texts.action_cant_be_reversed') }}. +

+
+ +
+
+
+
+
+@endsection diff --git a/tests/Browser/Client/PaymentMethods.php b/tests/Browser/Client/PaymentMethods.php new file mode 100644 index 000000000000..022ac902e986 --- /dev/null +++ b/tests/Browser/Client/PaymentMethods.php @@ -0,0 +1,34 @@ +browse(function (Browser $browser) { + + $browser->visit('/client/login') + ->type('email', 'user@example.com') + ->type('password', config('ninja.testvars.password')) + ->press('Login') + ->assertPathIs('/client/dashboard'); + + $browser->visit(route('client.payment_methods.index')) + ->waitFor('.dataTable') + ->waitFor('.dataTables_empty') + ->assertSee('No records found'); + + // TODO: Testing Stripe