@@ -16,10 +16,10 @@ |
||
16 | 16 | class Digipay extends Driver |
17 | 17 | { |
18 | 18 | /** |
19 | - * Digipay Client. |
|
20 | - * |
|
21 | - * @var object |
|
22 | - */ |
|
19 | + * Digipay Client. |
|
20 | + * |
|
21 | + * @var object |
|
22 | + */ |
|
23 | 23 | protected $client; |
24 | 24 | |
25 | 25 | /** |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | public function __construct(Invoice $invoice, $settings) |
53 | 53 | { |
54 | 54 | $this->invoice($invoice); |
55 | - $this->settings=$settings; |
|
55 | + $this->settings = $settings; |
|
56 | 56 | $this->client = new Client(); |
57 | 57 | $this->oauthToken = $this->oauth(); |
58 | 58 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | public function verify(): ReceiptInterface |
115 | 115 | { |
116 | - $tracingId=Request::input("trackingCode"); |
|
116 | + $tracingId = Request::input("trackingCode"); |
|
117 | 117 | |
118 | 118 | $response = $this->client->request( |
119 | 119 | 'POST', |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | "grant_type" => 'password', |
156 | 156 | ] |
157 | 157 | ); |
158 | - if ($response->getStatusCode()!=200) { |
|
159 | - if ($response->getStatusCode()==401) { |
|
158 | + if ($response->getStatusCode() != 200) { |
|
159 | + if ($response->getStatusCode() == 401) { |
|
160 | 160 | throw new PurchaseFailedException("خطا نام کاربری یا رمز عبور شما اشتباه می باشد."); |
161 | 161 | } else { |
162 | 162 | throw new PurchaseFailedException("خطا در هنگام احراز هویت."); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | $result = json_decode($response->getBody()->getContents(), true); |
102 | 102 | |
103 | 103 | // some error has happened |
104 | - if (! empty($result['errors']) || empty($result['data']) || $result['data']['code'] != 100) { |
|
104 | + if (!empty($result['errors']) || empty($result['data']) || $result['data']['code'] != 100) { |
|
105 | 105 | throw new PurchaseFailedException($result['errors']['message'], $result['errors']['code']); |
106 | 106 | } |
107 | 107 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | $result = json_decode($response->getBody()->getContents(), true); |
163 | 163 | |
164 | - if (empty($result['data']) || ! isset($result['data']['ref_id']) || $result['data']['code'] != 100) { |
|
164 | + if (empty($result['data']) || !isset($result['data']['ref_id']) || $result['data']['code'] != 100) { |
|
165 | 165 | $message = $result['errors']['message'] ?? ""; |
166 | 166 | $code = $result['errors']['code']; |
167 | 167 |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | if (true === $this->_checkCacheDir()) { |
107 | 107 | $filename = $this->getCache(); |
108 | 108 | $filename = preg_replace('/[^0-9a-z\.\_\-]/i', '', strtolower($filename)); |
109 | - return $this->getCachePath() . $this->_getHash($filename) . $this->getExtension(); |
|
109 | + return $this->getCachePath().$this->_getHash($filename).$this->getExtension(); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | private function _checkCacheDir() |
119 | 119 | { |
120 | 120 | if (!is_dir($this->getCachePath()) && !mkdir($this->getCachePath(), 0775, true)) { |
121 | - throw new \Exception('Unable to create cache directory ' . $this->getCachePath()); |
|
121 | + throw new \Exception('Unable to create cache directory '.$this->getCachePath()); |
|
122 | 122 | } elseif (!is_readable($this->getCachePath()) || !is_writable($this->getCachePath())) { |
123 | 123 | if (!chmod($this->getCachePath(), 0775)) { |
124 | - throw new \Exception($this->getCachePath() . ' must be readable and writeable'); |
|
124 | + throw new \Exception($this->getCachePath().' must be readable and writeable'); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | return true; |
@@ -228,7 +228,9 @@ |
||
228 | 228 | { |
229 | 229 | $cachedData = $this->_loadCache(); |
230 | 230 | (false === $timestamp) ? $type = 'data' : $type = 'time'; |
231 | - if (!isset($cachedData[$key][$type])) return null; |
|
231 | + if (!isset($cachedData[$key][$type])) { |
|
232 | + return null; |
|
233 | + } |
|
232 | 234 | return unserialize($cachedData[$key][$type]); |
233 | 235 | } |
234 | 236 |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function getOrderById($id) |
57 | 57 | { |
58 | - return $this->callCurl('/orders/' .$id, [], true, 0, 'GET'); |
|
58 | + return $this->callCurl('/orders/'.$id, [], true, 0, 'GET'); |
|
59 | 59 | |
60 | 60 | } |
61 | 61 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | return $this->generateNewToken(); |
80 | 80 | } |
81 | 81 | |
82 | - throw new \Shetabit\Multipay\Exceptions\PurchaseFailedException( 'unExcepted Err in generateToken.'); |
|
82 | + throw new \Shetabit\Multipay\Exceptions\PurchaseFailedException('unExcepted Err in generateToken.'); |
|
83 | 83 | |
84 | 84 | } |
85 | 85 | |
@@ -92,16 +92,16 @@ discard block |
||
92 | 92 | ]; |
93 | 93 | $result = $this->callCurl('/tokens/refresh', $data, false); |
94 | 94 | if (empty($result['accessToken'])) { |
95 | - throw new \Shetabit\Multipay\Exceptions\PurchaseFailedException( 'Err in refresh token.'); |
|
95 | + throw new \Shetabit\Multipay\Exceptions\PurchaseFailedException('Err in refresh token.'); |
|
96 | 96 | } |
97 | 97 | if (!empty($result['accessToken'])) { |
98 | - $this->cache->store('accessToken', 'Bearer ' . $result['accessToken'], 24 * 60 * 60 - 60); |
|
98 | + $this->cache->store('accessToken', 'Bearer '.$result['accessToken'], 24 * 60 * 60 - 60); |
|
99 | 99 | $this->cache->store('refreshToken', $result['refreshToken'], 48 * 60 * 60 - 60); |
100 | - $this->setAccessToken('Bearer ' . $result['accessToken']); |
|
100 | + $this->setAccessToken('Bearer '.$result['accessToken']); |
|
101 | 101 | $this->setRefreshToken($result['refreshToken']); |
102 | 102 | return 'ok'; |
103 | 103 | } |
104 | - throw new \Shetabit\Multipay\Exceptions\PurchaseFailedException( 'unExcepted Err in refreshToken.'); |
|
104 | + throw new \Shetabit\Multipay\Exceptions\PurchaseFailedException('unExcepted Err in refreshToken.'); |
|
105 | 105 | |
106 | 106 | } |
107 | 107 | |
@@ -122,15 +122,15 @@ discard block |
||
122 | 122 | if ($haveAuth) { |
123 | 123 | $accessToken = $this->getAccessToken(); |
124 | 124 | } |
125 | - $ch = curl_init($this->base_url . $url); |
|
125 | + $ch = curl_init($this->base_url.$url); |
|
126 | 126 | curl_setopt($ch, CURLOPT_USERAGENT, 'Jibit.class Rest Api'); |
127 | 127 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); |
128 | 128 | curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); |
129 | 129 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
130 | 130 | curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
131 | 131 | 'Content-Type: application/json', |
132 | - 'Authorization: ' . $accessToken, |
|
133 | - 'Content-Length: ' . strlen($jsonData) |
|
132 | + 'Authorization: '.$accessToken, |
|
133 | + 'Content-Length: '.strlen($jsonData) |
|
134 | 134 | )); |
135 | 135 | $result = curl_exec($ch); |
136 | 136 | $err = curl_error($ch); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | curl_close($ch); |
139 | 139 | |
140 | 140 | if ($err) { |
141 | - throw new \Shetabit\Multipay\Exceptions\PurchaseFailedException('cURL Error #:' . $err); |
|
141 | + throw new \Shetabit\Multipay\Exceptions\PurchaseFailedException('cURL Error #:'.$err); |
|
142 | 142 | } |
143 | 143 | if (empty($result['errors'])) { |
144 | 144 | return $result; |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | throw new \Shetabit\Multipay\Exceptions\PurchaseFailedException('Err in generate new token.'); |
192 | 192 | } |
193 | 193 | if (!empty($result['accessToken'])) { |
194 | - $this->cache->store('accessToken', 'Bearer ' . $result['accessToken'], 24 * 60 * 60 - 60); |
|
194 | + $this->cache->store('accessToken', 'Bearer '.$result['accessToken'], 24 * 60 * 60 - 60); |
|
195 | 195 | $this->cache->store('refreshToken', $result['refreshToken'], 48 * 60 * 60 - 60); |
196 | - $this->setAccessToken('Bearer ' . $result['accessToken']); |
|
196 | + $this->setAccessToken('Bearer '.$result['accessToken']); |
|
197 | 197 | $this->setRefreshToken($result['refreshToken']); |
198 | 198 | return 'ok'; |
199 | 199 | } |
@@ -211,6 +211,6 @@ discard block |
||
211 | 211 | $this->generateToken(); |
212 | 212 | $data = [ |
213 | 213 | ]; |
214 | - return $this->callCurl('/orders/' . $refNum . '/verify', $data, true, 0, 'GET'); |
|
214 | + return $this->callCurl('/orders/'.$refNum.'/verify', $data, true, 0, 'GET'); |
|
215 | 215 | } |
216 | 216 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | $this->invoice($invoice); // Set the invoice. |
27 | 27 | $this->settings = (object) $settings; // Set settings. |
28 | 28 | /** @var JibitBase $jibit */ |
29 | - $this->jibit = new JibitBase($this->settings->merchantId, $this->settings->apiSecret,$this->settings->apiPaymentUrl); |
|
29 | + $this->jibit = new JibitBase($this->settings->merchantId, $this->settings->apiSecret, $this->settings->apiPaymentUrl); |
|
30 | 30 | |
31 | 31 | } |
32 | 32 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | // Making payment request |
38 | 38 | // you should save the order details in DB, you need if for verify |
39 | - $requestResult = $this->jibit->paymentRequest($this->invoice->getAmount(), $this->invoice->getDetail('order_id'), $this->invoice->getDetail('mobile'),$this->settings->callbackUrl); |
|
39 | + $requestResult = $this->jibit->paymentRequest($this->invoice->getAmount(), $this->invoice->getDetail('order_id'), $this->invoice->getDetail('mobile'), $this->settings->callbackUrl); |
|
40 | 40 | |
41 | 41 | |
42 | 42 | if (!empty($requestResult['pspSwitchingUrl'])) { |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | } |
47 | 47 | if (!empty($requestResult['errors'])) { |
48 | 48 | //fail result and show the error |
49 | - $errMsgs = array_map(function ($err){ return $err['message']; }, $requestResult['errors']); |
|
49 | + $errMsgs = array_map(function($err) { return $err['message']; }, $requestResult['errors']); |
|
50 | 50 | throw new PurchaseFailedException(implode('\n', $errMsgs)); |
51 | 51 | } |
52 | 52 |