Browse Source

add events support

tags/2.0.1
0nepeop1e 4 years ago
parent
commit
7cc06c4679
3 changed files with 36 additions and 4 deletions
  1. 6
    3
      .idea/workspace.xml
  2. 29
    1
      src/DummyPayDriver.php
  3. 1
    0
      src/DummyPayServiceProvider.php

+ 6
- 3
.idea/workspace.xml View File

20
   </component>
20
   </component>
21
   <component name="ChangeListManager">
21
   <component name="ChangeListManager">
22
     <list default="true" id="d34cafd0-eade-4b43-97b9-dd7f3a1eae86" name="Default Changelist" comment="">
22
     <list default="true" id="d34cafd0-eade-4b43-97b9-dd7f3a1eae86" name="Default Changelist" comment="">
23
-      <change beforePath="$PROJECT_DIR$/.idea/laravel-payment-dummy.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/laravel-payment-dummy.iml" afterDir="false" />
24
-      <change beforePath="$PROJECT_DIR$/.idea/php.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/php.xml" afterDir="false" />
25
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
23
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
26
-      <change beforePath="$PROJECT_DIR$/composer.json" beforeDir="false" afterPath="$PROJECT_DIR$/composer.json" afterDir="false" />
27
       <change beforePath="$PROJECT_DIR$/src/DummyPayDriver.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/DummyPayDriver.php" afterDir="false" />
24
       <change beforePath="$PROJECT_DIR$/src/DummyPayDriver.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/DummyPayDriver.php" afterDir="false" />
28
     </list>
25
     </list>
29
     <option name="SHOW_DIALOG" value="false" />
26
     <option name="SHOW_DIALOG" value="false" />
115
       <workItem from="1600835177454" duration="172000" />
112
       <workItem from="1600835177454" duration="172000" />
116
       <workItem from="1600835569280" duration="44000" />
113
       <workItem from="1600835569280" duration="44000" />
117
       <workItem from="1601966890356" duration="4888000" />
114
       <workItem from="1601966890356" duration="4888000" />
115
+      <workItem from="1602126845532" duration="739000" />
116
+      <workItem from="1602134547803" duration="1213000" />
118
     </task>
117
     </task>
119
     <servers />
118
     <servers />
120
   </component>
119
   </component>
142
       <screen x="0" y="30" width="2560" height="1020" />
141
       <screen x="0" y="30" width="2560" height="1020" />
143
     </state>
142
     </state>
144
     <state x="1080" y="227" width="389" height="624" key="#com.intellij.ide.util.MemberChooser/0.30.2560.1020@0.30.2560.1020" timestamp="1601971187393" />
143
     <state x="1080" y="227" width="389" height="624" key="#com.intellij.ide.util.MemberChooser/0.30.2560.1020@0.30.2560.1020" timestamp="1601971187393" />
144
+    <state x="1013" y="298" width="524" height="482" key="#com.jetbrains.php.actions.copyPaste.importReferences.PhpImportReferencesDialog" timestamp="1602135359515">
145
+      <screen x="0" y="30" width="2560" height="1020" />
146
+    </state>
147
+    <state x="1013" y="298" width="524" height="482" key="#com.jetbrains.php.actions.copyPaste.importReferences.PhpImportReferencesDialog/0.30.2560.1020@0.30.2560.1020" timestamp="1602135359515" />
145
   </component>
148
   </component>
146
 </project>
149
 </project>

+ 29
- 1
src/DummyPayDriver.php View File

4
 namespace MirfalahTech\Laravel\Payment\Gateway\DummyPay;
4
 namespace MirfalahTech\Laravel\Payment\Gateway\DummyPay;
5
 
5
 
6
 
6
 
7
+use Illuminate\Events\Dispatcher;
7
 use Illuminate\Http\Request;
8
 use Illuminate\Http\Request;
8
 use Illuminate\Support\Facades\Response as Res;
9
 use Illuminate\Support\Facades\Response as Res;
9
 use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
10
 use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
10
 use MirfalahTech\Laravel\Payment\Contracts\PaymentGatewayDriver;
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
 use MirfalahTech\Laravel\Payment\Facade\Payment;
16
 use MirfalahTech\Laravel\Payment\Facade\Payment;
12
 use MirfalahTech\Laravel\Payment\Traits\BillStatusBoolean;
17
 use MirfalahTech\Laravel\Payment\Traits\BillStatusBoolean;
13
 use Symfony\Component\HttpFoundation\Response;
18
 use Symfony\Component\HttpFoundation\Response;
26
      */
31
      */
27
     protected $return_url;
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
         $this->callback_url = rtrim($callback_url, '/');
40
         $this->callback_url = rtrim($callback_url, '/');
31
         $this->return_url = rtrim($return_url, '/');
41
         $this->return_url = rtrim($return_url, '/');
42
+        $this->events = $events;
32
     }
43
     }
33
 
44
 
34
     public function createPaymentURL(PayableEntity $payable, array $options = []): string
45
     public function createPaymentURL(PayableEntity $payable, array $options = []): string
39
 
50
 
40
     public function verifyGatewayReturn(Request $request): bool
51
     public function verifyGatewayReturn(Request $request): bool
41
     {
52
     {
53
+        $this->events->dispatch(new ReturnVerifiedEvent('dummy', $this, $request));
54
+        $this->dispatchStatusEvent($request);
42
         return true;
55
         return true;
43
     }
56
     }
44
 
57
 
69
         return $request->query->get('status') == 'success' ?
82
         return $request->query->get('status') == 'success' ?
70
             Payment::SUCCESS : Payment::FAILED;
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
 }

+ 1
- 0
src/DummyPayServiceProvider.php View File

30
         $this->app->afterResolving('payment', function (PaymentManager $manager) use ($config) {
30
         $this->app->afterResolving('payment', function (PaymentManager $manager) use ($config) {
31
             $manager->extend('dummy', function () use ($config) {
31
             $manager->extend('dummy', function () use ($config) {
32
                 return new DummyPayDriver(
32
                 return new DummyPayDriver(
33
+                    $this->app->make('events'),
33
                     $config->get('payment.gateway.dummy.callback_url'),
34
                     $config->get('payment.gateway.dummy.callback_url'),
34
                     $config->get('payment.gateway.dummy.return_url')
35
                     $config->get('payment.gateway.dummy.return_url')
35
                 );
36
                 );

Loading…
Cancel
Save