Skip to content

Commit

Permalink
Blocked currencies KWD, OMR, BHD. (#461)
Browse files Browse the repository at this point in the history
* Blocked currencies KWD, OMR, BHD.
  • Loading branch information
yashgit891 authored Nov 9, 2023
1 parent 53426a7 commit 23d4734
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Controller/Payment/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions Model/Resolver/PlaceRazorpayOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class PlaceRazorpayOrder implements ResolverInterface

protected $rzp;

protected const THREE_DECIMAL_CURRENCIES = ["KWD", "OMR", "BHD"];

/**
* @var \Razorpay\Magento\Model\Config
*/
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 23d4734

Please sign in to comment.