diff --git a/Controller/Payment/Order.php b/Controller/Payment/Order.php index cc022f37..5c094e7f 100644 --- a/Controller/Payment/Order.php +++ b/Controller/Payment/Order.php @@ -44,6 +44,8 @@ class Order extends \Razorpay\Magento\Controller\BaseController protected $webhooks; + protected const THREE_DECIMAL_CURRENCIES = ["KWD", "OMR", "BHD"]; + /** * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Customer\Model\Session $customerSession @@ -249,6 +251,24 @@ public function execute() . " and amount:" . $amount); // @codeCoverageIgnoreEnd + if (in_array($mazeOrder->getOrderCurrencyCode(), static::THREE_DECIMAL_CURRENCIES) === true) + { + $this->logger->info($mazeOrder->getOrderCurrencyCode() . " currency is not supported at the moment."); + + $responseContent = [ + 'message' => 'Unable to create your order. Please contact support.', + 'parameters' => [] + ]; + + $code = 400; + + $response = $this->resultFactory->create(ResultFactory::TYPE_JSON); + $response->setData($responseContent); + $response->setHttpResponseCode($code); + + return $response; + } + $order = $this->rzp->order->create([ 'amount' => $amount, 'receipt' => $receipt_id, diff --git a/Model/Resolver/PlaceRazorpayOrder.php b/Model/Resolver/PlaceRazorpayOrder.php index 2e4187ca..66857682 100644 --- a/Model/Resolver/PlaceRazorpayOrder.php +++ b/Model/Resolver/PlaceRazorpayOrder.php @@ -46,6 +46,8 @@ class PlaceRazorpayOrder implements ResolverInterface protected $rzp; + protected const THREE_DECIMAL_CURRENCIES = ["KWD", "OMR", "BHD"]; + /** * @var \Razorpay\Magento\Model\Config */ @@ -132,6 +134,11 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value ]; } + if (in_array($order_currency_code, static::THREE_DECIMAL_CURRENCIES) === true) + { + throw new \Exception($order_currency_code . " currency is not supported at the moment."); + } + $amount = (int) (number_format($order_grand_total * 100, 0, ".", "")); $payment_action = $this->scopeConfig->getValue('payment/razorpay/rzp_payment_action', $storeScope); $payment_capture = 1;