|
@@ -4,10 +4,15 @@
|
4
|
4
|
namespace MirfalahTech\Laravel\Payment\Gateway\DummyPay;
|
5
|
5
|
|
6
|
6
|
|
|
7
|
+use Illuminate\Events\Dispatcher;
|
7
|
8
|
use Illuminate\Http\Request;
|
8
|
9
|
use Illuminate\Support\Facades\Response as Res;
|
9
|
10
|
use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
|
10
|
11
|
use MirfalahTech\Laravel\Payment\Contracts\PaymentGatewayDriver;
|
|
12
|
+use MirfalahTech\Laravel\Payment\Events\PaymentFailedEvent;
|
|
13
|
+use MirfalahTech\Laravel\Payment\Events\PaymentPendingEvent;
|
|
14
|
+use MirfalahTech\Laravel\Payment\Events\PaymentSuccessEvent;
|
|
15
|
+use MirfalahTech\Laravel\Payment\Events\ReturnVerifiedEvent;
|
11
|
16
|
use MirfalahTech\Laravel\Payment\Facade\Payment;
|
12
|
17
|
use MirfalahTech\Laravel\Payment\Traits\BillStatusBoolean;
|
13
|
18
|
use Symfony\Component\HttpFoundation\Response;
|
|
@@ -26,9 +31,15 @@ class DummyPayDriver implements PaymentGatewayDriver
|
26
|
31
|
*/
|
27
|
32
|
protected $return_url;
|
28
|
33
|
|
29
|
|
- public function __construct(string $callback_url, string $return_url){
|
|
34
|
+ /**
|
|
35
|
+ * @var Dispatcher
|
|
36
|
+ */
|
|
37
|
+ protected $events;
|
|
38
|
+
|
|
39
|
+ public function __construct(Dispatcher $events, string $callback_url, string $return_url){
|
30
|
40
|
$this->callback_url = rtrim($callback_url, '/');
|
31
|
41
|
$this->return_url = rtrim($return_url, '/');
|
|
42
|
+ $this->events = $events;
|
32
|
43
|
}
|
33
|
44
|
|
34
|
45
|
public function createPaymentURL(PayableEntity $payable, array $options = []): string
|
|
@@ -39,6 +50,8 @@ class DummyPayDriver implements PaymentGatewayDriver
|
39
|
50
|
|
40
|
51
|
public function verifyGatewayReturn(Request $request): bool
|
41
|
52
|
{
|
|
53
|
+ $this->events->dispatch(new ReturnVerifiedEvent('dummy', $this, $request));
|
|
54
|
+ $this->dispatchStatusEvent($request);
|
42
|
55
|
return true;
|
43
|
56
|
}
|
44
|
57
|
|
|
@@ -69,4 +82,19 @@ class DummyPayDriver implements PaymentGatewayDriver
|
69
|
82
|
return $request->query->get('status') == 'success' ?
|
70
|
83
|
Payment::SUCCESS : Payment::FAILED;
|
71
|
84
|
}
|
|
85
|
+
|
|
86
|
+ protected function dispatchStatusEvent(Request $request)
|
|
87
|
+ {
|
|
88
|
+ switch ($this->getBillStatus($request)) {
|
|
89
|
+ case Payment::SUCCESS:
|
|
90
|
+ $this->events->dispatch(new PaymentSuccessEvent('dummy', $this, $request));
|
|
91
|
+ break;
|
|
92
|
+ case Payment::PENDING:
|
|
93
|
+ $this->events->dispatch(new PaymentPendingEvent('dummy', $this, $request));
|
|
94
|
+ break;
|
|
95
|
+ case Payment::FAILED:
|
|
96
|
+ $this->events->dispatch(new PaymentFailedEvent('dummy', $this, $request));
|
|
97
|
+ break;
|
|
98
|
+ }
|
|
99
|
+ }
|
72
|
100
|
}
|