Browse Source

2.0

tags/2.0.3
0nepeop1e 4 years ago
parent
commit
4d2533c3d7
5 changed files with 115 additions and 47 deletions
  1. 3
    0
      .idea/laravel-payment-senangpay.iml
  2. 29
    26
      .idea/php.xml
  3. 1
    1
      composer.json
  4. 80
    13
      src/RazerPayDriver.php
  5. 2
    7
      src/RazerPayServiceProvider.php

+ 3
- 0
.idea/laravel-payment-senangpay.iml View File

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

+ 29
- 26
.idea/php.xml View File

2
 <project version="4">
2
 <project version="4">
3
   <component name="PhpIncludePathManager">
3
   <component name="PhpIncludePathManager">
4
     <include_path>
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
       <path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-idn" />
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
       <path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher-contracts" />
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
       <path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher" />
29
       <path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher" />
8
       <path value="$PROJECT_DIR$/vendor/mirfalah/laravel-payment" />
30
       <path value="$PROJECT_DIR$/vendor/mirfalah/laravel-payment" />
9
-      <path value="$PROJECT_DIR$/vendor/voku/portable-ascii" />
10
       <path value="$PROJECT_DIR$/vendor/doctrine/inflector" />
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
       <path value="$PROJECT_DIR$/vendor/paragonie/random_compat" />
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
       <path value="$PROJECT_DIR$/vendor/illuminate/support" />
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
       <path value="$PROJECT_DIR$/vendor/illuminate/filesystem" />
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
     </include_path>
42
     </include_path>
40
   </component>
43
   </component>
41
   <component name="PhpProjectSharedConfiguration" php_language_level="7.1" />
44
   <component name="PhpProjectSharedConfiguration" php_language_level="7.1" />

+ 1
- 1
composer.json View File

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

+ 80
- 13
src/RazerPayDriver.php View File

4
 namespace MirfalahTech\Laravel\Payment\Gateway\RazerPay;
4
 namespace MirfalahTech\Laravel\Payment\Gateway\RazerPay;
5
 
5
 
6
 
6
 
7
+use Illuminate\Contracts\Config\Repository;
8
+use Illuminate\Contracts\Events\Dispatcher;
7
 use Illuminate\Http\Request;
9
 use Illuminate\Http\Request;
8
 use Illuminate\Support\Arr;
10
 use Illuminate\Support\Arr;
9
 use Illuminate\Support\Facades\Response as Res;
11
 use Illuminate\Support\Facades\Response as Res;
10
 use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
12
 use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
11
 use MirfalahTech\Laravel\Payment\Contracts\PaymentGatewayDriver;
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
 use Symfony\Component\HttpFoundation\Response;
21
 use Symfony\Component\HttpFoundation\Response;
13
 
22
 
14
 class RazerPayDriver implements PaymentGatewayDriver
23
 class RazerPayDriver implements PaymentGatewayDriver
15
 {
24
 {
25
+    use BillStatusBoolean;
26
+
16
     /**
27
     /**
17
      * @var string
28
      * @var string
18
      */
29
      */
32
      */
43
      */
33
     protected $verify_key;
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
     public function createPaymentURL(PayableEntity $payable, array $options = []): string
67
     public function createPaymentURL(PayableEntity $payable, array $options = []): string
58
                 'amount', 'orderid', 'bill_name', 'bill_email', 'bill_mobile',
82
                 'amount', 'orderid', 'bill_name', 'bill_email', 'bill_mobile',
59
                 'bill_desc', 'country', 'verify_code', 'currency'
83
                 'bill_desc', 'country', 'verify_code', 'currency'
60
             ),
84
             ),
85
+            Arr::only($this->config->get('payment.gateway.razerpay.options', []), ['channel']),
61
             Arr::only($options, ['channel'])
86
             Arr::only($options, ['channel'])
62
         );
87
         );
63
-
64
         return "$this->endpoint/MOLPay/pay/$this->merchant_id/?" .
88
         return "$this->endpoint/MOLPay/pay/$this->merchant_id/?" .
65
             http_build_query($query);
89
             http_build_query($query);
66
     }
90
     }
67
 
91
 
68
     public function verifyGatewayReturn(Request $request): bool
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
         $tranID = $request->request->get('tranID');
118
         $tranID = $request->request->get('tranID');
71
         $order_id = $request->request->get('orderid');
119
         $order_id = $request->request->get('orderid');
83
         return $key1 == $request->request->get('skey');
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
         return $request->request->get('orderid');
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 View File

26
                 'verify_key' => env('RAZER_VERIFY_KEY'),
26
                 'verify_key' => env('RAZER_VERIFY_KEY'),
27
                 'secret_key' => env('RAZER_SECRET_KEY'),
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
         $this->app->afterResolving('payment', function (PaymentManager $manager) use ($config) {
32
         $this->app->afterResolving('payment', function (PaymentManager $manager) use ($config) {
33
             $manager->extend('razerpay', function () use ($config) {
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
     }

Loading…
Cancel
Save