|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Samerior\MobileMoney\Mpesa\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Samerior\MobileMoney\Mpesa\Events\QueueTimeoutEvent; |
|
6
|
|
|
use Samerior\MobileMoney\Mpesa\Repositories\Mpesa; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class MpesaController |
|
11
|
|
|
* @package Samerior\MobileMoney\Http\Controllers |
|
12
|
|
|
*/ |
|
13
|
|
|
class MpesaController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var Mpesa |
|
17
|
|
|
*/ |
|
18
|
|
|
private $repository; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* MpesaController constructor. |
|
22
|
|
|
* @param Mpesa $repository |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(Mpesa $repository) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->repository = $repository; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param Request $request |
|
31
|
|
|
* @param string|null $initiator |
|
32
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
33
|
|
|
*/ |
|
34
|
|
|
public function timeout(Request $request, $initiator = null) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->repository->notification('Queue timeout: *' . $initiator . '*'); |
|
37
|
|
|
event(new QueueTimeoutEvent($request, $initiator)); |
|
38
|
|
|
return response()->json( |
|
|
|
|
|
|
39
|
|
|
[ |
|
40
|
|
|
'ResponseCode' => '00000000', |
|
41
|
|
|
'ResponseDesc' => 'success' |
|
42
|
|
|
] |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param string|null $initiator |
|
48
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
49
|
|
|
*/ |
|
50
|
|
View Code Duplication |
public function result($initiator = null) |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
$this->repository->notification('Incoming result: *' . $initiator . '*'); |
|
53
|
|
|
$this->repository->handleResult($initiator); |
|
54
|
|
|
return response()->json( |
|
|
|
|
|
|
55
|
|
|
[ |
|
56
|
|
|
'ResponseCode' => '00000000', |
|
57
|
|
|
'ResponseDesc' => 'success' |
|
58
|
|
|
] |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string|null $initiator |
|
64
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
65
|
|
|
*/ |
|
66
|
|
View Code Duplication |
public function paymentCallback($initiator) |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
$this->repository->notification('Incoming payment callback: *' . $initiator . '*'); |
|
69
|
|
|
return response()->json( |
|
|
|
|
|
|
70
|
|
|
[ |
|
71
|
|
|
'ResponseCode' => '00000000', |
|
72
|
|
|
'ResponseDesc' => 'success' |
|
73
|
|
|
] |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param Request $request |
|
79
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
80
|
|
|
*/ |
|
81
|
|
View Code Duplication |
public function confirmation(Request $request) |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
$this->repository->notification('MPESA Confirmation: *C2B*', true); |
|
84
|
|
|
$this->repository->processConfirmation(json_encode($request->all())); |
|
85
|
|
|
$resp = [ |
|
86
|
|
|
'ResultCode' => 0, |
|
87
|
|
|
'ResultDesc' => 'Confirmation received successfully', |
|
88
|
|
|
]; |
|
89
|
|
|
return response()->json($resp); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
94
|
|
|
*/ |
|
95
|
|
View Code Duplication |
public function callback() |
|
|
|
|
|
|
96
|
|
|
{ |
|
97
|
|
|
$this->repository->notification('MPESA Callback: *C2B*', true); |
|
98
|
|
|
$resp = [ |
|
99
|
|
|
'ResultCode' => 0, |
|
100
|
|
|
'ResultDesc' => 'Callback received successfully', |
|
101
|
|
|
]; |
|
102
|
|
|
return response()->json($resp); |
|
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param Request $request |
|
107
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
108
|
|
|
*/ |
|
109
|
|
View Code Duplication |
public function stkCallback(Request $request) |
|
|
|
|
|
|
110
|
|
|
{ |
|
111
|
|
|
$this->repository->notification('MPESA STK Callback: *C2B*', true); |
|
112
|
|
|
$this->repository->processStkPushCallback(json_encode($request->Body)); |
|
113
|
|
|
$resp = [ |
|
114
|
|
|
'ResultCode' => 0, |
|
115
|
|
|
'ResultDesc' => 'STK Callback received successfully', |
|
116
|
|
|
]; |
|
117
|
|
|
return response()->json($resp); |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
122
|
|
|
*/ |
|
123
|
|
View Code Duplication |
public function validatePayment() |
|
|
|
|
|
|
124
|
|
|
{ |
|
125
|
|
|
$this->repository->notification('MPESA Validate Payment URL: *C2B*'); |
|
126
|
|
|
$resp = [ |
|
127
|
|
|
'ResultCode' => 0, |
|
128
|
|
|
'ResultDesc' => 'Validation passed successfully', |
|
129
|
|
|
]; |
|
130
|
|
|
return response()->json($resp); |
|
|
|
|
|
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: