Skip to content

Commit

Permalink
added verifySsl for laravel 8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
waadmawlood committed Nov 23, 2023
1 parent a312d2b commit f71e209
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 7 deletions.
12 changes: 12 additions & 0 deletions config/zaincash.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,16 @@
| make it 0 (zero) for unlimited timeout (not recommended).
*/
'timeout' => env('ZAINCASH_TIMEOUT', 10),

/*
|--------------------------------------------------------------------------
| Verify SSL
|--------------------------------------------------------------------------
|
| Set the verify SSL for the request to ZainCash's API.
| The default value is true.
| make it false for disable verify SSL (not recommended).
| if it is true and you used the `http` protocol so will get an error. so make it false.
*/
'verify_ssl' => env('ZAINCASH_VERIFY_SSL', true),
];
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ update config zaincash in `config/zaincash.php` or from `.env` file
| 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. |
| 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. |
| timeout | int | 10 | Set the timeout for the request in seconds. |
| verify_ssl | bool | true | Set the verify SSL for the request to ZainCash's API. |


<br>
Expand All @@ -86,6 +87,7 @@ ZAINCASH_MIN_AMOUNT=1000 # optional default 1000
ZAINCASH_TEST_URL=https://test.zaincash.iq/ # optional
ZAINCASH_LIVE_URL=https://api.zaincash.iq/ # optional
ZAINCASH_TIMEOUT=10 # optional
ZAINCASH_VERIFY_SSL=true # optional
```


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

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

Expand Down
5 changes: 4 additions & 1 deletion src/BaseZainCash.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ abstract class BaseZainCash
protected $transactionID;
protected $isReturnArray = false;
protected $timeout;
protected $verifySsl;

public function __construct(
$amount = null,
Expand All @@ -43,7 +44,8 @@ public function __construct(
$isTest = null,
$language = null,
$baseUrl = null,
$timeout = null
$timeout = null,
$verifySsl = null
) {
$this->amount = $amount;
$this->serviceType = $serviceType;
Expand All @@ -59,6 +61,7 @@ public function __construct(
$this->language = $language;
$this->baseUrl = $baseUrl;
$this->timeout = $timeout;
$this->verifySsl = $verifySsl;

$this->initial();
}
Expand Down
5 changes: 4 additions & 1 deletion src/Services/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ class HttpClient
* @param string $url
* @param array $data
* @param array $headers
* @param int $timeout
* @param bool $verify
* @return \Psr\Http\Message\ResponseInterface|\Illuminate\Http\Client\Response|array
*/
public function httpPost(string $url, array $data = [], array $headers = [], int $timeout = 10)
public function httpPost(string $url, array $data = [], array $headers = [], int $timeout = 10, bool $verify = false)
{
set_time_limit($timeout);

try {

$client = new Client([
'timeout' => $timeout,
'verify' => $verify,
]);

$response = $client->post($url, [
Expand Down
15 changes: 10 additions & 5 deletions src/Traits/HttpClientRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ protected function createTransactionHttpClient(string $token)
[
'Content-Type' => 'application/x-www-form-urlencoded'
],
$this->getTimeout()
$this->getTimeout(),
$this->getVerifySsl()
);
}

Expand All @@ -37,7 +38,8 @@ protected function sendRequestCheckTransaction(string $token)
[
'Content-Type' => 'application/x-www-form-urlencoded'
],
$this->getTimeout()
$this->getTimeout(),
$this->getVerifySsl()
);
}

Expand All @@ -59,7 +61,8 @@ protected function sendRequestProcessingTransaction(string $phonenumber, string
[
'Content-Type' => 'application/x-www-form-urlencoded'
],
$this->getTimeout()
$this->getTimeout(),
$this->getVerifySsl()
);
}

Expand All @@ -83,7 +86,8 @@ protected function sendRequestPayTransaction(string $phonenumber, string $pin, s
[
'Content-Type' => 'application/x-www-form-urlencoded'
],
$this->getTimeout()
$this->getTimeout(),
$this->getVerifySsl()
);
}

Expand All @@ -102,7 +106,8 @@ protected function sendRequestCancelTransaction()
[
'Content-Type' => 'application/x-www-form-urlencoded'
],
$this->getTimeout()
$this->getTimeout(),
$this->getVerifySsl()
);
}
}
5 changes: 5 additions & 0 deletions src/Traits/Initialable.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ protected function initial()
$this->setTimeout($this->getConfig("timeout"));
}

// Set the verify SSL.
if (is_null($this->getVerifySsl())) {
$this->setVerifySsl($this->getConfig("verify_ssl"));
}

// Set the URLs.
$this->initailUrls();
}
Expand Down
18 changes: 18 additions & 0 deletions src/Traits/getSetAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,22 @@ public function setTimeout(int $timeout)
$this->timeout = $timeout;
return $this;
}

/**
* @return bool|null
*/
public function getVerifySsl()
{
return $this->verifySsl;
}

/**
* @param bool $verifySsl
* @return self
*/
public function setVerifySsl(bool $verifySsl)
{
$this->verifySsl = $verifySsl;
return $this;
}
}

0 comments on commit f71e209

Please sign in to comment.