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
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-08-22 00:34:20 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-08-22 00:34:20 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-08-22 00:34:20 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
2021-06-29 12:42:44 +02:00
|
|
|
use App\Http\Requests\ClientPortal\PaymentMethod\CreatePaymentMethodRequest;
|
2020-11-01 18:47:48 +01:00
|
|
|
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\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
|
|
|
|
2022-05-11 07:25:33 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('throttle:10,1')->only('store');
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2020-04-08 14:19:07 +02:00
|
|
|
public function index()
|
2019-08-22 00:34:20 +02:00
|
|
|
{
|
2020-04-23 00:49:23 +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
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\View\View
|
2019-08-22 00:34:20 +02:00
|
|
|
*/
|
2020-04-06 23:23:05 +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;
|
2023-08-04 08:40:44 +02:00
|
|
|
|
|
|
|
/** @var \App\Models\ClientContact auth()->user() **/
|
|
|
|
$client_contact = auth()->user();
|
|
|
|
$data['client'] = $client_contact->client;
|
|
|
|
|
2020-06-26 13:25:58 +02:00
|
|
|
return $gateway
|
2023-08-04 08:40:44 +02:00
|
|
|
->driver($client_contact->client)
|
2020-07-03 14:39:29 +02:00
|
|
|
->setPaymentMethod($request->query('method'))
|
2020-11-25 14:38:49 +01:00
|
|
|
->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
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\View\View
|
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
|
|
|
|
2023-08-04 08:40:44 +02:00
|
|
|
/** @var \App\Models\ClientContact auth()->user() **/
|
|
|
|
$client_contact = auth()->user();
|
|
|
|
|
2020-06-26 13:25:58 +02:00
|
|
|
return $gateway
|
2023-08-04 08:40:44 +02:00
|
|
|
->driver($client_contact->client)
|
2020-07-03 14:39:29 +02:00
|
|
|
->setPaymentMethod($request->query('method'))
|
2020-11-25 14:38:49 +01:00
|
|
|
->checkRequirements()
|
2020-06-26 13:25:58 +02:00
|
|
|
->authorizeResponse($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
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return Factory|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
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2020-06-09 14:40:55 +02:00
|
|
|
public function verify(ClientGatewayToken $payment_method)
|
|
|
|
{
|
2023-08-04 08:40:44 +02:00
|
|
|
|
|
|
|
/** @var \App\Models\ClientContact auth()->user() **/
|
|
|
|
$client_contact = auth()->user();
|
|
|
|
|
2021-06-16 12:12:04 +02:00
|
|
|
return $payment_method->gateway
|
2023-08-04 08:40:44 +02:00
|
|
|
->driver($client_contact->client)
|
2020-07-03 14:39:29 +02:00
|
|
|
->setPaymentMethod(request()->query('method'))
|
2020-06-09 14:40:55 +02:00
|
|
|
->verificationView($payment_method);
|
|
|
|
}
|
|
|
|
|
2020-11-01 18:47:48 +01:00
|
|
|
public function processVerification(Request $request, ClientGatewaytoken $payment_method)
|
2020-06-09 14:40:55 +02:00
|
|
|
{
|
2023-08-04 08:40:44 +02:00
|
|
|
/** @var \App\Models\ClientContact auth()->user() **/
|
|
|
|
$client_contact = auth()->user();
|
2020-06-09 14:40:55 +02:00
|
|
|
|
2021-06-16 12:12:04 +02:00
|
|
|
return $payment_method->gateway
|
2023-08-04 08:40:44 +02:00
|
|
|
->driver($client_contact->client)
|
2020-07-03 14:39:29 +02:00
|
|
|
->setPaymentMethod(request()->query('method'))
|
2020-11-01 18:47:48 +01:00
|
|
|
->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.
|
|
|
|
*
|
2019-11-05 23:51:39 +01:00
|
|
|
* @param ClientGatewayToken $payment_method
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return 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
|
|
|
{
|
2023-08-04 08:40:44 +02:00
|
|
|
/** @var \App\Models\ClientContact auth()->user() **/
|
|
|
|
$client_contact = auth()->user();
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($payment_method->gateway()->exists()) {
|
2021-08-07 07:08:29 +02:00
|
|
|
$payment_method->gateway
|
2023-08-04 08:40:44 +02:00
|
|
|
->driver($client_contact->client)
|
2021-08-07 07:08:29 +02:00
|
|
|
->setPaymentMethod(request()->query('method'))
|
|
|
|
->detach($payment_method);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-02-16 03:24:10 +01:00
|
|
|
event(new MethodDeleted($payment_method, auth()->guard('contact')->user()->company, Ninja::eventVars(auth()->guard('contact')->user()->id)));
|
2021-08-07 06:58:04 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$payment_method->delete();
|
2020-10-28 11:10:49 +01:00
|
|
|
} catch (Exception $e) {
|
2021-01-25 13:16:43 +01:00
|
|
|
nlog($e->getMessage());
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-11-05 23:51:39 +01:00
|
|
|
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')
|
2022-03-05 21:50:12 +01:00
|
|
|
->withSuccess(ctrans('texts.payment_method_removed'));
|
2019-08-22 00:34:20 +02:00
|
|
|
}
|
2020-07-03 14:39:29 +02:00
|
|
|
|
|
|
|
private function getClientGateway()
|
|
|
|
{
|
2023-08-04 08:40:44 +02:00
|
|
|
/** @var \App\Models\ClientContact auth()->user() **/
|
|
|
|
$client_contact = auth()->user();
|
|
|
|
|
2020-07-03 14:39:29 +02:00
|
|
|
if (request()->query('method') == GatewayType::CREDIT_CARD) {
|
2023-08-04 08:40:44 +02:00
|
|
|
return $client_contact->client->getCreditCardGateway();
|
2020-07-03 14:39:29 +02:00
|
|
|
}
|
2022-12-16 12:05:10 +01:00
|
|
|
if (request()->query('method') == GatewayType::BACS) {
|
2023-08-04 08:40:44 +02:00
|
|
|
return $client_contact->client->getBACSGateway();
|
2022-12-16 12:05:10 +01:00
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
if (in_array(request()->query('method'), [GatewayType::BANK_TRANSFER, GatewayType::DIRECT_DEBIT, GatewayType::SEPA, GatewayType::ACSS])) {
|
2023-08-04 08:40:44 +02:00
|
|
|
return $client_contact->client->getBankTransferGateway();
|
2020-07-03 14:39:29 +02:00
|
|
|
}
|
|
|
|
|
2021-05-24 11:39:21 +02:00
|
|
|
abort(404, 'Gateway not found.');
|
2020-07-03 14:39:29 +02:00
|
|
|
}
|
2019-08-22 00:34:20 +02:00
|
|
|
}
|