Skip to content

Commit

Permalink
Merge pull request #2 from waadmawlood/10.x
Browse files Browse the repository at this point in the history
added verifySsl for laravel 10.x
  • Loading branch information
waadmawlood authored Nov 23, 2023
2 parents 162eca3 + 11852b5 commit 1ae2490
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 8 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' => 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
3 changes: 2 additions & 1 deletion src/BaseZainCash.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function __construct(
protected $cancelUrl = null,
protected $transactionID = null,
protected $isReturnArray = false,
protected $timeout = null
protected $timeout = null,
protected $verifySsl = null
) {
if ($orderId) {
$this->orderId = $this->getConfig("prefix_order_id") . $orderId;
Expand Down
4 changes: 2 additions & 2 deletions src/Services/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class HttpClient
/**
* @return \Psr\Http\Message\ResponseInterface|\Illuminate\Http\Client\Response|array
*/
public function httpPost(string $url, array $data = [], array $headers = [], $timeout = 10): mixed
public function httpPost(string $url, array $data = [], array $headers = [], int $timeout = 10, bool $verify = false): mixed
{
set_time_limit($timeout);

try {
$response = Http::timeout($timeout)->withHeaders($headers)->asForm()->post($url, $data);
$response = Http::timeout($timeout)->withHeaders($headers)->withOptions(['verify' => $verify])->asForm()->post($url, $data);
return $response;
} catch (RequestException $e) {
return [
Expand Down
15 changes: 10 additions & 5 deletions src/Traits/HttpClientRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ protected function createTransactionHttpClient(string $token)
->httpPost(
url: $this->getTUrl(),
data: $body,
timeout: $this->getTimeout()
timeout: $this->getTimeout(),
verify: $this->getVerifySsl()
);
}

Expand All @@ -31,7 +32,8 @@ protected function sendRequestCheckTransaction(string $token)
->httpPost(
url: $this->getCUrl(),
data: $body,
timeout: $this->getTimeout()
timeout: $this->getTimeout(),
verify: $this->getVerifySsl()
);
}

Expand All @@ -50,7 +52,8 @@ protected function sendRequestProcessingTransaction(string $phonenumber, string
'phonenumber' => $phonenumber,
'pin' => $pin,
],
timeout: $this->getTimeout()
timeout: $this->getTimeout(),
verify: $this->getVerifySsl()
);
}

Expand All @@ -71,7 +74,8 @@ protected function sendRequestPayTransaction(string $phonenumber, string $pin, s
'pin' => $pin,
'otp' => $otp,
],
timeout: $this->getTimeout()
timeout: $this->getTimeout(),
verify: $this->getVerifySsl()
);
}

Expand All @@ -87,7 +91,8 @@ protected function sendRequestCancelTransaction()
'id' => $this->getTransactionID(),
'type' => 'MERCHANT_PAYMENT'
],
timeout: $this->getTimeout()
timeout: $this->getTimeout(),
verify: $this->getVerifySsl()
);
}
}
5 changes: 5 additions & 0 deletions src/Traits/Initialable.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ protected function initial(): void
$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
11 changes: 11 additions & 0 deletions src/Traits/getSetAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,15 @@ public function setTimeout(int $timeout): self
$this->timeout = $timeout;
return $this;
}

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

public function setVerifySsl(bool $verifySsl): self
{
$this->verifySsl = $verifySsl;
return $this;
}
}

0 comments on commit 1ae2490

Please sign in to comment.