From 0f17875d6fcca7b654047b40eecf545398949cd3 Mon Sep 17 00:00:00 2001 From: Mohammad Ostadi <7m.ostadi5@gmail.com> Date: Mon, 7 Mar 2022 11:42:29 +0330 Subject: [PATCH 1/2] unwanted crc32 uuid bug fixed. --- src/Drivers/Asanpardakht/Asanpardakht.php | 6 +++--- src/Drivers/Etebarino/Etebarino.php | 4 ++-- src/Drivers/Irankish/Irankish.php | 6 +++--- src/Drivers/Nextpay/Nextpay.php | 2 +- src/Drivers/Parsian/Parsian.php | 2 +- src/Drivers/Pasargad/Pasargad.php | 2 +- src/Drivers/Sadad/Sadad.php | 4 ++-- src/Drivers/Saman/Saman.php | 2 +- src/Drivers/Yekpay/Yekpay.php | 2 +- src/Drivers/Zibal/Zibal.php | 2 +- src/Invoice.php | 5 ++++- 11 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Drivers/Asanpardakht/Asanpardakht.php b/src/Drivers/Asanpardakht/Asanpardakht.php index f73680d8..f6c5e953 100644 --- a/src/Drivers/Asanpardakht/Asanpardakht.php +++ b/src/Drivers/Asanpardakht/Asanpardakht.php @@ -73,7 +73,7 @@ public function __construct(Invoice $invoice, $settings) */ public function purchase() { - $this->invoice->uuid(crc32($this->invoice->getUuid())); + $this->invoice->uuid($this->invoice->getUuid(true)); $result = $this->token(); @@ -339,9 +339,9 @@ protected function purchaseFailed($status) ]; if (array_key_exists($status, $translations)) { - throw new PurchaseFailedException($translations[$status]); + throw new PurchaseFailedException($translations[$status], $status); } else { - throw new PurchaseFailedException('خطای ناشناخته ای رخ داده است.'); + throw new PurchaseFailedException('خطای ناشناخته ای رخ داده است.', $status); } } } diff --git a/src/Drivers/Etebarino/Etebarino.php b/src/Drivers/Etebarino/Etebarino.php index 6e4b3841..4ac9218f 100644 --- a/src/Drivers/Etebarino/Etebarino.php +++ b/src/Drivers/Etebarino/Etebarino.php @@ -48,7 +48,7 @@ public function __construct(Invoice $invoice, $settings) */ public function purchase() { - $this->invoice->uuid(crc32($this->invoice->getUuid())); + $this->invoice->uuid($this->invoice->getUuid(true)); $result = $this->token(); @@ -149,7 +149,7 @@ public function token(): array 'terminalUser' => $this->settings->username, 'merchantCode' => $this->settings->merchantId, 'terminalPass' => $this->settings->password, - 'merchantRefCode' => $this->invoice->getUuid(), + 'merchantRefCode' => $this->invoice->getUuid(true), "description" => $this->invoice->getDetail('description'), "returnUrl" => $this->settings->callbackUrl, 'paymentItems' => $this->getItems(), diff --git a/src/Drivers/Irankish/Irankish.php b/src/Drivers/Irankish/Irankish.php index c336c956..85bc364d 100644 --- a/src/Drivers/Irankish/Irankish.php +++ b/src/Drivers/Irankish/Irankish.php @@ -61,9 +61,9 @@ public function purchase() 'merchantId' => $this->settings->merchantId, 'description' => $description, 'revertURL' => $this->settings->callbackUrl, - 'invoiceNo' => crc32($this->invoice->getUuid()), - 'paymentId' => crc32($this->invoice->getUuid()), - 'specialPaymentId' => crc32($this->invoice->getUuid()), + 'invoiceNo' => $this->invoice->getUuid(true), + 'paymentId' => $this->invoice->getUuid(true), + 'specialPaymentId' => $this->invoice->getUuid(true), ); $soap = new \SoapClient( diff --git a/src/Drivers/Nextpay/Nextpay.php b/src/Drivers/Nextpay/Nextpay.php index 3c1fb328..49a56e7e 100644 --- a/src/Drivers/Nextpay/Nextpay.php +++ b/src/Drivers/Nextpay/Nextpay.php @@ -61,7 +61,7 @@ public function purchase() { $data = array( 'api_key' => $this->settings->merchantId, - 'order_id' => intval(1, time()).crc32($this->invoice->getUuid()), + 'order_id' => intval(1, time()).$this->invoice->getUuid(true), 'amount' => $this->invoice->getAmount(), 'callback_uri' => $this->settings->callbackUrl, ); diff --git a/src/Drivers/Parsian/Parsian.php b/src/Drivers/Parsian/Parsian.php index 27d4c266..178bf589 100644 --- a/src/Drivers/Parsian/Parsian.php +++ b/src/Drivers/Parsian/Parsian.php @@ -170,7 +170,7 @@ protected function preparePurchaseData() return array( 'LoginAccount' => $this->settings->merchantId, 'Amount' => $this->invoice->getAmount() * 10, // convert to rial - 'OrderId' => crc32($this->invoice->getUuid()), + 'OrderId' => $this->invoice->getUuid(), 'CallBackUrl' => $this->settings->callbackUrl, 'AdditionalData' => $description, ); diff --git a/src/Drivers/Pasargad/Pasargad.php b/src/Drivers/Pasargad/Pasargad.php index 3c19fa6f..9189f7b4 100644 --- a/src/Drivers/Pasargad/Pasargad.php +++ b/src/Drivers/Pasargad/Pasargad.php @@ -193,7 +193,7 @@ protected function prepareInvoiceData(): array $terminalCode = $this->settings->terminalCode; $amount = $this->invoice->getAmount(); //rial $redirectAddress = $this->settings->callbackUrl; - $invoiceNumber = crc32($this->invoice->getUuid()) . rand(0, time()); + $invoiceNumber = $this->invoice->getUuid(true) . rand(0, time()); $timeStamp = date("Y/m/d H:i:s"); $invoiceDate = date("Y/m/d H:i:s"); diff --git a/src/Drivers/Sadad/Sadad.php b/src/Drivers/Sadad/Sadad.php index 47ffb76f..93125b2e 100644 --- a/src/Drivers/Sadad/Sadad.php +++ b/src/Drivers/Sadad/Sadad.php @@ -60,7 +60,7 @@ public function __construct(Invoice $invoice, $settings) public function purchase() { $terminalId = $this->settings->terminalId; - $orderId = crc32($this->invoice->getUuid()); + $orderId = $this->invoice->getUuid(true); $amount = $this->invoice->getAmount() * 10; // convert to rial $key = $this->settings->key; @@ -210,7 +210,7 @@ protected function encrypt_pkcs7($str, $key) return base64_encode($ciphertext); } - + /** * Retrieve payment mode. * diff --git a/src/Drivers/Saman/Saman.php b/src/Drivers/Saman/Saman.php index efd6ecd7..76bd8c1e 100644 --- a/src/Drivers/Saman/Saman.php +++ b/src/Drivers/Saman/Saman.php @@ -124,7 +124,7 @@ public function verify(): ReceiptInterface $receipt = $this->createReceipt($data['RefNum']); $receipt->detail([ - 'traceNo' => Request::input('TraceNo'), + 'traceNo' => Request::input('TRACENO'), 'referenceNo' => Request::input('RRN'), 'transactionId' => Request::input('RefNum'), 'cardNo' => Request::input('SecurePan'), diff --git a/src/Drivers/Yekpay/Yekpay.php b/src/Drivers/Yekpay/Yekpay.php index 060d7c5c..06f6289d 100644 --- a/src/Drivers/Yekpay/Yekpay.php +++ b/src/Drivers/Yekpay/Yekpay.php @@ -73,7 +73,7 @@ public function purchase() $data->merchantId = $this->settings->merchantId; $data->amount = $this->invoice->getAmount(); $data->callback = $this->settings->callbackUrl; - $data->orderNumber = intval(1, time()).crc32($this->invoice->getUuid()); + $data->orderNumber = intval(1, time()).$this->invoice->getUuid(true); $data->fromCurrencyCode = (int) $this->settings->fromCurrencyCode; $data->toCurrencyCode = (int) $this->settings->toCurrencyCode; diff --git a/src/Drivers/Zibal/Zibal.php b/src/Drivers/Zibal/Zibal.php index 952ebf75..13b47b34 100644 --- a/src/Drivers/Zibal/Zibal.php +++ b/src/Drivers/Zibal/Zibal.php @@ -63,7 +63,7 @@ public function purchase() // convert to toman $toman = $this->invoice->getAmount() * 10; - $orderId = crc32($this->invoice->getUuid()).time(); + $orderId = $this->invoice->getUuid(true).time(); if (!empty($details['orderId'])) { $orderId = $details['orderId']; } elseif (!empty($details['order_id'])) { diff --git a/src/Invoice.php b/src/Invoice.php index ae96f52e..b0cf9d27 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -66,8 +66,11 @@ public function uuid($uuid = null) * * @return string */ - public function getUuid() + public function getUuid($needNumericUuid = false) { + if($needNumericUuid){ + $this->uuid = !is_numeric($this->uuid) ? crc32($this->uuid) : $this->uuid; + } return $this->uuid; } From 896ee8108efef8fd9ff40d962a2e50ee9c582dc4 Mon Sep 17 00:00:00 2001 From: Mohammad Ostadi <7m.ostadi5@gmail.com> Date: Mon, 7 Mar 2022 11:44:06 +0330 Subject: [PATCH 2/2] make invoice->uuid() method fluent. --- src/Invoice.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Invoice.php b/src/Invoice.php index b0cf9d27..531ef465 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -59,6 +59,7 @@ public function uuid($uuid = null) } $this->uuid = $uuid; + return $this; } /** @@ -68,7 +69,7 @@ public function uuid($uuid = null) */ public function getUuid($needNumericUuid = false) { - if($needNumericUuid){ + if ($needNumericUuid) { $this->uuid = !is_numeric($this->uuid) ? crc32($this->uuid) : $this->uuid; } return $this->uuid;