Parcourir la source

add events support

tags/2.0.1
0nepeop1e il y a 4 ans
Parent
révision
7cc06c4679
3 fichiers modifiés avec 36 ajouts et 4 suppressions
  1. 6
    3
      .idea/workspace.xml
  2. 29
    1
      src/DummyPayDriver.php
  3. 1
    0
      src/DummyPayServiceProvider.php

+ 6
- 3
.idea/workspace.xml Voir le fichier

@@ -20,10 +20,7 @@
20 20
   </component>
21 21
   <component name="ChangeListManager">
22 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 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 24
       <change beforePath="$PROJECT_DIR$/src/DummyPayDriver.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/DummyPayDriver.php" afterDir="false" />
28 25
     </list>
29 26
     <option name="SHOW_DIALOG" value="false" />
@@ -115,6 +112,8 @@
115 112
       <workItem from="1600835177454" duration="172000" />
116 113
       <workItem from="1600835569280" duration="44000" />
117 114
       <workItem from="1601966890356" duration="4888000" />
115
+      <workItem from="1602126845532" duration="739000" />
116
+      <workItem from="1602134547803" duration="1213000" />
118 117
     </task>
119 118
     <servers />
120 119
   </component>
@@ -142,5 +141,9 @@
142 141
       <screen x="0" y="30" width="2560" height="1020" />
143 142
     </state>
144 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 148
   </component>
146 149
 </project>

+ 29
- 1
src/DummyPayDriver.php Voir le fichier

@@ -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
 }

+ 1
- 0
src/DummyPayServiceProvider.php Voir le fichier

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

Chargement…
Annuler
Enregistrer