From 3e50f8e428e9b8445e5c290d06ead97508c37a6b Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Wed, 13 Jul 2022 20:39:17 +0530 Subject: [PATCH 01/14] Converting the currency to correct amounts for shipping_fee --- includes/api/shipping-info.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/includes/api/shipping-info.php b/includes/api/shipping-info.php index 61105fe6..aef474a8 100644 --- a/includes/api/shipping-info.php +++ b/includes/api/shipping-info.php @@ -63,6 +63,10 @@ function calculateShipping1cc(WP_REST_Request $request) WC()->cart->empty_cart(); $logObj['response'] = $response; rzpLogInfo(json_encode($logObj)); + if(is_plugin_active('woocommerce-currency-switcher/index.php')){ + $order = wc_get_order($orderId); + $response['0']['shipping_fee'] = currencyConvert($response['0']['shipping_fee'],$order); + } return new WP_REST_Response(array('addresses' => $response), 200); } @@ -696,3 +700,21 @@ function prepareHtmlResponse1cc($response) } return is_scalar($response) ? wp_kses_post(trim(convert_chars(wptexturize($response)))) : $response; } + +function currencyConvert($amountInPaise,$order){ + global $WOOCS; + $orderCurrency = getOrderCurrency($order); + $currencies = $WOOCS->get_currencies(); + $order_rate = $currencies[$orderCurrency]['rate']; + return $order_rate*$amountInPaise/100; +} + +function getOrderCurrency($order) +{ + if (version_compare(WOOCOMMERCE_VERSION, '2.7.0', '>=')) + { + return $order->get_currency(); + } + + return $order->get_order_currency(); +} \ No newline at end of file From 15b6efbce4df9efdc6eb4d0399692d40f6345b47 Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Thu, 14 Jul 2022 11:56:26 +0530 Subject: [PATCH 02/14] Added conversion logic to coupon amount --- includes/api/coupon-apply.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/includes/api/coupon-apply.php b/includes/api/coupon-apply.php index 039e1cc0..9f064780 100644 --- a/includes/api/coupon-apply.php +++ b/includes/api/coupon-apply.php @@ -4,6 +4,8 @@ * for coupon related API */ + require_once 'shipping-info.php'; + function applyCouponOnCart(WP_REST_Request $request) { global $woocommerce; @@ -165,6 +167,13 @@ function applyCouponOnCart(WP_REST_Request $request) $promotion["value"] = round($discountAmount ?? 0); $response["promotion"] = $promotion; + + + if(is_plugin_active('woocommerce-currency-switcher/index.php')){ + $order = wc_get_order($orderId); + $response['promotion']['value'] = currencyConvert($response['promotion']['value'],$order); + } + if ($couponError["failure_reason"] === "") { $logObj["response"] = $response; rzpLogInfo(json_encode($logObj)); From 8e2ee655cb5c9e67a662be5cb9a2d54da6296fe9 Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Thu, 14 Jul 2022 13:13:48 +0530 Subject: [PATCH 03/14] Correct amount for shipping --- includes/api/shipping-info.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/api/shipping-info.php b/includes/api/shipping-info.php index aef474a8..fd047404 100644 --- a/includes/api/shipping-info.php +++ b/includes/api/shipping-info.php @@ -706,7 +706,7 @@ function currencyConvert($amountInPaise,$order){ $orderCurrency = getOrderCurrency($order); $currencies = $WOOCS->get_currencies(); $order_rate = $currencies[$orderCurrency]['rate']; - return $order_rate*$amountInPaise/100; + return $order_rate*$amountInPaise; } function getOrderCurrency($order) From 59f3ea76bed99c163164cbdb4e143419b03fe4e2 Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Thu, 21 Jul 2022 12:23:06 +0530 Subject: [PATCH 04/14] restructuring to support folder --- includes/api/save-abandonment-data.php | 16 +- includes/api/shipping-info.php | 22 +- includes/support/cartbounty.php | 312 +++++++++++++++++++++++ includes/support/woocs-multicurrency.php | 18 ++ woo-razorpay.php | 32 ++- 5 files changed, 369 insertions(+), 31 deletions(-) mode change 100644 => 100755 includes/api/save-abandonment-data.php create mode 100644 includes/support/cartbounty.php create mode 100644 includes/support/woocs-multicurrency.php diff --git a/includes/api/save-abandonment-data.php b/includes/api/save-abandonment-data.php old mode 100644 new mode 100755 index 56baa47e..06663653 --- a/includes/api/save-abandonment-data.php +++ b/includes/api/save-abandonment-data.php @@ -3,6 +3,8 @@ * For abandon cart recovery related API */ +require_once __DIR__ . '/../support/cartbounty.php'; + function saveCartAbandonmentData(WP_REST_Request $request) { global $woocommerce; @@ -31,7 +33,6 @@ function saveCartAbandonmentData(WP_REST_Request $request) return new WP_REST_Response($response, $statusCode); } - if (isset($razorpayData['receipt'])) { $wcOrderId = $razorpayData['receipt']; @@ -63,6 +64,14 @@ function saveCartAbandonmentData(WP_REST_Request $request) return new WP_REST_Response($result['response'], $result['status_code']); } + //Check CartBounty plugin is activated or not + if (is_plugin_active('woo-save-abandoned-carts/cartbounty-abandoned-carts.php') && (empty($razorpayData['customer_details']['email']) == false || empty($customerEmail) == false)) { + + $result = saveCartBountyData($razorpayData); //save abandonment data + + return new WP_REST_Response($result['response'], $result['status_code']); + } + if (is_plugin_active('klaviyo/klaviyo.php') && empty($razorpayData['customer_details']['email']) == false) { WC()->cart->empty_cart(); $cart1cc = create1ccCart($wcOrderId); @@ -131,9 +140,8 @@ function saveWooAbandonmentCartLiteData($razorpayData, $wcOrderId) $billingLastName = " "; $billingZipcode = $razorpayData['customer_details']['billing_address']['zipcode'] ?? ''; $shippingZipcode = $razorpayData['customer_details']['shipping_address']['zipcode'] ?? ''; - - $shippingCharges = $razorpayData['shipping_fee'] / 100; - $email = $razorpayData['customer_details']['email']; + $shippingCharges = $razorpayData['shipping_fee'] / 100; + $email = $razorpayData['customer_details']['email']; // Insert record in abandoned cart table for the guest user. $userId = saveGuestUserDetails($billingFirstName, $billingLastName, $email, $billingZipcode, $shippingZipcode, $shippingCharges); diff --git a/includes/api/shipping-info.php b/includes/api/shipping-info.php index fd047404..5d796372 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(); @@ -63,10 +65,12 @@ function calculateShipping1cc(WP_REST_Request $request) WC()->cart->empty_cart(); $logObj['response'] = $response; rzpLogInfo(json_encode($logObj)); + if(is_plugin_active('woocommerce-currency-switcher/index.php')){ $order = wc_get_order($orderId); $response['0']['shipping_fee'] = currencyConvert($response['0']['shipping_fee'],$order); } + return new WP_REST_Response(array('addresses' => $response), 200); } @@ -699,22 +703,4 @@ function prepareHtmlResponse1cc($response) return array_map('prepareHtmlResponse1cc', $response); } return is_scalar($response) ? wp_kses_post(trim(convert_chars(wptexturize($response)))) : $response; -} - -function currencyConvert($amountInPaise,$order){ - global $WOOCS; - $orderCurrency = getOrderCurrency($order); - $currencies = $WOOCS->get_currencies(); - $order_rate = $currencies[$orderCurrency]['rate']; - return $order_rate*$amountInPaise; -} - -function getOrderCurrency($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/includes/support/cartbounty.php b/includes/support/cartbounty.php new file mode 100644 index 00000000..9faef794 --- /dev/null +++ b/includes/support/cartbounty.php @@ -0,0 +1,312 @@ +cart->get_cart(); + $ghost = false; + $name = $razorpayData['customer_details']['billing_address']['name'] ?? ''; + $surname = " "; + $email = $razorpayData['customer_details']['email']; + $phone = $razorpayData['customer_details']['contact']; + $cartTable = $wpdb->prefix . "cartbounty"; + $cart = readCartCB($razorpayData['receipt']); + $cartbountyPublic = new CartBounty_Public(CARTBOUNTY_PLUGIN_NAME_SLUG, CARTBOUNTY_VERSION_NUMBER); + $cartbountyAdmin = new CartBounty_Admin(CARTBOUNTY_PLUGIN_NAME_SLUG, CARTBOUNTY_VERSION_NUMBER); + + $location = array( + 'country' => $razorpayData['customer_details']['shipping_address']['country'] ?? '', + 'city' => $razorpayData['customer_details']['shipping_address']['city'] ?? '', + 'postcode' => $razorpayData['customer_details']['shipping_address']['zipcode'] ?? '', + ); + + $otherFields = array( + 'cartbounty_billing_company' => '', + 'cartbounty_billing_address_1' => $razorpayData['customer_details']['billing_address']['line1'] ?? '', + 'cartbounty_billing_address_2' => $razorpayData['customer_details']['billing_address']['line2'] ?? '', + 'cartbounty_billing_state' => $razorpayData['customer_details']['billing_address']['state'] ?? '', + 'cartbounty_shipping_first_name' => $razorpayData['customer_details']['billing_address']['name'] ?? '', + 'cartbounty_shipping_last_name' => '', + 'cartbounty_shipping_company' => '', + 'cartbounty_shipping_country' => $razorpayData['customer_details']['shipping_address']['country'] ?? '', + 'cartbounty_shipping_address_1' => $razorpayData['customer_details']['shipping_address']['line1'] ?? '', + 'cartbounty_shipping_address_2' => $razorpayData['customer_details']['shipping_address']['line2'] ?? '', + 'cartbounty_shipping_city' => $razorpayData['customer_details']['shipping_address']['city'] ?? '', + 'cartbounty_shipping_state' => $razorpayData['customer_details']['shipping_address']['state'] ?? '', + 'cartbounty_shipping_postcode' => $razorpayData['customer_details']['shipping_address']['zipcode'] ?? '', + 'cartbounty_order_comments' => '', + 'cartbounty_create_account' => '', + 'cartbounty_ship_elsewhere' => '', + ); + + $userData = array( + 'name' => $name, + 'surname' => $surname, + 'email' => $email, + 'phone' => $phone, + 'location' => $location, + 'other_fields' => $otherFields, + ); + + $sessionID = getSessionID($razorpayData['receipt']); + + if ($cartbountyPublic->cart_saved($sessionID) == false) { + //If cart is not saved + $wpdb->query( + $wpdb->prepare( + "INSERT INTO $cartTable + ( name, surname, email, phone, location, cart_contents, cart_total, currency, time, session_id, other_fields) + VALUES ( %s, %s, %s, %s, %s, %s, %0.2f, %s, %s, %s, %s)", + array( + 'name' => sanitize_text_field($userData['name']), + 'surname' => sanitize_text_field($userData['surname']), + 'email' => sanitize_email($userData['email']), + 'phone' => filter_var($userData['phone'], FILTER_SANITIZE_NUMBER_INT), + 'location' => sanitize_text_field(serialize($userData['location'])), + 'products' => serialize($cart['product_array']), + 'total' => sanitize_text_field($cart['cart_total']), + 'currency' => sanitize_text_field($cart['cart_currency']), + 'time' => sanitize_text_field($cart['current_time']), + 'session_id' => sanitize_text_field($cart['session_id']), + 'other_fields' => sanitize_text_field(serialize($userData['other_fields'])), + ) + ) + ); + + $cartbountyPublic->increase_recoverable_cart_count(); + $cartbountyPublic->set_cartbounty_session($sessionID); + } + $updatedRows = $wpdb->query( + $wpdb->prepare( + "UPDATE $cartTable + SET name = %s, + surname = %s, + email = %s, + phone = %s, + location = %s, + other_fields = '$otherFields' + WHERE session_id = %s and type=0", + sanitize_text_field($userData['name']), + sanitize_text_field($userData['surname']), + sanitize_email($userData['email']), + filter_var($userData['phone'], FILTER_SANITIZE_NUMBER_INT), + sanitize_text_field(serialize($userData['location'])), + $sessionID + ) + ); + + deleteDuplicateCarts($sessionID, $updatedRows, $cartTable); + $cartbountyPublic->set_cartbounty_session($sessionID); + $response['status'] = true; + $response['message'] = 'Data successfully inserted for CartBounty plugin'; + $statusCode = 200; + + update_post_meta($sessionID, 'FromEmail', "Y"); + WC()->session->set('cartbounty_from_link', true); + + $result['response'] = $response; + $result['status_code'] = $statusCode; + return $result; +} + +//Delete Duplicate carts CartBounty plugin +function deleteDuplicateCarts($sessionID, $duplicateCount, $cartTable) +{ + global $wpdb; + $cartbountyAdmin = new CartBounty_Admin(CARTBOUNTY_PLUGIN_NAME_SLUG, CARTBOUNTY_VERSION_NUMBER); + if ($duplicateCount) { + //If we have updated at least one row + if ($duplicateCount > 1) { //Checking if we have updated more than a single row to know if there were duplicates + $whereSentence = $cartbountyAdmin->get_where_sentence('ghost'); + //First delete all duplicate ghost carts + $deletedDuplicateGhostCarts = $wpdb->query( + $wpdb->prepare( + "DELETE FROM $cartTable + WHERE session_id = %s + $whereSentence", + $sessionID + ) + ); + + $limit = $duplicateCount - $deletedDuplicateGhostCarts - 1; + if ($limit < 1) { + $limit = 0; + } + + $wpdb->query( //Leaving one cart remaining that can be identified + $wpdb->prepare( + "DELETE FROM $cartTable + WHERE session_id = %s AND + type != %d + ORDER BY id DESC + LIMIT %d", + $sessionID, + 1, + $limit + ) + ); + } + } +} + +function getSessionID($orderID) +{ + $sessionID = WC()->session->get_customer_id(); + $order = wc_get_order($orderID); + $userID = $order->get_user_id(); + + if ($userID != 0 or $userID != null) { + //Used to check whether user is logged in + $sessionID = $userID; + } else { + $sessionID = WC()->session->get('cartbounty_session_id'); + if (empty($sessionID)) { //If session value does not exist - set one now + $sessionID = WC()->session->get_customer_id(); //Retrieving customer ID from WooCommerce sessions variable + } + if (WC()->session->get('cartbounty_from_link') && WC()->session->get('cartbounty_session_id')) { + $sessionID = WC()->session->get('cartbounty_session_id'); + } + } + return $sessionID; +} + +function handleCBRecoveredOrder($orderID) +{ + global $wpdb; + + if (!isset($orderID)) { + //Exit if Order ID is not present + return; + } + + $cartbountyPublic = new CartBounty_Public(CARTBOUNTY_PLUGIN_NAME_SLUG, CARTBOUNTY_VERSION_NUMBER); + $cartbountyAdmin = new CartBounty_Admin(CARTBOUNTY_PLUGIN_NAME_SLUG, CARTBOUNTY_VERSION_NUMBER); + + $cartbountyPublic->update_logged_customer_id(); //In case a user chooses to create an account during checkout process, the session id changes to a new one so we must update it + + $cartTable = $wpdb->prefix . CARTBOUNTY_TABLE_NAME; + + if (WC()->session) { + //If session exists + $cart = readCartCB($orderID); + $type = $cartbountyAdmin->get_cart_type('ordered'); //Default type describing an order has been placed + $sessionID = getSessionID($orderID); + $fromEmail = get_post_meta(getSessionID($orderID), 'FromEmail', true); + + if ($sessionID != null) { + if ($fromEmail === "Y") { + //If the user has arrived from CartBounty link + $type = $cartbountyAdmin->get_cart_type('recovered'); + update_post_meta($sessionID, 'FromEmail', "N"); + } + $cartbountyAdmin->update_cart_type($sessionID, $type); //Update cart type to recovered + + } + } + clearCartData($orderID, $cartTable); //Clearing abandoned cart after it has been synced + +} + +//CartBounty admin function to clearCartData +function clearCartData($wcOrderId, $cartTable) +{ + //If a new Order is added from the WooCommerce admin panel, we must check if WooCommerce session is set. Otherwise we would get a Fatal error. + if (!isset(WC()->session)) { + return; + } + + global $wpdb; + $cart = readCartCB($wcOrderId); + + if (!isset($cart['session_id'])) { + return; + } + + //Cleaning Cart data + $update_result = $wpdb->query( + $wpdb->prepare( + "UPDATE $cartTable + SET cart_contents = '', + cart_total = %d, + currency = %s, + time = %s + WHERE session_id = %s AND + type = %d", + 0, + sanitize_text_field($cart['cart_currency']), + sanitize_text_field($cart['current_time']), + $cart['session_id'], + 0 + ) + ); +} + +//CartBounty plugin function for retrieving the cart data +function readCartCB($wcOrderId) +{ + WC()->cart->empty_cart(); + $cart1cc = create1ccCart($wcOrderId); + $cart = WC()->cart; + + if (!WC()->cart) { + //Exit if Woocommerce cart has not been initialized + return; + } + + $cartTotal = WC()->cart->total; //Retrieving cart total value and currency + $cartCurrency = get_woocommerce_currency(); + $currentTime = current_time('mysql', false); //Retrieving current time + $sessionID = getSessionID($wcOrderId); + //Retrieving cart + $products = WC()->cart->get_cart_contents(); + $productArray = array(); + + foreach ($products as $key => $product) { + $item = wc_get_product($product['data']->get_id()); + $productTitle = $item->get_title(); + $productQuantity = $product['quantity']; + $productVariationPrice = ''; + $productTax = ''; + + if (isset($product['line_total'])) { + $productVariationPrice = $product['line_total']; + } + + if (isset($product['line_tax'])) { + //If we have taxes, add them to the price + $productTax = $product['line_tax']; + } + + // Handling product variations + if ($product['variation_id']) { + //If user has chosen a variation + $singleVariation = new WC_Product_Variation($product['variation_id']); + + //Handling variable product title output with attributes + $productAttributes = attribute_slug_to_title($singleVariation->get_variation_attributes()); + $productVariationID = $product['variation_id']; + } else { + $productAttributes = false; + $productVariationID = ''; + } + + $productData = array( + 'product_title' => $productTitle . $productAttributes, + 'quantity' => $productQuantity, + 'product_id' => $product['product_id'], + 'product_variation_id' => $productVariationID, + 'product_variation_price' => $productVariationPrice, + 'product_tax' => $productTax, + ); + + $productArray[] = $productData; + } + + return $resultsArray = array( + 'cart_total' => $cartTotal, + 'cart_currency' => $cartCurrency, + 'current_time' => $currentTime, + 'session_id' => $sessionID, + 'product_array' => $productArray, + ); +} diff --git a/includes/support/woocs-multicurrency.php b/includes/support/woocs-multicurrency.php new file mode 100644 index 00000000..66b1aa11 --- /dev/null +++ b/includes/support/woocs-multicurrency.php @@ -0,0 +1,18 @@ +get_currencies(); + $order_rate = $currencies[$orderCurrency]['rate']; + return $order_rate*$amountInPaise; +} + +function getOrderCurrency($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..1efa3028 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -3,8 +3,8 @@ * Plugin Name: Razorpay for WooCommerce * Plugin URI: https://razorpay.com * Description: Razorpay Payment Gateway Integration for WooCommerce - * Version: 3.9.2 - * Stable tag: 3.9.2 + * Version: 3.9.4 + * Stable tag: 3.9.4 * Author: Team Razorpay * WC tested up to: 6.4.1 * Author URI: https://razorpay.com @@ -23,6 +23,7 @@ require_once __DIR__.'/includes/api/api.php'; require_once __DIR__.'/includes/utils.php'; require_once __DIR__.'/includes/state-map.php'; +require_once __DIR__.'/includes/support/cartbounty.php'; use Razorpay\Api\Api; use Razorpay\Api\Errors; @@ -1073,7 +1074,7 @@ function process_payment($order_id) rzpLogInfo("Set transient with key " . self::SESSION_KEY . " params order_id $order_id"); $orderKey = $this->getOrderKey($order); - + if (version_compare(WOOCOMMERCE_VERSION, '2.1', '>=')) { return array( @@ -1327,7 +1328,7 @@ protected function getErrorMessage($orderId) { $message = 'An error occured. Please contact administrator for assistance'; } - rzpLogInfo("returning $getErrorMessage"); + rzpLogInfo("returning $message"); return $message; } @@ -1342,7 +1343,7 @@ public function updateOrder(& $order, $success, $errorMessage, $razorpayPaymentI $orderId = $order->get_order_number(); - rzpLogInfo("updateOrder orderId: $orderId , errorMessage: $errorMessage, razorpayPaymentId: $razorpayPaymentId , success: $success"); + rzpLogInfo("updateOrder orderId: $orderId , razorpayPaymentId: $razorpayPaymentId , success: $success"); if ($success === true) { @@ -1383,6 +1384,10 @@ public function updateOrder(& $order, $success, $errorMessage, $razorpayPaymentI { $order->payment_complete($razorpayPaymentId); } + + if(is_plugin_active('woo-save-abandoned-carts/cartbounty-abandoned-carts.php')){ + handleCBRecoveredOrder($orderId); + } $order->add_order_note("Razorpay payment successful
Razorpay Id: $razorpayPaymentId"); @@ -1500,8 +1505,8 @@ public function update1ccOrderWC(& $order, $wcOrderId, $razorpayPaymentId) if (sizeof($existingItems) != 0) { // Loop through shipping items - foreach ($existingItems as $existingItemId) { - $order->remove_item($existingItemId); + foreach ($existingItems as $existingItemKey => $existingItemVal) { + $order->remove_item($existingItemKey); } } @@ -1570,7 +1575,7 @@ public function update1ccOrderWC(& $order, $wcOrderId, $razorpayPaymentId) } else { - $item->set_method_title($shippingData[0]['name']); + $item->set_method_title($shippingData??[0]['name']); } // set an non existing Shipping method rate ID will mark the order as completed instead of processing status @@ -1946,7 +1951,6 @@ function enqueueScriptsFor1cc() wp_register_script('1cc_razorpay_checkout', RZP_CHECKOUTJS_URL, null, null); wp_enqueue_script('1cc_razorpay_checkout'); - wp_register_style(RZP_1CC_CSS_SCRIPT, plugin_dir_url(__FILE__) . 'public/css/1cc-product-checkout.css', null, null); wp_enqueue_style(RZP_1CC_CSS_SCRIPT); @@ -2073,3 +2077,13 @@ function disable_coupon_field_on_cart($enabled) add_action('woocommerce_cart_updated', 'enqueueScriptsFor1cc', 10); add_filter('woocommerce_order_needs_shipping_address', '__return_true'); } + +//Changes Recovery link URL to Magic cart URL to avoid redirection to checkout page +function cartbounty_alter_automation_button( $button ){ + return str_replace("cartbounty=","cartbounty=magic_",$button); +} + +if(is_plugin_active('woo-save-abandoned-carts/cartbounty-abandoned-carts.php')){ + add_filter( 'cartbounty_automation_button_html', 'cartbounty_alter_automation_button' ); +} + From 1501f2af3f7e82ab9777d2701b3df73d9aa3c092 Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Thu, 21 Jul 2022 12:30:16 +0530 Subject: [PATCH 05/14] upd --- includes/support/cartbounty.php | 312 -------------------------------- 1 file changed, 312 deletions(-) delete mode 100644 includes/support/cartbounty.php diff --git a/includes/support/cartbounty.php b/includes/support/cartbounty.php deleted file mode 100644 index 9faef794..00000000 --- a/includes/support/cartbounty.php +++ /dev/null @@ -1,312 +0,0 @@ -cart->get_cart(); - $ghost = false; - $name = $razorpayData['customer_details']['billing_address']['name'] ?? ''; - $surname = " "; - $email = $razorpayData['customer_details']['email']; - $phone = $razorpayData['customer_details']['contact']; - $cartTable = $wpdb->prefix . "cartbounty"; - $cart = readCartCB($razorpayData['receipt']); - $cartbountyPublic = new CartBounty_Public(CARTBOUNTY_PLUGIN_NAME_SLUG, CARTBOUNTY_VERSION_NUMBER); - $cartbountyAdmin = new CartBounty_Admin(CARTBOUNTY_PLUGIN_NAME_SLUG, CARTBOUNTY_VERSION_NUMBER); - - $location = array( - 'country' => $razorpayData['customer_details']['shipping_address']['country'] ?? '', - 'city' => $razorpayData['customer_details']['shipping_address']['city'] ?? '', - 'postcode' => $razorpayData['customer_details']['shipping_address']['zipcode'] ?? '', - ); - - $otherFields = array( - 'cartbounty_billing_company' => '', - 'cartbounty_billing_address_1' => $razorpayData['customer_details']['billing_address']['line1'] ?? '', - 'cartbounty_billing_address_2' => $razorpayData['customer_details']['billing_address']['line2'] ?? '', - 'cartbounty_billing_state' => $razorpayData['customer_details']['billing_address']['state'] ?? '', - 'cartbounty_shipping_first_name' => $razorpayData['customer_details']['billing_address']['name'] ?? '', - 'cartbounty_shipping_last_name' => '', - 'cartbounty_shipping_company' => '', - 'cartbounty_shipping_country' => $razorpayData['customer_details']['shipping_address']['country'] ?? '', - 'cartbounty_shipping_address_1' => $razorpayData['customer_details']['shipping_address']['line1'] ?? '', - 'cartbounty_shipping_address_2' => $razorpayData['customer_details']['shipping_address']['line2'] ?? '', - 'cartbounty_shipping_city' => $razorpayData['customer_details']['shipping_address']['city'] ?? '', - 'cartbounty_shipping_state' => $razorpayData['customer_details']['shipping_address']['state'] ?? '', - 'cartbounty_shipping_postcode' => $razorpayData['customer_details']['shipping_address']['zipcode'] ?? '', - 'cartbounty_order_comments' => '', - 'cartbounty_create_account' => '', - 'cartbounty_ship_elsewhere' => '', - ); - - $userData = array( - 'name' => $name, - 'surname' => $surname, - 'email' => $email, - 'phone' => $phone, - 'location' => $location, - 'other_fields' => $otherFields, - ); - - $sessionID = getSessionID($razorpayData['receipt']); - - if ($cartbountyPublic->cart_saved($sessionID) == false) { - //If cart is not saved - $wpdb->query( - $wpdb->prepare( - "INSERT INTO $cartTable - ( name, surname, email, phone, location, cart_contents, cart_total, currency, time, session_id, other_fields) - VALUES ( %s, %s, %s, %s, %s, %s, %0.2f, %s, %s, %s, %s)", - array( - 'name' => sanitize_text_field($userData['name']), - 'surname' => sanitize_text_field($userData['surname']), - 'email' => sanitize_email($userData['email']), - 'phone' => filter_var($userData['phone'], FILTER_SANITIZE_NUMBER_INT), - 'location' => sanitize_text_field(serialize($userData['location'])), - 'products' => serialize($cart['product_array']), - 'total' => sanitize_text_field($cart['cart_total']), - 'currency' => sanitize_text_field($cart['cart_currency']), - 'time' => sanitize_text_field($cart['current_time']), - 'session_id' => sanitize_text_field($cart['session_id']), - 'other_fields' => sanitize_text_field(serialize($userData['other_fields'])), - ) - ) - ); - - $cartbountyPublic->increase_recoverable_cart_count(); - $cartbountyPublic->set_cartbounty_session($sessionID); - } - $updatedRows = $wpdb->query( - $wpdb->prepare( - "UPDATE $cartTable - SET name = %s, - surname = %s, - email = %s, - phone = %s, - location = %s, - other_fields = '$otherFields' - WHERE session_id = %s and type=0", - sanitize_text_field($userData['name']), - sanitize_text_field($userData['surname']), - sanitize_email($userData['email']), - filter_var($userData['phone'], FILTER_SANITIZE_NUMBER_INT), - sanitize_text_field(serialize($userData['location'])), - $sessionID - ) - ); - - deleteDuplicateCarts($sessionID, $updatedRows, $cartTable); - $cartbountyPublic->set_cartbounty_session($sessionID); - $response['status'] = true; - $response['message'] = 'Data successfully inserted for CartBounty plugin'; - $statusCode = 200; - - update_post_meta($sessionID, 'FromEmail', "Y"); - WC()->session->set('cartbounty_from_link', true); - - $result['response'] = $response; - $result['status_code'] = $statusCode; - return $result; -} - -//Delete Duplicate carts CartBounty plugin -function deleteDuplicateCarts($sessionID, $duplicateCount, $cartTable) -{ - global $wpdb; - $cartbountyAdmin = new CartBounty_Admin(CARTBOUNTY_PLUGIN_NAME_SLUG, CARTBOUNTY_VERSION_NUMBER); - if ($duplicateCount) { - //If we have updated at least one row - if ($duplicateCount > 1) { //Checking if we have updated more than a single row to know if there were duplicates - $whereSentence = $cartbountyAdmin->get_where_sentence('ghost'); - //First delete all duplicate ghost carts - $deletedDuplicateGhostCarts = $wpdb->query( - $wpdb->prepare( - "DELETE FROM $cartTable - WHERE session_id = %s - $whereSentence", - $sessionID - ) - ); - - $limit = $duplicateCount - $deletedDuplicateGhostCarts - 1; - if ($limit < 1) { - $limit = 0; - } - - $wpdb->query( //Leaving one cart remaining that can be identified - $wpdb->prepare( - "DELETE FROM $cartTable - WHERE session_id = %s AND - type != %d - ORDER BY id DESC - LIMIT %d", - $sessionID, - 1, - $limit - ) - ); - } - } -} - -function getSessionID($orderID) -{ - $sessionID = WC()->session->get_customer_id(); - $order = wc_get_order($orderID); - $userID = $order->get_user_id(); - - if ($userID != 0 or $userID != null) { - //Used to check whether user is logged in - $sessionID = $userID; - } else { - $sessionID = WC()->session->get('cartbounty_session_id'); - if (empty($sessionID)) { //If session value does not exist - set one now - $sessionID = WC()->session->get_customer_id(); //Retrieving customer ID from WooCommerce sessions variable - } - if (WC()->session->get('cartbounty_from_link') && WC()->session->get('cartbounty_session_id')) { - $sessionID = WC()->session->get('cartbounty_session_id'); - } - } - return $sessionID; -} - -function handleCBRecoveredOrder($orderID) -{ - global $wpdb; - - if (!isset($orderID)) { - //Exit if Order ID is not present - return; - } - - $cartbountyPublic = new CartBounty_Public(CARTBOUNTY_PLUGIN_NAME_SLUG, CARTBOUNTY_VERSION_NUMBER); - $cartbountyAdmin = new CartBounty_Admin(CARTBOUNTY_PLUGIN_NAME_SLUG, CARTBOUNTY_VERSION_NUMBER); - - $cartbountyPublic->update_logged_customer_id(); //In case a user chooses to create an account during checkout process, the session id changes to a new one so we must update it - - $cartTable = $wpdb->prefix . CARTBOUNTY_TABLE_NAME; - - if (WC()->session) { - //If session exists - $cart = readCartCB($orderID); - $type = $cartbountyAdmin->get_cart_type('ordered'); //Default type describing an order has been placed - $sessionID = getSessionID($orderID); - $fromEmail = get_post_meta(getSessionID($orderID), 'FromEmail', true); - - if ($sessionID != null) { - if ($fromEmail === "Y") { - //If the user has arrived from CartBounty link - $type = $cartbountyAdmin->get_cart_type('recovered'); - update_post_meta($sessionID, 'FromEmail', "N"); - } - $cartbountyAdmin->update_cart_type($sessionID, $type); //Update cart type to recovered - - } - } - clearCartData($orderID, $cartTable); //Clearing abandoned cart after it has been synced - -} - -//CartBounty admin function to clearCartData -function clearCartData($wcOrderId, $cartTable) -{ - //If a new Order is added from the WooCommerce admin panel, we must check if WooCommerce session is set. Otherwise we would get a Fatal error. - if (!isset(WC()->session)) { - return; - } - - global $wpdb; - $cart = readCartCB($wcOrderId); - - if (!isset($cart['session_id'])) { - return; - } - - //Cleaning Cart data - $update_result = $wpdb->query( - $wpdb->prepare( - "UPDATE $cartTable - SET cart_contents = '', - cart_total = %d, - currency = %s, - time = %s - WHERE session_id = %s AND - type = %d", - 0, - sanitize_text_field($cart['cart_currency']), - sanitize_text_field($cart['current_time']), - $cart['session_id'], - 0 - ) - ); -} - -//CartBounty plugin function for retrieving the cart data -function readCartCB($wcOrderId) -{ - WC()->cart->empty_cart(); - $cart1cc = create1ccCart($wcOrderId); - $cart = WC()->cart; - - if (!WC()->cart) { - //Exit if Woocommerce cart has not been initialized - return; - } - - $cartTotal = WC()->cart->total; //Retrieving cart total value and currency - $cartCurrency = get_woocommerce_currency(); - $currentTime = current_time('mysql', false); //Retrieving current time - $sessionID = getSessionID($wcOrderId); - //Retrieving cart - $products = WC()->cart->get_cart_contents(); - $productArray = array(); - - foreach ($products as $key => $product) { - $item = wc_get_product($product['data']->get_id()); - $productTitle = $item->get_title(); - $productQuantity = $product['quantity']; - $productVariationPrice = ''; - $productTax = ''; - - if (isset($product['line_total'])) { - $productVariationPrice = $product['line_total']; - } - - if (isset($product['line_tax'])) { - //If we have taxes, add them to the price - $productTax = $product['line_tax']; - } - - // Handling product variations - if ($product['variation_id']) { - //If user has chosen a variation - $singleVariation = new WC_Product_Variation($product['variation_id']); - - //Handling variable product title output with attributes - $productAttributes = attribute_slug_to_title($singleVariation->get_variation_attributes()); - $productVariationID = $product['variation_id']; - } else { - $productAttributes = false; - $productVariationID = ''; - } - - $productData = array( - 'product_title' => $productTitle . $productAttributes, - 'quantity' => $productQuantity, - 'product_id' => $product['product_id'], - 'product_variation_id' => $productVariationID, - 'product_variation_price' => $productVariationPrice, - 'product_tax' => $productTax, - ); - - $productArray[] = $productData; - } - - return $resultsArray = array( - 'cart_total' => $cartTotal, - 'cart_currency' => $cartCurrency, - 'current_time' => $currentTime, - 'session_id' => $sessionID, - 'product_array' => $productArray, - ); -} From ce318676ffb987335b691dbcfa395d970ecdc359 Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Thu, 21 Jul 2022 12:32:51 +0530 Subject: [PATCH 06/14] removed extra files #1 --- woo-razorpay.php | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/woo-razorpay.php b/woo-razorpay.php index 1efa3028..1f449b9c 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -3,8 +3,8 @@ * Plugin Name: Razorpay for WooCommerce * Plugin URI: https://razorpay.com * Description: Razorpay Payment Gateway Integration for WooCommerce - * Version: 3.9.4 - * Stable tag: 3.9.4 + * Version: 3.9.2 + * Stable tag: 3.9.2 * Author: Team Razorpay * WC tested up to: 6.4.1 * Author URI: https://razorpay.com @@ -23,7 +23,6 @@ require_once __DIR__.'/includes/api/api.php'; require_once __DIR__.'/includes/utils.php'; require_once __DIR__.'/includes/state-map.php'; -require_once __DIR__.'/includes/support/cartbounty.php'; use Razorpay\Api\Api; use Razorpay\Api\Errors; @@ -1074,7 +1073,7 @@ function process_payment($order_id) rzpLogInfo("Set transient with key " . self::SESSION_KEY . " params order_id $order_id"); $orderKey = $this->getOrderKey($order); - + if (version_compare(WOOCOMMERCE_VERSION, '2.1', '>=')) { return array( @@ -1328,7 +1327,7 @@ protected function getErrorMessage($orderId) { $message = 'An error occured. Please contact administrator for assistance'; } - rzpLogInfo("returning $message"); + rzpLogInfo("returning $getErrorMessage"); return $message; } @@ -1343,7 +1342,7 @@ public function updateOrder(& $order, $success, $errorMessage, $razorpayPaymentI $orderId = $order->get_order_number(); - rzpLogInfo("updateOrder orderId: $orderId , razorpayPaymentId: $razorpayPaymentId , success: $success"); + rzpLogInfo("updateOrder orderId: $orderId , errorMessage: $errorMessage, razorpayPaymentId: $razorpayPaymentId , success: $success"); if ($success === true) { @@ -1384,10 +1383,6 @@ public function updateOrder(& $order, $success, $errorMessage, $razorpayPaymentI { $order->payment_complete($razorpayPaymentId); } - - if(is_plugin_active('woo-save-abandoned-carts/cartbounty-abandoned-carts.php')){ - handleCBRecoveredOrder($orderId); - } $order->add_order_note("Razorpay payment successful
Razorpay Id: $razorpayPaymentId"); @@ -1505,8 +1500,8 @@ public function update1ccOrderWC(& $order, $wcOrderId, $razorpayPaymentId) if (sizeof($existingItems) != 0) { // Loop through shipping items - foreach ($existingItems as $existingItemKey => $existingItemVal) { - $order->remove_item($existingItemKey); + foreach ($existingItems as $existingItemId) { + $order->remove_item($existingItemId); } } @@ -1575,7 +1570,7 @@ public function update1ccOrderWC(& $order, $wcOrderId, $razorpayPaymentId) } else { - $item->set_method_title($shippingData??[0]['name']); + $item->set_method_title($shippingData[0]['name']); } // set an non existing Shipping method rate ID will mark the order as completed instead of processing status @@ -1951,6 +1946,7 @@ function enqueueScriptsFor1cc() wp_register_script('1cc_razorpay_checkout', RZP_CHECKOUTJS_URL, null, null); wp_enqueue_script('1cc_razorpay_checkout'); + wp_register_style(RZP_1CC_CSS_SCRIPT, plugin_dir_url(__FILE__) . 'public/css/1cc-product-checkout.css', null, null); wp_enqueue_style(RZP_1CC_CSS_SCRIPT); @@ -2076,14 +2072,4 @@ function disable_coupon_field_on_cart($enabled) add_filter('woocommerce_coupons_enabled', 'disable_coupon_field_on_cart'); add_action('woocommerce_cart_updated', 'enqueueScriptsFor1cc', 10); add_filter('woocommerce_order_needs_shipping_address', '__return_true'); -} - -//Changes Recovery link URL to Magic cart URL to avoid redirection to checkout page -function cartbounty_alter_automation_button( $button ){ - return str_replace("cartbounty=","cartbounty=magic_",$button); -} - -if(is_plugin_active('woo-save-abandoned-carts/cartbounty-abandoned-carts.php')){ - add_filter( 'cartbounty_automation_button_html', 'cartbounty_alter_automation_button' ); -} - +} \ No newline at end of file From f3bd502a07732a75552421e6f4551c77daa1663d Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Thu, 21 Jul 2022 12:34:13 +0530 Subject: [PATCH 07/14] removed extra files #2 --- woo-razorpay.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woo-razorpay.php b/woo-razorpay.php index 1f449b9c..62f1c8a0 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -2072,4 +2072,4 @@ function disable_coupon_field_on_cart($enabled) add_filter('woocommerce_coupons_enabled', 'disable_coupon_field_on_cart'); add_action('woocommerce_cart_updated', 'enqueueScriptsFor1cc', 10); add_filter('woocommerce_order_needs_shipping_address', '__return_true'); -} \ No newline at end of file +} From 6532c4831cf47ff02f3e65ae080d6aec92e38c2b Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Thu, 21 Jul 2022 12:34:54 +0530 Subject: [PATCH 08/14] removed extra files #2 --- includes/api/save-abandonment-data.php | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/includes/api/save-abandonment-data.php b/includes/api/save-abandonment-data.php index 06663653..65f69f89 100755 --- a/includes/api/save-abandonment-data.php +++ b/includes/api/save-abandonment-data.php @@ -3,8 +3,6 @@ * For abandon cart recovery related API */ -require_once __DIR__ . '/../support/cartbounty.php'; - function saveCartAbandonmentData(WP_REST_Request $request) { global $woocommerce; @@ -33,6 +31,7 @@ function saveCartAbandonmentData(WP_REST_Request $request) return new WP_REST_Response($response, $statusCode); } + if (isset($razorpayData['receipt'])) { $wcOrderId = $razorpayData['receipt']; @@ -64,14 +63,6 @@ function saveCartAbandonmentData(WP_REST_Request $request) return new WP_REST_Response($result['response'], $result['status_code']); } - //Check CartBounty plugin is activated or not - if (is_plugin_active('woo-save-abandoned-carts/cartbounty-abandoned-carts.php') && (empty($razorpayData['customer_details']['email']) == false || empty($customerEmail) == false)) { - - $result = saveCartBountyData($razorpayData); //save abandonment data - - return new WP_REST_Response($result['response'], $result['status_code']); - } - if (is_plugin_active('klaviyo/klaviyo.php') && empty($razorpayData['customer_details']['email']) == false) { WC()->cart->empty_cart(); $cart1cc = create1ccCart($wcOrderId); @@ -140,8 +131,9 @@ function saveWooAbandonmentCartLiteData($razorpayData, $wcOrderId) $billingLastName = " "; $billingZipcode = $razorpayData['customer_details']['billing_address']['zipcode'] ?? ''; $shippingZipcode = $razorpayData['customer_details']['shipping_address']['zipcode'] ?? ''; - $shippingCharges = $razorpayData['shipping_fee'] / 100; - $email = $razorpayData['customer_details']['email']; + + $shippingCharges = $razorpayData['shipping_fee'] / 100; + $email = $razorpayData['customer_details']['email']; // Insert record in abandoned cart table for the guest user. $userId = saveGuestUserDetails($billingFirstName, $billingLastName, $email, $billingZipcode, $shippingZipcode, $shippingCharges); @@ -424,4 +416,4 @@ function checkRecordBySession($cookie) ); return $results; -} +} \ No newline at end of file From 2ff22b8a276952ee4e36df6f4c0e54ccb69fb8e1 Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Thu, 21 Jul 2022 12:36:23 +0530 Subject: [PATCH 09/14] Final restructuring and fix --- includes/support/woocs-multicurrency.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/support/woocs-multicurrency.php b/includes/support/woocs-multicurrency.php index 66b1aa11..4c0201f9 100644 --- a/includes/support/woocs-multicurrency.php +++ b/includes/support/woocs-multicurrency.php @@ -4,7 +4,7 @@ function currencyConvert($amountInPaise,$order){ $orderCurrency = getOrderCurrency($order); $currencies = $WOOCS->get_currencies(); $order_rate = $currencies[$orderCurrency]['rate']; - return $order_rate*$amountInPaise; + return round($order_rate*$amountInPaise,2); } function getOrderCurrency($order) From e12090719ab6adbef0ee60ba03112eb1c87c77d4 Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Thu, 21 Jul 2022 16:16:49 +0530 Subject: [PATCH 10/14] Using support import for multicurrency --- includes/api/coupon-apply.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/api/coupon-apply.php b/includes/api/coupon-apply.php index 9f064780..a8721647 100644 --- a/includes/api/coupon-apply.php +++ b/includes/api/coupon-apply.php @@ -4,7 +4,8 @@ * for coupon related API */ - require_once 'shipping-info.php'; + +require_once __DIR__ . '/../support/woocs-multicurrency.php'; function applyCouponOnCart(WP_REST_Request $request) { From 579f318670e3be8a1cdbd9c48037599cce23f1f1 Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Fri, 22 Jul 2022 17:44:44 +0530 Subject: [PATCH 11/14] Added 2 decimal point precision --- includes/support/woocs-multicurrency.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/support/woocs-multicurrency.php b/includes/support/woocs-multicurrency.php index 4c0201f9..e155d992 100644 --- a/includes/support/woocs-multicurrency.php +++ b/includes/support/woocs-multicurrency.php @@ -4,7 +4,7 @@ function currencyConvert($amountInPaise,$order){ $orderCurrency = getOrderCurrency($order); $currencies = $WOOCS->get_currencies(); $order_rate = $currencies[$orderCurrency]['rate']; - return round($order_rate*$amountInPaise,2); + return round($order_rate*$amountInPaise,0); } function getOrderCurrency($order) From c0e79be5bb24477f25efa42b47bd46abd0e9845c Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Fri, 5 Aug 2022 17:38:47 +0530 Subject: [PATCH 12/14] Fix according to Kinsta and Plugin dashboard settings --- includes/api/coupon-apply.php | 10 ++++++++-- includes/api/shipping-info.php | 23 ++++++++++++++--------- includes/support/woocs-multicurrency.php | 4 ++-- woo-razorpay.php | 6 ++++++ 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/includes/api/coupon-apply.php b/includes/api/coupon-apply.php index a8721647..6a1c451c 100644 --- a/includes/api/coupon-apply.php +++ b/includes/api/coupon-apply.php @@ -171,8 +171,14 @@ function applyCouponOnCart(WP_REST_Request $request) if(is_plugin_active('woocommerce-currency-switcher/index.php')){ - $order = wc_get_order($orderId); - $response['promotion']['value'] = currencyConvert($response['promotion']['value'],$order); + + $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"] === "") { diff --git a/includes/api/shipping-info.php b/includes/api/shipping-info.php index 5d796372..59e0472f 100644 --- a/includes/api/shipping-info.php +++ b/includes/api/shipping-info.php @@ -64,12 +64,15 @@ 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')){ - $order = wc_get_order($orderId); - $response['0']['shipping_fee'] = currencyConvert($response['0']['shipping_fee'],$order); - } + 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'] = currencyConvert($response['0']['shipping_fee'],$order); + } + } return new WP_REST_Response(array('addresses' => $response), 200); } @@ -149,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); @@ -255,7 +259,6 @@ function prepareRatesResponse1cc($package, $vendorId, $orderId, $address) function getRateResponse1cc($rate, $vendorId, $orderId, $address) { - return array_merge( array( 'rate_id' => getRateProp1cc($rate, 'id'), @@ -606,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); } /** diff --git a/includes/support/woocs-multicurrency.php b/includes/support/woocs-multicurrency.php index e155d992..40e49af0 100644 --- a/includes/support/woocs-multicurrency.php +++ b/includes/support/woocs-multicurrency.php @@ -3,8 +3,8 @@ function currencyConvert($amountInPaise,$order){ global $WOOCS; $orderCurrency = getOrderCurrency($order); $currencies = $WOOCS->get_currencies(); - $order_rate = $currencies[$orderCurrency]['rate']; - return round($order_rate*$amountInPaise,0); + $orderRate = $currencies[$orderCurrency]['rate']; + return round($orderRate*$amountInPaise,0); } function getOrderCurrency($order) 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(); From bc9c5ba8c1ffd6855d7170e9cb7340b1c29c9ae6 Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Fri, 5 Aug 2022 17:40:21 +0530 Subject: [PATCH 13/14] Re-formatting --- includes/api/coupon-apply.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/includes/api/coupon-apply.php b/includes/api/coupon-apply.php index 6a1c451c..32325582 100644 --- a/includes/api/coupon-apply.php +++ b/includes/api/coupon-apply.php @@ -171,14 +171,12 @@ function applyCouponOnCart(WP_REST_Request $request) 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"] === "") { From 11e34522991e0c7579f1ae727a53cf16b04a0b4b Mon Sep 17 00:00:00 2001 From: Anurag Bandyopadhyay Date: Tue, 9 Aug 2022 18:14:08 +0530 Subject: [PATCH 14/14] Currency switcher fxn name update --- includes/api/shipping-info.php | 2 +- includes/support/woocs-multicurrency.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/api/shipping-info.php b/includes/api/shipping-info.php index 59e0472f..528aa150 100644 --- a/includes/api/shipping-info.php +++ b/includes/api/shipping-info.php @@ -70,7 +70,7 @@ function calculateShipping1cc(WP_REST_Request $request) if($is_multiple_allowed==1){ $order = wc_get_order($orderId); - $response['0']['shipping_fee'] = currencyConvert($response['0']['shipping_fee'],$order); + $response['0']['shipping_fee'] = currencyConvertCS($response['0']['shipping_fee'],$order); } } diff --git a/includes/support/woocs-multicurrency.php b/includes/support/woocs-multicurrency.php index 40e49af0..67e180f9 100644 --- a/includes/support/woocs-multicurrency.php +++ b/includes/support/woocs-multicurrency.php @@ -1,13 +1,13 @@ get_currencies(); $orderRate = $currencies[$orderCurrency]['rate']; return round($orderRate*$amountInPaise,0); } -function getOrderCurrency($order) +function getOrderCurrencyCS($order) { if (version_compare(WOOCOMMERCE_VERSION, '2.7.0', '>=')) {