v2 first commit
This commit is contained in:
95
modules/OfflinePayments/Http/Controllers/Payment.php
Normal file
95
modules/OfflinePayments/Http/Controllers/Payment.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\OfflinePayments\Http\Controllers;
|
||||
|
||||
use App\Abstracts\Http\PaymentController;
|
||||
use App\Http\Requests\Portal\InvoicePayment as PaymentRequest;
|
||||
use App\Models\Income\Invoice;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class Payment extends PaymentController
|
||||
{
|
||||
public $alias = 'offline-payments';
|
||||
|
||||
public $type = 'redirect';
|
||||
|
||||
public function show(Invoice $invoice, PaymentRequest $request)
|
||||
{
|
||||
$setting = [];
|
||||
|
||||
$payment_methods = json_decode(setting('offline-payments.methods'), true);
|
||||
|
||||
foreach ($payment_methods as $payment_method) {
|
||||
if ($payment_method['code'] == $request['payment_method']) {
|
||||
$setting = $payment_method;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$html = view('offline-payments::show', compact('setting', 'invoice'))->render();
|
||||
|
||||
return response()->json([
|
||||
'code' => $setting['code'],
|
||||
'name' => $setting['name'],
|
||||
'description' => $setting['description'],
|
||||
'redirect' => false,
|
||||
'html' => $html,
|
||||
]);
|
||||
}
|
||||
|
||||
public function signed(Invoice $invoice, PaymentRequest $request)
|
||||
{
|
||||
$setting = [];
|
||||
|
||||
$payment_methods = json_decode(setting('offline-payments.methods'), true);
|
||||
|
||||
foreach ($payment_methods as $payment_method) {
|
||||
if ($payment_method['code'] == $request['payment_method']) {
|
||||
$setting = $payment_method;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$confirm_url = URL::signedRoute('signed.invoices.offline-payments.confirm', [$invoice->id, 'company_id' => session('company_id')]);
|
||||
|
||||
$html = view('offline-payments::signed', compact('setting', 'invoice', 'confirm_url'))->render();
|
||||
|
||||
return response()->json([
|
||||
'code' => $setting['code'],
|
||||
'name' => $setting['name'],
|
||||
'description' => $setting['description'],
|
||||
'redirect' => false,
|
||||
'html' => $html,
|
||||
]);
|
||||
}
|
||||
|
||||
public function confirm(Invoice $invoice, Request $request)
|
||||
{
|
||||
try {
|
||||
event(new \App\Events\Income\PaymentReceived($invoice, $request));
|
||||
|
||||
$message = trans('messages.success.added', ['type' => trans_choice('general.payments', 1)]);
|
||||
|
||||
$response = [
|
||||
'success' => true,
|
||||
'error' => false,
|
||||
'message' => $message,
|
||||
'data' => false,
|
||||
];
|
||||
} catch(\Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
|
||||
$response = [
|
||||
'success' => false,
|
||||
'error' => true,
|
||||
'message' => $message,
|
||||
'data' => false,
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
}
|
165
modules/OfflinePayments/Http/Controllers/Settings.php
Normal file
165
modules/OfflinePayments/Http/Controllers/Settings.php
Normal file
@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\OfflinePayments\Http\Controllers;
|
||||
|
||||
use Artisan;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\OfflinePayments\Http\Requests\Setting as Request;
|
||||
use Modules\OfflinePayments\Http\Requests\SettingGet as GRequest;
|
||||
use Modules\OfflinePayments\Http\Requests\SettingDelete as DRequest;
|
||||
|
||||
class Settings extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$items = json_decode(setting('offline-payments.methods'));
|
||||
|
||||
return view('offline-payments::edit', compact('items'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
$methods = json_decode(setting('offline-payments.methods'), true);
|
||||
|
||||
if (isset($request['method'])) {
|
||||
foreach ($methods as $key => $method) {
|
||||
if ($method['code'] != $request['method']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$method = explode('.', $request['method']);
|
||||
|
||||
$methods[$key]['code'] = 'offline-payments.' . $request['code'] . '.' . $method[2];
|
||||
$methods[$key]['name'] = $request['name'];
|
||||
$methods[$key]['customer'] = $request['customer'];
|
||||
$methods[$key]['order'] = $request['order'];
|
||||
$methods[$key]['description'] = $request['description'];
|
||||
}
|
||||
|
||||
$message = trans('messages.success.updated', ['type' => $request['name']]);
|
||||
} else {
|
||||
$methods[] = array(
|
||||
'code' => 'offline-payments.' . $request['code'] . '.' . (count($methods) + 1),
|
||||
'name' => $request['name'],
|
||||
'customer' => $request['customer'],
|
||||
'order' => $request['order'],
|
||||
'description' => $request['description']
|
||||
);
|
||||
|
||||
$message = trans('messages.success.added', ['type' => $request['name']]);
|
||||
}
|
||||
|
||||
// Set Api Token
|
||||
setting()->set('offline-payments.methods', json_encode($methods));
|
||||
|
||||
setting()->save();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
$response = [
|
||||
'status' => null,
|
||||
'success' => true,
|
||||
'error' => false,
|
||||
'message' => $message,
|
||||
'data' => null,
|
||||
'redirect' => route('offline-payments.edit'),
|
||||
];
|
||||
|
||||
flash($message)->success();
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param GRequest $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function get(GRequest $request)
|
||||
{
|
||||
$data = [];
|
||||
|
||||
$code = $request['code'];
|
||||
|
||||
$methods = json_decode(setting('offline-payments.methods'), true);
|
||||
|
||||
foreach ($methods as $key => $method) {
|
||||
if ($method['code'] != $code) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$method['title'] = trans('offline-payments::offline-payments.edit', ['method' => $method['name']]);
|
||||
$method['update'] = $code;
|
||||
|
||||
$code = explode('.', $method['code']);
|
||||
|
||||
$method['code'] = $code[1];
|
||||
|
||||
$data = $method;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'errors' => false,
|
||||
'success' => true,
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param DRequest $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy(DRequest $request)
|
||||
{
|
||||
$code = $request['code'];
|
||||
|
||||
$methods = json_decode(setting('offline-payments.methods'), true);
|
||||
|
||||
$remove = false;
|
||||
|
||||
foreach ($methods as $key => $method) {
|
||||
if ($method['code'] != $code) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$remove = $methods[$key];
|
||||
unset($methods[$key]);
|
||||
}
|
||||
|
||||
// Set Api Token
|
||||
setting()->set('offline-payments.methods', json_encode($methods));
|
||||
|
||||
setting()->save();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
$message = trans('messages.success.deleted', ['type' => $remove['name']]);
|
||||
|
||||
return response()->json([
|
||||
'errors' => false,
|
||||
'success' => true,
|
||||
'message' => $message
|
||||
]);
|
||||
}
|
||||
}
|
31
modules/OfflinePayments/Http/Requests/Setting.php
Normal file
31
modules/OfflinePayments/Http/Requests/Setting.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\OfflinePayments\Http\Requests;
|
||||
|
||||
use App\Abstracts\Http\FormRequest as Request;
|
||||
|
||||
class Setting extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required|string',
|
||||
'code' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
30
modules/OfflinePayments/Http/Requests/SettingDelete.php
Normal file
30
modules/OfflinePayments/Http/Requests/SettingDelete.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\OfflinePayments\Http\Requests;
|
||||
|
||||
use App\Abstracts\Http\FormRequest as Request;
|
||||
|
||||
class SettingDelete extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'code' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
30
modules/OfflinePayments/Http/Requests/SettingGet.php
Normal file
30
modules/OfflinePayments/Http/Requests/SettingGet.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\OfflinePayments\Http\Requests;
|
||||
|
||||
use App\Abstracts\Http\FormRequest as Request;
|
||||
|
||||
class SettingGet extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'code' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
30
modules/OfflinePayments/Http/Requests/Show.php
Normal file
30
modules/OfflinePayments/Http/Requests/Show.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\OfflinePayments\Http\Requests;
|
||||
|
||||
use App\Abstracts\Http\FormRequest as Request;
|
||||
|
||||
class Show extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'payment_method' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user