Razorpay for WooCommerce - Version 2.6.0

Version Description

  • Added webhook for virtual account credited event .
  • Tested upto WordPress 5.6 and WooCommerce 4.6.1
Download this release

Release Info

Developer chetangn
Plugin Icon 128x128 Razorpay for WooCommerce
Version 2.6.0
Comparing to
See all releases

Code changes from version 2.5.0 to 2.6.0

Files changed (3) hide show
  1. includes/razorpay-webhook.php +90 -1
  2. readme.txt +6 -2
  3. woo-razorpay.php +12 -7
includes/razorpay-webhook.php CHANGED
@@ -27,6 +27,7 @@ class RZP_Webhook
27
  const PAYMENT_FAILED = 'payment.failed';
28
  const SUBSCRIPTION_CANCELLED = 'subscription.cancelled';
29
  const REFUNDED_CREATED = 'refund.created';
 
30
 
31
  public function __construct()
32
  {
@@ -102,6 +103,9 @@ class RZP_Webhook
102
  case self::PAYMENT_AUTHORIZED:
103
  return $this->paymentAuthorized($data);
104
 
 
 
 
105
  case self::PAYMENT_FAILED:
106
  return $this->paymentFailed($data);
107
 
@@ -214,7 +218,92 @@ class RZP_Webhook
214
  }
215
  }
216
 
217
- $this->razorpay->updateOrder($order, $success, $errorMessage, $razorpayPaymentId, true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
 
219
  // Graceful exit since payment is now processed.
220
  exit;
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';
31
 
32
  public function __construct()
33
  {
103
  case self::PAYMENT_AUTHORIZED:
104
  return $this->paymentAuthorized($data);
105
 
106
+ case self::VIRTUAL_ACCOUNT_CREDITED:
107
+ return $this->virtualAccountCredited($data);
108
+
109
  case self::PAYMENT_FAILED:
110
  return $this->paymentFailed($data);
111
 
218
  }
219
  }
220
 
221
+ $this->razorpay->updateOrder($order, $success, $errorMessage, $razorpayPaymentId, null, true);
222
+
223
+ // Graceful exit since payment is now processed.
224
+ exit;
225
+ }
226
+
227
+ /**
228
+ * Handling the virtual account credited webhook
229
+ *
230
+ * @param array $data Webook Data
231
+ */
232
+ protected function virtualAccountCredited(array $data)
233
+ {
234
+ // We don't process subscription/invoice payments here
235
+ if (isset($data['payload']['payment']['entity']['invoice_id']) === true)
236
+ {
237
+ return;
238
+ }
239
+
240
+ //
241
+ // Order entity should be sent as part of the webhook payload
242
+ //
243
+ $orderId = $data['payload']['payment']['entity']['notes']['woocommerce_order_id'];
244
+
245
+ $order = new WC_Order($orderId);
246
+
247
+ // If it is already marked as paid, ignore the event
248
+ if ($order->needs_payment() === false)
249
+ {
250
+ return;
251
+ }
252
+
253
+ $razorpayPaymentId = $data['payload']['payment']['entity']['id'];
254
+ $virtualAccountId = $data['payload']['virtual_account']['entity']['id'];
255
+ $amountPaid = (int) $data['payload']['virtual_account']['entity']['amount_paid'];
256
+
257
+ $payment = $this->getPaymentEntity($razorpayPaymentId, $data);
258
+
259
+ $amount = $this->getOrderAmountAsInteger($order);
260
+
261
+ $success = false;
262
+ $errorMessage = 'The payment has failed.';
263
+
264
+ if ($payment['status'] === 'captured' and $amountPaid === $amount)
265
+ {
266
+ $success = true;
267
+ }
268
+ else if (($payment['status'] === 'authorized') and $amountPaid === $amount and
269
+ ($this->razorpay->getSetting('payment_action') === WC_Razorpay::CAPTURE))
270
+ {
271
+ //
272
+ // If the payment is only authorized, we capture it
273
+ // If the merchant has enabled auto capture
274
+ //
275
+ try
276
+ {
277
+ $payment->capture(array('amount' => $amount));
278
+
279
+ $success = true;
280
+ }
281
+ catch (Exception $e)
282
+ {
283
+ //
284
+ // Capture will fail if the payment is already captured
285
+ //
286
+ $log = array(
287
+ 'message' => $e->getMessage(),
288
+ 'payment_id' => $razorpayPaymentId,
289
+ 'event' => $data['event']
290
+ );
291
+
292
+ error_log(json_encode($log));
293
+
294
+ //
295
+ // We re-fetch the payment entity and check if the payment is captured now
296
+ //
297
+ $payment = $this->getPaymentEntity($razorpayPaymentId, $data);
298
+
299
+ if ($payment['status'] === 'captured')
300
+ {
301
+ $success = true;
302
+ }
303
+ }
304
+ }
305
+
306
+ $this->razorpay->updateOrder($order, $success, $errorMessage, $razorpayPaymentId, $virtualAccountId, true);
307
 
308
  // Graceful exit since payment is now processed.
309
  exit;
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: razorpay
3
  Tags: razorpay, payments, india, woocommerce, ecommerce
4
  Requires at least: 3.9.2
5
- Tested up to: 5.4.2
6
- Stable tag: 2.5.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,10 @@ This is compatible with WooCommerce>=2.4, including the new 3.0 release. It has
41
 
42
  == Changelog ==
43
 
 
 
 
 
44
  = 2.5.0 =
45
  * Added support for "Pay by Cred".
46
  * Tested upto WordPress 5.4.2 and WooCommerce 4.3.0
2
  Contributors: razorpay
3
  Tags: razorpay, payments, india, woocommerce, ecommerce
4
  Requires at least: 3.9.2
5
+ Tested up to: 5.6
6
+ Stable tag: 2.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
+ = 2.6.0 =
45
+ * Added webhook for virtual account credited event .
46
+ * Tested upto WordPress 5.6 and WooCommerce 4.6.1
47
+
48
  = 2.5.0 =
49
  * Added support for "Pay by Cred".
50
  * Tested upto WordPress 5.4.2 and WooCommerce 4.3.0
woo-razorpay.php CHANGED
@@ -3,10 +3,10 @@
3
  * Plugin Name: Razorpay for WooCommerce
4
  * Plugin URI: https://razorpay.com
5
  * Description: Razorpay Payment Gateway Integration for WooCommerce
6
- * Version: 2.5.0
7
- * Stable tag: 2.5.0
8
  * Author: Team Razorpay
9
- * WC tested up to: 4.3.0
10
  * Author URI: https://razorpay.com
11
  */
12
 
@@ -116,7 +116,7 @@ function woocommerce_razorpay_init()
116
  */
117
  public function getSetting($key)
118
  {
119
- return $this->settings[$key];
120
  }
121
 
122
  protected function getCustomOrdercreationMessage()
@@ -818,13 +818,13 @@ EOT;
818
  }
