Version Description
- New webhook event i.e payment.pending has been added to handle the magic checkout COD orders
Download this release
Release Info
Developer | razorpay |
Plugin | Razorpay for WooCommerce |
Version | 3.6.0 |
Comparing to | |
See all releases |
Code changes from version 3.5.1 to 3.6.0
- includes/razorpay-webhook.php +78 -0
- readme.txt +4 -1
- woo-razorpay.php +3 -2
includes/razorpay-webhook.php
CHANGED
@@ -25,6 +25,7 @@ class RZP_Webhook
|
|
25 |
*/
|
26 |
const PAYMENT_AUTHORIZED = 'payment.authorized';
|
27 |
const PAYMENT_FAILED = 'payment.failed';
|
|
|
28 |
const SUBSCRIPTION_CANCELLED = 'subscription.cancelled';
|
29 |
const REFUNDED_CREATED = 'refund.created';
|
30 |
const VIRTUAL_ACCOUNT_CREDITED = 'virtual_account.credited';
|
@@ -36,6 +37,7 @@ class RZP_Webhook
|
|
36 |
self::VIRTUAL_ACCOUNT_CREDITED,
|
37 |
self::REFUNDED_CREATED,
|
38 |
self::PAYMENT_FAILED,
|
|
|
39 |
self::SUBSCRIPTION_CANCELLED,
|
40 |
self::SUBSCRIPTION_PAUSED,
|
41 |
self::SUBSCRIPTION_RESUMED,
|
@@ -123,6 +125,9 @@ class RZP_Webhook
|
|
123 |
case self::PAYMENT_FAILED:
|
124 |
return $this->paymentFailed($data);
|
125 |
|
|
|
|
|
|
|
126 |
case self::SUBSCRIPTION_CANCELLED:
|
127 |
return $this->subscriptionCancelled($data);
|
128 |
|
@@ -283,6 +288,79 @@ class RZP_Webhook
|
|
283 |
exit;
|
284 |
}
|
285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
/**
|
287 |
* Handling the virtual account credited webhook
|
288 |
*
|
25 |
*/
|
26 |
const PAYMENT_AUTHORIZED = 'payment.authorized';
|
27 |
const PAYMENT_FAILED = 'payment.failed';
|
28 |
+
const PAYMENT_PENDING = 'payment.pending';
|
29 |
const SUBSCRIPTION_CANCELLED = 'subscription.cancelled';
|
30 |
const REFUNDED_CREATED = 'refund.created';
|
31 |
const VIRTUAL_ACCOUNT_CREDITED = 'virtual_account.credited';
|
37 |
self::VIRTUAL_ACCOUNT_CREDITED,
|
38 |
self::REFUNDED_CREATED,
|
39 |
self::PAYMENT_FAILED,
|
40 |
+
self::PAYMENT_PENDING,
|
41 |
self::SUBSCRIPTION_CANCELLED,
|
42 |
self::SUBSCRIPTION_PAUSED,
|
43 |
self::SUBSCRIPTION_RESUMED,
|
125 |
case self::PAYMENT_FAILED:
|
126 |
return $this->paymentFailed($data);
|
127 |
|
128 |
+
case self::PAYMENT_PENDING:
|
129 |
+
return $this->paymentPending($data);
|
130 |
+
|
131 |
case self::SUBSCRIPTION_CANCELLED:
|
132 |
return $this->subscriptionCancelled($data);
|
133 |
|
288 |
exit;
|
289 |
}
|
290 |
|
291 |
+
/**
|
292 |
+
* Handling the payment pending webhook to handle COD orders
|
293 |
+
*
|
294 |
+
* @param array $data Webook Data
|
295 |
+
*/
|
296 |
+
protected function paymentPending(array $data)
|
297 |
+
{
|
298 |
+
// We don't process subscription/invoice payments here
|
299 |
+
if (isset($data['payload']['payment']['entity']['invoice_id']) === true) {
|
300 |
+
return;
|
301 |
+
}
|
302 |
+
|
303 |
+
if (isset($data['payload']['payment']['entity']['method']) != 'cod' ) {
|
304 |
+
return;
|
305 |
+
}
|
306 |
+
|
307 |
+
//
|
308 |
+
// Order entity should be sent as part of the webhook payload
|
309 |
+
//
|
310 |
+
$orderId = $data['payload']['payment']['entity']['notes']['woocommerce_order_number'];
|
311 |
+
|
312 |
+
rzpLogInfo("Woocommerce orderId: $orderId webhook process intitiated for COD method payment pending event");
|
313 |
+
|
314 |
+
if(!empty($orderId))
|
315 |
+
{
|
316 |
+
$order = $this->checkIsObject($orderId);
|
317 |
+
}
|
318 |
+
//To give the priority to callback script to compleate the execution fist adding this locking.
|
319 |
+
$transientData = get_transient('webhook_trigger_count_for_' . $orderId);
|
320 |
+
|
321 |
+
if (empty($transientData) || $transientData == 1) {
|
322 |
+
rzpLogInfo("Woocommerce orderId: $orderId with transientData: $transientData webhook halted for 60 sec");
|
323 |
+
|
324 |
+
sleep(60);
|
325 |
+
}
|
326 |
+
|
327 |
+
$triggerCount = !empty($transientData) ? ($transientData + 1) : 1;
|
328 |
+
|
329 |
+
set_transient('webhook_trigger_count_for_' . $orderId, $triggerCount, 180);
|
330 |
+
|
331 |
+
$orderStatus = $order->get_status();
|
332 |
+
rzpLogInfo("Woocommerce orderId: $orderId order status: $orderStatus");
|
333 |
+
|
334 |
+
// If it is already marked as paid, ignore the event
|
335 |
+
if ($orderStatus != 'draft' && $order->needs_payment() === false) {
|
336 |
+
rzpLogInfo("Woocommerce orderId: $orderId webhook process exited with need payment status :". $order->needs_payment());
|
337 |
+
|
338 |
+
return;
|
339 |
+
}
|
340 |
+
|
341 |
+
if($orderStatus == 'draft')
|
342 |
+
{
|
343 |
+
updateOrderStatus($orderId, 'wc-pending');
|
344 |
+
}
|
345 |
+
|
346 |
+
$razorpayPaymentId = $data['payload']['payment']['entity']['id'];
|
347 |
+
|
348 |
+
$payment = $this->getPaymentEntity($razorpayPaymentId, $data);
|
349 |
+
|
350 |
+
$success = false;
|
351 |
+
$errorMessage = 'The payment has failed.';
|
352 |
+
|
353 |
+
if ($payment['status'] === 'pending' && $data['payload']['payment']['entity']['method'] == 'cod' && !empty($razorpayPaymentId)) {
|
354 |
+
$success = true;
|
355 |
+
|
356 |
+
$this->razorpay->updateOrder($order, $success, $errorMessage, $razorpayPaymentId, null, true);
|
357 |
+
rzpLogInfo("Woocommerce orderId: $orderId webhook process finished the update order function for COD");
|
358 |
+
}
|
359 |
+
|
360 |
+
// Graceful exit since payment is now processed.
|
361 |
+
exit;
|
362 |
+
}
|
363 |
+
|
364 |
/**
|
365 |
* Handling the virtual account credited webhook
|
366 |
*
|
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,9 @@ This is compatible with WooCommerce>=2.4, including the new 3.0 release. It has
|
|
41 |
|
42 |
== Changelog ==
|
43 |
|
|
|
|
|
|
|
44 |
= 3.5.1 =
|
45 |
* Bug fix for magic checkout blank order issue.
|
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.6.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.6.0 =
|
45 |
+
* New webhook event i.e payment.pending has been added to handle the magic checkout COD orders
|
46 |
+
|
47 |
= 3.5.1 =
|
48 |
* Bug fix for magic checkout blank order issue.
|
49 |
|
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
|
@@ -59,6 +59,7 @@ function woocommerce_razorpay_init()
|
|
59 |
|
60 |
protected $supportedWebhookEvents = array(
|
61 |
'payment.authorized',
|
|
|
62 |
'refund.created',
|
63 |
'virtual_account.credited'
|
64 |
);
|
3 |
* Plugin Name: Razorpay for WooCommerce
|
4 |
* Plugin URI: https://razorpay.com
|
5 |
* Description: Razorpay Payment Gateway Integration for WooCommerce
|
6 |
+
* Version: 3.6.0
|
7 |
+
* Stable tag: 3.6.0
|
8 |
* Author: Team Razorpay
|
9 |
* WC tested up to: 6.4.1
|
10 |
* Author URI: https://razorpay.com
|
59 |
|
60 |
protected $supportedWebhookEvents = array(
|
61 |
'payment.authorized',
|
62 |
+
'payment.pending',
|
63 |
'refund.created',
|
64 |
'virtual_account.credited'
|
65 |
);
|