Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for currencies KWD, OMR, BHD. #510

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions includes/razorpay-webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ protected function paymentAuthorized(array $data)
$razorpayPaymentId = $data['payload']['payment']['entity']['id'];

$payment = $this->getPaymentEntity($razorpayPaymentId, $data);

//change required
$amount = $this->getOrderAmountAsInteger($order);

$success = false;
Expand Down Expand Up @@ -525,6 +525,7 @@ protected function shouldConsumeWebhook($data)
*/
public function getOrderAmountAsInteger($order)
{
// change required
if (version_compare(WOOCOMMERCE_VERSION, '3.0.0', '>=')) {
return (int) round($order->get_total() * 100);
}
Expand Down Expand Up @@ -586,7 +587,7 @@ public function refundedCreated(array $data)

error_log(json_encode($log));
}

//change required
$refundAmount = round(($data['payload']['refund']['entity']['amount'] / 100), 2);

$refundReason = $data['payload']['refund']['entity']['notes']['comment'];
Expand Down
33 changes: 30 additions & 3 deletions woo-razorpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ class WC_Razorpay extends WC_Payment_Gateway
'refunds'
);

public $threeDecimalCurrencies = [
"KWD",
"BHD",
"OMR"
];

/**
* Can be set to true if you want payment fields
* to show on the checkout (if doing a direct integration).
Expand Down Expand Up @@ -1239,10 +1245,18 @@ private function getOrderCreationData($orderId)
$is1ccOrder = get_post_meta( $orderId, 'is_magic_checkout_order', true );
}

$currency = $this->getOrderCurrency($order);
$amount = (int) round($order->get_total() * 100);

if(in_array($currency, $this->threeDecimalCurrencies) === true)
{
$amount = (int) round($order->get_total() * 1000);
}

$data = array(
'receipt' => (string)$orderId,
'amount' => (int) round($order->get_total() * 100),
'currency' => $this->getOrderCurrency($order),
'amount' => $amount,
'currency' => $currency,
'payment_capture' => ($this->getSetting('payment_action') === self::AUTHORIZE) ? 0 : 1,
'app_offer' => ($order->get_discount_total() > 0) ? 1 : 0,
'notes' => array(
Expand Down Expand Up @@ -1456,8 +1470,21 @@ public function process_refund($orderId, $amount = null, $reason = '')

$paymentId = $order->get_transaction_id();

$currency = $this->getOrderCurrency($order);


if(in_array($currency, $this->threeDecimalCurrencies) === true)
{
$amount = (int) round($amount * 1000);
}
else
{
$amount = (int) round($amount * 100);
}

// changes required
$data = array(
'amount' => (int) round($amount * 100),
'amount' => $amount,
'notes' => array(
'reason' => $reason,
'order_id' => $orderId,
Expand Down
Loading