Version Description
- Magic Checkout support for Klaviyo plugin.
- Bug fix for warning message on place order and callback script.
- Bug fix in smart cod support in magic checkout.
Download this release
Release Info
Developer | razorpay |
Plugin | Razorpay for WooCommerce |
Version | 3.7.0 |
Comparing to | |
See all releases |
Code changes from version 3.6.0 to 3.7.0
- includes/api/save-abandonment-data.php +338 -86
- includes/api/shipping-info.php +4 -3
- readme.txt +6 -1
- woo-razorpay.php +79 -10
includes/api/save-abandonment-data.php
CHANGED
@@ -54,114 +54,366 @@ function saveCartAbandonmentData(WP_REST_Request $request)
|
|
54 |
rzpLogInfo('Woocommerce order id:');
|
55 |
rzpLogInfo(json_encode($wcOrderId));
|
56 |
|
|
|
57 |
if (is_plugin_active('woo-cart-abandonment-recovery/woo-cart-abandonment-recovery.php') && empty($customerEmail) == false) {
|
58 |
|
59 |
-
|
60 |
-
$
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
'wcf_shipping_country' => $razorpayData['customer_details']['shipping_address']['country'] ?? '',
|
78 |
-
'wcf_shipping_address_1' => $razorpayData['customer_details']['shipping_address']['line1'] ?? '',
|
79 |
-
'wcf_shipping_address_2' => $razorpayData['customer_details']['shipping_address']['line2'] ?? '',
|
80 |
-
'wcf_shipping_city' => $razorpayData['customer_details']['shipping_address']['city'] ?? '',
|
81 |
-
'wcf_shipping_state' => $razorpayData['customer_details']['shipping_address']['state'] ?? '',
|
82 |
-
'wcf_shipping_postcode' => $razorpayData['customer_details']['shipping_address']['zipcode'] ?? '',
|
83 |
-
'wcf_order_comments' => "",
|
84 |
-
'wcf_first_name' => $razorpayData['customer_details']['shipping_address']['name'] ?? '',
|
85 |
-
'wcf_last_name' => "",
|
86 |
-
'wcf_phone_number' => $razorpayData['customer_details']['shipping_address']['contact'] ?? '',
|
87 |
-
'wcf_location' => $razorpayData['customer_details']['shipping_address']['country'] ?? '',
|
88 |
-
);
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
'cart_contents' => serialize($products),
|
93 |
-
'cart_total' => sanitize_text_field($cartTotal),
|
94 |
-
'time' => $currentTime,
|
95 |
-
'other_fields' => serialize($otherFields),
|
96 |
-
'checkout_id' => wc_get_page_id('cart'),
|
97 |
-
);
|
98 |
|
99 |
-
|
|
|
|
|
|
|
|
|
100 |
|
101 |
-
$
|
|
|
|
|
|
|
102 |
|
103 |
-
|
|
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
$cartAbandonmentTable,
|
113 |
-
$checkoutDetails,
|
114 |
-
array('session_id' => $sessionId)
|
115 |
-
);
|
116 |
-
|
117 |
-
if ($wpdb->last_error) {
|
118 |
-
$response['status'] = false;
|
119 |
-
$response['message'] = $wpdb->last_error;
|
120 |
-
$statusCode = 400;
|
121 |
-
} else {
|
122 |
-
$response['status'] = true;
|
123 |
-
$response['message'] = 'Data successfully updated for wooCommerce cart abandonment recovery';
|
124 |
-
$statusCode = 200;
|
125 |
-
}
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
}
|
149 |
|
150 |
-
$
|
151 |
-
$logObj['status_code'] = $statusCode;
|
152 |
-
rzpLogInfo(json_encode($logObj));
|
153 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
|
|
|
|
155 |
} else {
|
156 |
-
$
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
$logObj['response'] = $response;
|
161 |
$logObj['status_code'] = $statusCode;
|
162 |
rzpLogInfo(json_encode($logObj));
|
163 |
}
|
164 |
|
165 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
}
|
54 |
rzpLogInfo('Woocommerce order id:');
|
55 |
rzpLogInfo(json_encode($wcOrderId));
|
56 |
|
57 |
+
//check woocommerce cart abandonment recovery plugin is activated or not
|
58 |
if (is_plugin_active('woo-cart-abandonment-recovery/woo-cart-abandonment-recovery.php') && empty($customerEmail) == false) {
|
59 |
|
60 |
+
//save abandonment data
|
61 |
+
$result = saveWooCartAbandonmentRecoveryData($razorpayData);
|
62 |
|
63 |
+
return new WP_REST_Response($result['response'], $result['status_code']);
|
64 |
+
}
|
65 |
+
|
66 |
+
if (is_plugin_active('klaviyo/klaviyo.php') && empty($razorpayData['customer_details']['email']) == false) {
|
67 |
+
WC()->cart->empty_cart();
|
68 |
+
$cart1cc = create1ccCart($wcOrderId);
|
69 |
+
|
70 |
+
$cart = WC()->cart;
|
71 |
+
//Insert data for tracking started checkout.
|
72 |
+
$eventData = wck_build_cart_data($cart);
|
73 |
+
if (empty($eventData['$extra']['Items'])) {
|
74 |
+
$response['status'] = false;
|
75 |
+
$response['message'] = 'cart item not exist in kalviyo';
|
76 |
+
$statusCode = 400;
|
77 |
+
return new WP_REST_Response($response, $statusCode);
|
78 |
}
|
79 |
+
$eventData['$service'] = 'woocommerce';
|
80 |
+
unset($eventData['Tags']);
|
81 |
+
unset($eventData['Quantity']);
|
82 |
+
$email = $customerEmail;
|
83 |
+
|
84 |
+
//Get token from kalviyo plugin
|
85 |
+
$klaviyoApi = WooCommerceKlaviyo::instance();
|
86 |
+
$token = $klaviyoApi->options->get_klaviyo_option('klaviyo_public_api_key');
|
87 |
+
$eventObject = ['token' => $token, 'event' => '$started_checkout', 'customer_properties' => array('$email' => $email), 'properties' => $eventData];
|
88 |
+
$dataParam = json_encode($eventObject);
|
89 |
+
$data = base64_encode($dataParam);
|
90 |
+
$event = 'track';
|
91 |
+
|
92 |
+
$logObj['klaviyoData'] = $eventData;
|
93 |
+
//calling kalviyo plugin public api
|
94 |
+
$url = "https://a.klaviyo.com/api/" . $event . '?data=' . $data;
|
95 |
+
file_get_contents($url);
|
96 |
+
}
|
97 |
|
98 |
+
//check Abondonment cart lite plugin active or not
|
99 |
+
if (is_plugin_active('woocommerce-abandoned-cart/woocommerce-ac.php') && empty($razorpayData['customer_details']['email']) == false) {
|
100 |
+
//To verify whether the email id is already exist on WordPress
|
101 |
+
if (email_exists($razorpayData['customer_details']['email'])) {
|
102 |
+
$response['status'] = false;
|
103 |
+
$response['message'] = 'For Register user we can not insert data';
|
104 |
+
$statusCode = 400;
|
105 |
+
return new WP_REST_Response($response, $statusCode);
|
106 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
+
// Save Abondonment data for Abondonment cart lite
|
109 |
+
$result = saveWooAbandonmentCartLiteData($razorpayData, $wcOrderId);
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
+
return new WP_REST_Response($result['response'], $result['status_code']);
|
112 |
+
} else {
|
113 |
+
$response['status'] = false;
|
114 |
+
$response['message'] = 'Failed to insert data';
|
115 |
+
$statusCode = 400;
|
116 |
|
117 |
+
$logObj['response'] = $response;
|
118 |
+
$logObj['status_code'] = $statusCode;
|
119 |
+
rzpLogInfo(json_encode($logObj));
|
120 |
+
}
|
121 |
|
122 |
+
return new WP_REST_Response($response, $statusCode);
|
123 |
+
}
|
124 |
|
125 |
+
//Save abandonment data for woocommerce Abondonment cart lite plugin
|
126 |
+
function saveWooAbandonmentCartLiteData($razorpayData, $wcOrderId)
|
127 |
+
{
|
128 |
+
global $woocommerce;
|
129 |
+
global $wpdb;
|
130 |
+
$billingFirstName = $razorpayData['customer_details']['billing_address']['name'] ?? '';
|
131 |
+
$billingLastName = " ";
|
132 |
+
$billingZipcode = $razorpayData['customer_details']['billing_address']['zipcode'] ?? '';
|
133 |
+
$shippingZipcode = $razorpayData['customer_details']['shipping_address']['zipcode'] ?? '';
|
134 |
|
135 |
+
$shippingCharges = $razorpayData['shipping_fee'] / 100;
|
136 |
+
$email = $razorpayData['customer_details']['email'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
+
// Insert record in abandoned cart table for the guest user.
|
139 |
+
$userId = saveGuestUserDetails($billingFirstName, $billingLastName, $email, $billingZipcode, $shippingZipcode, $shippingCharges);
|
140 |
+
|
141 |
+
wcal_common::wcal_set_cart_session('user_id', $userId);
|
142 |
+
|
143 |
+
$currentTime = current_time('timestamp'); // phpcs:ignore
|
144 |
+
|
145 |
+
$results = checkUserIdExist($userId);
|
146 |
+
|
147 |
+
$cart = array();
|
148 |
+
|
149 |
+
$cart['cart'] = WC()->session->cart;
|
150 |
+
|
151 |
+
if (count($results) === 0) {
|
152 |
+
$getCookie = WC()->session->get_session_cookie();
|
153 |
+
|
154 |
+
$cartInfo = wp_json_encode($cart);
|
155 |
+
$recResults = checkRecordBySession($getCookie[0]);
|
156 |
+
|
157 |
+
if (get_post_meta($wcOrderId, 'abandoned_user_id', true) == '') {
|
158 |
+
add_post_meta($wcOrderId, 'abandoned_user_id', $userId);} else {
|
159 |
+
update_post_meta($wcOrderId, 'abandoned_user_id', $userId);
|
160 |
+
}
|
161 |
+
|
162 |
+
if (count($recResults) === 0) {
|
163 |
+
$abandoned_cart_id = saveUserDetails($userId, $cartInfo, $currentTime, $getCookie[0]);
|
164 |
+
|
165 |
+
wcal_common::wcal_set_cart_session('abandoned_cart_id_lite', $abandoned_cart_id);
|
166 |
+
|
167 |
+
insertCartInfo($userId, $cartInfo);
|
168 |
+
} else {
|
169 |
+
updateUserDetails($userId, $cartInfo, $currentTime, $getCookie[0]);
|
170 |
+
|
171 |
+
$get_abandoned_record = getAbandonedRecord($userId, $getCookie[0]);
|
172 |
+
|
173 |
+
if (count($get_abandoned_record) > 0) {
|
174 |
+
$abandoned_cart_id = $get_abandoned_record[0]->id;
|
175 |
+
wcal_common::wcal_set_cart_session('abandoned_cart_id_lite', $abandoned_cart_id);
|
176 |
}
|
177 |
|
178 |
+
insertCartInfo($userId, $cartInfo);
|
|
|
|
|
179 |
}
|
180 |
+
}
|
181 |
+
|
182 |
+
$response['status'] = true;
|
183 |
+
$response['message'] = 'Data successfully inserted for cart abandonment recovery lite';
|
184 |
+
$statusCode = 200;
|
185 |
+
$logObj['response'] = $response;
|
186 |
+
$logObj['status_code'] = $statusCode;
|
187 |
+
rzpLogInfo(json_encode($logObj));
|
188 |
+
|
189 |
+
return $logObj;
|
190 |
+
}
|
191 |
+
|
192 |
+
//Save abandonment data for woocommerce cart abandonment recovery plugin
|
193 |
+
function saveWooCartAbandonmentRecoveryData($razorpayData)
|
194 |
+
{
|
195 |
+
global $woocommerce;
|
196 |
+
global $wpdb;
|
197 |
+
$products = WC()->cart->get_cart();
|
198 |
+
$currentTime = current_time('Y-m-d H:i:s');
|
199 |
|
200 |
+
if (isset($razorpayData['shipping_fee'])) {
|
201 |
+
$cartTotal = $razorpayData['amount'] / 100 - $razorpayData['shipping_fee'] / 100;
|
202 |
} else {
|
203 |
+
$cartTotal = $razorpayData['amount'] / 100;
|
204 |
+
}
|
205 |
+
|
206 |
+
$otherFields = array(
|
207 |
+
'wcf_billing_company' => "",
|
208 |
+
'wcf_billing_address_1' => $razorpayData['customer_details']['billing_address']['line1'] ?? '',
|
209 |
+
'wcf_billing_address_2' => $razorpayData['customer_details']['billing_address']['line2'] ?? '',
|
210 |
+
'wcf_billing_state' => $razorpayData['customer_details']['billing_address']['state'] ?? '',
|
211 |
+
'wcf_billing_postcode' => $razorpayData['customer_details']['billing_address']['zipcode'] ?? '',
|
212 |
+
'wcf_shipping_first_name' => $razorpayData['customer_details']['billing_address']['name'] ?? '',
|
213 |
+
'wcf_shipping_last_name' => "",
|
214 |
+
'wcf_shipping_company' => "",
|
215 |
+
'wcf_shipping_country' => $razorpayData['customer_details']['shipping_address']['country'] ?? '',
|
216 |
+
'wcf_shipping_address_1' => $razorpayData['customer_details']['shipping_address']['line1'] ?? '',
|
217 |
+
'wcf_shipping_address_2' => $razorpayData['customer_details']['shipping_address']['line2'] ?? '',
|
218 |
+
'wcf_shipping_city' => $razorpayData['customer_details']['shipping_address']['city'] ?? '',
|
219 |
+
'wcf_shipping_state' => $razorpayData['customer_details']['shipping_address']['state'] ?? '',
|
220 |
+
'wcf_shipping_postcode' => $razorpayData['customer_details']['shipping_address']['zipcode'] ?? '',
|
221 |
+
'wcf_order_comments' => "",
|
222 |
+
'wcf_first_name' => $razorpayData['customer_details']['shipping_address']['name'] ?? '',
|
223 |
+
'wcf_last_name' => "",
|
224 |
+
'wcf_phone_number' => $razorpayData['customer_details']['shipping_address']['contact'] ?? '', 'wcf_location' => $razorpayData['customer_details']['shipping_address']['country'] ?? '',
|
225 |
+
);
|
226 |
+
|
227 |
+
$checkoutDetails = array(
|
228 |
+
'email' => $razorpayData['customer_details']['email'] ?? $customerEmail,
|
229 |
+
'cart_contents' => serialize($products),
|
230 |
+
'cart_total' => sanitize_text_field($cartTotal),
|
231 |
+
'time' => $currentTime,
|
232 |
+
'other_fields' => serialize($otherFields),
|
233 |
+
'checkout_id' => wc_get_page_id('cart'),
|
234 |
+
);
|
235 |
+
|
236 |
+
$sessionId = WC()->session->get('wcf_session_id');
|
237 |
+
|
238 |
+
$cartAbandonmentTable = $wpdb->prefix . "cartflows_ca_cart_abandonment";
|
239 |
+
|
240 |
+
$logObj['checkoutDetails'] = $checkoutDetails;
|
241 |
+
|
242 |
+
if (empty($checkoutDetails) == false) {
|
243 |
+
$result = $wpdb->get_row(
|
244 |
+
$wpdb->prepare('SELECT * FROM `' . $cartAbandonmentTable . '` WHERE session_id = %s and order_status IN (%s, %s)', $sessionId, 'normal', 'abandoned') // phpcs:ignore
|
245 |
+
);
|
246 |
+
|
247 |
+
if (isset($result)) {
|
248 |
+
$wpdb->update(
|
249 |
+
$cartAbandonmentTable,
|
250 |
+
$checkoutDetails,
|
251 |
+
array('session_id' => $sessionId)
|
252 |
+
);
|
253 |
+
if ($wpdb->last_error) {
|
254 |
+
$response['status'] = false;
|
255 |
+
$response['message'] = $wpdb->last_error;
|
256 |
+
$statusCode = 400;
|
257 |
+
} else {
|
258 |
+
$response['status'] = true;
|
259 |
+
$response['message'] = 'Data successfully updated for wooCommerce cart abandonment recovery';
|
260 |
+
$statusCode = 200;
|
261 |
+
}
|
262 |
+
|
263 |
+
} else {
|
264 |
+
$sessionId = md5(uniqid(wp_rand(), true));
|
265 |
+
$checkoutDetails['session_id'] = sanitize_text_field($sessionId);
|
266 |
+
|
267 |
+
// Inserting row into Database.
|
268 |
+
$wpdb->insert(
|
269 |
+
$cartAbandonmentTable,
|
270 |
+
$checkoutDetails
|
271 |
+
);
|
272 |
+
|
273 |
+
if ($wpdb->last_error) {
|
274 |
+
$response['status'] = false;
|
275 |
+
$response['message'] = $wpdb->last_error;
|
276 |
+
$statusCode = 400;
|
277 |
+
} else {
|
278 |
+
// Storing session_id in WooCommerce session.
|
279 |
+
WC()->session->set('wcf_session_id', $sessionId);
|
280 |
+
$response['status'] = true;
|
281 |
+
$response['message'] = 'Data successfully inserted for wooCommerce cart abandonment recovery';
|
282 |
+
$statusCode = 200;
|
283 |
+
}
|
284 |
+
}
|
285 |
|
286 |
$logObj['response'] = $response;
|
287 |
$logObj['status_code'] = $statusCode;
|
288 |
rzpLogInfo(json_encode($logObj));
|
289 |
}
|
290 |
|
291 |
+
return $logObj;
|
292 |
+
}
|
293 |
+
|
294 |
+
//Insert abandonment data into guest user history
|
295 |
+
function saveGuestUserDetails($firstName, $lastName, $email, $billingZipcode, $shippingZipcode, $shippingCharges)
|
296 |
+
{
|
297 |
+
global $woocommerce;
|
298 |
+
global $wpdb;
|
299 |
+
$wpdb->query( // phpcs:ignore
|
300 |
+
$wpdb->prepare(
|
301 |
+
'INSERT INTO `' . $wpdb->prefix . 'ac_guest_abandoned_cart_history_lite`( billing_first_name, billing_last_name, email_id, billing_zipcode, shipping_zipcode, shipping_charges ) VALUES ( %s, %s, %s, %s, %s, %s )',
|
302 |
+
$firstName,
|
303 |
+
$lastName,
|
304 |
+
$email,
|
305 |
+
$billingZipcode,
|
306 |
+
$shippingZipcode,
|
307 |
+
$shippingCharges
|
308 |
+
)
|
309 |
+
);
|
310 |
+
|
311 |
+
return $wpdb->insert_id;
|
312 |
+
}
|
313 |
|
314 |
+
//Update usermeta
|
315 |
+
function insertCartInfo($userId, $cartInfo)
|
316 |
+
{
|
317 |
+
global $woocommerce;
|
318 |
+
global $wpdb;
|
319 |
+
$wpdb->query( // phpcs:ignore
|
320 |
+
$wpdb->prepare(
|
321 |
+
'INSERT INTO `' . $wpdb->prefix . 'usermeta`( user_id, meta_key, meta_value ) VALUES ( %s, %s, %s )',
|
322 |
+
$userId,
|
323 |
+
'_woocommerce_persistent_cart',
|
324 |
+
$cartInfo
|
325 |
+
)
|
326 |
+
);
|
327 |
+
}
|
328 |
+
|
329 |
+
//Update abandonment cart data
|
330 |
+
function updateUserDetails($userId, $cartInfo, $currentTime, $cookie)
|
331 |
+
{
|
332 |
+
global $woocommerce;
|
333 |
+
global $wpdb;
|
334 |
+
$wpdb->query( // phpcS:ignore
|
335 |
+
$wpdb->prepare(
|
336 |
+
'UPDATE `' . $wpdb->prefix . 'ac_abandoned_cart_history_lite` SET user_id = %s, abandoned_cart_info = %s, abandoned_cart_time = %s WHERE session_id = %s AND cart_ignored = %s',
|
337 |
+
$userId,
|
338 |
+
$cartInfo,
|
339 |
+
$currentTime,
|
340 |
+
$cookie,
|
341 |
+
0
|
342 |
+
)
|
343 |
+
);
|
344 |
+
}
|
345 |
+
|
346 |
+
//Insert abandonment data into cart history
|
347 |
+
function saveUserDetails($userId, $cartInfo, $time, $cookie)
|
348 |
+
{
|
349 |
+
global $woocommerce;
|
350 |
+
global $wpdb;
|
351 |
+
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
352 |
+
$wpdb->query(
|
353 |
+
$wpdb->prepare(
|
354 |
+
'INSERT INTO `' . $wpdb->prefix . 'ac_abandoned_cart_history_lite`( user_id, abandoned_cart_info, abandoned_cart_time, cart_ignored, recovered_cart, user_type, session_id ) VALUES ( %s, %s, %s, %s, %s, %s, %s )',
|
355 |
+
$userId,
|
356 |
+
$cartInfo,
|
357 |
+
$time,
|
358 |
+
0,
|
359 |
+
0,
|
360 |
+
'GUEST',
|
361 |
+
$cookie
|
362 |
+
)
|
363 |
+
);
|
364 |
+
|
365 |
+
return $wpdb->insert_id;
|
366 |
+
}
|
367 |
+
|
368 |
+
//Get record by userid and session
|
369 |
+
function getAbandonedRecord($userId, $cookie)
|
370 |
+
{
|
371 |
+
global $woocommerce;
|
372 |
+
global $wpdb;
|
373 |
+
$get_abandoned_record = $wpdb->get_results( // phpcS:ignore
|
374 |
+
$wpdb->prepare(
|
375 |
+
'SELECT * FROM `' . $wpdb->prefix . 'ac_abandoned_cart_history_lite` WHERE user_id = %d AND cart_ignored = %s AND session_id = %s',
|
376 |
+
$userId,
|
377 |
+
0,
|
378 |
+
$cookie
|
379 |
+
)
|
380 |
+
);
|
381 |
+
|
382 |
+
return $get_abandoned_record;
|
383 |
+
}
|
384 |
+
|
385 |
+
//Check record already exist or not
|
386 |
+
function checkUserIdExist($userId)
|
387 |
+
{
|
388 |
+
global $woocommerce;
|
389 |
+
global $wpdb;
|
390 |
+
$results = $wpdb->get_results( // phpcs:ignore
|
391 |
+
$wpdb->prepare(
|
392 |
+
'SELECT * FROM `' . $wpdb->prefix . 'ac_abandoned_cart_history_lite` WHERE user_id = %d AND cart_ignored = %s AND recovered_cart = %s AND user_type = %s',
|
393 |
+
$userId,
|
394 |
+
0,
|
395 |
+
0,
|
396 |
+
'GUEST'
|
397 |
+
)
|
398 |
+
);
|
399 |
+
|
400 |
+
return $results;
|
401 |
+
}
|
402 |
+
|
403 |
+
//Get record by session
|
404 |
+
function checkRecordBySession($cookie)
|
405 |
+
{
|
406 |
+
global $woocommerce;
|
407 |
+
global $wpdb;
|
408 |
+
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
409 |
+
$results = $wpdb->get_results(
|
410 |
+
$wpdb->prepare(
|
411 |
+
'SELECT * FROM `' . $wpdb->prefix . 'ac_abandoned_cart_history_lite` WHERE session_id LIKE %s AND cart_ignored = %s AND recovered_cart = %s',
|
412 |
+
$cookie,
|
413 |
+
0,
|
414 |
+
0
|
415 |
+
)
|
416 |
+
);
|
417 |
+
|
418 |
+
return $results;
|
419 |
}
|
includes/api/shipping-info.php
CHANGED
@@ -472,13 +472,14 @@ function smartCodRestriction($addresses, $order)
|
|
472 |
}
|
473 |
|
474 |
// country based restriction
|
|
|
475 |
if (!empty($restriction['country_restrictions'])) {
|
476 |
if ($restrictionSettings->country_restrictions === 0) {
|
477 |
-
if (in_array($
|
478 |
return false;
|
479 |
}
|
480 |
} else {
|
481 |
-
if (!in_array($
|
482 |
return false;
|
483 |
}
|
484 |
}
|
@@ -486,7 +487,7 @@ function smartCodRestriction($addresses, $order)
|
|
486 |
|
487 |
// state based restriction
|
488 |
$stateCode = normalizeWcStateCode($addresses['state_code']);
|
489 |
-
$state = $
|
490 |
if (!empty($restriction['state_restrictions'])) {
|
491 |
if ($restrictionSettings->state_restrictions === 0) {
|
492 |
if (in_array($state, $restriction['state_restrictions'])) {
|
472 |
}
|
473 |
|
474 |
// country based restriction
|
475 |
+
$country = strtoupper($addresses['country']);
|
476 |
if (!empty($restriction['country_restrictions'])) {
|
477 |
if ($restrictionSettings->country_restrictions === 0) {
|
478 |
+
if (in_array($country, $restriction['country_restrictions'])) {
|
479 |
return false;
|
480 |
}
|
481 |
} else {
|
482 |
+
if (!in_array($country, $restriction['country_restrictions'])) {
|
483 |
return false;
|
484 |
}
|
485 |
}
|
487 |
|
488 |
// state based restriction
|
489 |
$stateCode = normalizeWcStateCode($addresses['state_code']);
|
490 |
+
$state = $country . '_' . $stateCode;
|
491 |
if (!empty($restriction['state_restrictions'])) {
|
492 |
if ($restrictionSettings->state_restrictions === 0) {
|
493 |
if (in_array($state, $restriction['state_restrictions'])) {
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: razorpay
|
|
3 |
Tags: razorpay, payments, india, woocommerce, ecommerce
|
4 |
Requires at least: 3.9.2
|
5 |
Tested up to: 5.9
|
6 |
-
Stable tag: 3.
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -41,6 +41,11 @@ This is compatible with WooCommerce>=2.4, including the new 3.0 release. It has
|
|
41 |
|
42 |
== Changelog ==
|
43 |
|
|
|
|
|
|
|
|
|
|
|
44 |
= 3.6.0 =
|
45 |
* New webhook event i.e payment.pending has been added to handle the magic checkout COD orders
|
46 |
|
3 |
Tags: razorpay, payments, india, woocommerce, ecommerce
|
4 |
Requires at least: 3.9.2
|
5 |
Tested up to: 5.9
|
6 |
+
Stable tag: 3.7.0
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
41 |
|
42 |
== Changelog ==
|
43 |
|
44 |
+
= 3.7.0 =
|
45 |
+
* Magic Checkout support for Klaviyo plugin.
|
46 |
+
* Bug fix for warning message on place order and callback script.
|
47 |
+
* Bug fix in smart cod support in magic checkout.
|
48 |
+
|
49 |
= 3.6.0 =
|
50 |
* New webhook event i.e payment.pending has been added to handle the magic checkout COD orders
|
51 |
|
woo-razorpay.php
CHANGED
@@ -3,8 +3,8 @@
|
|
3 |
* Plugin Name: Razorpay for WooCommerce
|
4 |
* Plugin URI: https://razorpay.com
|
5 |
* Description: Razorpay Payment Gateway Integration for WooCommerce
|
6 |
-
* Version: 3.
|
7 |
-
* Stable tag: 3.
|
8 |
* Author: Team Razorpay
|
9 |
* WC tested up to: 6.4.1
|
10 |
* Author URI: https://razorpay.com
|
@@ -524,8 +524,6 @@ function woocommerce_razorpay_init()
|
|
524 |
{
|
525 |
$razorpayOrderId = get_transient($sessionKey);
|
526 |
rzpLogInfo("razorpayOrderId $razorpayOrderId | sessionKey $sessionKey");
|
527 |
-
rzpLogInfo("verifying amt");
|
528 |
-
rzpLogInfo($this->verifyOrderAmount($razorpayOrderId, $orderId));
|
529 |
// If we don't have an Order
|
530 |
// or the if the order is present in transient but doesn't match what we have saved
|
531 |
if (($razorpayOrderId === false) or
|
@@ -1072,22 +1070,26 @@ EOT;
|
|
1072 |
global $wpdb;
|
1073 |
|
1074 |
$order = false;
|
1075 |
-
rzpLogInfo("Called check_razorpay_response");
|
1076 |
|
1077 |
$post_type = 'shop_order';
|
1078 |
|
1079 |
$post_password = sanitize_text_field($_GET['order_key']);
|
1080 |
|
1081 |
-
|
1082 |
|
1083 |
-
|
|
|
|
|
1084 |
{
|
1085 |
-
$orderId = $
|
1086 |
|
1087 |
-
|
|
|
|
|
|
|
1088 |
|
1089 |
$order = wc_get_order($orderId);
|
1090 |
-
rzpLogInfo("
|
1091 |
}
|
1092 |
|
1093 |
// TODO: Handle redirect
|
@@ -1538,6 +1540,12 @@ EOT;
|
|
1538 |
$order->save();
|
1539 |
}
|
1540 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1541 |
$note = __('Order placed through Razorpay Magic Checkout');
|
1542 |
$order->add_order_note( $note );
|
1543 |
}
|
@@ -1638,6 +1646,67 @@ EOT;
|
|
1638 |
update_user_meta($order->get_user_id(), $addressKeyPrefix . 'state', $stateValue);
|
1639 |
}
|
1640 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1641 |
protected function handleErrorCase(& $order)
|
1642 |
{
|
1643 |
$orderId = $order->get_order_number();
|
3 |
* Plugin Name: Razorpay for WooCommerce
|
4 |
* Plugin URI: https://razorpay.com
|
5 |
* Description: Razorpay Payment Gateway Integration for WooCommerce
|
6 |
+
* Version: 3.7.0
|
7 |
+
* Stable tag: 3.7.0
|
8 |
* Author: Team Razorpay
|
9 |
* WC tested up to: 6.4.1
|
10 |
* Author URI: https://razorpay.com
|
524 |
{
|
525 |
$razorpayOrderId = get_transient($sessionKey);
|
526 |
rzpLogInfo("razorpayOrderId $razorpayOrderId | sessionKey $sessionKey");
|
|
|
|
|
527 |
// If we don't have an Order
|
528 |
// or the if the order is present in transient but doesn't match what we have saved
|
529 |
if (($razorpayOrderId === false) or
|
1070 |
global $wpdb;
|
1071 |
|
1072 |
$order = false;
|
|
|
1073 |
|
1074 |
$post_type = 'shop_order';
|
1075 |
|
1076 |
$post_password = sanitize_text_field($_GET['order_key']);
|
1077 |
|
1078 |
+
rzpLogInfo("Called check_razorpay_response: $post_password");
|
1079 |
|
1080 |
+
$postData = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_status FROM $wpdb->posts AS P WHERE post_type=%s AND post_password = %s", $post_type, $post_password ) );
|
1081 |
+
|
1082 |
+
if (count($postData[0]) > 0)
|
1083 |
{
|
1084 |
+
$orderId = $postData[0]->ID;
|
1085 |
|
1086 |
+
if($postData[0]->post_status == 'draft')
|
1087 |
+
{
|
1088 |
+
updateOrderStatus($orderId, 'wc-pending');
|
1089 |
+
}
|
1090 |
|
1091 |
$order = wc_get_order($orderId);
|
1092 |
+
rzpLogInfo("Get order id in check_razorpay_response: orderId $orderId");
|
1093 |
}
|
1094 |
|
1095 |
// TODO: Handle redirect
|
1540 |
$order->save();
|
1541 |
}
|
1542 |
|
1543 |
+
//For abandon cart Lite recovery plugin recovery function
|
1544 |
+
if(is_plugin_active( 'woocommerce-abandoned-cart/woocommerce-ac.php'))
|
1545 |
+
{
|
1546 |
+
$this->updateRecoverCartInfo($wcOrderId);
|
1547 |
+
}
|
1548 |
+
|
1549 |
$note = __('Order placed through Razorpay Magic Checkout');
|
1550 |
$order->add_order_note( $note );
|
1551 |
}
|
1646 |
update_user_meta($order->get_user_id(), $addressKeyPrefix . 'state', $stateValue);
|
1647 |
}
|
1648 |
|
1649 |
+
// Update Abandonment cart plugin table for recovered cart.
|
1650 |
+
protected function updateRecoverCartInfo($wcOrderId)
|
1651 |
+
{
|
1652 |
+
global $woocommerce;
|
1653 |
+
global $wpdb;
|
1654 |
+
|
1655 |
+
$userId = get_post_meta($wcOrderId, '_customer_user', true);
|
1656 |
+
$currentTime = current_time('timestamp'); // phpcs:ignore
|
1657 |
+
$cutOffTime = get_option('ac_lite_cart_abandoned_time');
|
1658 |
+
|
1659 |
+
if (isset($cut_off_time))
|
1660 |
+
{
|
1661 |
+
$cartCutOffTime = intval($cutOffTime) * 60;
|
1662 |
+
}
|
1663 |
+
else
|
1664 |
+
{
|
1665 |
+
$cartCutOffTime = 60 * 60;
|
1666 |
+
}
|
1667 |
+
|
1668 |
+
$compareTime = $currentTime - $cutOffTime;
|
1669 |
+
if($userId > 0)
|
1670 |
+
{
|
1671 |
+
$userType = 'REGISTERED';
|
1672 |
+
}
|
1673 |
+
else
|
1674 |
+
{
|
1675 |
+
$userType = 'GUEST';
|
1676 |
+
$userId = get_post_meta($wcOrderId, 'abandoned_user_id', true);
|
1677 |
+
}
|
1678 |
+
|
1679 |
+
$results = $wpdb->get_results( // phpcs:ignore
|
1680 |
+
$wpdb->prepare(
|
1681 |
+
'SELECT * FROM `' . $wpdb->prefix . 'ac_abandoned_cart_history_lite` WHERE user_id = %s AND cart_ignored = %s AND recovered_cart = %s AND user_type = %s',
|
1682 |
+
$userId,
|
1683 |
+
0,
|
1684 |
+
0,
|
1685 |
+
$userType
|
1686 |
+
)
|
1687 |
+
);
|
1688 |
+
|
1689 |
+
if(count($results) > 0)
|
1690 |
+
{
|
1691 |
+
if(isset($results[0]->abandoned_cart_time) && $compareTime > $results[0]->abandoned_cart_time)
|
1692 |
+
{
|
1693 |
+
wcal_common::wcal_set_cart_session('abandoned_cart_id_lite', $results[0]->id);
|
1694 |
+
}
|
1695 |
+
}
|
1696 |
+
|
1697 |
+
$abandonedOrderId = wcal_common::wcal_get_cart_session('abandoned_cart_id_lite');
|
1698 |
+
|
1699 |
+
add_post_meta($wcOrderId, 'abandoned_id', $abandonedOrderId);
|
1700 |
+
$wpdb->query( // phpcS:ignore
|
1701 |
+
$wpdb->prepare(
|
1702 |
+
'UPDATE `' . $wpdb->prefix . 'ac_abandoned_cart_history_lite` SET recovered_cart = %s, cart_ignored = %s WHERE id = %s',
|
1703 |
+
$wcOrderId,
|
1704 |
+
'1',
|
1705 |
+
$abandonedOrderId
|
1706 |
+
)
|
1707 |
+
);
|
1708 |
+
}
|
1709 |
+
|
1710 |
protected function handleErrorCase(& $order)
|
1711 |
{
|
1712 |
$orderId = $order->get_order_number();
|