0nepeop1e 4 роки тому
джерело
коміт
4d2533c3d7

+ 3
- 0
.idea/laravel-payment-senangpay.iml Переглянути файл

@@ -7,9 +7,11 @@
7 7
       <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="MirfalahTech\Laravel\Payment\Gateway\RazerPay\" />
8 8
       <excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
9 9
       <excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/inflector" />
10
+      <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/collections" />
10 11
       <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/contracts" />
11 12
       <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/filesystem" />
12 13
       <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/http" />
14
+      <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/macroable" />
13 15
       <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/session" />
14 16
       <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/support" />
15 17
       <excludeFolder url="file://$MODULE_DIR$/vendor/mirfalah/laravel-payment" />
@@ -24,6 +26,7 @@
24 26
       <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/event-dispatcher" />
25 27
       <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/event-dispatcher-contracts" />
26 28
       <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/finder" />
29
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-client-contracts" />
27 30
       <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-foundation" />
28 31
       <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-kernel" />
29 32
       <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/mime" />

+ 29
- 26
.idea/php.xml Переглянути файл

@@ -2,40 +2,43 @@
2 2
 <project version="4">
3 3
   <component name="PhpIncludePathManager">
4 4
     <include_path>
5
+      <path value="$PROJECT_DIR$/vendor/psr/log" />
6
+      <path value="$PROJECT_DIR$/vendor/psr/container" />
7
+      <path value="$PROJECT_DIR$/vendor/voku/portable-ascii" />
8
+      <path value="$PROJECT_DIR$/vendor/psr/event-dispatcher" />
9
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-normalizer" />
10
+      <path value="$PROJECT_DIR$/vendor/nesbot/carbon" />
11
+      <path value="$PROJECT_DIR$/vendor/symfony/deprecation-contracts" />
5 12
       <path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-idn" />
13
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
14
+      <path value="$PROJECT_DIR$/vendor/symfony/http-foundation" />
15
+      <path value="$PROJECT_DIR$/vendor/symfony/http-client-contracts" />
16
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php73" />
17
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
18
+      <path value="$PROJECT_DIR$/vendor/symfony/mime" />
19
+      <path value="$PROJECT_DIR$/vendor/symfony/finder" />
20
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
21
+      <path value="$PROJECT_DIR$/vendor/symfony/http-kernel" />
22
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php70" />
23
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php72" />
24
+      <path value="$PROJECT_DIR$/vendor/symfony/var-dumper" />
6 25
       <path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher-contracts" />
26
+      <path value="$PROJECT_DIR$/vendor/symfony/error-handler" />
27
+      <path value="$PROJECT_DIR$/vendor/symfony/translation" />
28
+      <path value="$PROJECT_DIR$/vendor/symfony/translation-contracts" />
7 29
       <path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher" />
8 30
       <path value="$PROJECT_DIR$/vendor/mirfalah/laravel-payment" />
9
-      <path value="$PROJECT_DIR$/vendor/voku/portable-ascii" />
10 31
       <path value="$PROJECT_DIR$/vendor/doctrine/inflector" />
11
-      <path value="$PROJECT_DIR$/vendor/composer" />
12
-      <path value="$PROJECT_DIR$/vendor/nesbot/carbon" />
13
-      <path value="$PROJECT_DIR$/vendor/symfony/var-dumper" />
14
-      <path value="$PROJECT_DIR$/vendor/psr/event-dispatcher" />
15
-      <path value="$PROJECT_DIR$/vendor/psr/simple-cache" />
16
-      <path value="$PROJECT_DIR$/vendor/psr/container" />
32
+      <path value="$PROJECT_DIR$/vendor/illuminate/http" />
17 33
       <path value="$PROJECT_DIR$/vendor/paragonie/random_compat" />
18
-      <path value="$PROJECT_DIR$/vendor/psr/log" />
19
-      <path value="$PROJECT_DIR$/vendor/symfony/error-handler" />
20
-      <path value="$PROJECT_DIR$/vendor/illuminate/contracts" />
21
-      <path value="$PROJECT_DIR$/vendor/illuminate/session" />
22
-      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php72" />
23 34
       <path value="$PROJECT_DIR$/vendor/illuminate/support" />
24
-      <path value="$PROJECT_DIR$/vendor/symfony/translation-contracts" />
35
+      <path value="$PROJECT_DIR$/vendor/illuminate/macroable" />
36
+      <path value="$PROJECT_DIR$/vendor/illuminate/contracts" />
25 37
       <path value="$PROJECT_DIR$/vendor/illuminate/filesystem" />
