Browse Source

update driver

tags/2.0.3
0nepeop1e 3 years ago
parent
commit
d5f04a4692
4 changed files with 28 additions and 6 deletions
  1. 3
    0
      .idea/laravel-payment-senangpay.iml
  2. 3
    0
      .idea/php.xml
  3. 1
    1
      composer.json
  4. 21
    5
      src/SenangPayDriver.php

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

7
       <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
7
       <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
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" />

+ 3
- 0
.idea/php.xml View File

36
       <path value="$PROJECT_DIR$/vendor/symfony/mime" />
36
       <path value="$PROJECT_DIR$/vendor/symfony/mime" />
37
       <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
37
       <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
38
       <path value="$PROJECT_DIR$/vendor/symfony/translation" />
38
       <path value="$PROJECT_DIR$/vendor/symfony/translation" />
39
+      <path value="$PROJECT_DIR$/vendor/illuminate/collections" />
40
+      <path value="$PROJECT_DIR$/vendor/illuminate/macroable" />
41
+      <path value="$PROJECT_DIR$/vendor/symfony/http-client-contracts" />
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": [

+ 21
- 5
src/SenangPayDriver.php View File

8
 use Illuminate\Support\Facades\Response as Res;
8
 use Illuminate\Support\Facades\Response as Res;
9
 use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
9
 use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
10
 use MirfalahTech\Laravel\Payment\Contracts\PaymentGatewayDriver;
10
 use MirfalahTech\Laravel\Payment\Contracts\PaymentGatewayDriver;
11
+use MirfalahTech\Laravel\Payment\Facade\Payment;
12
+use MirfalahTech\Laravel\Payment\Traits\BillStatusBoolean;
11
 use Symfony\Component\HttpFoundation\Response;
13
 use Symfony\Component\HttpFoundation\Response;
12
 
14
 
13
 class SenangPayDriver implements PaymentGatewayDriver
15
 class SenangPayDriver implements PaymentGatewayDriver
14
 {
16
 {
17
+    use BillStatusBoolean;
18
+
15
     /**
19
     /**
16
      * @var string
20
      * @var string
17
      */
21
      */
43
         $amount = sprintf('%0.2f', $amount);
47
         $amount = sprintf('%0.2f', $amount);
44
         $hash = md5($this->secret_key.$detail.$amount.$order_id);
48
         $hash = md5($this->secret_key.$detail.$amount.$order_id);
45
 
49
 
46
-        return "$this->endpoint/payment/$this->merchant_id?'".
50
+        return "$this->endpoint/payment/$this->merchant_id?".
47
             http_build_query(compact('detail', 'order_id', 'amount', 'hash'));
51
             http_build_query(compact('detail', 'order_id', 'amount', 'hash'));
48
     }
52
     }
49
 
53
 
50
     public function verifyGatewayReturn(Request $request): bool
54
     public function verifyGatewayReturn(Request $request): bool
51
     {
55
     {
52
-        return true;
56
+        $hash = $request->query->get('hash');
57
+        return $hash == $this->computeHash($request->request->all());
53
     }
58
     }
54
 
59
 
55
     public function verifyGatewayCallback(Request $request, Response &$response = null): bool
60
     public function verifyGatewayCallback(Request $request, Response &$response = null): bool
56
     {
61
     {
57
         $response = Res::make('OK');
62
         $response = Res::make('OK');
58
-        return true;
63
+        $hash = $request->request->get('hash');
64
+        return $hash == $this->computeHash($request->request->all());
65
+    }
66
+
67
+    public function getBillIdFromRequest(Request $request): ?string{
68
+        return $request->get('order_id');
69
+    }
70
+
71
+    public function getBillStatus(Request $request): ?int
72
+    {
73
+        return $request->request->get('status') == 1 ? Payment::SUCCESS : Payment::PENDING;
59
     }
74
     }
60
 
75
 
61
-    public function getBillIdFromRequest(Request $request){
62
-        return $request->query->get('order_id');
76
+    public function computeHash($payload){
77
+        $payload['hash'] = '[HASH]';
78
+        return md5($this->secret_key.'?'.http_build_query($payload));
63
     }
79
     }
64
 }
80
 }

Loading…
Cancel
Save