Version Description
- Bug fix for cart bounty plugin support issue in magic checkout.
- Added mandatory store account creation feature for magic checkout.
- Bug fix for sticky add to cart plugin support.
- Magic checkout new script endpoint.
- Added instrumentation
- Added auto webhook log
- Added validation for key and secret
Download this release
Release Info
Developer | razorpay |
Plugin | Razorpay for WooCommerce |
Version | 4.2.0 |
Comparing to | |
See all releases |
Code changes from version 4.1.0 to 4.2.0
- btn-1cc-checkout.js +135 -25
- includes/api/api.php +12 -5
- includes/api/coupon-apply.php +1 -1
- includes/api/order.php +11 -12
- includes/api/save-abandonment-data.php +1 -1
- includes/api/shipping-info.php +1 -1
- includes/support/cartbounty.php +7 -5
- includes/utils.php +7 -0
- readme.txt +10 -1
- woo-razorpay.php +115 -11
btn-1cc-checkout.js
CHANGED
@@ -43,47 +43,157 @@ function btnCheckout(){
|
|
43 |
});
|
44 |
}
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
addEventListenerToMinicart('wc_fragments_refreshed');
|
47 |
addEventListenerToMinicart('wc_fragments_loaded');
|
48 |
addEventListenerToMinicart('added_to_cart');
|
49 |
|
50 |
if (btnPdp != null) {
|
51 |
-
|
|
|
52 |
|
53 |
-
|
54 |
-
var productId = btnPdp.getAttribute('product_id');
|
55 |
-
var quantity = btnPdp.getAttribute('quantity');
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
|
69 |
-
|
70 |
-
|
|
|
71 |
|
72 |
-
|
|
|
73 |
|
74 |
-
|
75 |
|
76 |
-
|
77 |
-
var fieldKey = customProductFieldForm.getElementsByTagName('label');
|
78 |
-
var fieldArray = [];
|
79 |
-
var fieldObj = {};
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
84 |
|
85 |
-
|
|
|
86 |
}
|
|
|
|
|
87 |
}
|
88 |
}
|
89 |
|
43 |
});
|
44 |
}
|
45 |
|
46 |
+
var stickyBtn = document.querySelectorAll('#btn-1cc-pdp')[1];
|
47 |
+
|
48 |
+
if (stickyBtn != null) {
|
49 |
+
|
50 |
+
// For attaching event listener to Woodmart's sticky add-to-cart
|
51 |
+
document.addEventListener('scroll',(e)=>{
|
52 |
+
|
53 |
+
let i = 0;
|
54 |
+
while (typeof quantity === 'undefined') {
|
55 |
+
var quantity = document.getElementsByClassName("qty")[i].value;
|
56 |
+
i++;
|
57 |
+
}
|
58 |
+
|
59 |
+
stickyBtn.setAttribute('quantity', quantity);
|
60 |
+
|
61 |
+
jQuery('.qty').on('change',function(e)
|
62 |
+
{
|
63 |
+
let x = 0;
|
64 |
+
while (typeof quantity === 'undefined') {
|
65 |
+
var quantity = document.getElementsByClassName("qty")[x].value;
|
66 |
+
x++;
|
67 |
+
}
|
68 |
+
|
69 |
+
stickyBtn.setAttribute('quantity', quantity);
|
70 |
+
|
71 |
+
if(quantity <= 0)
|
72 |
+
{
|
73 |
+
stickyBtn.classList.add("disabled");
|
74 |
+
stickyBtn.disabled = true;
|
75 |
+
}
|
76 |
+
else
|
77 |
+
{
|
78 |
+
stickyBtn.classList.remove("disabled");
|
79 |
+
stickyBtn.disabled = false;
|
80 |
+
}
|
81 |
+
});
|
82 |
+
|
83 |
+
(function($){
|
84 |
+
|
85 |
+
$('form.variations_form').on('show_variation', function(event, data){
|
86 |
+
|
87 |
+
stickyBtn.classList.remove("disabled");
|
88 |
+
stickyBtn.disabled = false;
|
89 |
+
|
90 |
+
stickyBtn.setAttribute('variation_id', data.variation_id);
|
91 |
+
|
92 |
+
var variationArr = {};
|
93 |
+
|
94 |
+
$.each( data.attributes, function( key, value ) {
|
95 |
+
variationArr[key] = $("[name="+key+"]").val();
|
96 |
+
});
|
97 |
+
|
98 |
+
stickyBtn.setAttribute('variations', JSON.stringify(variationArr));
|
99 |
+
|
100 |
+
}).on('hide_variation', function() {
|
101 |
+
|
102 |
+
stickyBtn.classList.add("disabled");
|
103 |
+
stickyBtn.disabled = true;
|
104 |
+
});
|
105 |
+
})(jQuery);
|
106 |
+
|
107 |
+
if (stickyBtn != null) {
|
108 |
+
stickyBtn.onclick = function(){
|
109 |
+
|
110 |
+
var pdpCheckout = stickyBtn.getAttribute('pdp_checkout');
|
111 |
+
var productId = stickyBtn.getAttribute('product_id');
|
112 |
+
var quantity = stickyBtn.getAttribute('quantity');
|
113 |
+
|
114 |
+
rzp1ccCheckoutData.pdpCheckout = pdpCheckout;
|
115 |
+
rzp1ccCheckoutData.productId = productId;
|
116 |
+
rzp1ccCheckoutData.quantity = quantity;
|
117 |
+
|
118 |
+
if (btnPdp.getAttribute('variation_id') != null) {
|
119 |
+
var variationId = stickyBtn.getAttribute('variation_id');
|
120 |
+
var variations = stickyBtn.getAttribute('variations');
|
121 |
+
|
122 |
+
rzp1ccCheckoutData.variationId = variationId;
|
123 |
+
rzp1ccCheckoutData.variations = variations;
|
124 |
+
}
|
125 |
+
|
126 |
+
//To support custom product fields plugin.
|
127 |
+
const customFieldForm = document.getElementsByClassName('wcpa_form_outer');
|
128 |
+
|
129 |
+
if (customFieldForm && customFieldForm.length > 0) {
|
130 |
+
|
131 |
+
var customProductFieldForm = customFieldForm[0];
|
132 |
+
|
133 |
+
var fieldValues = customProductFieldForm.getElementsByTagName('input');
|
134 |
+
var fieldKey = customProductFieldForm.getElementsByTagName('label');
|
135 |
+
var fieldArray = [];
|
136 |
+
var fieldObj = {};
|
137 |
+
|
138 |
+
for (i = 0; i < fieldKey.length; i++) {
|
139 |
+
fieldObj[fieldKey[i].innerText] = fieldValues[i].value;
|
140 |
+
}
|
141 |
+
|
142 |
+
rzp1ccCheckoutData.fieldObj = fieldObj;
|
143 |
+
}
|
144 |
+
}
|
145 |
+
}
|
146 |
+
|
147 |
+
if (stickyBtn !== null) {
|
148 |
+
stickyBtn.addEventListener('click', openRzpCheckout);
|
149 |
+
}
|
150 |
+
})
|
151 |
+
}
|
152 |
+
|
153 |
+
|
154 |
addEventListenerToMinicart('wc_fragments_refreshed');
|
155 |
addEventListenerToMinicart('wc_fragments_loaded');
|
156 |
addEventListenerToMinicart('added_to_cart');
|
157 |
|
158 |
if (btnPdp != null) {
|
159 |
+
btnPdp.onclick = productInfoHandler;
|
160 |
+
}
|
161 |
|
162 |
+
function productInfoHandler(){
|
|
|
|
|
163 |
|
164 |
+
var pdpCheckout = btnPdp.getAttribute('pdp_checkout');
|
165 |
+
var productId = btnPdp.getAttribute('product_id');
|
166 |
+
var quantity = btnPdp.getAttribute('quantity');
|
167 |
|
168 |
+
rzp1ccCheckoutData.pdpCheckout = pdpCheckout;
|
169 |
+
rzp1ccCheckoutData.productId = productId;
|
170 |
+
rzp1ccCheckoutData.quantity = quantity;
|
171 |
|
172 |
+
if (btnPdp.getAttribute('variation_id') != null) {
|
173 |
+
var variationId = btnPdp.getAttribute('variation_id');
|
174 |
+
var variations = btnPdp.getAttribute('variations');
|
175 |
|
176 |
+
rzp1ccCheckoutData.variationId = variationId;
|
177 |
+
rzp1ccCheckoutData.variations = variations;
|
178 |
+
}
|
179 |
|
180 |
+
//To support custom product fields plugin.
|
181 |
+
const customFieldForm = document.getElementsByClassName('wcpa_form_outer');
|
182 |
|
183 |
+
if (customFieldForm && customFieldForm.length > 0) {
|
184 |
|
185 |
+
var customProductFieldForm = customFieldForm[0];
|
|
|
|
|
|
|
186 |
|
187 |
+
var fieldValues = customProductFieldForm.getElementsByTagName('input');
|
188 |
+
var fieldKey = customProductFieldForm.getElementsByTagName('label');
|
189 |
+
var fieldArray = [];
|
190 |
+
var fieldObj = {};
|
191 |
|
192 |
+
for (i = 0; i < fieldKey.length; i++) {
|
193 |
+
fieldObj[fieldKey[i].innerText] = fieldValues[i].value;
|
194 |
}
|
195 |
+
|
196 |
+
rzp1ccCheckoutData.fieldObj = fieldObj;
|
197 |
}
|
198 |
}
|
199 |
|
includes/api/api.php
CHANGED
@@ -200,21 +200,28 @@ function addMagicCheckoutSettingFields(&$defaultFormFields)
|
|
200 |
'description' => "To track orders using Facebook Pixel",
|
201 |
'label' => __('Activate Magic Checkout Facebook Analytics'),
|
202 |
'default' => 'no',
|
203 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
);
|
205 |
|
206 |
$defaultFormFields = array_merge($defaultFormFields, $magicCheckoutConfigFields);
|
207 |
|
208 |
}
|
209 |
|
210 |
-
//To handle rest cookies invalid issue
|
211 |
add_filter("nonce_user_logged_out", function ($uid, $action) {
|
212 |
if ($uid === 0 && $action === 'wp_rest') {
|
213 |
-
|
214 |
}
|
215 |
return $uid;
|
216 |
}, 10, 2);
|
217 |
|
218 |
-
add_filter(
|
219 |
return true;
|
220 |
-
});
|
200 |
'description' => "To track orders using Facebook Pixel",
|
201 |
'label' => __('Activate Magic Checkout Facebook Analytics'),
|
202 |
'default' => 'no',
|
203 |
+
),
|
204 |
+
'1cc_account_creation' => array(
|
205 |
+
'title' => __('Allow customers to create store Account'),
|
206 |
+
'type' => 'checkbox',
|
207 |
+
'description' => 'Allow customers to create store Account',
|
208 |
+
'label' => __('Allow customers to create store Account'),
|
209 |
+
'default' => 'No',
|
210 |
+
),
|
211 |
);
|
212 |
|
213 |
$defaultFormFields = array_merge($defaultFormFields, $magicCheckoutConfigFields);
|
214 |
|
215 |
}
|
216 |
|
217 |
+
//To handle rest cookies invalid issue
|
218 |
add_filter("nonce_user_logged_out", function ($uid, $action) {
|
219 |
if ($uid === 0 && $action === 'wp_rest') {
|
220 |
+
return null;
|
221 |
}
|
222 |
return $uid;
|
223 |
}, 10, 2);
|
224 |
|
225 |
+
add_filter('rest_authentication_errors', function ($maybe_error) {
|
226 |
return true;
|
227 |
+
});
|
includes/api/coupon-apply.php
CHANGED
@@ -125,7 +125,7 @@ function applyCouponOnCart(WP_REST_Request $request)
|
|
125 |
WC()->cart->empty_cart();
|
126 |
|
127 |
$cart1cc = create1ccCart($orderId);
|
128 |
-
|
129 |
WC()->cart->remove_coupon($couponCode);
|
130 |
|
131 |
if ($cart1cc) {
|
125 |
WC()->cart->empty_cart();
|
126 |
|
127 |
$cart1cc = create1ccCart($orderId);
|
128 |
+
|
129 |
WC()->cart->remove_coupon($couponCode);
|
130 |
|
131 |
if ($cart1cc) {
|
includes/api/order.php
CHANGED
@@ -98,7 +98,7 @@ function createWcOrder(WP_REST_Request $request)
|
|
98 |
updateOrderStatus($orderId, 'draft');
|
99 |
} else {
|
100 |
$existingOrder = wc_get_order($orderIdFromHash);
|
101 |
-
$orderStatus
|
102 |
$existingOrder->calculate_totals();
|
103 |
if ($orderStatus != 'draft' && $existingOrder->needs_payment() == false) {
|
104 |
$woocommerce->session->__unset(RZP_1CC_CART_HASH . $cartHash);
|
@@ -239,9 +239,9 @@ function createWcOrder(WP_REST_Request $request)
|
|
239 |
}
|
240 |
|
241 |
$woocommerce->session->set(RZP_1CC_CART_HASH . $cartHash, $orderId);
|
242 |
-
set_transient(RZP_1CC_CART_HASH . $orderId, $cartHash,
|
243 |
-
set_transient(RZP_1CC_CART_HASH . $cartHash, $orderId,
|
244 |
-
set_transient($razorpay::SESSION_KEY, $orderId,
|
245 |
|
246 |
$logObj['response'] = $response;
|
247 |
rzpLogInfo(json_encode($logObj));
|
@@ -277,15 +277,14 @@ function wooSaveCheckoutUTMFields($orderId, $params)
|
|
277 |
$browserTime = $params['dateTime'];
|
278 |
$pysData['pys_landing'] = isset($cookieData['pys_landing_page']) ? ($cookieData['pys_landing_page']) : "";
|
279 |
$pysData['pys_source'] = isset($cookieData['pysTrafficSource']) ? ($cookieData['pysTrafficSource']) : "direct";
|
280 |
-
if($pysData['pys_source'] == 'direct')
|
281 |
-
|
282 |
-
$pysData['pys_source'] = $params['referrerDomain'] != '' ? $params['referrerDomain'] : "direct";
|
283 |
}
|
284 |
-
$pysUTMSource
|
285 |
-
$pysUTMMedium
|
286 |
-
$pysUTMCampaign
|
287 |
-
$pysUTMTerm
|
288 |
-
$pysUTMContent
|
289 |
|
290 |
$pysData['pys_utm'] = "utm_source:" . $pysUTMSource . "|utm_medium:" . $pysUTMMedium . "|utm_campaign:" . $pysUTMCampaign . "|utm_term:" . $pysUTMTerm . "|utm_content:" . $pysUTMContent;
|
291 |
$pysData['pys_browser_time'] = $browserTime[0] . "|" . $browserTime[1] . "|" . $browserTime[2];
|
98 |
updateOrderStatus($orderId, 'draft');
|
99 |
} else {
|
100 |
$existingOrder = wc_get_order($orderIdFromHash);
|
101 |
+
$orderStatus = $existingOrder->get_status();
|
102 |
$existingOrder->calculate_totals();
|
103 |
if ($orderStatus != 'draft' && $existingOrder->needs_payment() == false) {
|
104 |
$woocommerce->session->__unset(RZP_1CC_CART_HASH . $cartHash);
|
239 |
}
|
240 |
|
241 |
$woocommerce->session->set(RZP_1CC_CART_HASH . $cartHash, $orderId);
|
242 |
+
set_transient(RZP_1CC_CART_HASH . $orderId, $cartHash, 14400);
|
243 |
+
set_transient(RZP_1CC_CART_HASH . $cartHash, $orderId, 14400);
|
244 |
+
set_transient($razorpay::SESSION_KEY, $orderId, 14400);
|
245 |
|
246 |
$logObj['response'] = $response;
|
247 |
rzpLogInfo(json_encode($logObj));
|
277 |
$browserTime = $params['dateTime'];
|
278 |
$pysData['pys_landing'] = isset($cookieData['pys_landing_page']) ? ($cookieData['pys_landing_page']) : "";
|
279 |
$pysData['pys_source'] = isset($cookieData['pysTrafficSource']) ? ($cookieData['pysTrafficSource']) : "direct";
|
280 |
+
if ($pysData['pys_source'] == 'direct') {
|
281 |
+
$pysData['pys_source'] = $params['referrerDomain'] != '' ? $params['referrerDomain'] : "direct";
|
|
|
282 |
}
|
283 |
+
$pysUTMSource = $cookieData['pys_utm_source'] ?? $getQuery['utm_source'];
|
284 |
+
$pysUTMMedium = $cookieData['pys_utm_medium'] ?? $getQuery['utm_medium'];
|
285 |
+
$pysUTMCampaign = $cookieData['pys_utm_campaign'] ?? $getQuery['utm_medium'];
|
286 |
+
$pysUTMTerm = $cookieData['pys_utm_term'] ?? $getQuery['utm_term'];
|
287 |
+
$pysUTMContent = $cookieData['pys_utm_content'] ?? $getQuery['utm_content'];
|
288 |
|
289 |
$pysData['pys_utm'] = "utm_source:" . $pysUTMSource . "|utm_medium:" . $pysUTMMedium . "|utm_campaign:" . $pysUTMCampaign . "|utm_term:" . $pysUTMTerm . "|utm_content:" . $pysUTMContent;
|
290 |
$pysData['pys_browser_time'] = $browserTime[0] . "|" . $browserTime[1] . "|" . $browserTime[2];
|
includes/api/save-abandonment-data.php
CHANGED
@@ -43,7 +43,7 @@ function saveCartAbandonmentData(WP_REST_Request $request)
|
|
43 |
}
|
44 |
$order = wc_get_order($wcOrderId);
|
45 |
}
|
46 |
-
|
47 |
$razorpay->UpdateOrderAddress($razorpayData, $order);
|
48 |
|
49 |
initCustomerSessionAndCart();
|
43 |
}
|
44 |
$order = wc_get_order($wcOrderId);
|
45 |
}
|
46 |
+
|
47 |
$razorpay->UpdateOrderAddress($razorpayData, $order);
|
48 |
|
49 |
initCustomerSessionAndCart();
|
includes/api/shipping-info.php
CHANGED
@@ -281,7 +281,7 @@ function getCodShippingInfo1cc($instanceId, $methodId, $orderId, $address)
|
|
281 |
$minCODAmount1cc = !empty(get_option('woocommerce_razorpay_settings')['1cc_min_COD_slab_amount']) ? get_option('woocommerce_razorpay_settings')['1cc_min_COD_slab_amount'] : 0;
|
282 |
$maxCODAmount1cc = !empty(get_option('woocommerce_razorpay_settings')['1cc_max_COD_slab_amount']) ? get_option('woocommerce_razorpay_settings')['1cc_max_COD_slab_amount'] : 0;
|
283 |
|
284 |
-
if (!isset($availablePaymentMethods['cod']) || 'no' == $availablePaymentMethods['cod']->enabled
|
285 |
return false;
|
286 |
}
|
287 |
|
281 |
$minCODAmount1cc = !empty(get_option('woocommerce_razorpay_settings')['1cc_min_COD_slab_amount']) ? get_option('woocommerce_razorpay_settings')['1cc_min_COD_slab_amount'] : 0;
|
282 |
$maxCODAmount1cc = !empty(get_option('woocommerce_razorpay_settings')['1cc_max_COD_slab_amount']) ? get_option('woocommerce_razorpay_settings')['1cc_max_COD_slab_amount'] : 0;
|
283 |
|
284 |
+
if (!isset($availablePaymentMethods['cod']) || 'no' == $availablePaymentMethods['cod']->enabled) {
|
285 |
return false;
|
286 |
}
|
287 |
|
includes/support/cartbounty.php
CHANGED
@@ -116,7 +116,8 @@ function deleteDuplicateCarts($sessionID, $duplicateCount, $cartTable)
|
|
116 |
$cartbountyAdmin = new CartBounty_Admin(CARTBOUNTY_PLUGIN_NAME_SLUG, CARTBOUNTY_VERSION_NUMBER);
|
117 |
if ($duplicateCount) {
|
118 |
//If we have updated at least one row
|
119 |
-
if ($duplicateCount > 1) {
|
|
|
120 |
$whereSentence = $cartbountyAdmin->get_where_sentence('ghost');
|
121 |
//First delete all duplicate ghost carts
|
122 |
$deletedDuplicateGhostCarts = $wpdb->query(
|
@@ -173,7 +174,7 @@ function getSessionID($orderID)
|
|
173 |
function handleCBRecoveredOrder($orderID)
|
174 |
{
|
175 |
global $wpdb;
|
176 |
-
|
177 |
if (!isset($orderID)) {
|
178 |
//Exit if Order ID is not present
|
179 |
return;
|
@@ -245,8 +246,9 @@ function clearCartData($wcOrderId, $cartTable)
|
|
245 |
function readCartCB($wcOrderId)
|
246 |
{
|
247 |
WC()->cart->empty_cart();
|
248 |
-
$cart1cc
|
249 |
-
$cart
|
|
|
250 |
|
251 |
if (!WC()->cart) {
|
252 |
//Exit if Woocommerce cart has not been initialized
|
@@ -283,7 +285,7 @@ function readCartCB($wcOrderId)
|
|
283 |
$singleVariation = new WC_Product_Variation($product['variation_id']);
|
284 |
|
285 |
//Handling variable product title output with attributes
|
286 |
-
$productAttributes = attribute_slug_to_title($singleVariation->get_variation_attributes());
|
287 |
$productVariationID = $product['variation_id'];
|
288 |
} else {
|
289 |
$productAttributes = false;
|
116 |
$cartbountyAdmin = new CartBounty_Admin(CARTBOUNTY_PLUGIN_NAME_SLUG, CARTBOUNTY_VERSION_NUMBER);
|
117 |
if ($duplicateCount) {
|
118 |
//If we have updated at least one row
|
119 |
+
if ($duplicateCount > 1) {
|
120 |
+
//Checking if we have updated more than a single row to know if there were duplicates
|
121 |
$whereSentence = $cartbountyAdmin->get_where_sentence('ghost');
|
122 |
//First delete all duplicate ghost carts
|
123 |
$deletedDuplicateGhostCarts = $wpdb->query(
|
174 |
function handleCBRecoveredOrder($orderID)
|
175 |
{
|
176 |
global $wpdb;
|
177 |
+
|
178 |
if (!isset($orderID)) {
|
179 |
//Exit if Order ID is not present
|
180 |
return;
|
246 |
function readCartCB($wcOrderId)
|
247 |
{
|
248 |
WC()->cart->empty_cart();
|
249 |
+
$cart1cc = create1ccCart($wcOrderId);
|
250 |
+
$cart = WC()->cart;
|
251 |
+
$cartbountyPublic = new CartBounty_Public(CARTBOUNTY_PLUGIN_NAME_SLUG, CARTBOUNTY_VERSION_NUMBER);
|
252 |
|
253 |
if (!WC()->cart) {
|
254 |
//Exit if Woocommerce cart has not been initialized
|
285 |
$singleVariation = new WC_Product_Variation($product['variation_id']);
|
286 |
|
287 |
//Handling variable product title output with attributes
|
288 |
+
$productAttributes = $cartbountyPublic->attribute_slug_to_title($singleVariation->get_variation_attributes());
|
289 |
$productVariationID = $product['variation_id'];
|
290 |
} else {
|
291 |
$productAttributes = false;
|
includes/utils.php
CHANGED
@@ -68,6 +68,13 @@ function isMiniCartCheckoutEnabled()
|
|
68 |
);
|
69 |
}
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
function validateInput($route, $param)
|
72 |
{
|
73 |
$failure_reason = null;
|
68 |
);
|
69 |
}
|
70 |
|
71 |
+
function isMandatoryAccCreationEnabled()
|
72 |
+
{
|
73 |
+
return (
|
74 |
+
empty(get_option('woocommerce_razorpay_settings')['1cc_account_creation']) === false
|
75 |
+
&& 'yes' == get_option('woocommerce_razorpay_settings')['1cc_account_creation']
|
76 |
+
);
|
77 |
+
}
|
78 |
function validateInput($route, $param)
|
79 |
{
|
80 |
$failure_reason = null;
|
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: 6.0.1
|
6 |
-
Stable tag: 4.
|
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,15 @@ This is compatible with WooCommerce>=2.4, including the new 3.0 release. It has
|
|
41 |
|
42 |
== Changelog ==
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
= 4.1.0 =
|
45 |
* Bug fix for jquery undefined issue.
|
46 |
* Bug fix for duplicate wooc orderId and Razorpay ID form same carthash.
|
3 |
Tags: razorpay, payments, india, woocommerce, ecommerce
|
4 |
Requires at least: 3.9.2
|
5 |
Tested up to: 6.0.1
|
6 |
+
Stable tag: 4.2.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 |
+
= 4.2.0 =
|
45 |
+
* Bug fix for cart bounty plugin support issue in magic checkout.
|
46 |
+
* Added mandatory store account creation feature for magic checkout.
|
47 |
+
* Bug fix for sticky add to cart plugin support.
|
48 |
+
* Magic checkout new script endpoint.
|
49 |
+
* Added instrumentation
|
50 |
+
* Added auto webhook log
|
51 |
+
* Added validation for key and secret
|
52 |
+
|
53 |
= 4.1.0 =
|
54 |
* Bug fix for jquery undefined issue.
|
55 |
* Bug fix for duplicate wooc orderId and Razorpay ID form same carthash.
|
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: 4.
|
7 |
-
* Stable tag: 4.
|
8 |
* Author: Team Razorpay
|
9 |
* WC tested up to: 6.7.0
|
10 |
* Author URI: https://razorpay.com
|
@@ -37,6 +37,7 @@ add_action('activated_plugin', 'razorpayPluginActivated', 10, 2 );
|
|
37 |
add_action('deactivated_plugin', 'razorpayPluginDeactivated', 10, 2 );
|
38 |
add_action('upgrader_process_complete', 'razorpayPluginUpgraded', 10, 2);
|
39 |
|
|
|
40 |
function woocommerce_razorpay_init()
|
41 |
{
|
42 |
if (!class_exists('WC_Payment_Gateway'))
|
@@ -168,6 +169,7 @@ function woocommerce_razorpay_init()
|
|
168 |
$this->icon = "https://cdn.razorpay.com/static/assets/logo/payment.svg";
|
169 |
// 1cc flags should be enabled only if merchant has access to 1cc feature
|
170 |
$is1ccAvailable = false;
|
|
|
171 |
|
172 |
// Load preference API call only for administrative interface page.
|
173 |
if (is_admin())
|
@@ -183,6 +185,10 @@ function woocommerce_razorpay_init()
|
|
183 |
$is1ccAvailable = true;
|
184 |
}
|
185 |
|
|
|
|
|
|
|
|
|
186 |
} catch (\Exception $e) {
|
187 |
rzpLogError($e->getMessage());
|
188 |
}
|
@@ -203,6 +209,13 @@ function woocommerce_razorpay_init()
|
|
203 |
'1cc_min_COD_slab_amount',
|
204 |
'1cc_max_COD_slab_amount',
|
205 |
));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
}
|
207 |
|
208 |
$this->init_form_fields();
|
@@ -350,6 +363,26 @@ function woocommerce_razorpay_init()
|
|
350 |
return;
|
351 |
}
|
352 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
|
354 |
$domain = parse_url($webhookUrl, PHP_URL_HOST);
|
355 |
|
@@ -1383,7 +1416,7 @@ EOT;
|
|
1383 |
|
1384 |
$razorpayData = $api->order->fetch($razorpayOrderId);
|
1385 |
|
1386 |
-
$this->
|
1387 |
}
|
1388 |
|
1389 |
$this->handleErrorCase($order);
|
@@ -1532,7 +1565,7 @@ EOT;
|
|
1532 |
$order->payment_complete($razorpayPaymentId);
|
1533 |
}
|
1534 |
|
1535 |
-
if(is_plugin_active('woo-save-abandoned-carts/cartbounty-abandoned-carts.php')){
|
1536 |
handleCBRecoveredOrder($orderId);
|
1537 |
}
|
1538 |
|
@@ -1608,7 +1641,8 @@ EOT;
|
|
1608 |
|
1609 |
$razorpayData = $api->order->fetch($razorpayOrderId);
|
1610 |
|
1611 |
-
$this->
|
|
|
1612 |
|
1613 |
|
1614 |
if (empty($razorpayData['promotions'][0]) === false)
|
@@ -1744,9 +1778,9 @@ EOT;
|
|
1744 |
$payment_method_title = $this->title;
|
1745 |
|
1746 |
// To verify the payment method for particular payment id.
|
1747 |
-
$
|
1748 |
|
1749 |
-
$paymentDoneBy = $
|
1750 |
|
1751 |
if (($paymentDoneBy === 'cod') && isset($razorpayData['cod_fee']) == true)
|
1752 |
{
|
@@ -1793,6 +1827,7 @@ EOT;
|
|
1793 |
//To update customer address info to wc order.
|
1794 |
public function updateOrderAddress($razorpayData, $order)
|
1795 |
{
|
|
|
1796 |
rzpLogInfo("updateOrderAddress function called");
|
1797 |
$receipt = $razorpayData['receipt'];
|
1798 |
|
@@ -1855,6 +1890,78 @@ EOT;
|
|
1855 |
}
|
1856 |
}
|
1857 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1858 |
/**
|
1859 |
* Retrieve a Shipping Zone by it's ID.
|
1860 |
*
|
@@ -1869,9 +1976,6 @@ EOT;
|
|
1869 |
return $zone;
|
1870 |
}
|
1871 |
|
1872 |
-
|
1873 |
-
|
1874 |
-
|
1875 |
// Update user billing and shipping information
|
1876 |
protected function updateUserAddressInfo($addressKeyPrefix, $addressValue, $stateValue, $order)
|
1877 |
{
|
@@ -2079,7 +2183,7 @@ function razorpay_webhook_init()
|
|
2079 |
}
|
2080 |
|
2081 |
define('RZP_PATH', plugin_dir_path( __FILE__ ));
|
2082 |
-
define('RZP_CHECKOUTJS_URL', 'https://checkout.razorpay.com/v1/checkout.js');
|
2083 |
define('RZP_1CC_CSS_SCRIPT', 'RZP_1CC_CSS_SCRIPT');
|
2084 |
|
2085 |
|
3 |
* Plugin Name: Razorpay for WooCommerce
|
4 |
* Plugin URI: https://razorpay.com
|
5 |
* Description: Razorpay Payment Gateway Integration for WooCommerce
|
6 |
+
* Version: 4.2.0
|
7 |
+
* Stable tag: 4.2.0
|
8 |
* Author: Team Razorpay
|
9 |
* WC tested up to: 6.7.0
|
10 |
* Author URI: https://razorpay.com
|
37 |
add_action('deactivated_plugin', 'razorpayPluginDeactivated', 10, 2 );
|
38 |
add_action('upgrader_process_complete', 'razorpayPluginUpgraded', 10, 2);
|
39 |
|
40 |
+
|
41 |
function woocommerce_razorpay_init()
|
42 |
{
|
43 |
if (!class_exists('WC_Payment_Gateway'))
|
169 |
$this->icon = "https://cdn.razorpay.com/static/assets/logo/payment.svg";
|
170 |
// 1cc flags should be enabled only if merchant has access to 1cc feature
|
171 |
$is1ccAvailable = false;
|
172 |
+
$isAccCreationAvailable = false;
|
173 |
|
174 |
// Load preference API call only for administrative interface page.
|
175 |
if (is_admin())
|
185 |
$is1ccAvailable = true;
|
186 |
}
|
187 |
|
188 |
+
if (!empty($merchantPreferences['features']['one_cc_store_account'])) {
|
189 |
+
$isAccCreationAvailable = true;
|
190 |
+
}
|
191 |
+
|
192 |
} catch (\Exception $e) {
|
193 |
rzpLogError($e->getMessage());
|
194 |
}
|
209 |
'1cc_min_COD_slab_amount',
|
210 |
'1cc_max_COD_slab_amount',
|
211 |
));
|
212 |
+
|
213 |
+
if ($isAccCreationAvailable) {
|
214 |
+
$this->visibleSettings = array_merge($this->visibleSettings, array(
|
215 |
+
'1cc_account_creation',
|
216 |
+
));
|
217 |
+
}
|
218 |
+
|
219 |
}
|
220 |
|
221 |
$this->init_form_fields();
|
363 |
return;
|
364 |
}
|
365 |
|
366 |
+
try
|
367 |
+
{
|
368 |
+
$api = $this->getRazorpayApiInstance();
|
369 |
+
$validateKeySecret = $api->request->request("GET", "orders");
|
370 |
+
}
|
371 |
+
catch (Exception $e)
|
372 |
+
{
|
373 |
+
?>
|
374 |
+
<div class="notice error is-dismissible" >
|
375 |
+
<p><b><?php _e( 'Please check Key Id and Key Secret.'); ?></b></p>
|
376 |
+
</div>
|
377 |
+
<?php
|
378 |
+
|
379 |
+
$log = array(
|
380 |
+
'message' => $e->getMessage(),
|
381 |
+
);
|
382 |
+
rzpLogError(json_encode($log));
|
383 |
+
|
384 |
+
return;
|
385 |
+
}
|
386 |
|
387 |
$domain = parse_url($webhookUrl, PHP_URL_HOST);
|
388 |
|
1416 |
|
1417 |
$razorpayData = $api->order->fetch($razorpayOrderId);
|
1418 |
|
1419 |
+
$this->UpdateOrderAddress($razorpayData, $order);
|
1420 |
}
|
1421 |
|
1422 |
$this->handleErrorCase($order);
|
1565 |
$order->payment_complete($razorpayPaymentId);
|
1566 |
}
|
1567 |
|
1568 |
+
if(is1ccEnabled() && !empty($is1ccOrder) && $is1ccOrder == 'yes' && is_plugin_active('woo-save-abandoned-carts/cartbounty-abandoned-carts.php')){
|
1569 |
handleCBRecoveredOrder($orderId);
|
1570 |
}
|
1571 |
|
1641 |
|
1642 |
$razorpayData = $api->order->fetch($razorpayOrderId);
|
1643 |
|
1644 |
+
$this->UpdateOrderAddress($razorpayData, $order);
|
1645 |
+
|
1646 |
|
1647 |
|
1648 |
if (empty($razorpayData['promotions'][0]) === false)
|
1778 |
$payment_method_title = $this->title;
|
1779 |
|
1780 |
// To verify the payment method for particular payment id.
|
1781 |
+
$razorpayPaymentData = $api->payment->fetch($razorpayPaymentId);
|
1782 |
|
1783 |
+
$paymentDoneBy = $razorpayPaymentData['method'];
|
1784 |
|
1785 |
if (($paymentDoneBy === 'cod') && isset($razorpayData['cod_fee']) == true)
|
1786 |
{
|
1827 |
//To update customer address info to wc order.
|
1828 |
public function updateOrderAddress($razorpayData, $order)
|
1829 |
{
|
1830 |
+
$this->newUserAccount($razorpayData, $order);
|
1831 |
rzpLogInfo("updateOrderAddress function called");
|
1832 |
$receipt = $razorpayData['receipt'];
|
1833 |
|
1890 |
}
|
1891 |
}
|
1892 |
|
1893 |
+
//Create new user account
|
1894 |
+
public function newUserAccount($razorpayData, $order)
|
1895 |
+
{
|
1896 |
+
global $woocommerce;
|
1897 |
+
|
1898 |
+
if (!email_exists($razorpayData['customer_details']['email']) && isMandatoryAccCreationEnabled()) {
|
1899 |
+
|
1900 |
+
$contact = $razorpayData['customer_details']['contact'];
|
1901 |
+
|
1902 |
+
$email = $razorpayData['customer_details']['email'];
|
1903 |
+
$random_password = wp_generate_password(8, false);
|
1904 |
+
|
1905 |
+
//create user name with the help default woocommerce function
|
1906 |
+
$username = wc_create_new_customer_username( $email , $name);
|
1907 |
+
$userId = wp_create_user( $username, $random_password, $email );
|
1908 |
+
$user = get_user_by('id', $userId);
|
1909 |
+
|
1910 |
+
update_post_meta($order->id, '_customer_user', $userId);
|
1911 |
+
|
1912 |
+
// Get all WooCommerce emails Objects from WC_Emails Object instance
|
1913 |
+
$emails = wc()->mailer()->emails;
|
1914 |
+
|
1915 |
+
// Send WooCommerce "Customer New Account" email notification with the password
|
1916 |
+
$emails['WC_Email_Customer_New_Account']->trigger( $userId, $random_password, true );
|
1917 |
+
|
1918 |
+
update_user_meta( $userId, 'shipping_email', $email);
|
1919 |
+
update_user_meta( $userId, 'shipping_phone', $contact );
|
1920 |
+
|
1921 |
+
if (isset($razorpayData['customer_details']['shipping_address']))
|
1922 |
+
{
|
1923 |
+
$shpping = $razorpayData['customer_details']['shipping_address'];
|
1924 |
+
|
1925 |
+
//extract data
|
1926 |
+
if (empty($razorpayData['customer_details']['billing_address']) == false)
|
1927 |
+
{
|
1928 |
+
$billing = $razorpayData['customer_details']['billing_address'];
|
1929 |
+
}
|
1930 |
+
else
|
1931 |
+
{
|
1932 |
+
$billing = $razorpayData['customer_details']['shipping_address'];
|
1933 |
+
}
|
1934 |
+
|
1935 |
+
$shippingState = strtoupper($shpping->state);
|
1936 |
+
$shippingStateName = str_replace(" ", '', $shippingState);
|
1937 |
+
$shippingStateCode = getWcStateCodeFromName($shippingStateName);
|
1938 |
+
|
1939 |
+
$billingState = strtoupper($billing->state);
|
1940 |
+
$billingStateName = str_replace(" ", '', $billingState);
|
1941 |
+
$billingStateCode = getWcStateCodeFromName($billingStateName);
|
1942 |
+
|
1943 |
+
// user's shipping data
|
1944 |
+
update_user_meta( $userId, 'shipping_first_name', $shpping->name );
|
1945 |
+
update_user_meta( $userId, 'shipping_address_1', $shpping->line1);
|
1946 |
+
update_user_meta( $userId, 'shipping_address_2', $shpping->line2);
|
1947 |
+
update_user_meta( $userId, 'shipping_city', $shpping->city);
|
1948 |
+
update_user_meta( $userId, 'shipping_country', strtoupper($shpping->country));
|
1949 |
+
update_user_meta( $userId, 'shipping_postcode', $shpping->zipcode);
|
1950 |
+
update_user_meta( $userId, 'shipping_state', $shippingStateCode);
|
1951 |
+
|
1952 |
+
// user's billing data
|
1953 |
+
update_user_meta( $userId, 'billing_first_name', $shpping->name);
|
1954 |
+
update_user_meta( $userId, 'billing_phone', $contact);
|
1955 |
+
update_user_meta( $userId, 'billing_address_1', $billing->line1);
|
1956 |
+
update_user_meta( $userId, 'billing_address_2', $billing->line2);
|
1957 |
+
update_user_meta( $userId, 'billing_city', $billing->city);
|
1958 |
+
update_user_meta( $userId, 'billing_country', strtoupper($billing->country));
|
1959 |
+
update_user_meta( $userId, 'billing_postcode', $billing->zipcode);
|
1960 |
+
update_user_meta( $userId, 'billing_state', $billingStateCode);
|
1961 |
+
}
|
1962 |
+
}
|
1963 |
+
}
|
1964 |
+
|
1965 |
/**
|
1966 |
* Retrieve a Shipping Zone by it's ID.
|
1967 |
*
|
1976 |
return $zone;
|
1977 |
}
|
1978 |
|
|
|
|
|
|
|
1979 |
// Update user billing and shipping information
|
1980 |
protected function updateUserAddressInfo($addressKeyPrefix, $addressValue, $stateValue, $order)
|
1981 |
{
|
2183 |
}
|
2184 |
|
2185 |
define('RZP_PATH', plugin_dir_path( __FILE__ ));
|
2186 |
+
define('RZP_CHECKOUTJS_URL', 'https://checkout.razorpay.com/v1/checkout-1cc.js');
|
2187 |
define('RZP_1CC_CSS_SCRIPT', 'RZP_1CC_CSS_SCRIPT');
|
2188 |
|
2189 |
|