26
-      <path value="$PROJECT_DIR$/vendor/symfony/http-foundation" />
27
-      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php70" />
28
-      <path value="$PROJECT_DIR$/vendor/illuminate/http" />
29
-      <path value="$PROJECT_DIR$/vendor/symfony/finder" />
30
-      <path value="$PROJECT_DIR$/vendor/symfony/http-kernel" />
31
-      <path value="$PROJECT_DIR$/vendor/symfony/deprecation-contracts" />
32
-      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
33
-      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
34
-      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-normalizer" />
35
-      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php73" />
36
-      <path value="$PROJECT_DIR$/vendor/symfony/mime" />
37
-      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
38
-      <path value="$PROJECT_DIR$/vendor/symfony/translation" />
38
+      <path value="$PROJECT_DIR$/vendor/illuminate/collections" />
39
+      <path value="$PROJECT_DIR$/vendor/illuminate/session" />
40
+      <path value="$PROJECT_DIR$/vendor/composer" />
41
+      <path value="$PROJECT_DIR$/vendor/psr/simple-cache" />
39 42
     </include_path>
40 43
   </component>
41 44
   <component name="PhpProjectSharedConfiguration" php_language_level="7.1" />

+ 1
- 1
composer.json Переглянути файл

@@ -6,7 +6,7 @@
6 6
     "readme": "README.md",
7 7
     "require": {
8 8
         "php": ">=7.1",
9
-        "mirfalah/laravel-payment": "^1.0"
9
+        "mirfalah/laravel-payment": "^2.0"
10 10
     },
11 11
     "license": "Mirfalah-Tech",
12 12
     "authors": [

+ 80
- 13
src/RazerPayDriver.php Переглянути файл

@@ -4,15 +4,26 @@
4 4
 namespace MirfalahTech\Laravel\Payment\Gateway\RazerPay;
5 5
 
6 6
 
7
+use Illuminate\Contracts\Config\Repository;
8
+use Illuminate\Contracts\Events\Dispatcher;
7 9
 use Illuminate\Http\Request;
8 10
 use Illuminate\Support\Arr;
9 11
 use Illuminate\Support\Facades\Response as Res;
10 12
 use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
11 13
 use MirfalahTech\Laravel\Payment\Contracts\PaymentGatewayDriver;
14
+use MirfalahTech\Laravel\Payment\Events\CallbackVerifiedEvent;
15
+use MirfalahTech\Laravel\Payment\Events\PaymentFailedEvent;
16
+use MirfalahTech\Laravel\Payment\Events\PaymentPendingEvent;
17
+use MirfalahTech\Laravel\Payment\Events\PaymentSuccessEvent;
18
+use MirfalahTech\Laravel\Payment\Events\ReturnVerifiedEvent;
19
+use MirfalahTech\Laravel\Payment\Facade\Payment;
20
+use MirfalahTech\Laravel\Payment\Traits\BillStatusBoolean;
12 21
 use Symfony\Component\HttpFoundation\Response;
13 22
 
14 23
 class RazerPayDriver implements PaymentGatewayDriver
15 24
 {
25
+    use BillStatusBoolean;
26
+
16 27
     /**
17 28
      * @var string
18 29
      */
@@ -32,12 +43,25 @@ class RazerPayDriver implements PaymentGatewayDriver
32 43
      */
33 44
     protected $verify_key;
34 45
 
35
-    public function __construct(string $endpoint, string $merchant_id, string $verify_key, string $secret_key)
46
+    /**
47
+     * @var Repository
48
+     */
49
+    protected $config;
50
+
51
+    /**
52
+     * @var Dispatcher
53
+     */
54
+    protected $events;
55
+
56
+    public function __construct(Repository $config, Dispatcher $events)
36 57
     {
37
-        $this->endpoint = rtrim($endpoint, '/');
38
-        $this->merchant_id = $merchant_id;
39
-        $this->secret_key = $secret_key;
40
-        $this->verify_key = $verify_key;
58
+        $this->config = $config;
59
+        $this->events = $events;
60
+
61
+        $this->endpoint = rtrim($config->get('payment.gateway.razerpay.endpoint'), '/');
62
+        $this->merchant_id = $config->get('payment.gateway.razerpay.merchant_id');
63
+        $this->secret_key = $config->get('payment.gateway.razerpay.secret_key');
64
+        $this->verify_key = $config->get('payment.gateway.razerpay.verify_key');
41 65
     }
42 66
 
43 67
     public function createPaymentURL(PayableEntity $payable, array $options = []): string
@@ -58,14 +82,38 @@ class RazerPayDriver implements PaymentGatewayDriver
58 82
                 'amount', 'orderid', 'bill_name', 'bill_email', 'bill_mobile',
59 83
                 'bill_desc', 'country', 'verify_code', 'currency'
60 84
             ),
85
+            Arr::only($this->config->get('payment.gateway.razerpay.options', []), ['channel']),
61 86
             Arr::only($options, ['channel'])
62 87
         );
