Razorpay for WooCommerce - Version 1.6.2

Version Description

  • Fixes webhook capture flow by re-fetching payment and checking for status
Download this release

Release Info

Developer mayankamencherla
Plugin Icon 128x128 Razorpay for WooCommerce
Version 1.6.2
Comparing to
See all releases

Code changes from version 1.6.1 to 1.6.2

.editorconfig DELETED
@@ -1,13 +0,0 @@
1
- ; This file is for unifying the coding style for different editors and IDEs.
2
- ; More information at http://EditorConfig.org
3
-
4
- root = true
5
- ; Use 2 spaces for indentation in all files
6
-
7
- [*.php]
8
- end_of_line = lf
9
- charset = utf-8
10
- trim_trailing_whitespace = true
11
- indent_style = space
12
- indent_size = 4
13
- insert_final_newline = true
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/razorpay-webhook.php CHANGED
@@ -143,22 +143,7 @@ class RZP_Webhook
143
 
144
  $razorpayPaymentId = $data['payload']['payment']['entity']['id'];
145
 
146
- try
147
- {
148
- $payment = $this->api->payment->fetch($razorpayPaymentId);
149
- }
150
- catch (Exception $e)
151
- {
152
- $log = array(
153
- 'message' => $e->getMessage(),
154
- 'payment_id' => $razorpayPaymentId,
155
- 'event' => $data['event']
156
- );
157
-
158
- error_log(json_encode($log));
159
-
160
- exit;
161
- }
162
 
163
  $amount = $this->getOrderAmountAsInteger($order);
164
 
@@ -176,9 +161,35 @@ class RZP_Webhook
176
  // If the payment is only authorized, we capture it
177
  // If the merchant has enabled auto capture
178
  //
179
- $payment->capture(array('amount' => $amount));
 
 
180
 
181
- $success = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  }
183
 
184
  $this->razorpay->updateOrder($order, $success, $errorMessage, $razorpayPaymentId, true);
@@ -187,6 +198,28 @@ class RZP_Webhook
187
  exit;
188
  }
189
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  /**
191
  * Returns the order amount, rounded as integer
192
  * @param WC_Order $order WooCommerce Order instance
143
 
144
  $razorpayPaymentId = $data['payload']['payment']['entity']['id'];
145
 
146
+ $payment = $this->getPaymentEntity($razorpayPaymentId, $data);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
  $amount = $this->getOrderAmountAsInteger($order);
149
 
161
  // If the payment is only authorized, we capture it
162
  // If the merchant has enabled auto capture
163
  //
164
+ try
165
+ {
166
+ $payment->capture(array('amount' => $amount));
167
 
168
+ $success = true;
169
+ }
170
+ catch (Exception $e)
171
+ {
172
+ //
173
+ // Capture will fail if the payment is already captured
174
+ //
175
+ $log = array(
176
+ 'message' => $e->getMessage(),
177
+ 'payment_id' => $razorpayPaymentId,
178
+ 'event' => $data['event']
179
+ );
180
+
181
+ error_log(json_encode($log));
182
+
183
+ //
184
+ // We re-fetch the payment entity and check if the payment is captured now
185
+ //
186
+ $payment = $this->getPaymentEntity($razorpayPaymentId, $data);
187
+
188
+ if ($payment['status'] === 'captured')
189
+ {
190
+ $success = true;
191
+ }
192
+ }
193
  }
194
 
195
  $this->razorpay->updateOrder($order, $success, $errorMessage, $razorpayPaymentId, true);
198
  exit;
199
  }
200
 
201
+ protected function getPaymentEntity($razorpayPaymentId, $data)
202
+ {
203
+ try
204
+ {
205
+ $payment = $this->api->payment->fetch($razorpayPaymentId);
206
+ }
207
+ catch (Exception $e)
208
+ {
209
+ $log = array(
210
+ 'message' => $e->getMessage(),
211
+ 'payment_id' => $razorpayPaymentId,
212
+ 'event' => $data['event']
213
+ );
214
+
215
+ error_log(json_encode($log));
216
+
217
+ exit;
218
+ }
219
+
220
+ return $payment;
221
+ }
222
+
223
  /**
224
  * Returns the order amount, rounded as integer
225
  * @param WC_Order $order WooCommerce Order instance
razorpay-payments.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: 1.6.1
7
- * Stable tag: 1.6.1
8
  * Author: Team Razorpay
9
  * WC tested up to: 3.2.1
10
  * Author URI: https://razorpay.com
3
  * Plugin Name: Razorpay for WooCommerce
4
  * Plugin URI: https://razorpay.com
5
  * Description: Razorpay Payment Gateway Integration for WooCommerce
6
+ * Version: 1.6.2
7
+ * Stable tag: 1.6.2
8
  * Author: Team Razorpay
9
  * WC tested up to: 3.2.1
10
  * Author URI: https://razorpay.com
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: 4.8
6
- Stable tag: 1.6.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -36,6 +36,9 @@ This is compatible with WooCommerce>=2.4, including the new 3.0 release. It has
36
 
37
  == Changelog ==
38
 
 
 
 
39
  = 1.6.1 =
40
  * Fixes payment title/description in WC Checkout page.
41
  * Adds WooCommerce version tested in the plugin metadata
3
  Tags: razorpay, payments, india, woocommerce, ecommerce
4
  Requires at least: 3.9.2
5
  Tested up to: 4.8
6
+ Stable tag: 1.6.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
36
 
37
  == Changelog ==
38
 
39
+ = 1.6.2 =
40
+ * Fixes webhook capture flow by re-fetching payment and checking for status
41
+
42
  = 1.6.1 =
43
  * Fixes payment title/description in WC Checkout page.
44
  * Adds WooCommerce version tested in the plugin metadata