1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/app/Http/Controllers/ClientPortal/PaymentMethodController.php

135 lines
3.5 KiB
PHP
Raw Normal View History

2019-08-22 00:34:20 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @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;
2019-09-18 04:39:53 +02:00
use App\Models\ClientGatewayToken;
2020-06-09 14:54:22 +02:00
use App\PaymentDrivers\AuthorizePaymentDriver;
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;
use Illuminate\Support\Facades\Log;
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-03-23 18:10:42 +01:00
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\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.
*
* @return \Illuminate\Http\Response
*/
public function create(CreatePaymentMethodRequest $request)
2019-08-22 00:34:20 +02:00
{
2019-09-14 14:34:05 +02:00
$gateway = auth()->user()->client->getCreditCardGateway();
2020-06-09 14:54:22 +02:00
$auth = new AuthorizePaymentDriver($gateway, auth()->user()->client);
return $auth->authorizeView();
2019-09-13 07:52:01 +02:00
2020-06-09 14:54:22 +02:00
// $data = [
// 'gateway' => $gateway,
// 'gateway_type_id' => 1,
// 'token' => false,
// ];
// return $gateway
// ->driver(auth()->user()->client)
// ->setPaymentMethod('App\\PaymentDrivers\\Stripe\\CreditCard')
// ->authorizeView($data);
2019-08-22 00:34:20 +02:00
}
/**
* Store a newly created resource in storage.
*
* @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();
2020-06-01 14:14:41 +02:00
return $gateway
->driver(auth()->user()->client)
->setPaymentMethod('App\\PaymentDrivers\\Stripe\\CreditCard')
->authorizeCreditCardResponse($request);
2019-08-22 00:34:20 +02:00
}
/**
* Display the specified resource.
*
* @param ClientGatewayToken $payment_method
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\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
2019-08-22 00:34:20 +02:00
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @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.
*
* @param ClientGatewayToken $payment_method
* @return \Illuminate\Http\RedirectResponse
2019-08-22 00:34:20 +02:00
*/
public function destroy(ClientGatewayToken $payment_method)
2019-08-22 00:34:20 +02: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
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
}
}