63
-
64 88
         return "$this->endpoint/MOLPay/pay/$this->merchant_id/?" .
65 89
             http_build_query($query);
66 90
     }
67 91
 
68 92
     public function verifyGatewayReturn(Request $request): bool
93
+    {
94
+        if ($this->verifyRequest($request)) {
95
+            $this->events->dispatch(new ReturnVerifiedEvent('razerpay', $this, $request));
96
+            $this->dispatchStatusEvent($request);
97
+            return true;
98
+        }
99
+        return false;
100
+    }
101
+
102
+    public function verifyGatewayCallback(Request $request, Response &$response = null): bool
103
+    {
104
+        $response = $request->request->has('nbcb') ?
105
+            Res::make('CBTOKEN:MPSTATOK') :
106
+            Res::make('OK');
107
+
108
+        if ($this->verifyRequest($request)) {
109
+            $this->events->dispatch(new CallbackVerifiedEvent('razerpay', $this, $request));
110
+            $this->dispatchStatusEvent($request);
111
+            return true;
112
+        }
113
+        return false;
114
+    }
115
+
116
+    protected function verifyRequest(Request $request): bool
69 117
     {
70 118
         $tranID = $request->request->get('tranID');
71 119
         $order_id = $request->request->get('orderid');
@@ -83,16 +131,35 @@ class RazerPayDriver implements PaymentGatewayDriver
83 131
         return $key1 == $request->request->get('skey');
84 132
     }
85 133
 
86
-    public function verifyGatewayCallback(Request $request, Response &$response = null): bool
134
+    protected function dispatchStatusEvent(Request $request)
87 135
     {
88
-        $response = $request->request->has('nbcb') ?
89
-            Res::make('CBTOKEN:MPSTATOK') :
90
-            Res::make('OK');
91
-
92
-        return $this->verifyGatewayReturn($request);
136
+        switch ($this->getBillStatus($request)) {
137
+            case Payment::SUCCESS:
138
+                $this->events->dispatch(new PaymentSuccessEvent('razerpay', $this, $request));
139
+                break;
140
+            case Payment::PENDING:
141
+                $this->events->dispatch(new PaymentPendingEvent('razerpay', $this, $request));
142
+                break;
143
+            case Payment::FAILED:
144
+                $this->events->dispatch(new PaymentFailedEvent('razerpay', $this, $request));
145
+                break;
146
+        }
93 147
     }
94 148
 
95
-    public function getBillIdFromRequest(Request $request){
149
+    public function getBillIdFromRequest(Request $request): ?string
150
+    {
96 151
         return $request->request->get('orderid');
97 152
     }
153
+
154
+    public function getBillStatus(Request $request): ?int
155
+    {
156
+        if ($request->request->has('status')) {
157
+            $status = $request->request->get('status');
158
+            return $status == '00' ? Payment::SUCCESS :
159
+                $status == '11' ? Payment::FAILED :
160
+                    Payment::PENDING;
161
+        } else {
162
+            return null;
163
+        }
164
+    }
98 165
 }

+ 2
- 7
src/RazerPayServiceProvider.php Переглянути файл

@@ -26,17 +26,12 @@ class RazerPayServiceProvider extends ServiceProvider
26 26
                 'verify_key' => env('RAZER_VERIFY_KEY'),
27 27
                 'secret_key' => env('RAZER_SECRET_KEY'),
28 28
             ],
29
-            $config->get('payment.gateway.razerpay', [])
29
+            $config->get('payment.gateway.razerpay', []) ?? []
30 30
         ));
31 31
 
32 32
         $this->app->afterResolving('payment', function (PaymentManager $manager) use ($config) {
33 33
             $manager->extend('razerpay', function () use ($config) {
34
-                return new RazerPayDriver(
35
-                    $config->get('payment.gateway.razerpay.endpoint'),
36
-                    $config->get('payment.gateway.razerpay.merchant_id'),
37
-                    $config->get('payment.gateway.razerpay.verify_key'),
38
-                    $config->get('payment.gateway.razerpay.secret_key')
39
-                );
34
+                return new RazerPayDriver($config, $this->app->make('events'));
40 35
             });
41 36
         });
42 37
     }

Завантаження…
Відмінити
Зберегти