diff --git a/composer.json b/composer.json index a098f7b7..7dd9f0e0 100755 --- a/composer.json +++ b/composer.json @@ -91,7 +91,8 @@ "guzzlehttp/guzzle": ">=6.2", "nesbot/carbon": "^1.39|^2.0|^3.0", "ramsey/uuid": "^3.7|^3.8|^3.9|^4.0", - "ext-json": "*" + "ext-json": "*", + "ext-curl": "*" }, "require-dev": { "phpunit/phpunit": "^8.0|^9.0", diff --git a/src/Drivers/Zibal/Zibal.php b/src/Drivers/Zibal/Zibal.php index 1247e206..36198453 100644 --- a/src/Drivers/Zibal/Zibal.php +++ b/src/Drivers/Zibal/Zibal.php @@ -47,7 +47,7 @@ public function __construct(Invoice $invoice, $settings) * * @return string * - * @throws \GuzzleHttp\Exception\GuzzleException + * */ public function purchase() { @@ -62,31 +62,22 @@ public function purchase() $orderId = $details['order_id']; } - $curl = curl_init(); - - curl_setopt_array($curl, array( - CURLOPT_URL => $this->settings->apiPurchaseUrl, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => '', - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 0, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS =>'{ - "merchant": "'.$this->settings->merchantId.'", - "amount": "'.$amount.'", - "callbackUrl": "'.$this->settings->callbackUrl.'", - "orderId": "'.$orderId.'" - }', - CURLOPT_HTTPHEADER => array( - 'Content-Type: application/json' - ), - )); - - $response = curl_exec($curl); - - curl_close($curl); + $parameters = [ + 'merchant' => $this->settings->merchantId, + 'amount' => $amount, + 'callbackUrl' => $this->settings->callbackUrl, + 'orderId' => $orderId + ]; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->settings->apiPurchaseUrl); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($parameters)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($ch); + curl_close($ch); + $body = json_decode($response, false); if ($body->result != 100) { @@ -122,7 +113,7 @@ public function pay() : RedirectionForm * @return mixed|void * * @throws InvalidPaymentException - * @throws \GuzzleHttp\Exception\GuzzleException + * */ public function verify() : ReceiptInterface { @@ -134,31 +125,21 @@ public function verify() : ReceiptInterface $this->notVerified($this->translateStatus($status), $status); } - //start verfication - - $curl = curl_init(); - - curl_setopt_array($curl, array( - CURLOPT_URL => $this->settings->apiVerificationUrl, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => '', - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 0, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS =>'{ - "merchant": "'.$this->settings->merchantId.'", - "trackId": "'.$transactionId.'", - }', - CURLOPT_HTTPHEADER => array( - 'Content-Type: application/json' - ), - )); - - $response = curl_exec($curl); - - curl_close($curl); + //start verification + $parameters = [ + 'merchant' => $this->settings->merchantId, + 'trackId' => $transactionId + ]; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->settings->apiVerificationUrl); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($parameters)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($ch); + curl_close($ch); + $body = json_decode($response, false); if ($body->result != 100) {