From 3fb4880b1b5eb56c3091bf73ee7de2ab827ad1f1 Mon Sep 17 00:00:00 2001 From: Ali Sasani Date: Wed, 13 May 2026 00:46:35 +0330 Subject: [PATCH 1/3] [feat] define Currency Constants --- src/Constants/Currency.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/Constants/Currency.php diff --git a/src/Constants/Currency.php b/src/Constants/Currency.php new file mode 100644 index 0000000..7793bc0 --- /dev/null +++ b/src/Constants/Currency.php @@ -0,0 +1,15 @@ + 10, + self::RIAL => 1 + ]; +} From fcba4a3d5b0005adc1557e8f06fef045afa4cb83 Mon Sep 17 00:00:00 2001 From: Ali Sasani Date: Wed, 13 May 2026 00:50:23 +0330 Subject: [PATCH 2/3] [chore] use Currency Constant on config file, and define method normalizeByCurrency --- config/payment.php | 76 +++++++++++++++++++++------------------- src/Abstracts/Driver.php | 12 +++++++ 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/config/payment.php b/config/payment.php index ee01415..ac816f8 100755 --- a/config/payment.php +++ b/config/payment.php @@ -1,5 +1,7 @@ 'https://gooyapay.ir/startPay/', 'merchantId' => 'XXXX-XXXX-XXXX-XXXXXXXXXXXXXXXXXXXXX', 'callbackUrl' => 'http://yoursite.com/path/to', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'fanavacard' => [ 'baseUri' => 'https://fcp.shaparak.ir', @@ -49,14 +51,14 @@ 'username' => 'xxxxxxx', 'password' => 'xxxxxxx', 'callbackUrl' => 'http://yoursite.com/path/to', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'atipay' => [ 'atipayTokenUrl' => 'https://mipg.atipay.net/v1/get-token', 'atipayRedirectGatewayUrl' => 'https://mipg.atipay.net/v1/redirect-to-gateway', 'atipayVerifyUrl' => 'https://mipg.atipay.net/v1/verify-payment', 'apikey' => '', - 'currency' => 'R', //Can be R, T (Rial, Toman) + 'currency' => Currency::RIAL, 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using Atipay', ], @@ -66,7 +68,7 @@ 'username' => '', 'password' => '', 'merchantConfigID' => '', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using asanpardakht', ], @@ -79,7 +81,7 @@ 'password' => '', 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using behpardakht', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, 'cumulativeDynamicPayStatus' => false, ], 'digipay' => [ @@ -89,7 +91,7 @@ 'client_id' => '', 'client_secret' => '', 'callbackUrl' => 'http://yoursite.com/path/to', - 'currency' => 'R', //Can be R, T (Rial, Toman) + 'currency' => Currency::RIAL, ], 'etebarino' => [ 'apiPurchaseUrl' => 'https://api.etebarino.com/public/merchant/request-payment', @@ -116,7 +118,7 @@ 'sandbox' => false, // Set it to true for test environments 'merchantId' => '', // Set `TEST` for test environments (sandbox) 'callbackUrl' => '', - 'currency' => 'R', //Can be R, T (Rial, Toman) + 'currency' => Currency::RIAL, ], 'irankish' => [ 'apiPurchaseUrl' => 'https://ikc.shaparak.ir/api/v3/tokenization/make', @@ -128,7 +130,7 @@ 'password' => '', 'acceptorId' => '', 'pubKey' => '', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'jibit' => [ 'apiPaymentUrl' => 'https://napi.jibit.ir/ppg/v3', @@ -139,7 +141,7 @@ 'tokenStoragePath' => 'jibit/', 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using jibit', - 'currency' => 'T', // Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, // Can be R, T (Rial, Toman) ], 'nextpay' => [ 'apiPurchaseUrl' => 'https://nextpay.org/nx/gateway/token', @@ -148,7 +150,7 @@ 'merchantId' => '', 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using nextpay', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'omidpay' => [ 'apiGenerateTokenUrl' => 'https://ref.sayancard.ir/ref-payment/RestServices/mts/generateTokenWithNoSign/', @@ -159,7 +161,7 @@ 'password' => '', 'callbackUrl' => '', 'description' => 'payment using omidpay', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'parsian' => [ 'apiPurchaseUrl' => 'https://pec.shaparak.ir/NewIPGServices/Sale/SaleService.asmx?wsdl', @@ -168,7 +170,7 @@ 'merchantId' => '', 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using parsian', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'parspal' => [ /* Normal api */ @@ -187,7 +189,7 @@ 'sandbox' => false, // Set it to true for test environments 'merchantId' => '', // Set `00000000aaaabbbbcccc000000000000` for test environments (sandbox) 'callbackUrl' => '', - 'currency' => 'T', // Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, // Can be R, T (Rial, Toman) ], 'pasargad' => [ 'baseUrl' => 'https://pep.shaparak.ir/dorsa1', @@ -196,7 +198,7 @@ 'merchantId' => '', 'terminalCode' => '', 'callbackUrl' => 'http://yoursite.com/path/to', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'panapal' => [ 'apiPurchaseUrl' => 'https://paanapardakht.com/webservice/rest/PaymentRequest', @@ -204,7 +206,7 @@ 'apiPaymentUrl' => 'https://paanapardakht.com/startPay/', 'merchantId' => 'XXXX-XXXX-XXXX-XXXXXXXXXXXXXXXXXXXXX', 'callbackUrl' => 'http://yoursite.com/path/to', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'paypal' => [ /* normal api */ @@ -232,7 +234,7 @@ 'merchantId' => '', 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using payping', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'paystar' => [ 'apiPurchaseUrl' => 'https://core.paystar.ir/api/pardakht/create/', @@ -242,7 +244,7 @@ 'signKey' => '', // sign key of your gateway 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using paystar', - 'currency' => 'R', //Can be R, T (Rial, Toman) + 'currency' => Currency::RIAL, ], 'poolam' => [ 'apiPurchaseUrl' => 'https://poolam.ir/invoice/request/', @@ -251,14 +253,14 @@ 'merchantId' => '', 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using poolam', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'pna' => [ 'apiNormalSale' => 'https://pna.shaparak.ir/mhipg/api/Payment/NormalSale', 'apiPaymentUrl' => 'https://pna.shaparak.ir/mhui/home/index/', 'apiConfirmationUrl' => 'https://pna.shaparak.ir/mhipg/api/Payment/confirm', 'CorporationPin' => '', - 'currency' => 'R',//Can be R, T (Rial, Toman) + 'currency' => Currency::RIAL, 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using pna', ], @@ -272,7 +274,7 @@ 'merchantId' => '', 'terminalId' => '', 'callbackUrl' => '', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, 'mode' => 'normal', // can be normal, PaymentByIdentity, PaymentByMultiIdentity, 'PaymentIdentity' => '', 'MultiIdentityRows' => [ @@ -292,7 +294,7 @@ 'password' => '', 'callbackUrl' => '', 'description' => 'payment using saman', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'sep' => [ 'apiGetToken' => 'https://sep.shaparak.ir/onlinepg/onlinepg', @@ -301,7 +303,7 @@ 'terminalId' => '', 'callbackUrl' => '', 'description' => 'Saman Electronic Payment for Saderat & Keshavarzi', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'sepehr' => [ 'apiGetToken' => 'https://sepehr.shaparak.ir:8081/V1/PeymentApi/GetToken', @@ -310,7 +312,7 @@ 'terminalId' => '', 'callbackUrl' => '', 'description' => 'payment using sepehr(saderat)', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'yekpay' => [ 'apiPurchaseUrl' => 'https://gate.yekpay.com/api/payment/server?wsdl', @@ -342,7 +344,7 @@ 'merchantId' => '', 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using zarinpal', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'zibal' => [ /* normal api */ @@ -355,7 +357,7 @@ 'merchantId' => '', 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using zibal', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'sepordeh' => [ 'apiPurchaseUrl' => 'https://sepordeh.com/merchant/invoices/add', @@ -366,7 +368,7 @@ 'merchantId' => '', 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using sepordeh', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'rayanpay' => [ 'apiPurchaseUrl' => 'https://bpm.shaparak.ir/pgwchannel/startpay.mellat', @@ -377,7 +379,7 @@ 'client_id' => '', 'password' => '', 'callbackUrl' => '', - 'currency' => 'R', //Can be R, T (Rial, Toman) + 'currency' => Currency::RIAL, ], 'shepa' => [ /* Normal api */ @@ -393,7 +395,7 @@ 'sandbox' => false, // Set it to true for test environments 'merchantId' => '', // Set `sandbox` for test environments (sandbox) 'callbackUrl' => '', - 'currency' => 'R', //Can be R, T (Rial, Toman) + 'currency' => Currency::RIAL, ], 'sizpay' => [ 'apiPurchaseUrl' => 'https://rt.sizpay.ir/KimiaIPGRouteService.asmx?WSDL', @@ -405,7 +407,7 @@ 'password' => '', 'SignData' => '', 'callbackUrl' => '', - 'currency' => 'R', //Can be R, T (Rial, Toman) + 'currency' => Currency::RIAL, ], 'vandar' => [ 'apiPurchaseUrl' => 'https://ipg.vandar.io/api/v3/send', @@ -414,7 +416,7 @@ 'callbackUrl' => '', 'merchantId' => '', 'description' => 'payment using Vandar', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'aqayepardakht' => [ 'apiPurchaseUrl' => 'https://panel.aqayepardakht.ir/api/v2/create', @@ -428,7 +430,7 @@ 'mobile' => '', 'email' => '', 'description' => 'payment using Aqayepardakht', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'azki' => [ 'apiPaymentUrl' => 'https://api.azkivam.com', @@ -436,7 +438,7 @@ 'fallbackUrl' => 'http://yoursite.com/path/to', 'merchantId' => '', 'key' => '', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, 'description' => 'payment using azki', ], 'payfa' => [ @@ -445,7 +447,7 @@ 'apiVerificationUrl' => 'https://payment.payfa.com/v2/api/Transaction/Verify/', 'callbackUrl' => '', 'apiKey' => '', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'toman' => [ 'base_url' => 'https://escrow-api.toman.ir/api/v1', @@ -460,7 +462,7 @@ 'callbackUrl' => '', 'api_token' => '', 'description' => 'payment using Bitpay', - 'currency' => 'R', //Can be R, T (Rial, Toman) + 'currency' => Currency::RIAL, ], 'minipay' => [ 'apiPurchaseUrl' => 'https://v1.minipay.me/api/pg/request/', @@ -469,7 +471,7 @@ 'merchantId' => '', 'callbackUrl' => 'http://yoursite.com/path/to', 'description' => 'payment using Minipay.', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'snapppay' => [ 'apiPaymentUrl' => 'https://fms-gateway-staging.apps.public.teh-1.snappcloud.io', @@ -479,7 +481,7 @@ 'client_id' => '', 'client_secret' => '', 'description' => 'payment using Snapp Pay.', - 'currency' => 'T', //Can be R, T (Rial, Toman) + 'currency' => Currency::TOMAN, ], 'daracard' => [ 'apiPurchaseUrl' => 'https://ipg.daracard.co/api/v0/Request/PaymentRequest/', @@ -506,7 +508,7 @@ 'client_secret' => '', 'username' =>'', 'password' => '', - 'currency' => 'T', // یا 'R' + 'currency' => Currency::TOMAN, // یا Currency::RIAL 'callbackUrl' => 'http://yoursite.com/path/to', ], 'xendit' => [ diff --git a/src/Abstracts/Driver.php b/src/Abstracts/Driver.php index d4d040f..b79feaa 100644 --- a/src/Abstracts/Driver.php +++ b/src/Abstracts/Driver.php @@ -2,6 +2,7 @@ namespace Shetabit\Multipay\Abstracts; +use Shetabit\Multipay\Constants\Currency; use Shetabit\Multipay\Contracts\DriverInterface; use Shetabit\Multipay\Contracts\ReceiptInterface; use Shetabit\Multipay\Invoice; @@ -100,6 +101,17 @@ public function redirectWithForm($action, array $inputs = [], $method = 'POST') return new RedirectionForm($action, $inputs, $method); } + /** + * Normalize the price based on the selected currency ratio on config. + * + * @param int|float $price + * @return int|float + */ + protected function normalizeByCurrency(int|float $price): int|float + { + return $price * Currency::RATIO[$this->settings->currency]; + } + /** * Purchase the invoice * From 3c0f08f747400fb7292eb66bd37a5b0868a02450 Mon Sep 17 00:00:00 2001 From: Ali Sasani Date: Wed, 13 May 2026 01:04:11 +0330 Subject: [PATCH 3/3] [chore] use method normalizeByCurrency on drivers --- src/Drivers/Asanpardakht/Asanpardakht.php | 2 +- src/Drivers/Atipay/Atipay.php | 4 +-- src/Drivers/Azki/Azki.php | 4 +-- src/Drivers/Behpardakht/Behpardakht.php | 2 +- src/Drivers/Bitpay/Bitpay.php | 4 +-- src/Drivers/Digipay/Digipay.php | 4 +-- src/Drivers/Fanavacard/Fanavacard.php | 4 +-- src/Drivers/Irankish/Irankish.php | 2 +- src/Drivers/Jibit/Jibit.php | 2 +- src/Drivers/Minipay/Minipay.php | 4 +-- src/Drivers/Omidpay/Omidpay.php | 2 +- src/Drivers/Parsian/Parsian.php | 2 +- src/Drivers/Pasargad/Pasargad.php | 4 +-- src/Drivers/Payfa/Payfa.php | 2 +- src/Drivers/Paystar/Paystar.php | 4 +-- src/Drivers/Pna/Pna.php | 2 +- src/Drivers/Poolam/Poolam.php | 2 +- src/Drivers/Rayanpay/Rayanpay.php | 2 +- src/Drivers/SEP/SEP.php | 6 ++--- src/Drivers/Sadad/Sadad.php | 2 +- src/Drivers/Saman/Saman.php | 4 +-- src/Drivers/Sepehr/Sepehr.php | 4 +-- src/Drivers/Sizpay/Sizpay.php | 2 +- src/Drivers/SnappPay/SnappPay.php | 27 +++++++++------------ src/Drivers/TorobPay/TorobPay.php | 2 +- src/Drivers/Zarinpal/Strategies/Normal.php | 4 +-- src/Drivers/Zarinpal/Strategies/Sandbox.php | 6 ++--- src/Drivers/Zibal/Zibal.php | 2 +- 28 files changed, 53 insertions(+), 58 deletions(-) diff --git a/src/Drivers/Asanpardakht/Asanpardakht.php b/src/Drivers/Asanpardakht/Asanpardakht.php index 39323a0..70c59bd 100644 --- a/src/Drivers/Asanpardakht/Asanpardakht.php +++ b/src/Drivers/Asanpardakht/Asanpardakht.php @@ -190,7 +190,7 @@ public function token(): array 'serviceTypeId' => 1, 'merchantConfigurationId' => $this->settings->merchantConfigID, 'localInvoiceId' => $this->invoice->getUuid(), - 'amountInRials' => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + 'amountInRials' => $this->normalizeByCurrency($this->invoice->getAmount()), // convert to rial 'localDate' => $this->getTime()['content'], 'callbackURL' => $this->settings->callbackUrl . $query, 'paymentId' => "0", diff --git a/src/Drivers/Atipay/Atipay.php b/src/Drivers/Atipay/Atipay.php index 711b314..e5ef26d 100644 --- a/src/Drivers/Atipay/Atipay.php +++ b/src/Drivers/Atipay/Atipay.php @@ -71,7 +71,7 @@ private function extractDetails(string $name) */ public function purchase() { - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial $order_id = $this->invoice->getUuid(); $mobile = $this->extractDetails('mobile'); @@ -121,7 +121,7 @@ public function verify(): ReceiptInterface $result = fn_check_callback_data($params); if ($result['success'] == 1) { //will verify here $apiKey = $this->settings->apikey; - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial $verify_params = ['apiKey' => $apiKey, 'referenceNumber' => $params['referenceNumber'] ]; diff --git a/src/Drivers/Azki/Azki.php b/src/Drivers/Azki/Azki.php index ba3d81f..3b76e02 100644 --- a/src/Drivers/Azki/Azki.php +++ b/src/Drivers/Azki/Azki.php @@ -93,7 +93,7 @@ public function purchase() ); $data = [ - "amount" => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + "amount" => $this->normalizeByCurrency($this->invoice->getAmount()), // convert to rial "redirect_uri" => $callback, "fallback_uri" => $fallback, "provider_id" => $order_id, @@ -180,7 +180,7 @@ private function convertAmountItems(): array $new_items = array_map( function (array $item) { - $item['amount'] *= ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $item['amount'] = $this->normalizeByCurrency($item['amount']) ; // convert to rial return $item; }, $this->invoice->getDetails()['items'] ?? [] diff --git a/src/Drivers/Behpardakht/Behpardakht.php b/src/Drivers/Behpardakht/Behpardakht.php index e845f2b..17a8e4b 100644 --- a/src/Drivers/Behpardakht/Behpardakht.php +++ b/src/Drivers/Behpardakht/Behpardakht.php @@ -200,7 +200,7 @@ protected function preparePurchaseData(): array 'userName' => $this->settings->username, 'userPassword' => $this->settings->password, 'callBackUrl' => $this->settings->callbackUrl, - 'amount' => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + 'amount' => $this->normalizeByCurrency($this->invoice->getAmount()), 'localDate' => Carbon::now()->format('Ymd'), 'localTime' => Carbon::now()->format('Gis'), 'orderId' => crc32($this->invoice->getUuid()), diff --git a/src/Drivers/Bitpay/Bitpay.php b/src/Drivers/Bitpay/Bitpay.php index 6e6bf37..34c0a07 100644 --- a/src/Drivers/Bitpay/Bitpay.php +++ b/src/Drivers/Bitpay/Bitpay.php @@ -55,7 +55,7 @@ public function purchase() $description = $this->extractDetails('description'); $factorId = $this->extractDetails('factorId'); $api = $this->settings->api_token; - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial $redirect = $this->settings->callbackUrl; $ch = curl_init(); @@ -109,7 +109,7 @@ public function verify(): ReceiptInterface $receipt = $this->createReceipt($trans_id); $receipt->detail([ - "amount" => $parseDecode->amount / ($this->settings->currency == 'T' ? 10 : 1), // convert to config currency + "amount" => $parseDecode->amount / ($this->settings->currency == 'T' ? 1 : 10), // convert to config currency "cardNum" => $parseDecode->cardNum, "factorId" => $parseDecode->factorId, ]); diff --git a/src/Drivers/Digipay/Digipay.php b/src/Drivers/Digipay/Digipay.php index 30dd8a5..2465f1b 100644 --- a/src/Drivers/Digipay/Digipay.php +++ b/src/Drivers/Digipay/Digipay.php @@ -83,7 +83,7 @@ public function purchase(): string * @see https://docs.mydigipay.com/upg.html#_request_fields_2 */ $data = [ - 'amount' => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), + 'amount' => $this->normalizeByCurrency($this->invoice->getAmount()), 'cellNumber' => $phone, 'providerId' => $this->invoice->getUuid(), 'callbackUrl' => $this->settings->callbackUrl, @@ -386,7 +386,7 @@ public function refundTransaction() $data = [ 'providerId' => $providerId, - 'amount' => $amount * ($this->settings->currency == 'T' ? 10 : 1), + 'amount' => $this->normalizeByCurrency($amount), 'saleTrackingCode' => $saleTrackingCode, ]; diff --git a/src/Drivers/Fanavacard/Fanavacard.php b/src/Drivers/Fanavacard/Fanavacard.php index 63e20fa..444116a 100644 --- a/src/Drivers/Fanavacard/Fanavacard.php +++ b/src/Drivers/Fanavacard/Fanavacard.php @@ -88,7 +88,7 @@ public function pay(): RedirectionForm public function verify(): ReceiptInterface { $transaction_amount = Request::input('transactionAmount'); - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial if ($amount == $transaction_amount) { $param = ['Token'=>Request::input('token'), 'RefNum'=>Request::input('RefNum')]; @@ -153,7 +153,7 @@ public function getToken(): array 'WSContext'=> $this->getWsContext(), 'TransType'=>'EN_GOODS', 'ReserveNum'=>$this->invoice->getDetail('invoice_number') ?? crc32($this->invoice->getUuid()), - 'Amount'=> $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + 'Amount'=> $this->normalizeByCurrency($this->invoice->getAmount()), // convert to rial 'RedirectUrl'=>$this->settings->callbackUrl, ]]); diff --git a/src/Drivers/Irankish/Irankish.php b/src/Drivers/Irankish/Irankish.php index cea6766..731f8e3 100644 --- a/src/Drivers/Irankish/Irankish.php +++ b/src/Drivers/Irankish/Irankish.php @@ -77,7 +77,7 @@ public function purchase() $pubKey = $this->settings->pubKey; $terminalID = $this->settings->terminalId; $password = $this->settings->password; - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial $token = $this->generateAuthenticationEnvelope($pubKey, $terminalID, $password, $amount); diff --git a/src/Drivers/Jibit/Jibit.php b/src/Drivers/Jibit/Jibit.php index f9446cd..26037ed 100644 --- a/src/Drivers/Jibit/Jibit.php +++ b/src/Drivers/Jibit/Jibit.php @@ -57,7 +57,7 @@ public function __construct(Invoice $invoice, $settings) */ public function purchase() { - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // Convert to Rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // Convert to Rial $requestResult = $this->jibit->paymentRequest( $amount, diff --git a/src/Drivers/Minipay/Minipay.php b/src/Drivers/Minipay/Minipay.php index 41b4180..30381cc 100644 --- a/src/Drivers/Minipay/Minipay.php +++ b/src/Drivers/Minipay/Minipay.php @@ -68,7 +68,7 @@ public function purchase() $data = [ "merchant_id" => $this->settings->merchantId, - "amount" => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + "amount" => $this->normalizeByCurrency($this->invoice->getAmount()), // convert to rial "callback_url" => $this->settings->callbackUrl, "description" => $description, "metadata" => array_merge($this->invoice->getDetails() ?? [], $metadata), @@ -124,7 +124,7 @@ public function verify(): ReceiptInterface $data = [ "merchant_id" => $this->settings->merchantId, "authority" => $authority, - "amount" => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + "amount" => $this->normalizeByCurrency($this->invoice->getAmount()), // convert to rial ]; $response = $this->client->request( diff --git a/src/Drivers/Omidpay/Omidpay.php b/src/Drivers/Omidpay/Omidpay.php index 1e87a5a..c857814 100644 --- a/src/Drivers/Omidpay/Omidpay.php +++ b/src/Drivers/Omidpay/Omidpay.php @@ -65,7 +65,7 @@ public function purchase(): string 'TransType' => 'EN_GOODS', 'ReserveNum' => $this->invoice->getUuid(), 'MerchantId' => $this->settings->merchantId, - 'Amount' => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + 'Amount' => $this->normalizeByCurrency($this->invoice->getAmount()), // convert to rial 'RedirectUrl' => $this->settings->callbackUrl, ]; diff --git a/src/Drivers/Parsian/Parsian.php b/src/Drivers/Parsian/Parsian.php index 1480310..7cba772 100644 --- a/src/Drivers/Parsian/Parsian.php +++ b/src/Drivers/Parsian/Parsian.php @@ -168,7 +168,7 @@ protected function preparePurchaseData(): array return [ 'LoginAccount' => $this->settings->merchantId, - 'Amount' => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + 'Amount' => $this->normalizeByCurrency($this->invoice->getAmount()), // convert to rial 'OrderId' => crc32($this->invoice->getUuid()), 'CallBackUrl' => $this->settings->callbackUrl, 'Originator' => $phone, diff --git a/src/Drivers/Pasargad/Pasargad.php b/src/Drivers/Pasargad/Pasargad.php index bdde5c0..82813ab 100644 --- a/src/Drivers/Pasargad/Pasargad.php +++ b/src/Drivers/Pasargad/Pasargad.php @@ -128,7 +128,7 @@ public function verify() : ReceiptInterface throw new InvalidPaymentException($responseErrorStatusMessage); } - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial if ($amount != $invoiceDetails['amount']) { throw new InvalidPaymentException('Invalid amount'); } @@ -224,7 +224,7 @@ protected function prepareInvoiceData(): array { $serviceCode = 8; // 8 : for PURCHASE request $terminalCode = $this->settings->terminalCode; - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial $redirectAddress = $this->settings->callbackUrl; $invoiceNumber = crc32($this->invoice->getUuid()) . rand(0, time()); diff --git a/src/Drivers/Payfa/Payfa.php b/src/Drivers/Payfa/Payfa.php index a70f78c..7968247 100644 --- a/src/Drivers/Payfa/Payfa.php +++ b/src/Drivers/Payfa/Payfa.php @@ -64,7 +64,7 @@ public function purchase() $cardNumber = $this->extractDetails('cardNumber'); $data = [ - 'amount' => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + 'amount' => $this->normalizeByCurrency($this->invoice->getAmount()), // convert to rial 'callbackUrl' => $this->settings->callbackUrl, 'mobileNumber' => $mobile, 'invoiceId' => $this->invoice->getUuid(), diff --git a/src/Drivers/Paystar/Paystar.php b/src/Drivers/Paystar/Paystar.php index 901de63..519c5dd 100644 --- a/src/Drivers/Paystar/Paystar.php +++ b/src/Drivers/Paystar/Paystar.php @@ -67,7 +67,7 @@ public function purchase() { $details = $this->invoice->getDetails(); $order_id = $this->invoice->getUuid(); - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial $callback = $this->settings->callbackUrl; $data = [ @@ -138,7 +138,7 @@ public function pay() : RedirectionForm */ public function verify() : ReceiptInterface { - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial $refNum = Request::post('ref_num'); $cardNumber = Request::post('card_number'); $trackingCode = Request::post('tracking_code'); diff --git a/src/Drivers/Pna/Pna.php b/src/Drivers/Pna/Pna.php index ee6c5c7..b7bf129 100644 --- a/src/Drivers/Pna/Pna.php +++ b/src/Drivers/Pna/Pna.php @@ -59,7 +59,7 @@ public function __construct(Invoice $invoice, $settings) */ public function purchase() { - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial if (!empty($this->invoice->getDetails()['description'])) { $description = $this->invoice->getDetails()['description']; } else { diff --git a/src/Drivers/Poolam/Poolam.php b/src/Drivers/Poolam/Poolam.php index a985268..8a9120e 100644 --- a/src/Drivers/Poolam/Poolam.php +++ b/src/Drivers/Poolam/Poolam.php @@ -57,7 +57,7 @@ public function __construct(Invoice $invoice, $settings) */ public function purchase() { - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial $data = [ 'api_key' => $this->settings->merchantId, diff --git a/src/Drivers/Rayanpay/Rayanpay.php b/src/Drivers/Rayanpay/Rayanpay.php index 5053cab..548c38b 100644 --- a/src/Drivers/Rayanpay/Rayanpay.php +++ b/src/Drivers/Rayanpay/Rayanpay.php @@ -103,7 +103,7 @@ public function purchase() $mobile = ''; } - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial if ($amount <= 10000) { throw new PurchaseFailedException('مقدار مبلغ ارسالی بزگتر از 10000 ریال باشد.'); diff --git a/src/Drivers/SEP/SEP.php b/src/Drivers/SEP/SEP.php index 15b44fd..1a6c616 100644 --- a/src/Drivers/SEP/SEP.php +++ b/src/Drivers/SEP/SEP.php @@ -63,7 +63,7 @@ public function purchase() $data = [ 'action' => 'token', 'TerminalId' => $this->settings->terminalId, - 'Amount' => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + 'Amount' => $this->normalizeByCurrency($this->invoice->getAmount()), // convert to rial 'ResNum' => $this->invoice->getUuid(), 'RedirectUrl' => $this->settings->callbackUrl, 'CellNumber' => $this->invoice->getDetail('mobile') ?? '', @@ -160,7 +160,7 @@ public function verify(): ReceiptInterface $transactionDetail = $responseData['TransactionDetail']; - $verifiedAmount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); + $verifiedAmount = $this->normalizeByCurrency($this->invoice->getAmount()); if ($verifiedAmount !== $transactionDetail['AffectiveAmount']) { $this->notVerified(-107); } @@ -184,7 +184,7 @@ public function verify(): ReceiptInterface // between variable name in docs and actual returned values. 'Amount' => $transactionDetail['OrginalAmount'], ]); - + return $receipt; } diff --git a/src/Drivers/Sadad/Sadad.php b/src/Drivers/Sadad/Sadad.php index fc322da..29fce03 100644 --- a/src/Drivers/Sadad/Sadad.php +++ b/src/Drivers/Sadad/Sadad.php @@ -62,7 +62,7 @@ public function purchase() { $terminalId = $this->settings->terminalId; $orderId = crc32($this->invoice->getUuid()); - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial $key = $this->settings->key; $signData = $this->encrypt_pkcs7("$terminalId;$orderId;$amount", $key); diff --git a/src/Drivers/Saman/Saman.php b/src/Drivers/Saman/Saman.php index ea2f970..20ed27b 100644 --- a/src/Drivers/Saman/Saman.php +++ b/src/Drivers/Saman/Saman.php @@ -52,7 +52,7 @@ public function purchase() $data = [ 'MID' => $this->settings->merchantId, 'ResNum' => $this->invoice->getUuid(), - 'Amount' => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + 'Amount' => $this->normalizeByCurrency($this->invoice->getAmount()), // convert to rial 'CellNumber' => '' ]; @@ -140,7 +140,7 @@ public function verify(): ReceiptInterface } $verifiedAmount = $status; // if status is bigger than 0 , it represents amount - if ($verifiedAmount !== $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1)) { + if ($verifiedAmount !== $this->normalizeByCurrency($this->invoice->getAmount())) { $soap->ReverseTransaction($data["RefNum"], $data["merchantId"], $data["password"], $verifiedAmount); $status = -100; $this->notVerified($status); diff --git a/src/Drivers/Sepehr/Sepehr.php b/src/Drivers/Sepehr/Sepehr.php index ff25164..76f081a 100644 --- a/src/Drivers/Sepehr/Sepehr.php +++ b/src/Drivers/Sepehr/Sepehr.php @@ -48,7 +48,7 @@ public function __construct(Invoice $invoice, $settings) */ public function purchase() { - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial $mobile = ''; //set CellNumber for get user cards @@ -100,7 +100,7 @@ public function pay(): RedirectionForm public function verify(): ReceiptInterface { $responseCode = Request::input('respcode'); - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial if ($responseCode != 0) { $this->notVerified($responseCode); diff --git a/src/Drivers/Sizpay/Sizpay.php b/src/Drivers/Sizpay/Sizpay.php index 938ac00..2a5b015 100644 --- a/src/Drivers/Sizpay/Sizpay.php +++ b/src/Drivers/Sizpay/Sizpay.php @@ -62,7 +62,7 @@ public function purchase() 'TerminalID' => $this->settings->terminal, 'UserName' => $this->settings->username, 'Password' => $this->settings->password, - 'Amount' => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + 'Amount' => $this->normalizeByCurrency($this->invoice->getAmount()), // convert to rial 'OrderID' => time(), 'ReturnURL' => $this->settings->callbackUrl, 'InvoiceNo' => time(), diff --git a/src/Drivers/SnappPay/SnappPay.php b/src/Drivers/SnappPay/SnappPay.php index 4610d4e..e7d1c80 100644 --- a/src/Drivers/SnappPay/SnappPay.php +++ b/src/Drivers/SnappPay/SnappPay.php @@ -87,7 +87,7 @@ public function purchase(): string $phone = preg_replace('/^0/', '+98', $phone); $data = [ - 'amount' => $this->normalizerAmount($this->invoice->getAmount()), + 'amount' => $this->normalizeByCurrency($this->invoice->getAmount()), 'mobile' => $phone, 'paymentMethodTypeDto' => 'INSTALLMENT', 'transactionId' => $this->invoice->getTransactionId(), @@ -95,11 +95,11 @@ public function purchase(): string ]; if (!is_null($discountAmount = $this->invoice->getDetail('discountAmount'))) { - $data['discountAmount'] = $this->normalizerAmount($discountAmount); + $data['discountAmount'] = $this->normalizeByCurrency($discountAmount); } if (!is_null($externalSourceAmount = $this->invoice->getDetail('externalSourceAmount'))) { - $data['externalSourceAmount'] = $this->normalizerAmount($externalSourceAmount) ; + $data['externalSourceAmount'] = $this->normalizeByCurrency($externalSourceAmount) ; } if (is_null($this->invoice->getDetail('cartList'))) { @@ -239,7 +239,7 @@ public function eligible() 'Authorization' => 'Bearer '.$this->oauthToken, ], RequestOptions::QUERY => [ - 'amount' => $this->normalizerAmount($amount), + 'amount' => $this->normalizeByCurrency($amount), ], RequestOptions::HTTP_ERRORS => false, RequestOptions::TIMEOUT => 10, // 10 seconds @@ -255,11 +255,6 @@ public function eligible() return $body['response']; } - private function normalizerAmount(int $amount): int - { - return $amount * ($this->settings->currency == 'T' ? 10 : 1); - } - private function normalizerCartList(array &$data): void { if (isset($data['cartList']['shippingAmount'])) { @@ -268,19 +263,19 @@ private function normalizerCartList(array &$data): void foreach ($data['cartList'] as &$item) { if (isset($item['shippingAmount'])) { - $item['shippingAmount'] = $this->normalizerAmount($item['shippingAmount']); + $item['shippingAmount'] = $this->normalizeByCurrency($item['shippingAmount']); } if (isset($item['taxAmount'])) { - $item['taxAmount'] = $this->normalizerAmount($item['taxAmount']); + $item['taxAmount'] = $this->normalizeByCurrency($item['taxAmount']); } if (isset($item['totalAmount'])) { - $item['totalAmount'] = $this->normalizerAmount($item['totalAmount']); + $item['totalAmount'] = $this->normalizeByCurrency($item['totalAmount']); } foreach ($item['cartItems'] as &$cartItem) { - $cartItem['amount'] = $this->normalizerAmount($cartItem['amount']); + $cartItem['amount'] = $this->normalizeByCurrency($cartItem['amount']); } } } @@ -412,17 +407,17 @@ public function cancel() public function update() { $data = [ - 'amount' => $this->normalizerAmount($this->invoice->getAmount()), + 'amount' => $this->normalizeByCurrency($this->invoice->getAmount()), 'paymentMethodTypeDto' => 'INSTALLMENT', 'paymentToken' => $this->invoice->getTransactionId(), ]; if (!is_null($discountAmount = $this->invoice->getDetail('discountAmount'))) { - $data['discountAmount'] = $this->normalizerAmount($discountAmount); + $data['discountAmount'] = $this->normalizeByCurrency($discountAmount); } if (!is_null($externalSourceAmount = $this->invoice->getDetail('externalSourceAmount'))) { - $data['externalSourceAmount'] = $this->normalizerAmount($externalSourceAmount) ; + $data['externalSourceAmount'] = $this->normalizeByCurrency($externalSourceAmount) ; } if (is_null($this->invoice->getDetail('cartList'))) { diff --git a/src/Drivers/TorobPay/TorobPay.php b/src/Drivers/TorobPay/TorobPay.php index 84b21f8..98476e9 100644 --- a/src/Drivers/TorobPay/TorobPay.php +++ b/src/Drivers/TorobPay/TorobPay.php @@ -79,7 +79,7 @@ public function purchase() ?? $this->invoice->getDetail('mobile'); - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); $transactionId = $this->invoice->getUuid(); $returnUrl = $this->settings->callbackUrl; diff --git a/src/Drivers/Zarinpal/Strategies/Normal.php b/src/Drivers/Zarinpal/Strategies/Normal.php index 0cee202..45bfb53 100644 --- a/src/Drivers/Zarinpal/Strategies/Normal.php +++ b/src/Drivers/Zarinpal/Strategies/Normal.php @@ -58,7 +58,7 @@ public function __construct(Invoice $invoice, $settings) */ public function purchase() { - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial if (!empty($this->invoice->getDetails()['description'])) { $description = $this->invoice->getDetails()['description']; @@ -129,7 +129,7 @@ public function verify(): ReceiptInterface $data = [ "merchant_id" => $this->settings->merchantId, "authority" => $authority, - "amount" => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + "amount" => $this->normalizeByCurrency($this->invoice->getAmount()), // convert to rial ]; $response = $this->client->request( diff --git a/src/Drivers/Zarinpal/Strategies/Sandbox.php b/src/Drivers/Zarinpal/Strategies/Sandbox.php index 05fb9c2..14e262d 100644 --- a/src/Drivers/Zarinpal/Strategies/Sandbox.php +++ b/src/Drivers/Zarinpal/Strategies/Sandbox.php @@ -15,7 +15,7 @@ class Sandbox extends Driver { protected \GuzzleHttp\Client $client; - + /** * Invoice * @@ -52,7 +52,7 @@ public function __construct(Invoice $invoice, $settings) */ public function purchase() { - $amount = $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1); // convert to rial + $amount = $this->normalizeByCurrency($this->invoice->getAmount()); // convert to rial if (!empty($this->invoice->getDetails()['description'])) { $description = $this->invoice->getDetails()['description']; @@ -121,7 +121,7 @@ public function verify() : ReceiptInterface $data = [ "merchant_id" => $this->settings->merchantId, "authority" => $authority, - "amount" => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), // convert to rial + "amount" => $this->normalizeByCurrency($this->invoice->getAmount()), // convert to rial ]; $response = $this->client->request( diff --git a/src/Drivers/Zibal/Zibal.php b/src/Drivers/Zibal/Zibal.php index 7e54fb7..03ff426 100644 --- a/src/Drivers/Zibal/Zibal.php +++ b/src/Drivers/Zibal/Zibal.php @@ -67,7 +67,7 @@ public function purchase() $data = [ 'callbackUrl' => $this->settings->callbackUrl, 'merchant' => $this->settings->merchantId, - 'amount' => $this->invoice->getAmount() * ($this->settings->currency == 'T' ? 10 : 1), + 'amount' => $this->normalizeByCurrency($this->invoice->getAmount()), 'description' => $this->invoice->getDetail('description') ?? $this->settings->description, 'mobile' => $mobile, 'orderId' => $orderId