diff --git a/includes/api/coupon-apply.php b/includes/api/coupon-apply.php index 039e1cc0..32325582 100644 --- a/includes/api/coupon-apply.php +++ b/includes/api/coupon-apply.php @@ -4,6 +4,9 @@ * for coupon related API */ + +require_once __DIR__ . '/../support/woocs-multicurrency.php'; + function applyCouponOnCart(WP_REST_Request $request) { global $woocommerce; @@ -165,6 +168,17 @@ function applyCouponOnCart(WP_REST_Request $request) $promotion["value"] = round($discountAmount ?? 0); $response["promotion"] = $promotion; + + + if(is_plugin_active('woocommerce-currency-switcher/index.php')){ + $is_multiple_allowed = get_option('woocs_is_multiple_allowed', 0); + + if($is_multiple_allowed==1){ + $order = wc_get_order($orderId); + $response['promotion']['value'] = currencyConvert($response['promotion']['value'],$order); + } + } + if ($couponError["failure_reason"] === "") { $logObj["response"] = $response; rzpLogInfo(json_encode($logObj)); diff --git a/includes/api/save-abandonment-data.php b/includes/api/save-abandonment-data.php old mode 100644 new mode 100755 index 56baa47e..65f69f89 --- a/includes/api/save-abandonment-data.php +++ b/includes/api/save-abandonment-data.php @@ -416,4 +416,4 @@ function checkRecordBySession($cookie) ); return $results; -} +} \ No newline at end of file diff --git a/includes/api/shipping-info.php b/includes/api/shipping-info.php index 61105fe6..528aa150 100644 --- a/includes/api/shipping-info.php +++ b/includes/api/shipping-info.php @@ -7,6 +7,8 @@ * @return array|WP_Error|WP_REST_Response * @throws Exception If failed to add items to cart or no shipping options available for address. */ +require_once __DIR__ . '/../support/woocs-multicurrency.php'; + function calculateShipping1cc(WP_REST_Request $request) { $params = $request->get_params(); @@ -62,7 +64,16 @@ function calculateShipping1cc(WP_REST_Request $request) // Cleanup cart. WC()->cart->empty_cart(); $logObj['response'] = $response; - rzpLogInfo(json_encode($logObj)); + + if(is_plugin_active('woocommerce-currency-switcher/index.php')){ + $is_multiple_allowed = get_option('woocs_is_multiple_allowed', 0); + + if($is_multiple_allowed==1){ + $order = wc_get_order($orderId); + $response['0']['shipping_fee'] = currencyConvertCS($response['0']['shipping_fee'],$order); + } + } + return new WP_REST_Response(array('addresses' => $response), 200); } @@ -141,6 +152,7 @@ function shippingCalculatePackages1cc($id, $orderId, $address) $vendorId[] = $packages[$key]['vendor_id']; } } + $calculatedPackages = wc()->shipping()->calculate_shipping($packages); return getItemResponse1cc($calculatedPackages, $id, $vendorId, $orderId, $address); @@ -247,7 +259,6 @@ function prepareRatesResponse1cc($package, $vendorId, $orderId, $address) function getRateResponse1cc($rate, $vendorId, $orderId, $address) { - return array_merge( array( 'rate_id' => getRateProp1cc($rate, 'id'), @@ -598,11 +609,13 @@ function smartCodRestriction($addresses, $order) * @returns int */ function convertToPaisa($price) -{ +{ if (is_string($price)) { - $price = (int) $price; + $price = floatval($price); } - return $price * 100; + round($price,2); + + return ($price * 100); } /** @@ -695,4 +708,4 @@ function prepareHtmlResponse1cc($response) return array_map('prepareHtmlResponse1cc', $response); } return is_scalar($response) ? wp_kses_post(trim(convert_chars(wptexturize($response)))) : $response; -} +} \ No newline at end of file diff --git a/includes/support/woocs-multicurrency.php b/includes/support/woocs-multicurrency.php new file mode 100644 index 00000000..67e180f9 --- /dev/null +++ b/includes/support/woocs-multicurrency.php @@ -0,0 +1,18 @@ +get_currencies(); + $orderRate = $currencies[$orderCurrency]['rate']; + return round($orderRate*$amountInPaise,0); +} + +function getOrderCurrencyCS($order) +{ + if (version_compare(WOOCOMMERCE_VERSION, '2.7.0', '>=')) + { + return $order->get_currency(); + } + + return $order->get_order_currency(); +} \ No newline at end of file diff --git a/woo-razorpay.php b/woo-razorpay.php index 62f1c8a0..af885086 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -684,6 +684,12 @@ public function getDefaultCheckoutArguments($order) */ private function getOrderCurrency($order) { + if(is_plugin_active('woocommerce-currency-switcher/index.php')){ + $is_multiple_allowed = get_option('woocs_is_multiple_allowed', 0); + if($is_multiple_allowed==0){ + return get_option('woocs_welcome_currency',0); + } + } if (version_compare(WOOCOMMERCE_VERSION, '2.7.0', '>=')) { return $order->get_currency();