Passed
Pull Request — master (#122)
by
unknown
07:52
created
src/Drivers/Atipay/Core/fn.atipay.php 2 patches
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -1,36 +1,36 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-define('ATIPAY_URL','https://mipg.atipay.net/v1/');
4
-define('ATIPAY_TOKEN_URL',ATIPAY_URL . 'get-token');
5
-define('ATIPAY_REDIRECT_TO_PSP_URL',ATIPAY_URL . 'redirect-to-gateway');
6
-define('ATIPAY_VERIFY_URL',ATIPAY_URL . 'verify-payment');
3
+define('ATIPAY_URL', 'https://mipg.atipay.net/v1/');
4
+define('ATIPAY_TOKEN_URL', ATIPAY_URL.'get-token');
5
+define('ATIPAY_REDIRECT_TO_PSP_URL', ATIPAY_URL.'redirect-to-gateway');
6
+define('ATIPAY_VERIFY_URL', ATIPAY_URL.'verify-payment');
7 7
 
8 8
 function fn_atipay_get_token($params)
9 9
 {
10 10
 
11
-    $r = wsRequestPost(ATIPAY_TOKEN_URL,$params);
11
+    $r = wsRequestPost(ATIPAY_TOKEN_URL, $params);
12 12
     $return = array();
13
-    if ($r){
14
-        if (isset($r['status']) && !empty($r['status'])){
13
+    if ($r) {
14
+        if (isset($r['status']) && !empty($r['status'])) {
15 15
             $status = $r['status'];
16
-            if ($status == 1){
17
-                $return['success']=1;
18
-                $return['token']=$r['token'];
19
-            }else{
20
-                $return['success']=0;
21
-                $return['']=$r['errorDescription'];
16
+            if ($status == 1) {
17
+                $return['success'] = 1;
18
+                $return['token'] = $r['token'];
19
+            } else {
20
+                $return['success'] = 0;
21
+                $return[''] = $r['errorDescription'];
22 22
             }
23
-        }else{
24
-            $return['success']=0;
25
-            if (isset($r['faMessage']) && !empty($r['faMessage'])){
23
+        } else {
24
+            $return['success'] = 0;
25
+            if (isset($r['faMessage']) && !empty($r['faMessage'])) {
26 26
                 $return['errorMessage'] = $r['faMessage'];
27
-            }else{
27
+            } else {
28 28
                 $return['errorMessage'] = "خطا در دریافت توکن پرداخت";
29 29
             }
30 30
         }
31 31
 
32
-    }else{
33
-        $return['success']=0;
32
+    } else {
33
+        $return['success'] = 0;
34 34
         $return['errorMessage'] = "خطا در دریافت اطلاعات توکن پرداخت";
35 35
     }
36 36
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     return $form;
56 56
 }
57 57
 
58
-function fn_atipay_get_token_form($params, $submit_text,$action)
58
+function fn_atipay_get_token_form($params, $submit_text, $action)
59 59
 {
60 60
     $form = _fn_generate_get_token_form($params, $submit_text, $action);
61 61
     return $form;
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
 function _fn_generate_get_token_form($params, $submit_text, $action)
65 65
 {
66 66
 
67
-    $form ="<form action='$action' method='POST' align='center' name='atipay_payment_form_token' id='atipay_payment_form_token' >";
68
-    foreach ($params as $k=>$v){
67
+    $form = "<form action='$action' method='POST' align='center' name='atipay_payment_form_token' id='atipay_payment_form_token' >";
68
+    foreach ($params as $k=>$v) {
69 69
         $form .= "<input type='hidden' value='$v' name='$k' >";
70 70
     }
71 71
 
@@ -78,43 +78,43 @@  discard block
 block discarded – undo
78 78
 function fn_check_callback_data($params)
79 79
 {
80 80
     $result = array();
81
-    if (isset($params['state']) && !empty($params['state'])){
81
+    if (isset($params['state']) && !empty($params['state'])) {
82 82
         $state = $params['state'];
83
-        if ($state == 'OK'){
84
-            $result['success']=1;
85
-            $result['error']="";
86
-        }else{
87
-            $result['success']=0;
88
-            $result['error']= _fn_return_state_text($state);
83
+        if ($state == 'OK') {
84
+            $result['success'] = 1;
85
+            $result['error'] = "";
86
+        } else {
87
+            $result['success'] = 0;
88
+            $result['error'] = _fn_return_state_text($state);
89 89
         }
90
-    }else{
91
-        $result['success']=0;
92
-        $result['error']="خطای نامشخص در پرداخت. در صورتیکه مبلغی از شما کسر شده باشد، برگشت داده می شود.";
90
+    } else {
91
+        $result['success'] = 0;
92
+        $result['error'] = "خطای نامشخص در پرداخت. در صورتیکه مبلغی از شما کسر شده باشد، برگشت داده می شود.";
93 93
     }
94 94
 
95 95
     return $result;
96 96
 }
97 97
 
98
-function fn_atipay_verify_payment($params,$amount)
98
+function fn_atipay_verify_payment($params, $amount)
99 99
 {
100
-    $r = wsRequestPost(ATIPAY_VERIFY_URL,$params);
100
+    $r = wsRequestPost(ATIPAY_VERIFY_URL, $params);
101 101
     $return = array();
102
-    if ($r){
103
-
104
-        if (isset($r['amount']) && !empty($r['amount'])){
105
-            if ($r['amount'] == $amount){
106
-                $return['success']=1;
107
-                $return['errorMessage']="";
108
-            }else{
109
-                $return['success']=0;
110
-                $return['errorMessage']="خطا در تایید مبلغ پرداخت.در صورتیکه مبلغی از شما کسر شده باشد، برگشت داده می شود.";
102
+    if ($r) {
103
+
104
+        if (isset($r['amount']) && !empty($r['amount'])) {
105
+            if ($r['amount'] == $amount) {
106
+                $return['success'] = 1;
107
+                $return['errorMessage'] = "";
108
+            } else {
109
+                $return['success'] = 0;
110
+                $return['errorMessage'] = "خطا در تایید مبلغ پرداخت.در صورتیکه مبلغی از شما کسر شده باشد، برگشت داده می شود.";
111 111
             }
112
-        }else{
113
-            $return['success']=0;
114
-            $return['errorMessage']="خطا در تایید اطلاعات پرداخت. در صورتیکه مبلغی از شما کسر شده باشد، برگشت داده می شود.";
112
+        } else {
113
+            $return['success'] = 0;
114
+            $return['errorMessage'] = "خطا در تایید اطلاعات پرداخت. در صورتیکه مبلغی از شما کسر شده باشد، برگشت داده می شود.";
115 115
         }
116
-    }else{
117
-        $return['success']=0;
116
+    } else {
117
+        $return['success'] = 0;
118 118
         $return['errorMessage'] = "خطا در تایید نهایی پرداخت. در صورتیکه مبلغی از شما کسر شده باشد، برگشت داده می شود.";
119 119
     }
120 120
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 
124 124
 function _fn_return_state_text($state)
125 125
 {
126
-    switch ($state){
126
+    switch ($state) {
127 127
         case "CanceledByUser":
128 128
             return "پرداخت توسط شما لغو شده است.";
129 129
             break;
@@ -162,9 +162,9 @@  discard block
 block discarded – undo
162 162
         !isset($params['reservationNumber']) ||
163 163
         !isset($params['referenceNumber']) ||
164 164
         !isset($params['terminalId']) ||
165
-        !isset($params['traceNumber'])){
165
+        !isset($params['traceNumber'])) {
166 166
         return false;
167
-    }else{
167
+    } else {
168 168
         return true;
169 169
     }
170 170
 }
@@ -185,16 +185,16 @@  discard block
 block discarded – undo
185 185
     $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
186 186
     curl_close($ch);
187 187
 
188
-    if ($httpcode == "200"){
188
+    if ($httpcode == "200") {
189 189
         //nothing YET
190
-    }else{
191
-        $json= json_encode(array('error'=>'Y'));
190
+    } else {
191
+        $json = json_encode(array('error'=>'Y'));
192 192
     }
193 193
 
194 194
     return $json;
195 195
 }
196 196
 
197
-function wsRequestPost($url,$params)
197
+function wsRequestPost($url, $params)
198 198
 {
199 199
     set_time_limit(30);
200 200
     $ch = curl_init($url);
@@ -204,15 +204,15 @@  discard block
 block discarded – undo
204 204
     curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout in seconds
205 205
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json;"));
206 206
     curl_setopt($ch, CURLOPT_POST, 1);
207
-    curl_setopt($ch, CURLOPT_POSTFIELDS,$postFields);
207
+    curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
208 208
     $json = curl_exec($ch);
209 209
     $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
210 210
     curl_close($ch);
211 211
 
212
-    if ($httpcode == "200"){
213
-        return json_decode($json,true);
214
-    }else{
215
-        $json = array('error'=>'Y','jsonError'=>$httpcode,'message'=>$httpcode);
212
+    if ($httpcode == "200") {
213
+        return json_decode($json, true);
214
+    } else {
215
+        $json = array('error'=>'Y', 'jsonError'=>$httpcode, 'message'=>$httpcode);
216 216
     }
217 217
 
218 218
     return $json;
Please login to merge, or discard this patch.
Braces   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -16,20 +16,20 @@  discard block
 block discarded – undo
16 16
             if ($status == 1){
17 17
                 $return['success']=1;
18 18
                 $return['token']=$r['token'];
19
-            }else{
19
+            } else{
20 20
                 $return['success']=0;
21 21
                 $return['']=$r['errorDescription'];
22 22
             }
23
-        }else{
23
+        } else{
24 24
             $return['success']=0;
25 25
             if (isset($r['faMessage']) && !empty($r['faMessage'])){
26 26
                 $return['errorMessage'] = $r['faMessage'];
27
-            }else{
27
+            } else{
28 28
                 $return['errorMessage'] = "خطا در دریافت توکن پرداخت";
29 29
             }
30 30
         }
31 31
 
32
-    }else{
32
+    } else{
33 33
         $return['success']=0;
34 34
         $return['errorMessage'] = "خطا در دریافت اطلاعات توکن پرداخت";
35 35
     }
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
         if ($state == 'OK'){
84 84
             $result['success']=1;
85 85
             $result['error']="";
86
-        }else{
86
+        } else{
87 87
             $result['success']=0;
88 88
             $result['error']= _fn_return_state_text($state);
89 89
         }
90
-    }else{
90
+    } else{
91 91
         $result['success']=0;
92 92
         $result['error']="خطای نامشخص در پرداخت. در صورتیکه مبلغی از شما کسر شده باشد، برگشت داده می شود.";
93 93
     }
@@ -105,15 +105,15 @@  discard block
 block discarded – undo
105 105
             if ($r['amount'] == $amount){
106 106
                 $return['success']=1;
107 107
                 $return['errorMessage']="";
108
-            }else{
108
+            } else{
109 109
                 $return['success']=0;
110 110
                 $return['errorMessage']="خطا در تایید مبلغ پرداخت.در صورتیکه مبلغی از شما کسر شده باشد، برگشت داده می شود.";
111 111
             }
112
-        }else{
112
+        } else{
113 113
             $return['success']=0;
114 114
             $return['errorMessage']="خطا در تایید اطلاعات پرداخت. در صورتیکه مبلغی از شما کسر شده باشد، برگشت داده می شود.";
115 115
         }
116
-    }else{
116
+    } else{
117 117
         $return['success']=0;
118 118
         $return['errorMessage'] = "خطا در تایید نهایی پرداخت. در صورتیکه مبلغی از شما کسر شده باشد، برگشت داده می شود.";
119 119
     }
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         !isset($params['terminalId']) ||
165 165
         !isset($params['traceNumber'])){
166 166
         return false;
167
-    }else{
167
+    } else{
168 168
         return true;
169 169
     }
170 170
 }
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 
188 188
     if ($httpcode == "200"){
189 189
         //nothing YET
190
-    }else{
190
+    } else{
191 191
         $json= json_encode(array('error'=>'Y'));
192 192
     }
193 193
 
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 
212 212
     if ($httpcode == "200"){
213 213
         return json_decode($json,true);
214
-    }else{
214
+    } else{
215 215
         $json = array('error'=>'Y','jsonError'=>$httpcode,'message'=>$httpcode);
216 216
     }
217 217
 
Please login to merge, or discard this patch.
src/Drivers/Atipay/Atipay.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         
74 74
 
75 75
         $amount = $this->invoice->getAmount();
76
-        if ($this->settings->currency == 'T'){ //convert amount to rial, payment gateways need rial
76
+        if ($this->settings->currency == 'T') { //convert amount to rial, payment gateways need rial
77 77
             $amount = $amount * 10;
78 78
         }
79 79
         
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             $token = $r['token'];
96 96
             $this->invoice->transactionId($token);
97 97
             return $this->invoice->getTransactionId();
98
-        }else{
98
+        } else {
99 99
             $error_message = $r['errorMessage'];
100 100
             throw new PurchaseFailedException($error_message);
101 101
         }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         if ($result['success'] == 1) { //will verify here
133 133
             $apiKey = $this->setting->apikey;
134 134
             $amount = $this->invoice->getAmount();
135
-            if ($this->settings->currency == 'T'){ //convert amount to rial, payment gateways need rial
135
+            if ($this->settings->currency == 'T') { //convert amount to rial, payment gateways need rial
136 136
                 $amount = $amount * 10;
137 137
             }
138 138
             $verify_params = array('apiKey' => $apiKey,
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
                 $error_message = $r['errorMessage'];
145 145
                 throw new InvalidPaymentException($error_message);
146 146
             } else { //success
147
-                $receipt =  $this->createReceipt($data['referenceNumber']);
147
+                $receipt = $this->createReceipt($data['referenceNumber']);
148 148
                 $receipt->detail([
149 149
                     'referenceNo' => $params['referenceNumber'],
150 150
                     'rrn' => Request::input('rrn'),
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@
 block discarded – undo
95 95
             $token = $r['token'];
96 96
             $this->invoice->transactionId($token);
97 97
             return $this->invoice->getTransactionId();
98
-        }else{
98
+        } else{
99 99
             $error_message = $r['errorMessage'];
100 100
             throw new PurchaseFailedException($error_message);
101 101
         }
Please login to merge, or discard this patch.