1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Azizbek Eshonaliyev |
5
|
|
|
* Date: 2/20/2019 |
6
|
|
|
* Time: 8:41 PM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Goodoneuz\PayUz\Http\Controllers; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use Illuminate\Http\Request; |
13
|
|
|
use App\Http\Controllers\Controller; |
14
|
|
|
use Illuminate\Support\Facades\Validator; |
15
|
|
|
use Goodoneuz\PayUz\Models\PaymentSystem; |
16
|
|
|
use Goodoneuz\PayUz\Models\PaymentSystemParam; |
17
|
|
|
use Goodoneuz\PayUz\Services\PaymentSystemService; |
18
|
|
|
|
19
|
|
|
class PaymentSystemController extends Controller |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Display a listing of the resource. |
23
|
|
|
* |
24
|
|
|
* @return \Illuminate\Http\Response |
25
|
|
|
*/ |
26
|
|
|
public function index() |
27
|
|
|
{ |
28
|
|
|
$payment_systems = PaymentSystem::latest()->get(); |
29
|
|
|
return view('pay-uz::payment_systems.index',compact('payment_systems')); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Show the form for creating a new resource. |
34
|
|
|
* |
35
|
|
|
* @return \Illuminate\Http\Response |
36
|
|
|
*/ |
37
|
|
|
public function create() |
38
|
|
|
{ |
39
|
|
|
return view('pay-uz::payment_systems.create'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Store a newly created resource in storage. |
44
|
|
|
* |
45
|
|
|
* @param \Illuminate\Http\Request $request |
46
|
|
|
* @return \Illuminate\Http\Response |
47
|
|
|
*/ |
48
|
|
|
public function store(Request $request) |
49
|
|
|
{ |
50
|
|
|
$rules = [ |
51
|
|
|
'system' => 'required|unique:payment_systems|max:255', |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
$messages = [ |
55
|
|
|
'system.required' => "Payment system cannot be exist!", |
56
|
|
|
'system.unique' => "The payment system has already been taken!", |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
$validator = Validator::make($request->all(), $rules, $messages); |
60
|
|
|
|
61
|
|
|
if ($validator->fails()) { |
62
|
|
|
return redirect()->route('payment.payment_systems.create') |
63
|
|
|
->withErrors($validator) |
64
|
|
|
->withInput(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
PaymentSystemService::createPaymentSystem($request); |
68
|
|
|
|
69
|
|
|
return redirect()->route('payment.payment_systems.index')->with(['success' => "Payment system successfully saved."]); |
70
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Display the specified resource. |
75
|
|
|
* |
76
|
|
|
* @param int $id |
77
|
|
|
* @return \Illuminate\Http\Response |
78
|
|
|
*/ |
79
|
|
|
public function show($id) |
80
|
|
|
{ |
81
|
|
|
// |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param PaymentSystem $payment_system |
86
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
87
|
|
|
*/ |
88
|
|
|
public function edit(PaymentSystem $payment_system) |
89
|
|
|
{ |
90
|
|
|
return view('pay-uz::payment_systems.edit',compact('payment_system')); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param Request $request |
96
|
|
|
* @param PaymentSystem $payment_system |
97
|
|
|
* @return \Illuminate\Http\RedirectResponse |
98
|
|
|
*/ |
99
|
|
|
public function update(Request $request, PaymentSystem $payment_system) |
100
|
|
|
{ |
101
|
|
|
$rules = [ |
102
|
|
|
'system' => 'required|max:255|unique:payment_systems'. ',system,' . $payment_system->id, |
103
|
|
|
]; |
104
|
|
|
|
105
|
|
|
$messages = [ |
106
|
|
|
'system.required' => "Payment system cannot be exist!", |
107
|
|
|
'system.unique' => "The payment system has already been taken!", |
108
|
|
|
]; |
109
|
|
|
|
110
|
|
|
$validator = Validator::make($request->all(), $rules, $messages); |
111
|
|
|
|
112
|
|
|
if ($validator->fails()) { |
113
|
|
|
return redirect()->route('payment.payment_systems.edit',['payment_system' => $payment_system->id]) |
114
|
|
|
->withErrors($validator) |
115
|
|
|
->withInput(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
PaymentSystemService::updatePaymentSystem($request,$payment_system); |
119
|
|
|
|
120
|
|
|
return redirect()->route('payment.payment_systems.edit',['payment_system' => $payment_system->id])->with(['success' => "Payment system successfully saved."]); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param PaymentSystem $payment_system |
125
|
|
|
* @return \Illuminate\Http\RedirectResponse |
126
|
|
|
* @throws \Exception |
127
|
|
|
*/ |
128
|
|
|
public function destroy(PaymentSystem $payment_system) |
129
|
|
|
{ |
130
|
|
|
$payment_system->delete(); |
131
|
|
|
return redirect()->back()->with(['success' => "To'lov tizimi o'chirildi"]); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function editStatus(PaymentSystem $paymentSystem){ |
135
|
|
|
$paymentSystem->status = ($paymentSystem->status == PaymentSystem::NOT_ACTIVE) ? PaymentSystem::ACTIVE : PaymentSystem::NOT_ACTIVE; |
136
|
|
|
$paymentSystem->update(); |
137
|
|
|
return redirect()->back()->with(['success' => "Status o'xgartirildi"]); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function deleteParam($param_id){ |
141
|
|
|
$param = PaymentSystemParam::find($param_id); |
142
|
|
|
if ($param){ |
143
|
|
|
$param->delete(); |
144
|
|
|
return redirect()->back()->with(['success' => 'Param deleted!']); |
145
|
|
|
} |
146
|
|
|
return redirect()->back()->with(['warning' => 'Param not found!']); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|