Payment methods (#3045)

- Deleting payment methods
This commit is contained in:
Benjamin Beganović 2019-11-05 23:51:39 +01:00 committed by David Bomba
parent 97a4fb3696
commit 4694675b91
5 changed files with 179 additions and 21 deletions

View File

@ -0,0 +1,42 @@
<?php
namespace App\Events\Payment\Methods;
use App\Models\ClientGatewayToken;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class MethodDeleted
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* @var ClientGatewayToken
*/
private $payment_method;
/**
* Create a new event instance.
*
* @param ClientGatewayToken $payment_method
*/
public function __construct(ClientGatewayToken $payment_method)
{
$this->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');
}
}

View File

@ -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 '<a href="/client/payment_methods/'. $payment_method->hashed_id .'" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i>'.ctrans('texts.view').'</a>';
})
->editColumn('gateway_type_id', function ($payment_method){
return '<a href="/client/payment_methods/' . $payment_method->hashed_id . '" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i>' . ctrans('texts.view') . '</a>';
})
->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');
}
}

View File

@ -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;

View File

@ -0,0 +1,67 @@
@section('meta_title', __('texts.payment_methods'))
@extends('portal.default.layouts.master')
@section('body')
<main class="main">
<div class="container-fluid">
<div class="row mt-3">
<div class="col-md-12">
<div class="card">
<div class="card-header">
{{ ctrans("texts.{$payment_method->gateway_type->alias}") }}
</div>
<div class="card-body">
<p>
<b>{{ ctrans('texts.payment_type') }}:</b>
{{ $payment_method->gateway_type->name }}
</p>
<p>
<b>{{ ctrans('texts.type') }}:</b>
{{ ucfirst($payment_method->meta->brand) }}
</p>
<p>
<b>{{ ctrans('texts.card_number') }}:</b>
**** **** **** {{ ucfirst($payment_method->meta->last4) }}
</p>
@isset($payment_method->meta->exp_month)
<p>
<b>{{ ctrans('texts.expires') }}:</b>
{{ "{$payment_method->meta->exp_month}/{$payment_method->meta->exp_year}" }}
</p>
@endisset
<p>
<b>{{ ctrans('texts.date_created') }}:</b>
{{ date(auth()->user()->client->date_format(), $payment_method->created_at) }}
</p>
<p class="mb-0">
<b>{{ ctrans('texts.default') }}:</b>
{{ $payment_method->is_default ? ctrans('texts.yes') : ctrans('texts.no') }}
</p>
</div>
</div>
</div>
<div class="col-md-12">
<div class="card">
<div class="card-header">
{{ ctrans("texts.delete_payment_method") }}
</div>
<div class="card-body">
<p class="mb-0">
{{ ctrans('texts.about_to_delete_payment_method') }}
{{ ctrans('texts.action_cant_be_reversed') }}.
</p>
</div>
<div class="card-footer d-flex justify-content-end">
{!! Former::horizontal_open()->route('client.payment_methods.destroy', $payment_method->hashed_id)->method('DELETE') !!}
<button class="btn btn-danger btn-sm">{{ ctrans('texts.i_understand_delete') }}</button>
{!! Former::close() !!}
</div>
</div>
</div>
</div>
</div>
</main>
@endsection

View File

@ -0,0 +1,34 @@
<?php
namespace Tests\Browser\Client;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
class PaymentMethods extends DuskTestCase
{
public function testAddPaymentMethodPage(): void
{
$this->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 <iframe>
$browser->visit(route('client.payment_methods.create'))
->assertSee('Add Payment Method')
->assertSee('Save');
});
}
}