Browse Source

update driver

tags/2.0.3
0nepeop1e 4 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,9 +7,11 @@
7 7
       <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
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" />

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

@@ -36,6 +36,9 @@
36 36
       <path value="$PROJECT_DIR$/vendor/symfony/mime" />
37 37
       <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
38 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 42
     </include_path>
40 43
   </component>
41 44
   <component name="PhpProjectSharedConfiguration" php_language_level="7.1" />

+ 1
- 1
composer.json View File

@@ -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": [

+ 21
- 5
src/SenangPayDriver.php View File

@@ -8,10 +8,14 @@ use Illuminate\Http\Request;
8 8
 use Illuminate\Support\Facades\Response as Res;
9 9
 use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
10 10
 use MirfalahTech\Laravel\Payment\Contracts\PaymentGatewayDriver;
11
+use MirfalahTech\Laravel\Payment\Facade\Payment;
12
+use MirfalahTech\Laravel\Payment\Traits\BillStatusBoolean;
11 13
 use Symfony\Component\HttpFoundation\Response;
12 14
 
13 15
 class SenangPayDriver implements PaymentGatewayDriver
14 16
 {
17
+    use BillStatusBoolean;
18
+
15 19
     /**
16 20
      * @var string
17 21
      */
@@ -43,22 +47,34 @@ class SenangPayDriver implements PaymentGatewayDriver
43 47
         $amount = sprintf('%0.2f', $amount);
44 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 51
             http_build_query(compact('detail', 'order_id', 'amount', 'hash'));
48 52
     }
49 53
 
50 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 60
     public function verifyGatewayCallback(Request $request, Response &$response = null): bool
56 61
     {
57 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