Skip to content

Commit b872ef6

Browse files
committed
added verifySsl for laravel 9.x
1 parent baf8d79 commit b872ef6

File tree

7 files changed

+45
-9
lines changed

7 files changed

+45
-9
lines changed

config/zaincash.php

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

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +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-
72+
| verify_ssl | bool | true | Set the verify SSL for the request to ZainCash's API. |
7373

7474
<br>
7575

@@ -86,6 +86,7 @@ ZAINCASH_MIN_AMOUNT=1000 # optional default 1000
8686
ZAINCASH_TEST_URL=https://test.zaincash.iq/ # optional
8787
ZAINCASH_LIVE_URL=https://api.zaincash.iq/ # optional
8888
ZAINCASH_TIMEOUT=10 # optional
89+
ZAINCASH_VERIFY_SSL=true # optional
8990
```
9091

9192

@@ -213,6 +214,7 @@ class PaymentController extends Controller
213214
| processingOtpUrl |🔴| string-null | `getProcessingOtpUrl()` | `setProcessingOtpUrl($processingOtpUrl)` | - |
214215
| cancelUrl |🔴| string-null | `getCancelUrl()` | `setCancelUrl($cancelUrl)` | - |
215216
| timeout |🔴| int-null | `getTimeout()` | `setTimeout($timeout)` | - |
217+
| verifySsl |🔴| bool-null | `getVerifySsl()` | `setVerifySsl($verifySsl)` | - |
216218

217219
⚠️ `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`.
218220

src/BaseZainCash.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public function __construct(
3232
protected $cancelUrl = null,
3333
protected $transactionID = null,
3434
protected $isReturnArray = false,
35-
protected $timeout = null
35+
protected $timeout = null,
36+
protected $verifySsl = null
3637
) {
3738
if ($orderId) {
3839
$this->orderId = $this->getConfig("prefix_order_id") . $orderId;

src/Services/HttpClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ class HttpClient
1010
/**
1111
* @return \Psr\Http\Message\ResponseInterface|\Illuminate\Http\Client\Response|array
1212
*/
13-
public function httpPost(string $url, array $data = [], array $headers = [], $timeout = 10): mixed
13+
public function httpPost(string $url, array $data = [], array $headers = [], int $timeout = 10, bool $verify = false): mixed
1414
{
1515
set_time_limit($timeout);
1616

1717
try {
18-
$response = Http::timeout($timeout)->withHeaders($headers)->asForm()->post($url, $data);
18+
$response = Http::timeout($timeout)->withHeaders($headers)->withOptions(['verify' => $verify])->asForm()->post($url, $data);
1919
return $response;
2020
} catch (RequestException $e) {
2121
return [

src/Traits/HttpClientRequests.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ protected function createTransactionHttpClient(string $token)
1616
->httpPost(
1717
url: $this->getTUrl(),
1818
data: $body,
19-
timeout: $this->getTimeout()
19+
timeout: $this->getTimeout(),
20+
verify: $this->getVerifySsl()
2021
);
2122
}
2223

@@ -31,7 +32,8 @@ protected function sendRequestCheckTransaction(string $token)
3132
->httpPost(
3233
url: $this->getCUrl(),
3334
data: $body,
34-
timeout: $this->getTimeout()
35+
timeout: $this->getTimeout(),
36+
verify: $this->getVerifySsl()
3537
);
3638
}
3739

@@ -50,7 +52,8 @@ protected function sendRequestProcessingTransaction(string $phonenumber, string
5052
'phonenumber' => $phonenumber,
5153
'pin' => $pin,
5254
],
53-
timeout: $this->getTimeout()
55+
timeout: $this->getTimeout(),
56+
verify: $this->getVerifySsl()
5457
);
5558
}
5659

@@ -71,7 +74,8 @@ protected function sendRequestPayTransaction(string $phonenumber, string $pin, s
7174
'pin' => $pin,
7275
'otp' => $otp,
7376
],
74-
timeout: $this->getTimeout()
77+
timeout: $this->getTimeout(),
78+
verify: $this->getVerifySsl()
7579
);
7680
}
7781

@@ -87,7 +91,8 @@ protected function sendRequestCancelTransaction()
8791
'id' => $this->getTransactionID(),
8892
'type' => 'MERCHANT_PAYMENT'
8993
],
90-
timeout: $this->getTimeout()
94+
timeout: $this->getTimeout(),
95+
verify: $this->getVerifySsl()
9196
);
9297
}
9398
}

src/Traits/Initialable.php

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

52+
// Set the verify SSL.
53+
if (is_null($this->getVerifySsl())) {
54+
$this->setVerifySsl($this->getConfig("verify_ssl"));
55+
}
56+
5257
// Set the URLs.
5358
$this->initailUrls();
5459
}

src/Traits/getSetAttributes.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,15 @@ public function setTimeout(int $timeout): self
226226
$this->timeout = $timeout;
227227
return $this;
228228
}
229+
230+
public function getVerifySsl(): bool|null
231+
{
232+
return $this->verifySsl;
233+
}
234+
235+
public function setVerifySsl(bool $verifySsl): self
236+
{
237+
$this->verifySsl = $verifySsl;
238+
return $this;
239+
}
229240
}

0 commit comments

Comments
 (0)