819
 
820
  $this->handleErrorCase($order);
821
- $this->updateOrder($order, $success, $error, $razorpayPaymentId);
822
 
823
  wp_redirect(wc_get_checkout_url());
824
  exit;
825
  }
826
 
827
- $this->updateOrder($order, $success, $error, $razorpayPaymentId);
828
 
829
  $this->redirectUser($order);
830
  }
@@ -889,7 +889,7 @@ EOT;
889
  *
890
  * @param $success, & $order
891
  */
892
- public function updateOrder(& $order, $success, $errorMessage, $razorpayPaymentId, $webhook = false)
893
  {
894
  global $woocommerce;
895
 
@@ -903,6 +903,11 @@ EOT;
903
  $order->payment_complete($razorpayPaymentId);
904
  $order->add_order_note("Razorpay payment successful <br/>Razorpay Id: $razorpayPaymentId");
905
 
 
 
 
 
 
906
  if (isset($woocommerce->cart) === true)
907
  {
908
  $woocommerce->cart->empty_cart();
3
  * Plugin Name: Razorpay for WooCommerce
4
  * Plugin URI: https://razorpay.com
5
  * Description: Razorpay Payment Gateway Integration for WooCommerce
6
+ * Version: 2.6.0
7
+ * Stable tag: 2.6.0
8
  * Author: Team Razorpay
9
+ * WC tested up to: 4.6.1
10
  * Author URI: https://razorpay.com
11
  */
12
 
116
  */
117
  public function getSetting($key)
118
  {
119
+ return $this->get_option($key);
120
  }
121
 
122
  protected function getCustomOrdercreationMessage()
818
  }
819
 
820
  $this->handleErrorCase($order);
821
+ $this->updateOrder($order, $success, $error, $razorpayPaymentId, null);
822
 
823
  wp_redirect(wc_get_checkout_url());
824
  exit;
825
  }
826
 
827
+ $this->updateOrder($order, $success, $error, $razorpayPaymentId, null);
828
 
829
  $this->redirectUser($order);
830
  }
889
  *
890
  * @param $success, & $order
891
  */
892
+ public function updateOrder(& $order, $success, $errorMessage, $razorpayPaymentId, $virtualAccountId = null, $webhook = false)
893
  {
894
  global $woocommerce;
895
 
903
  $order->payment_complete($razorpayPaymentId);
904
  $order->add_order_note("Razorpay payment successful <br/>Razorpay Id: $razorpayPaymentId");
905
 
906
+ if($virtualAccountId != null)
907
+ {
908
+ $order->add_order_note("Virtual Account Id: $virtualAccountId");
909
+ }
910
+
911
  if (isset($woocommerce->cart) === true)
912
  {
913
  $woocommerce->cart->empty_cart();