Skip to content

Commit f71e209

Browse files
committed
added verifySsl for laravel 8.x
1 parent a312d2b commit f71e209

File tree

7 files changed

+56
-7
lines changed

7 files changed

+56
-7
lines changed

config/zaincash.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,16 @@
105105
| make it 0 (zero) for unlimited timeout (not recommended).
106106
*/
107107
'timeout' => env('ZAINCASH_TIMEOUT', 10),
108+
109+
/*
110+
|--------------------------------------------------------------------------
111+
| Verify SSL
112+
|--------------------------------------------------------------------------
113+
|
114+
| Set the verify SSL for the request to ZainCash's API.
115+
| The default value is true.
116+
| make it false for disable verify SSL (not recommended).
117+
| if it is true and you used the `http` protocol so will get an error. so make it false.
118+
*/
119+
'verify_ssl' => env('ZAINCASH_VERIFY_SSL', true),
108120
];

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ update config zaincash in `config/zaincash.php` or from `.env` file
6969
| is_redirect | bool | false | Specify whether or not to redirect to the ZainCash payment page. If false, ZainCash returns a Transaction ID to the backend. If true, redirection after the request. |
7070
| min_amount | int | 1000 | Set the minimum amount for a valid transaction in Iraqi Dinar (IQD). Transactions with amounts less than this value will be considered invalid. |
7171
| timeout | int | 10 | Set the timeout for the request in seconds. |
72+
| verify_ssl | bool | true | Set the verify SSL for the request to ZainCash's API. |
7273

7374

7475
<br>
@@ -86,6 +87,7 @@ ZAINCASH_MIN_AMOUNT=1000 # optional default 1000
8687
ZAINCASH_TEST_URL=https://test.zaincash.iq/ # optional
8788
ZAINCASH_LIVE_URL=https://api.zaincash.iq/ # optional
8889
ZAINCASH_TIMEOUT=10 # optional
90+
ZAINCASH_VERIFY_SSL=true # optional
8991
```
9092

9193

@@ -213,6 +215,7 @@ class PaymentController extends Controller
213215
| processingOtpUrl |🔴| string-null | `getProcessingOtpUrl()` | `setProcessingOtpUrl($processingOtpUrl)` | - |
214216
| cancelUrl |🔴| string-null | `getCancelUrl()` | `setCancelUrl($cancelUrl)` | - |
215217
| timeout |🔴| int-null | `getTimeout()` | `setTimeout($timeout)` | - |
218+
| verifySsl |🔴| bool-null | `getVerifySsl()` | `setVerifySsl($verifySsl)` | - |
216219

217220
⚠️ `Important` column means that this attribute is constantly used and has no default value. On the contrary, we can change it, but it will take the default value from `config/zaincash.php`.
218221

src/BaseZainCash.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ abstract class BaseZainCash
3232
protected $transactionID;
3333
protected $isReturnArray = false;
3434
protected $timeout;
35+
protected $verifySsl;
3536

3637
public function __construct(
3738
$amount = null,
@@ -43,7 +44,8 @@ public function __construct(
4344
$isTest = null,
4445
$language = null,
4546
$baseUrl = null,
46-
$timeout = null
47+
$timeout = null,
48+
$verifySsl = null
4749
) {
4850
$this->amount = $amount;
4951
$this->serviceType = $serviceType;
@@ -59,6 +61,7 @@ public function __construct(
5961
$this->language = $language;
6062
$this->baseUrl = $baseUrl;
6163
$this->timeout = $timeout;
64+
$this->verifySsl = $verifySsl;
6265

6366
$this->initial();
6467
}

src/Services/HttpClient.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ class HttpClient
1111
* @param string $url
1212
* @param array $data
1313
* @param array $headers
14+
* @param int $timeout
15+
* @param bool $verify
1416
* @return \Psr\Http\Message\ResponseInterface|\Illuminate\Http\Client\Response|array
1517
*/
16-
public function httpPost(string $url, array $data = [], array $headers = [], int $timeout = 10)
18+
public function httpPost(string $url, array $data = [], array $headers = [], int $timeout = 10, bool $verify = false)
1719
{
1820
set_time_limit($timeout);
1921

2022
try {
2123

2224
$client = new Client([
2325
'timeout' => $timeout,
26+
'verify' => $verify,
2427
]);
2528

2629
$response = $client->post($url, [

src/Traits/HttpClientRequests.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ protected function createTransactionHttpClient(string $token)
1919
[
2020
'Content-Type' => 'application/x-www-form-urlencoded'
2121
],
22-
$this->getTimeout()
22+
$this->getTimeout(),
23+
$this->getVerifySsl()
2324
);
2425
}
2526

@@ -37,7 +38,8 @@ protected function sendRequestCheckTransaction(string $token)
3738
[
3839
'Content-Type' => 'application/x-www-form-urlencoded'
3940
],
40-
$this->getTimeout()
41+
$this->getTimeout(),
42+
$this->getVerifySsl()
4143
);
4244
}
4345

@@ -59,7 +61,8 @@ protected function sendRequestProcessingTransaction(string $phonenumber, string
5961
[
6062
'Content-Type' => 'application/x-www-form-urlencoded'
6163
],
62-
$this->getTimeout()
64+
$this->getTimeout(),
65+
$this->getVerifySsl()
6366
);
6467
}
6568

@@ -83,7 +86,8 @@ protected function sendRequestPayTransaction(string $phonenumber, string $pin, s
8386
[
8487
'Content-Type' => 'application/x-www-form-urlencoded'
8588
],
86-
$this->getTimeout()
89+
$this->getTimeout(),
90+
$this->getVerifySsl()
8791
);
8892
}
8993

@@ -102,7 +106,8 @@ protected function sendRequestCancelTransaction()
102106
[
103107
'Content-Type' => 'application/x-www-form-urlencoded'
104108
],
105-
$this->getTimeout()
109+
$this->getTimeout(),
110+
$this->getVerifySsl()
106111
);
107112
}
108113
}

src/Traits/Initialable.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ protected function initial()
5151
$this->setTimeout($this->getConfig("timeout"));
5252
}
5353

54+
// Set the verify SSL.
55+
if (is_null($this->getVerifySsl())) {
56+
$this->setVerifySsl($this->getConfig("verify_ssl"));
57+
}
58+
5459
// Set the URLs.
5560
$this->initailUrls();
5661
}

src/Traits/getSetAttributes.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,22 @@ public function setTimeout(int $timeout)
364364
$this->timeout = $timeout;
365365
return $this;
366366
}
367+
368+
/**
369+
* @return bool|null
370+
*/
371+
public function getVerifySsl()
372+
{
373+
return $this->verifySsl;
374+
}
375+
376+
/**
377+
* @param bool $verifySsl
378+
* @return self
379+
*/
380+
public function setVerifySsl(bool $verifySsl)
381+
{
382+
$this->verifySsl = $verifySsl;
383+
return $this;
384+
}
367385
}

0 commit comments

Comments
 (0)