Version Description
- Support for Smart COD plugin in magic checkout.
- Payment title update for magic checkout COD orders.
- Bug fix for theme specific qty issue on magic checkout buy now checkout option.
Download this release
Release Info
Developer | razorpay |
Plugin | Razorpay for WooCommerce |
Version | 3.1.0 |
Comparing to | |
See all releases |
Code changes from version 3.0.1 to 3.1.0
- includes/api/coupon-apply.php +12 -10
- includes/api/coupon-get.php +7 -5
- includes/api/order.php +11 -0
- includes/api/shipping-info.php +285 -11
- readme.txt +6 -1
- templates/rzp-pdp-checkout-btn.php +10 -2
- woo-razorpay.php +33 -6
includes/api/coupon-apply.php
CHANGED
@@ -58,19 +58,21 @@ function applyCouponOnCart(WP_REST_Request $request)
|
|
58 |
|
59 |
return new WP_REST_Response($response, 400);
|
60 |
}
|
61 |
-
|
62 |
//check woo-discount-rule plugin disabling the coupons
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
$
|
68 |
-
|
69 |
-
|
|
|
70 |
|
71 |
-
|
72 |
|
73 |
-
|
|
|
74 |
}
|
75 |
}
|
76 |
|
58 |
|
59 |
return new WP_REST_Response($response, 400);
|
60 |
}
|
61 |
+
|
62 |
//check woo-discount-rule plugin disabling the coupons
|
63 |
+
if (is_plugin_active('woo-discount-rules/woo-discount-rules.php')) {
|
64 |
+
$discountOptions = get_option('woo-discount-config-v2', []);
|
65 |
+
if (!empty($discountOptions)) {
|
66 |
+
$isCouponEnabled = $discountOptions['disable_coupon_when_rule_applied'];
|
67 |
+
if ($isCouponEnabled == 'disable_coupon') {
|
68 |
+
$response["failure_reason"] = "Coupon feature disabled";
|
69 |
+
$response["failure_code"] = "INVALID_COUPON";
|
70 |
+
$logObj["response"] = $response;
|
71 |
|
72 |
+
rzpLogError(json_encode($logObj));
|
73 |
|
74 |
+
return new WP_REST_Response($response, 400);
|
75 |
+
}
|
76 |
}
|
77 |
}
|
78 |
|
includes/api/coupon-get.php
CHANGED
@@ -68,11 +68,13 @@ function getCouponList($request)
|
|
68 |
);
|
69 |
|
70 |
//check woo-discount-rule plugin disabling the coupons
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
$
|
|
|
|
|
76 |
}
|
77 |
}
|
78 |
|
68 |
);
|
69 |
|
70 |
//check woo-discount-rule plugin disabling the coupons
|
71 |
+
if (is_plugin_active('woo-discount-rules/woo-discount-rules.php')) {
|
72 |
+
$discountOptions = get_option('woo-discount-config-v2', []);
|
73 |
+
if (!empty($discountOptions)) {
|
74 |
+
$isCouponEnabled = $discountOptions['disable_coupon_when_rule_applied'];
|
75 |
+
if ($isCouponEnabled == 'disable_coupon') {
|
76 |
+
$args = array();
|
77 |
+
}
|
78 |
}
|
79 |
}
|
80 |
|
includes/api/order.php
CHANGED
@@ -115,6 +115,17 @@ function createWcOrder(WP_REST_Request $request)
|
|
115 |
$order = wc_get_order($orderId);
|
116 |
|
117 |
if ($order) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
//To remove by default shipping method added on order.
|
119 |
$items = (array) $order->get_items('shipping');
|
120 |
|
115 |
$order = wc_get_order($orderId);
|
116 |
|
117 |
if ($order) {
|
118 |
+
|
119 |
+
// To remove coupon added on order.
|
120 |
+
$coupons = $order->get_used_coupons();
|
121 |
+
if(!empty($coupons)){
|
122 |
+
foreach($coupons as $coupon){
|
123 |
+
$order->remove_coupon($coupon);
|
124 |
+
}
|
125 |
+
$couponCode = $coupons[0];
|
126 |
+
}
|
127 |
+
|
128 |
+
|
129 |
//To remove by default shipping method added on order.
|
130 |
$items = (array) $order->get_items('shipping');
|
131 |
|
includes/api/shipping-info.php
CHANGED
@@ -50,7 +50,7 @@ function calculateShipping1cc(WP_REST_Request $request)
|
|
50 |
}
|
51 |
|
52 |
if ($customerResponse) {
|
53 |
-
$response[] = shippingCalculatePackages1cc($address['id'], $orderId);
|
54 |
} else {
|
55 |
$response['failure_reason'] = 'Set customer shipping information failed';
|
56 |
$response['failure_code'] = 'VALIDATION_ERROR';
|
@@ -106,7 +106,7 @@ function shippingUpdateCustomerInformation1cc($params)
|
|
106 |
*
|
107 |
* @return mixed
|
108 |
*/
|
109 |
-
function shippingCalculatePackages1cc($id, $orderId)
|
110 |
{
|
111 |
// Get packages for the cart.
|
112 |
$packages = WC()->cart->get_shipping_packages();
|
@@ -143,7 +143,7 @@ function shippingCalculatePackages1cc($id, $orderId)
|
|
143 |
}
|
144 |
$calculatedPackages = wc()->shipping()->calculate_shipping($packages);
|
145 |
|
146 |
-
return getItemResponse1cc($calculatedPackages, $id, $vendorId, $orderId);
|
147 |
}
|
148 |
|
149 |
/**
|
@@ -152,7 +152,7 @@ function shippingCalculatePackages1cc($id, $orderId)
|
|
152 |
* @param array $package WooCommerce shipping packages.
|
153 |
* @return array
|
154 |
*/
|
155 |
-
function getItemResponse1cc($package, $id, $vendorId, $orderId)
|
156 |
{
|
157 |
|
158 |
// Add product names and quantities.
|
@@ -168,7 +168,7 @@ function getItemResponse1cc($package, $id, $vendorId, $orderId)
|
|
168 |
}
|
169 |
}
|
170 |
|
171 |
-
$shippingResponse = prepareRatesResponse1cc($package, $vendorId, $orderId);
|
172 |
|
173 |
$isServiceable = count($shippingResponse) > 0 ? true : false;
|
174 |
// TODO: also return 'state'?
|
@@ -191,7 +191,7 @@ function getItemResponse1cc($package, $id, $vendorId, $orderId)
|
|
191 |
* @param array $package Shipping package complete with rates from WooCommerce.
|
192 |
* @return array
|
193 |
*/
|
194 |
-
function prepareRatesResponse1cc($package, $vendorId, $orderId)
|
195 |
{
|
196 |
|
197 |
$response = array();
|
@@ -200,14 +200,14 @@ function prepareRatesResponse1cc($package, $vendorId, $orderId)
|
|
200 |
foreach ($vendorId as $id) {
|
201 |
$rates = $package[$id]['rates'];
|
202 |
foreach ($rates as $rate) {
|
203 |
-
$response[] = getRateResponse1cc($rate, $id, $orderId);
|
204 |
}
|
205 |
}
|
206 |
}
|
207 |
|
208 |
$rates = $package[0]['rates'];
|
209 |
foreach ($rates as $val) {
|
210 |
-
$response[] = getRateResponse1cc($val, "", $orderId);
|
211 |
}
|
212 |
|
213 |
if (empty($response) === true) {
|
@@ -245,7 +245,7 @@ function prepareRatesResponse1cc($package, $vendorId, $orderId)
|
|
245 |
* @return array
|
246 |
*/
|
247 |
|
248 |
-
function getRateResponse1cc($rate, $vendorId, $orderId)
|
249 |
{
|
250 |
|
251 |
return array_merge(
|
@@ -260,7 +260,7 @@ function getRateResponse1cc($rate, $vendorId, $orderId)
|
|
260 |
'method_id' => getRateProp1cc($rate, 'method_id'),
|
261 |
'meta_data' => getRateMetaData1cc($rate),
|
262 |
'vendor_id' => $vendorId,
|
263 |
-
'cod' => getCodShippingInfo1cc(getRateProp1cc($rate, 'instance_id'), getRateProp1cc($rate, 'method_id'), $orderId),
|
264 |
),
|
265 |
getStoreCurrencyResponse1cc()
|
266 |
);
|
@@ -271,7 +271,7 @@ function getRateResponse1cc($rate, $vendorId, $orderId)
|
|
271 |
*
|
272 |
* @returns bool
|
273 |
*/
|
274 |
-
function getCodShippingInfo1cc($instanceId, $methodId, $orderId)
|
275 |
{
|
276 |
|
277 |
global $woocommerce;
|
@@ -298,7 +298,13 @@ function getCodShippingInfo1cc($instanceId, $methodId, $orderId)
|
|
298 |
return false;
|
299 |
}
|
300 |
|
|
|
|
|
|
|
|
|
|
|
301 |
if (isset($availablePaymentMethods['cod'])) {
|
|
|
302 |
$shipping_method_ids_cod = $availablePaymentMethods['cod']->enable_for_methods;
|
303 |
|
304 |
foreach ($shipping_method_ids_cod as $shipping_method_id) {
|
@@ -317,6 +323,274 @@ function getCodShippingInfo1cc($instanceId, $methodId, $orderId)
|
|
317 |
return false;
|
318 |
}
|
319 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
320 |
/**
|
321 |
* Convert to paisa
|
322 |
* @returns int
|
50 |
}
|
51 |
|
52 |
if ($customerResponse) {
|
53 |
+
$response[] = shippingCalculatePackages1cc($address['id'], $orderId, $address);
|
54 |
} else {
|
55 |
$response['failure_reason'] = 'Set customer shipping information failed';
|
56 |
$response['failure_code'] = 'VALIDATION_ERROR';
|
106 |
*
|
107 |
* @return mixed
|
108 |
*/
|
109 |
+
function shippingCalculatePackages1cc($id, $orderId, $address)
|
110 |
{
|
111 |
// Get packages for the cart.
|
112 |
$packages = WC()->cart->get_shipping_packages();
|
143 |
}
|
144 |
$calculatedPackages = wc()->shipping()->calculate_shipping($packages);
|
145 |
|
146 |
+
return getItemResponse1cc($calculatedPackages, $id, $vendorId, $orderId, $address);
|
147 |
}
|
148 |
|
149 |
/**
|
152 |
* @param array $package WooCommerce shipping packages.
|
153 |
* @return array
|
154 |
*/
|
155 |
+
function getItemResponse1cc($package, $id, $vendorId, $orderId, $address)
|
156 |
{
|
157 |
|
158 |
// Add product names and quantities.
|
168 |
}
|
169 |
}
|
170 |
|
171 |
+
$shippingResponse = prepareRatesResponse1cc($package, $vendorId, $orderId, $address);
|
172 |
|
173 |
$isServiceable = count($shippingResponse) > 0 ? true : false;
|
174 |
// TODO: also return 'state'?
|
191 |
* @param array $package Shipping package complete with rates from WooCommerce.
|
192 |
* @return array
|
193 |
*/
|
194 |
+
function prepareRatesResponse1cc($package, $vendorId, $orderId, $address)
|
195 |
{
|
196 |
|
197 |
$response = array();
|
200 |
foreach ($vendorId as $id) {
|
201 |
$rates = $package[$id]['rates'];
|
202 |
foreach ($rates as $rate) {
|
203 |
+
$response[] = getRateResponse1cc($rate, $id, $orderId, $address);
|
204 |
}
|
205 |
}
|
206 |
}
|
207 |
|
208 |
$rates = $package[0]['rates'];
|
209 |
foreach ($rates as $val) {
|
210 |
+
$response[] = getRateResponse1cc($val, "", $orderId, $address);
|
211 |
}
|
212 |
|
213 |
if (empty($response) === true) {
|
245 |
* @return array
|
246 |
*/
|
247 |
|
248 |
+
function getRateResponse1cc($rate, $vendorId, $orderId, $address)
|
249 |
{
|
250 |
|
251 |
return array_merge(
|
260 |
'method_id' => getRateProp1cc($rate, 'method_id'),
|
261 |
'meta_data' => getRateMetaData1cc($rate),
|
262 |
'vendor_id' => $vendorId,
|
263 |
+
'cod' => getCodShippingInfo1cc(getRateProp1cc($rate, 'instance_id'), getRateProp1cc($rate, 'method_id'), $orderId, $address),
|
264 |
),
|
265 |
getStoreCurrencyResponse1cc()
|
266 |
);
|
271 |
*
|
272 |
* @returns bool
|
273 |
*/
|
274 |
+
function getCodShippingInfo1cc($instanceId, $methodId, $orderId, $address)
|
275 |
{
|
276 |
|
277 |
global $woocommerce;
|
298 |
return false;
|
299 |
}
|
300 |
|
301 |
+
//product and product catgaroy restriction for smart COD plugin
|
302 |
+
if (class_exists('Wc_Smart_Cod')) {
|
303 |
+
return smartCodRestriction($address, $order);
|
304 |
+
}
|
305 |
+
|
306 |
if (isset($availablePaymentMethods['cod'])) {
|
307 |
+
|
308 |
$shipping_method_ids_cod = $availablePaymentMethods['cod']->enable_for_methods;
|
309 |
|
310 |
foreach ($shipping_method_ids_cod as $shipping_method_id) {
|
323 |
return false;
|
324 |
}
|
325 |
|
326 |
+
/**
|
327 |
+
* product and product catgaroy restriction for smart COD plugin
|
328 |
+
*
|
329 |
+
* @returns bool
|
330 |
+
*/
|
331 |
+
function smartCodRestriction($addresses, $order)
|
332 |
+
{
|
333 |
+
$restriction = get_option('woocommerce_cod_settings');
|
334 |
+
$restrictionSettings = json_decode($restriction['restriction_settings']);
|
335 |
+
|
336 |
+
$items = WC()->cart->get_cart();
|
337 |
+
|
338 |
+
$products = [];
|
339 |
+
$restrictCount = 0;
|
340 |
+
foreach ($items as $key => $item) {
|
341 |
+
$id = isset($item['variation_id']) && $item['variation_id'] !== 0 ? $item['variation_id'] : $item['product_id'];
|
342 |
+
array_push($products, $id);
|
343 |
+
}
|
344 |
+
|
345 |
+
$productCount = WC()->cart->cart_contents_count;
|
346 |
+
$productVal = [];
|
347 |
+
|
348 |
+
if (empty($restriction['product_restriction'])) {
|
349 |
+
$productVal[0] = $restriction['product_restriction'];
|
350 |
+
} else {
|
351 |
+
$productVal = $restriction['product_restriction'];
|
352 |
+
}
|
353 |
+
|
354 |
+
foreach ($products as $product_id) {
|
355 |
+
if ($restrictionSettings->product_restriction === 0) {
|
356 |
+
if (in_array($product_id, $productVal)) {
|
357 |
+
if ($restriction['product_restriction_mode'] === 'one_product') {
|
358 |
+
return false;
|
359 |
+
} else {
|
360 |
+
$restrictCount++;
|
361 |
+
}
|
362 |
+
}
|
363 |
+
} else {
|
364 |
+
if (!in_array($product_id, $productVal)) {
|
365 |
+
if ($restriction['product_restriction_mode'] === 'all_products') {
|
366 |
+
return false;
|
367 |
+
} else {
|
368 |
+
$restrictCount++;
|
369 |
+
}
|
370 |
+
}
|
371 |
+
}
|
372 |
+
|
373 |
+
}
|
374 |
+
if ($restrictionSettings->product_restriction === 0) {
|
375 |
+
if ($restriction['product_restriction_mode'] === 'all_products' && $restrictCount === $productCount) {
|
376 |
+
return false;
|
377 |
+
}
|
378 |
+
} else {
|
379 |
+
if ($restriction['product_restriction_mode'] === 'one_product' && $restrictCount === $productCount) {
|
380 |
+
return false;
|
381 |
+
}
|
382 |
+
}
|
383 |
+
|
384 |
+
// product category based restriction
|
385 |
+
$restrictCatCount = 0;
|
386 |
+
$productCat = [];
|
387 |
+
foreach ($products as $product_id) {
|
388 |
+
$product = wc_get_product($product_id);
|
389 |
+
$type = $product->get_type();
|
390 |
+
if ($type === 'variation') {
|
391 |
+
$product = wc_get_product($product->get_parent_id());
|
392 |
+
}
|
393 |
+
|
394 |
+
$categoryIds = $product->get_category_ids();
|
395 |
+
|
396 |
+
if (empty($restriction['category_restriction'])) {
|
397 |
+
$productCat[0] = $restriction['category_restriction'];
|
398 |
+
} else {
|
399 |
+
$productCat = $restriction['category_restriction'];
|
400 |
+
}
|
401 |
+
if ($restrictionSettings->category_restriction === 0) {
|
402 |
+
if (array_intersect($categoryIds, $productCat)) {
|
403 |
+
if ($restriction['category_restriction_mode'] === 'one_product') {
|
404 |
+
return false;
|
405 |
+
} else {
|
406 |
+
$restrictCatCount++;
|
407 |
+
}
|
408 |
+
}
|
409 |
+
} else {
|
410 |
+
if (!array_intersect($categoryIds, $productCat)) {
|
411 |
+
if ($restriction['category_restriction_mode'] === 'all_product') {
|
412 |
+
return false;
|
413 |
+
} else {
|
414 |
+
$restrictCatCount++;
|
415 |
+
}
|
416 |
+
}
|
417 |
+
}
|
418 |
+
}
|
419 |
+
|
420 |
+
if ($restrictionSettings->category_restriction === 0) {
|
421 |
+
if ($restriction['category_restriction_mode'] === 'all_products' && $restrictCatCount === $productCount) {
|
422 |
+
return false;
|
423 |
+
}
|
424 |
+
} else {
|
425 |
+
if ($restriction['category_restriction_mode'] === 'one_product' && $restrictCatCount === $productCount) {
|
426 |
+
return false;
|
427 |
+
}
|
428 |
+
}
|
429 |
+
|
430 |
+
// zip code restriction
|
431 |
+
$postals = explode(',', trim($restriction['restrict_postals']));
|
432 |
+
$postals = array_map('trim', $postals);
|
433 |
+
$customerZipcode = $addresses['zipcode'];
|
434 |
+
|
435 |
+
foreach ($postals as $p) {
|
436 |
+
if (!$p) {
|
437 |
+
continue;
|
438 |
+
}
|
439 |
+
$prepare = explode('...', $p);
|
440 |
+
$count = count($prepare);
|
441 |
+
|
442 |
+
if ($count === 1) {
|
443 |
+
// single
|
444 |
+
if ($prepare[0] === $customerZipcode) {
|
445 |
+
if ($restrictionSettings->restrict_postals === 0) {
|
446 |
+
return false;
|
447 |
+
} else {
|
448 |
+
$flag = 1;
|
449 |
+
}
|
450 |
+
}
|
451 |
+
|
452 |
+
} elseif ($count === 2) {
|
453 |
+
// range
|
454 |
+
if (!is_numeric($prepare[0]) || !is_numeric($prepare[1]) || !is_numeric($customerZipcode)) {
|
455 |
+
continue;
|
456 |
+
}
|
457 |
+
|
458 |
+
if ($customerZipcode >= $prepare[0] && $customerZipcode <= $prepare[1]) {
|
459 |
+
if ($restrictionSettings->restrict_postals === 0) {
|
460 |
+
return false;
|
461 |
+
} else {
|
462 |
+
$flag = 1;
|
463 |
+
}
|
464 |
+
}
|
465 |
+
} else {
|
466 |
+
continue;
|
467 |
+
}
|
468 |
+
}
|
469 |
+
|
470 |
+
if ($restrictionSettings->restrict_postals === 1 && $flag !== 1) {
|
471 |
+
return false;
|
472 |
+
}
|
473 |
+
|
474 |
+
// country based restriction
|
475 |
+
if (!empty($restriction['country_restrictions'])) {
|
476 |
+
if ($restrictionSettings->country_restrictions === 0) {
|
477 |
+
if (in_array($addresses['country'], $restriction['country_restrictions'])) {
|
478 |
+
return false;
|
479 |
+
}
|
480 |
+
} else {
|
481 |
+
if (!in_array($addresses['country'], $restriction['country_restrictions'])) {
|
482 |
+
return false;
|
483 |
+
}
|
484 |
+
}
|
485 |
+
}
|
486 |
+
|
487 |
+
// state based restriction
|
488 |
+
$stateCode = normalizeWcStateCode($addresses['state_code']);
|
489 |
+
$state = $addresses['country'] . '_' . $stateCode;
|
490 |
+
if (!empty($restriction['state_restrictions'])) {
|
491 |
+
if ($restrictionSettings->state_restrictions === 0) {
|
492 |
+
if (in_array($state, $restriction['state_restrictions'])) {
|
493 |
+
return false;
|
494 |
+
}
|
495 |
+
} else {
|
496 |
+
if (!in_array($state, $restriction['state_restrictions'])) {
|
497 |
+
return false;
|
498 |
+
}
|
499 |
+
}
|
500 |
+
|
501 |
+
}
|
502 |
+
|
503 |
+
// city based restriction
|
504 |
+
if (!empty($restriction['city_restrictions'])) {
|
505 |
+
$cityRes = explode(',', trim($restriction['city_restrictions']));
|
506 |
+
$restrict = array_map('trim', $cityRes);
|
507 |
+
$cityRestriction = array_map('strtolower', $restrict);
|
508 |
+
if ($restrictionSettings->city_restrictions === 0) {
|
509 |
+
if (in_array($addresses['city'], $cityRestriction)) {
|
510 |
+
return false;
|
511 |
+
}
|
512 |
+
} else {
|
513 |
+
if (!in_array($addresses['city'], $cityRestriction)) {
|
514 |
+
return false;
|
515 |
+
}
|
516 |
+
}
|
517 |
+
|
518 |
+
}
|
519 |
+
|
520 |
+
// shipping zone based restriction
|
521 |
+
if (!empty($restriction['shipping_zone_restrictions'])) {
|
522 |
+
$items = WC()->cart->get_cart();
|
523 |
+
$package = WC()->cart->get_shipping_packages();
|
524 |
+
$customerShippingZone = WC_Shipping_Zones::get_zone_matching_package($package[0]);
|
525 |
+
if ($restrictionSettings->shipping_zone_restrictions === 0) {
|
526 |
+
if (in_array($customerShippingZone->get_id(), $restriction['shipping_zone_restrictions'])) {
|
527 |
+
return false;
|
528 |
+
}
|
529 |
+
} else {
|
530 |
+
if (!in_array($customerShippingZone->get_id(), $restriction['shipping_zone_restrictions'])) {
|
531 |
+
return false;
|
532 |
+
}
|
533 |
+
}
|
534 |
+
|
535 |
+
}
|
536 |
+
|
537 |
+
// user role restriction
|
538 |
+
$user = get_user_by('id', $order->get_user_id());
|
539 |
+
$role = !empty($user) ? $user->roles : [];
|
540 |
+
if (!empty($restriction['user_role_restriction']) && !empty($role)) {
|
541 |
+
if ($restrictionSettings->user_role_restriction === 0) {
|
542 |
+
if (array_intersect($restriction['user_role_restriction'], $role)) {
|
543 |
+
return false;
|
544 |
+
}
|
545 |
+
} else {
|
546 |
+
if (!array_intersect($restriction['user_role_restriction'], $role)) {
|
547 |
+
return false;
|
548 |
+
}
|
549 |
+
}
|
550 |
+
|
551 |
+
}
|
552 |
+
|
553 |
+
// shipping class restriction
|
554 |
+
if (!empty($restriction['shipping_class_restriction'])) {
|
555 |
+
$restrictClassCount = 0;
|
556 |
+
foreach ($products as $product_id) {
|
557 |
+
$product = wc_get_product($product_id);
|
558 |
+
$shippingClassId = $product->get_shipping_class_id();
|
559 |
+
if ($restrictionSettings->shipping_class_restriction === 0) {
|
560 |
+
if (in_array($shippingClassId, $restriction['shipping_class_restriction'])) {
|
561 |
+
if ($restriction['shipping_class_restriction_mode'] === 'one_product') {
|
562 |
+
return false;
|
563 |
+
} else {
|
564 |
+
$restrictClassCount++;
|
565 |
+
}
|
566 |
+
}
|
567 |
+
} else {
|
568 |
+
if (!in_array($shippingClassId, $restriction['shipping_class_restriction'])) {
|
569 |
+
if ($restriction['shipping_class_restriction_mode'] === 'all_products') {
|
570 |
+
return false;
|
571 |
+
} else {
|
572 |
+
$restrictClassCount++;
|
573 |
+
}
|
574 |
+
}
|
575 |
+
}
|
576 |
+
|
577 |
+
}
|
578 |
+
|
579 |
+
if ($restrictionSettings->shipping_class_restriction === 0) {
|
580 |
+
if ($restriction['shipping_class_restriction_mode'] === 'all_products' && $restrictClassCount === $productCount) {
|
581 |
+
return false;
|
582 |
+
}
|
583 |
+
} else {
|
584 |
+
if ($restriction['shipping_class_restriction_mode'] === 'one_product' && $restrictClassCount === $productCount) {
|
585 |
+
return false;
|
586 |
+
}
|
587 |
+
}
|
588 |
+
|
589 |
+
}
|
590 |
+
|
591 |
+
return true;
|
592 |
+
}
|
593 |
+
|
594 |
/**
|
595 |
* Convert to paisa
|
596 |
* @returns int
|
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.0
|
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.0.1 =
|
45 |
* Bug fix for Stock Management issue on magic checkout buy now option.
|
46 |
* Bug fix for Cart page checkout style issue on magic checkout.
|
3 |
Tags: razorpay, payments, india, woocommerce, ecommerce
|
4 |
Requires at least: 3.9.2
|
5 |
Tested up to: 5.9
|
6 |
+
Stable tag: 3.1.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.1.0 =
|
45 |
+
* Support for Smart COD plugin in magic checkout.
|
46 |
+
* Payment title update for magic checkout COD orders.
|
47 |
+
* Bug fix for theme specific qty issue on magic checkout buy now checkout option.
|
48 |
+
|
49 |
= 3.0.1 =
|
50 |
* Bug fix for Stock Management issue on magic checkout buy now option.
|
51 |
* Bug fix for Cart page checkout style issue on magic checkout.
|
templates/rzp-pdp-checkout-btn.php
CHANGED
@@ -22,7 +22,11 @@ $productData = wp_json_encode(['id' => $product->get_id(), 'quantity' => 1]);
|
|
22 |
</div>
|
23 |
|
24 |
<script type="">
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
var btnPdp = document.getElementById('btn-1cc-pdp');
|
28 |
|
@@ -30,7 +34,11 @@ $productData = wp_json_encode(['id' => $product->get_id(), 'quantity' => 1]);
|
|
30 |
|
31 |
jQuery('.qty').on('change',function(e)
|
32 |
{
|
33 |
-
|
|
|
|
|
|
|
|
|
34 |
btnPdp.setAttribute('quantity', quantity);
|
35 |
|
36 |
if(quantity <= 0)
|
22 |
</div>
|
23 |
|
24 |
<script type="">
|
25 |
+
let i = 0;
|
26 |
+
while (typeof quantity === 'undefined') {
|
27 |
+
var quantity = document.getElementsByClassName("qty")[i].value;
|
28 |
+
i++;
|
29 |
+
}
|
30 |
|
31 |
var btnPdp = document.getElementById('btn-1cc-pdp');
|
32 |
|
34 |
|
35 |
jQuery('.qty').on('change',function(e)
|
36 |
{
|
37 |
+
let i = 0;
|
38 |
+
while (typeof quantity === 'undefined') {
|
39 |
+
var quantity = document.getElementsByClassName("qty")[i].value;
|
40 |
+
i++;
|
41 |
+
}
|
42 |
btnPdp.setAttribute('quantity', quantity);
|
43 |
|
44 |
if(quantity <= 0)
|
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.0
|
7 |
-
* Stable tag: 3.0
|
8 |
* Author: Team Razorpay
|
9 |
* WC tested up to: 6.2.1
|
10 |
* Author URI: https://razorpay.com
|
@@ -528,13 +528,15 @@ function woocommerce_razorpay_init()
|
|
528 |
public function createOrGetRazorpayOrderId($orderId, $is1ccCheckout = 'no')
|
529 |
{
|
530 |
global $woocommerce;
|
531 |
-
rzpLogInfo("createOrGetRazorpayOrderId $orderId");
|
532 |
|
533 |
$create = false;
|
534 |
|
535 |
if($is1ccCheckout == 'no')
|
536 |
{
|
537 |
update_post_meta( $orderId, 'is_magic_checkout_order', 'no' );
|
|
|
|
|
538 |
}
|
539 |
|
540 |
$sessionKey = $this->getOrderSessionKey($orderId);
|
@@ -847,9 +849,12 @@ function woocommerce_razorpay_init()
|
|
847 |
}
|
848 |
}
|
849 |
|
|
|
|
|
850 |
if (is1ccEnabled() && !empty($is1ccOrder) && $is1ccOrder == 'yes')
|
851 |
{
|
852 |
$data = $this->orderArg1CC($data, $order);
|
|
|
853 |
}
|
854 |
|
855 |
return $data;
|
@@ -1100,6 +1105,8 @@ EOT;
|
|
1100 |
// TODO: Add test mode condition
|
1101 |
if (is1ccEnabled())
|
1102 |
{
|
|
|
|
|
1103 |
wp_redirect(wc_get_cart_url());
|
1104 |
exit;
|
1105 |
}
|
@@ -1111,6 +1118,8 @@ EOT;
|
|
1111 |
// redirect user to success page
|
1112 |
if ($order->needs_payment() === false)
|
1113 |
{
|
|
|
|
|
1114 |
$cartHash = get_transient(RZP_1CC_CART_HASH.$orderId);
|
1115 |
|
1116 |
if ($cartHash != false)
|
@@ -1289,11 +1298,17 @@ EOT;
|
|
1289 |
|
1290 |
$is1ccOrder = get_post_meta( $wcOrderId, 'is_magic_checkout_order', true );
|
1291 |
|
|
|
|
|
1292 |
if (is1ccEnabled() && !empty($is1ccOrder) && $is1ccOrder == 'yes')
|
1293 |
{
|
|
|
|
|
1294 |
//To verify whether the 1cc update order function already under execution or not
|
1295 |
if(get_transient('wc_order_under_process_'.$wcOrderId) === false)
|
1296 |
{
|
|
|
|
|
1297 |
$this->update1ccOrderWC($order, $wcOrderId, $razorpayPaymentId);
|
1298 |
}
|
1299 |
|
@@ -1401,6 +1416,9 @@ EOT;
|
|
1401 |
// TODO: Test if individual use coupon fails by hardcoding here
|
1402 |
$isApplied = $order->apply_coupon($couponKey);
|
1403 |
$order->save();
|
|
|
|
|
|
|
1404 |
}
|
1405 |
|
1406 |
//Apply shipping charges to woo-order
|
@@ -1490,6 +1508,7 @@ EOT;
|
|
1490 |
|
1491 |
// set default payment method
|
1492 |
$payment_method = $this->id;
|
|
|
1493 |
|
1494 |
// To verify the payment method for particular payment id.
|
1495 |
$razorpayPyamentData = $api->payment->fetch($razorpayPaymentId);
|
@@ -1500,11 +1519,12 @@ EOT;
|
|
1500 |
{
|
1501 |
$codKey = $razorpayData['cod_fee']/100;
|
1502 |
$payment_method = 'cod';
|
|
|
1503 |
}
|
1504 |
|
1505 |
//update payment method title
|
1506 |
$order->set_payment_method($payment_method);
|
1507 |
-
$order->set_payment_method_title($
|
1508 |
$order->save();
|
1509 |
|
1510 |
if (($paymentDoneBy === 'cod') && isset($razorpayData['cod_fee']) == true)
|
@@ -1534,6 +1554,9 @@ EOT;
|
|
1534 |
//To update customer address info to wc order.
|
1535 |
public function updateOrderAddress($razorpayData, $order)
|
1536 |
{
|
|
|
|
|
|
|
1537 |
if (isset($razorpayData['customer_details']['shipping_address']))
|
1538 |
{
|
1539 |
$shippingAddressKey = $razorpayData['customer_details']['shipping_address'];
|
@@ -1557,6 +1580,7 @@ EOT;
|
|
1557 |
$order->set_shipping_state($shippingStateCode);
|
1558 |
|
1559 |
$this->updateUserAddressInfo('shipping_', $shippingAddress, $shippingStateCode, $order);
|
|
|
1560 |
|
1561 |
if (empty($razorpayData['customer_details']['billing_address']) == false)
|
1562 |
{
|
@@ -1576,6 +1600,7 @@ EOT;
|
|
1576 |
$order->set_billing_state($billingStateCode);
|
1577 |
|
1578 |
$this->updateUserAddressInfo('billing_', $billingAddress, $billingStateCode, $order);
|
|
|
1579 |
}
|
1580 |
else
|
1581 |
{
|
@@ -1585,6 +1610,8 @@ EOT;
|
|
1585 |
$this->updateUserAddressInfo('billing_', $shippingAddress, $shippingStateCode, $order);
|
1586 |
}
|
1587 |
|
|
|
|
|
1588 |
$order->save();
|
1589 |
}
|
1590 |
}
|
@@ -1878,12 +1905,12 @@ function disable_coupon_field_on_cart($enabled)
|
|
1878 |
if (isTestModeEnabled()) {
|
1879 |
$current_user = wp_get_current_user();
|
1880 |
if ($current_user->has_cap( 'administrator' ) || preg_match( '/@razorpay.com$/i', $current_user->user_email )) {
|
1881 |
-
if (is_cart()
|
1882 |
$enabled = false;
|
1883 |
}
|
1884 |
}
|
1885 |
} else {
|
1886 |
-
if (is_cart()
|
1887 |
$enabled = false;
|
1888 |
}
|
1889 |
}
|
3 |
* Plugin Name: Razorpay for WooCommerce
|
4 |
* Plugin URI: https://razorpay.com
|
5 |
* Description: Razorpay Payment Gateway Integration for WooCommerce
|
6 |
+
* Version: 3.1.0
|
7 |
+
* Stable tag: 3.1.0
|
8 |
* Author: Team Razorpay
|
9 |
* WC tested up to: 6.2.1
|
10 |
* Author URI: https://razorpay.com
|
528 |
public function createOrGetRazorpayOrderId($orderId, $is1ccCheckout = 'no')
|
529 |
{
|
530 |
global $woocommerce;
|
531 |
+
rzpLogInfo("createOrGetRazorpayOrderId $orderId and is1ccCheckout is set to $is1ccCheckout");
|
532 |
|
533 |
$create = false;
|
534 |
|
535 |
if($is1ccCheckout == 'no')
|
536 |
{
|
537 |
update_post_meta( $orderId, 'is_magic_checkout_order', 'no' );
|
538 |
+
|
539 |
+
rzpLogInfo("Called createOrGetRazorpayOrderId with params orderId $orderId and is_magic_checkout_order is set to no");
|
540 |
}
|
541 |
|
542 |
$sessionKey = $this->getOrderSessionKey($orderId);
|
849 |
}
|
850 |
}
|
851 |
|
852 |
+
rzpLogInfo("Called getOrderCreationData with params orderId $orderId and is1ccOrder is set to $is1ccOrder");
|
853 |
+
|
854 |
if (is1ccEnabled() && !empty($is1ccOrder) && $is1ccOrder == 'yes')
|
855 |
{
|
856 |
$data = $this->orderArg1CC($data, $order);
|
857 |
+
rzpLogInfo("Called getOrderCreationData with params orderId $orderId and adding line_items_total");
|
858 |
}
|
859 |
|
860 |
return $data;
|
1105 |
// TODO: Add test mode condition
|
1106 |
if (is1ccEnabled())
|
1107 |
{
|
1108 |
+
rzpLogInfo("Order details not found for the orderId: $orderId");
|
1109 |
+
|
1110 |
wp_redirect(wc_get_cart_url());
|
1111 |
exit;
|
1112 |
}
|
1118 |
// redirect user to success page
|
1119 |
if ($order->needs_payment() === false)
|
1120 |
{
|
1121 |
+
rzpLogInfo("Order payment is already done for the orderId: $orderId");
|
1122 |
+
|
1123 |
$cartHash = get_transient(RZP_1CC_CART_HASH.$orderId);
|
1124 |
|
1125 |
if ($cartHash != false)
|
1298 |
|
1299 |
$is1ccOrder = get_post_meta( $wcOrderId, 'is_magic_checkout_order', true );
|
1300 |
|
1301 |
+
rzpLogInfo("Order details check initiated step 1 for the orderId: $wcOrderId");
|
1302 |
+
|
1303 |
if (is1ccEnabled() && !empty($is1ccOrder) && $is1ccOrder == 'yes')
|
1304 |
{
|
1305 |
+
rzpLogInfo("Order details update initiated step 1 for the orderId: $wcOrderId");
|
1306 |
+
|
1307 |
//To verify whether the 1cc update order function already under execution or not
|
1308 |
if(get_transient('wc_order_under_process_'.$wcOrderId) === false)
|
1309 |
{
|
1310 |
+
rzpLogInfo("Order details update initiated step 2 for the orderId: $wcOrderId");
|
1311 |
+
|
1312 |
$this->update1ccOrderWC($order, $wcOrderId, $razorpayPaymentId);
|
1313 |
}
|
1314 |
|
1416 |
// TODO: Test if individual use coupon fails by hardcoding here
|
1417 |
$isApplied = $order->apply_coupon($couponKey);
|
1418 |
$order->save();
|
1419 |
+
|
1420 |
+
rzpLogInfo("Coupon details updated for orderId: $wcOrderId");
|
1421 |
+
|
1422 |
}
|
1423 |
|
1424 |
//Apply shipping charges to woo-order
|
1508 |
|
1509 |
// set default payment method
|
1510 |
$payment_method = $this->id;
|
1511 |
+
$payment_method_title = $this->title;
|
1512 |
|
1513 |
// To verify the payment method for particular payment id.
|
1514 |
$razorpayPyamentData = $api->payment->fetch($razorpayPaymentId);
|
1519 |
{
|
1520 |
$codKey = $razorpayData['cod_fee']/100;
|
1521 |
$payment_method = 'cod';
|
1522 |
+
$payment_method_title = 'Cash on delivery';
|
1523 |
}
|
1524 |
|
1525 |
//update payment method title
|
1526 |
$order->set_payment_method($payment_method);
|
1527 |
+
$order->set_payment_method_title($payment_method_title);
|
1528 |
$order->save();
|
1529 |
|
1530 |
if (($paymentDoneBy === 'cod') && isset($razorpayData['cod_fee']) == true)
|
1554 |
//To update customer address info to wc order.
|
1555 |
public function updateOrderAddress($razorpayData, $order)
|
1556 |
{
|
1557 |
+
rzpLogInfo("updateOrderAddress function called");
|
1558 |
+
$receipt = $razorpayData['receipt'];
|
1559 |
+
|
1560 |
if (isset($razorpayData['customer_details']['shipping_address']))
|
1561 |
{
|
1562 |
$shippingAddressKey = $razorpayData['customer_details']['shipping_address'];
|
1580 |
$order->set_shipping_state($shippingStateCode);
|
1581 |
|
1582 |
$this->updateUserAddressInfo('shipping_', $shippingAddress, $shippingStateCode, $order);
|
1583 |
+
rzpLogInfo('shipping details for receipt id: '.$receipt .' is '. json_encode($shippingAddress));
|
1584 |
|
1585 |
if (empty($razorpayData['customer_details']['billing_address']) == false)
|
1586 |
{
|
1600 |
$order->set_billing_state($billingStateCode);
|
1601 |
|
1602 |
$this->updateUserAddressInfo('billing_', $billingAddress, $billingStateCode, $order);
|
1603 |
+
rzpLogInfo('billing details for receipt id: '.$receipt .' is '. json_encode($billingAddress));
|
1604 |
}
|
1605 |
else
|
1606 |
{
|
1610 |
$this->updateUserAddressInfo('billing_', $shippingAddress, $shippingStateCode, $order);
|
1611 |
}
|
1612 |
|
1613 |
+
rzpLogInfo("updateOrderAddress function executed");
|
1614 |
+
|
1615 |
$order->save();
|
1616 |
}
|
1617 |
}
|
1905 |
if (isTestModeEnabled()) {
|
1906 |
$current_user = wp_get_current_user();
|
1907 |
if ($current_user->has_cap( 'administrator' ) || preg_match( '/@razorpay.com$/i', $current_user->user_email )) {
|
1908 |
+
if (is_cart()) {
|
1909 |
$enabled = false;
|
1910 |
}
|
1911 |
}
|
1912 |
} else {
|
1913 |
+
if (is_cart()) {
|
1914 |
$enabled = false;
|
1915 |
}
|
1916 |
}
|