1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Http/Controllers/ClientPortal/PaymentMethodController.php

177 lines
4.5 KiB
PHP
Raw Normal View History

2019-08-22 00:34:20 +02:00
<?php
2020-07-03 14:39:29 +02:00
2019-08-22 00:34:20 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-08-22 00:34:20 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @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;
use App\Events\Payment\Methods\MethodDeleted;
2019-08-22 00:34:20 +02:00
use App\Http\Controllers\Controller;
use App\Http\Requests\ClientPortal\CreatePaymentMethodRequest;
use App\Http\Requests\Request;
2019-09-18 04:39:53 +02:00
use App\Models\ClientGatewayToken;
2020-06-10 10:05:30 +02:00
use App\Models\GatewayType;
2020-07-08 14:02:16 +02:00
use App\Utils\Ninja;
2019-09-19 12:16:41 +02:00
use App\Utils\Traits\MakesDates;
2020-10-28 11:10:49 +01:00
use Exception;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Log;
2020-10-28 11:10:49 +01:00
use Illuminate\View\View;
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.
*
2020-10-28 11:10:49 +01:00
* @return Factory|View
2019-08-22 00:34:20 +02:00
*/
public function index()
2019-08-22 00:34:20 +02:00
{
return $this->render('payment_methods.index');
2019-08-22 00:34:20 +02:00
}
/**
* Show the form for creating a new resource.
*
2020-10-28 11:10:49 +01:00
* @param CreatePaymentMethodRequest $request
* @return Response
2019-08-22 00:34:20 +02:00
*/
public function create(CreatePaymentMethodRequest $request)
2019-08-22 00:34:20 +02:00
{
2020-07-03 14:39:29 +02:00
$gateway = $this->getClientGateway();
2019-09-14 14:34:05 +02:00
2020-06-26 13:25:58 +02:00
$data['gateway'] = $gateway;
2020-06-10 03:06:37 +02:00
2020-06-26 13:25:58 +02:00
return $gateway
->driver(auth()->user()->client)
2020-07-03 14:39:29 +02:00
->setPaymentMethod($request->query('method'))
->checkRequirements()
2020-06-26 13:25:58 +02:00
->authorizeView($data);
2019-08-22 00:34:20 +02:00
}
/**
* Store a newly created resource in storage.
*
2020-10-28 11:10:49 +01:00
* @param Request $request
* @return Response
2019-08-22 00:34:20 +02:00
*/
public function store(Request $request)
{
2020-07-03 14:39:29 +02:00
$gateway = $this->getClientGateway();
2019-09-16 13:03:25 +02:00
2020-06-26 13:25:58 +02:00
return $gateway
->driver(auth()->user()->client)
2020-07-03 14:39:29 +02:00
->setPaymentMethod($request->query('method'))
->checkRequirements()
2020-06-26 13:25:58 +02:00
->authorizeResponse($request);
2019-08-22 00:34:20 +02:00
}
/**
* Display the specified resource.
*
* @param ClientGatewayToken $payment_method
2020-10-28 11:10:49 +01:00
* @return Factory|View
2019-08-22 00:34:20 +02:00
*/
public function show(ClientGatewayToken $payment_method)
2019-08-22 00:34:20 +02:00
{
2020-03-23 18:10:42 +01:00
return $this->render('payment_methods.show', [
'payment_method' => $payment_method,
]);
2019-08-22 00:34:20 +02:00
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
2020-10-28 11:10:49 +01:00
* @return void
2019-08-22 00:34:20 +02:00
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
2020-10-28 11:10:49 +01:00
* @param Request $request
* @param int $id
2020-10-28 11:10:49 +01:00
* @return void
2019-08-22 00:34:20 +02:00
*/
public function update(Request $request, $id)
{
//
}
2020-06-09 14:40:55 +02:00
public function verify(ClientGatewayToken $payment_method)
{
2020-07-03 14:39:29 +02:00
$gateway = $this->getClientGateway();
2020-06-09 14:40:55 +02:00
return $gateway
->driver(auth()->user()->client)
2020-07-03 14:39:29 +02:00
->setPaymentMethod(request()->query('method'))
2020-06-09 14:40:55 +02:00
->verificationView($payment_method);
}
public function processVerification(Request $request, ClientGatewaytoken $payment_method)
2020-06-09 14:40:55 +02:00
{
2020-07-03 14:39:29 +02:00
$gateway = $this->getClientGateway();
2020-06-09 14:40:55 +02:00
return $gateway
->driver(auth()->user()->client)
2020-07-03 14:39:29 +02:00
->setPaymentMethod(request()->query('method'))
->processVerification($request, $payment_method);
2020-06-09 14:40:55 +02:00
}
2019-08-22 00:34:20 +02:00
/**
* Remove the specified resource from storage.
*
* @param ClientGatewayToken $payment_method
2020-10-28 11:10:49 +01:00
* @return RedirectResponse
2019-08-22 00:34:20 +02:00
*/
public function destroy(ClientGatewayToken $payment_method)
2019-08-22 00:34:20 +02:00
{
$gateway = $this->getClientGateway();
$gateway
->driver(auth()->user()->client)
->setPaymentMethod(request()->query('method'))
->detach($payment_method);
try {
2020-07-08 14:02:16 +02:00
event(new MethodDeleted($payment_method, auth('contact')->user()->company, Ninja::eventVars()));
$payment_method->delete();
2020-10-28 11:10:49 +01:00
} catch (Exception $e) {
Log::error(json_encode($e));
return back();
}
2019-08-22 00:34:20 +02:00
2020-03-23 18:10:42 +01:00
return redirect()
->route('client.payment_methods.index')
->withSuccess('Payment method has been successfully removed.');
2019-08-22 00:34:20 +02:00
}
2020-07-03 14:39:29 +02:00
private function getClientGateway()
{
if (request()->query('method') == GatewayType::CREDIT_CARD) {
return $gateway = auth()->user()->client->getCreditCardGateway();
}
if (request()->query('method') == GatewayType::BANK_TRANSFER) {
return $gateway = auth()->user()->client->getBankTransferGateway();
}
return abort(404);
}
2019-08-22 00:34:20 +02:00
}