2019-08-22 00:34:20 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-08-22 00:34:20 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\ClientPortal;
|
|
|
|
|
2019-11-05 23:51:39 +01:00
|
|
|
use App\Events\Payment\Methods\MethodDeleted;
|
2019-08-22 00:34:20 +02:00
|
|
|
use App\Http\Controllers\Controller;
|
2019-09-18 04:39:53 +02:00
|
|
|
use App\Models\ClientGatewayToken;
|
2019-09-19 12:16:41 +02:00
|
|
|
use App\Utils\Traits\MakesDates;
|
2019-08-22 00:34:20 +02:00
|
|
|
use Illuminate\Http\Request;
|
2019-11-05 23:51:39 +01:00
|
|
|
use Illuminate\Http\Response;
|
2019-08-22 00:34:20 +02:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2019-09-18 04:39:53 +02:00
|
|
|
use Yajra\DataTables\Facades\DataTables;
|
2019-09-19 12:16:41 +02:00
|
|
|
use Yajra\DataTables\Html\Builder;
|
2019-08-22 00:34:20 +02:00
|
|
|
|
|
|
|
class PaymentMethodController extends Controller
|
|
|
|
{
|
2019-09-19 12:16:41 +02:00
|
|
|
use MakesDates;
|
2019-08-22 00:34:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-09-19 12:16:41 +02:00
|
|
|
public function index(Builder $builder)
|
2019-08-22 00:34:20 +02:00
|
|
|
{
|
2019-09-18 04:39:53 +02:00
|
|
|
$payment_methods = ClientGatewayToken::whereClientId(auth()->user()->client->id);
|
2019-09-19 12:16:41 +02:00
|
|
|
$payment_methods->with('gateway_type');
|
2019-09-18 04:39:53 +02:00
|
|
|
|
|
|
|
if (request()->ajax()) {
|
2019-09-19 12:16:41 +02:00
|
|
|
return DataTables::of($payment_methods)->addColumn('action', function ($payment_method) {
|
2019-11-05 23:51:39 +01:00
|
|
|
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) {
|
2019-09-19 12:16:41 +02:00
|
|
|
return ctrans("texts.{$payment_method->gateway_type->alias}");
|
2019-11-05 23:51:39 +01:00
|
|
|
})->editColumn('created_at', function ($payment_method) {
|
2019-10-03 14:17:48 +02:00
|
|
|
return $this->formatDateTimestamp($payment_method->created_at, auth()->user()->client->date_format());
|
2019-11-05 23:51:39 +01:00
|
|
|
})->editColumn('is_default', function ($payment_method) {
|
2019-09-19 12:16:41 +02:00
|
|
|
return $payment_method->is_default ? ctrans('texts.default') : '';
|
|
|
|
})->editColumn('meta', function ($payment_method) {
|
2019-12-30 22:59:12 +01:00
|
|
|
if (isset($payment_method->meta->exp_month) && isset($payment_method->meta->exp_year)) {
|
2019-09-19 12:16:41 +02:00
|
|
|
return "{$payment_method->meta->exp_month}/{$payment_method->meta->exp_year}";
|
2019-12-30 22:59:12 +01:00
|
|
|
} else {
|
2019-09-19 12:16:41 +02:00
|
|
|
return "";
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-09-19 12:16:41 +02:00
|
|
|
})->addColumn('last4', function ($payment_method) {
|
2019-12-30 22:59:12 +01:00
|
|
|
if (isset($payment_method->meta->last4)) {
|
2019-09-19 12:16:41 +02:00
|
|
|
return $payment_method->meta->last4;
|
2019-12-30 22:59:12 +01:00
|
|
|
} else {
|
2019-09-19 12:16:41 +02:00
|
|
|
return "";
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-09-19 12:16:41 +02:00
|
|
|
})->addColumn('brand', function ($payment_method) {
|
2019-12-30 22:59:12 +01:00
|
|
|
if (isset($payment_method->meta->brand)) {
|
2019-09-19 12:16:41 +02:00
|
|
|
return $payment_method->meta->brand;
|
2019-12-30 22:59:12 +01:00
|
|
|
} else {
|
2019-09-19 12:16:41 +02:00
|
|
|
return "";
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-09-18 04:39:53 +02:00
|
|
|
})
|
2019-11-05 23:51:39 +01:00
|
|
|
->rawColumns(['action', 'status_id', 'last4', 'brand'])
|
2019-09-18 04:39:53 +02:00
|
|
|
->make(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$data['html'] = $builder;
|
2019-11-05 23:51:39 +01:00
|
|
|
|
2019-09-18 04:39:53 +02:00
|
|
|
return view('portal.default.payment_methods.index', $data);
|
2019-08-22 00:34:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2019-09-14 14:34:05 +02:00
|
|
|
$gateway = auth()->user()->client->getCreditCardGateway();
|
|
|
|
|
2019-09-13 07:52:01 +02:00
|
|
|
$data = [
|
|
|
|
'gateway' => $gateway,
|
2019-09-18 14:43:37 +02:00
|
|
|
'gateway_type_id' => 1,
|
2019-09-13 07:52:01 +02:00
|
|
|
'token' => false,
|
|
|
|
];
|
|
|
|
|
2019-09-16 06:59:59 +02:00
|
|
|
return $gateway->driver(auth()->user()->client)->authorizeCreditCardView($data);
|
2019-08-22 00:34:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2019-11-05 23:51:39 +01:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2019-08-22 00:34:20 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2019-09-16 13:03:25 +02:00
|
|
|
$gateway = auth()->user()->client->getCreditCardGateway();
|
|
|
|
|
|
|
|
return $gateway->driver(auth()->user()->client)->authorizeCreditCardResponse($request);
|
2019-08-22 00:34:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2019-11-05 23:51:39 +01:00
|
|
|
* @param ClientGatewayToken $payment_method
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
2019-08-22 00:34:20 +02:00
|
|
|
*/
|
2019-11-05 23:51:39 +01:00
|
|
|
public function show(ClientGatewayToken $payment_method)
|
2019-08-22 00:34:20 +02:00
|
|
|
{
|
2019-11-05 23:51:39 +01:00
|
|
|
return view('portal.default.payment_methods.show', compact('payment_method'));
|
2019-08-22 00:34:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2019-11-05 23:51:39 +01:00
|
|
|
* @param int $id
|
2019-08-22 00:34:20 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2019-11-05 23:51:39 +01:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
2019-08-22 00:34:20 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2019-11-05 23:51:39 +01:00
|
|
|
* @param ClientGatewayToken $payment_method
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2019-08-22 00:34:20 +02:00
|
|
|
*/
|
2019-11-05 23:51:39 +01:00
|
|
|
public function destroy(ClientGatewayToken $payment_method)
|
2019-08-22 00:34:20 +02:00
|
|
|
{
|
2019-11-05 23:51:39 +01:00
|
|
|
try {
|
|
|
|
event(new MethodDeleted($payment_method));
|
|
|
|
$payment_method->delete();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error(json_encode($e));
|
|
|
|
return back();
|
|
|
|
}
|
2019-08-22 00:34:20 +02:00
|
|
|
|
2019-11-05 23:51:39 +01:00
|
|
|
return redirect()->route('client.payment_methods.index');
|
2019-08-22 00:34:20 +02:00
|
|
|
}
|
|
|
|
}
|