diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index ad7a104e0adc..73be23385af9 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -11,7 +11,7 @@ namespace App\Http\Controllers\ClientPortal; -use = namespace\Cache; +use Cache; use App\Filters\PaymentFilters; use App\Http\Controllers\Controller; use App\Models\CompanyGateway; diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index ceccdf29d1d1..d7d4e69f4205 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -13,39 +13,54 @@ namespace App\Http\Controllers\ClientPortal; use App\Http\Controllers\Controller; use App\Models\ClientGatewayToken; +use App\Utils\Traits\MakesDates; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use Yajra\DataTables\Facades\DataTables; +use Yajra\DataTables\Html\Builder; class PaymentMethodController extends Controller { + use MakesDates; /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ - public function index() + public function index(Builder $builder) { $payment_methods = ClientGatewayToken::whereClientId(auth()->user()->client->id); + $payment_methods->with('gateway_type'); if (request()->ajax()) { - return DataTables::of($payment_methods)->addColumn('action', function ($invoice) { - return ''.ctrans('texts.view').''; + return DataTables::of($payment_methods)->addColumn('action', function ($payment_method) { + return ''.ctrans('texts.view').''; }) - ->editColumn('status_id', function ($invoice){ - return Invoice::badgeForStatus($invoice->status); - })->editColumn('invoice_date', function ($invoice){ - return $this->formatDate($invoice->invoice_date, $invoice->client->date_format()); - })->editColumn('due_date', function ($invoice){ - return $this->formatDate($invoice->due_date, $invoice->client->date_format()); - })->editColumn('balance', function ($invoice) { - return Number::formatMoney($invoice->balance, $invoice->client); - })->editColumn('amount', function ($invoice) { - return Number::formatMoney($invoice->amount, $invoice->client); + ->editColumn('gateway_type_id', function ($payment_method){ + return ctrans("texts.{$payment_method->gateway_type->alias}"); + })->editColumn('created_at', function ($payment_method){ + return $this->formatDate($payment_method->created_at, auth()->user()->client->date_format()); + })->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)) + return "{$payment_method->meta->exp_month}/{$payment_method->meta->exp_year}"; + else + return ""; + })->addColumn('last4', function ($payment_method) { + if(isset($payment_method->meta->last4)) + return $payment_method->meta->last4; + else + return ""; + })->addColumn('brand', function ($payment_method) { + if(isset($payment_method->meta->brand)) + return $payment_method->meta->brand; + else + return ""; }) - ->rawColumns(['action', 'status_id']) + ->rawColumns(['action', 'status_id','last4','brand']) ->make(true); } diff --git a/app/Http/ViewComposers/PortalComposer.php b/app/Http/ViewComposers/PortalComposer.php index 7b7cb9daaa6f..4a11f780af35 100644 --- a/app/Http/ViewComposers/PortalComposer.php +++ b/app/Http/ViewComposers/PortalComposer.php @@ -63,6 +63,7 @@ class PortalComposer $data[] = [ 'title' => ctrans('texts.invoices'), 'url' => 'client.invoices.index', 'icon' => 'fa fa-file-pdf-o fa-fw fa-2x']; $data[] = [ 'title' => ctrans('texts.recurring_invoices'), 'url' => 'client.recurring_invoices.index', 'icon' => 'fa fa-files-o fa-fw fa-2x']; $data[] = [ 'title' => ctrans('texts.payments'), 'url' => 'client.payments.index', 'icon' => 'fa fa-credit-card fa-fw fa-2x']; + $data[] = [ 'title' => ctrans('texts.payment_methods'), 'url' => 'client.payment_methods.index', 'icon' => 'fa fa-cc-stripe fa-fw fa-2x']; return $data; diff --git a/app/Models/ClientGatewayToken.php b/app/Models/ClientGatewayToken.php index a2d72af8b2c7..576c9f370652 100644 --- a/app/Models/ClientGatewayToken.php +++ b/app/Models/ClientGatewayToken.php @@ -36,7 +36,7 @@ class ClientGatewayToken extends BaseModel public function gateway_type() { - return $this->hasOne(GatewayType::class); + return $this->hasOne(GatewayType::class, 'id','gateway_type_id'); } public function company() diff --git a/resources/views/portal/default/payment_methods/index.blade.php b/resources/views/portal/default/payment_methods/index.blade.php index 973233d7c493..af88c1014f83 100644 --- a/resources/views/portal/default/payment_methods/index.blade.php +++ b/resources/views/portal/default/payment_methods/index.blade.php @@ -26,7 +26,7 @@
- {{ ctrans('texts.add_payment_method') }} + {{ ctrans('texts.add_payment_method') }}
@@ -69,25 +69,14 @@ $(function() { loadingRecords: "{{ trans('texts.loading') }}", zeroRecords: "{{ trans('texts.no_records_found') }}" }, - ajax: { - url: '{!! route('client.payment_methods.index') !!}', - data: function(data) { - } - - }, - drawCallback: function(settings){ - - data = this.api().ajax.json().data; - - }, columns: [ - {data: 'invoice_number', name: 'invoice_number', title: '{{ctrans('texts.invoice_number')}}', visible: true}, - {data: 'invoice_date', name: 'invoice_date', title: '{{ctrans('texts.invoice_date')}}', visible: true}, - {data: 'amount', name: 'amount', title: '{{ctrans('texts.total')}}', visible: true}, - {data: 'balance', name: 'balance', title: '{{ctrans('texts.balance')}}', visible: true}, - {data: 'due_date', name: 'due_date', title: '{{ctrans('texts.due_date')}}', visible: true}, - {data: 'status_id', name: 'status_id', title: '{{ctrans('texts.status')}}', visible: true}, + {data: 'created_at', name: 'created_at', title: '{{ctrans('texts.created_at')}}', visible: true}, + {data: 'gateway_type_id', name: 'gateway_type_id', title: '{{ctrans('texts.payment_type_id')}}', visible: true}, + {data: 'brand', name: 'brand', title: '{{ctrans('texts.type')}}', visible: true}, + {data: 'meta', name: 'meta', title: '{{ctrans('texts.card_expiration')}}', visible: true}, + {data: 'last4', name: 'last4', title: '{{ctrans('texts.card_number')}}', visible: true}, + {data: 'is_default', name: 'is_default', title: '{{ctrans('texts.default')}}', visible: true}, {data: 'action', name: 'action', title: '', searchable: false, orderable: false}, ] }); @@ -95,5 +84,4 @@ $(function() { -@endpush - +@endpush \ No newline at end of file