PluginProbe ʕ •ᴥ•ʔ
Razorpay for WooCommerce / 4.8.6
Razorpay for WooCommerce v4.8.6
4.8.6 4.8.5 4.8.4 trunk 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.0-beta 1.6.1 1.6.2 1.6.3 1.6.5 2.0.0 2.0.1 2.1.0 2.2.0 2.3.0 2.3.1 2.3.2 2.4.0 2.4.1 2.4.2 2.4.3 2.5.0 2.6.0 2.7.0 2.7.1 2.7.2 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 3.0.0 3.0.1 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 3.3.0 3.4.0 3.4.1 3.5.0 3.5.1 3.6.0 3.7.0 3.7.1 3.7.2 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.0.1 4.1.0 4.2.0 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.4.0 4.4.1 4.4.2 4.4.3 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3
woo-razorpay / includes / razorpay-route-actions.php
woo-razorpay / includes Last commit date
Errors 8 years ago api 2 months ago cron 2 years ago support 5 months ago debug.php 4 years ago plugin-instrumentation.php 3 months ago razorpay-affordability-widget.php 4 weeks ago razorpay-route-actions.php 2 years ago razorpay-route.php 4 weeks ago razorpay-webhook.php 5 months ago state-map.php 4 years ago utils.php 3 years ago
razorpay-route-actions.php
320 lines
1 <?php
2
3 use Razorpay\Api\Api;
4 use Razorpay\Api\Errors;
5
6 require_once __DIR__ .'/razorpay-route.php';
7
8 class RZP_Route_Action
9 {
10
11 public function __construct()
12 {
13 $this->Wc_Razorpay_Loader = new WC_Razorpay();
14 }
15
16 protected function fetchRazorpayApiInstance()
17 {
18 return $this->Wc_Razorpay_Loader->getRazorpayApiInstance();
19 }
20
21 public function redirect($pageUrl)
22 {
23 wp_redirect($pageUrl);
24 }
25
26 public function authorizeAndAuthenticate($nonce, $action)
27 {
28 if(current_user_can('manage_woocommerce') === false)
29 {
30 rzpLogError("Authorization Failed");
31 wp_die('<div class="error notice">
32 <p>RAZORPAY ERROR: User is not Authorized to perform Operation</p>
33 </div>');
34 }
35
36 $verifyReq = wp_verify_nonce($nonce, $action);
37
38 if ($verifyReq === false)
39 {
40 rzpLogError("nonce Authentication failed");
41 wp_die('<div class="error notice">
42 <p>RAZORPAY ERROR: Authentication Failed</p>
43 </div>');
44 }
45 }
46
47 function directTransfer()
48 {
49 $trfAccount = sanitize_text_field($_POST['drct_trf_account']);
50 $trfAmount = sanitize_text_field($_POST['drct_trf_amount']);
51 $nonce = sanitize_text_field($_POST['nonce']);
52
53 $this->authorizeAndAuthenticate($nonce, 'rzp_direct_transfer');
54
55 $pageUrl = admin_url('admin.php?page=razorpayRouteWoocommerce');
56 try {
57 $transferData = array(
58
59 'account' => $trfAccount,
60 'amount' => (int)round($trfAmount * 100),
61 'currency' => 'INR'
62 );
63
64 $this->api = $this->fetchRazorpayApiInstance();
65
66 $this->api->transfer->create($transferData);
67 } catch (Exception $e) {
68 $message = $e->getMessage();
69
70 wp_die('<div class="error notice">
71 <p>RAZORPAY ERROR: Transfers create failed with the following message: ' . $message . '</p>
72 </div>');
73 }
74 $this->redirect($pageUrl);
75 }
76
77 function reverseTransfer()
78 {
79 $transferId = sanitize_text_field($_POST['transfer_id']);
80 $reversalAmount = sanitize_text_field($_POST['reversal_amount']);
81 $nonce = sanitize_text_field($_POST['nonce']);
82
83 $this->authorizeAndAuthenticate($nonce, 'rzp_reverse_transfer');
84
85 $pageUrl = admin_url('admin.php?page=razorpayTransfers&id=' . $transferId);
86 try {
87 $reversalData = array(
88 'amount' => (int)round($reversalAmount * 100),
89 );
90
91 $this->api = $this->fetchRazorpayApiInstance();
92
93 $this->api->transfer->fetch($transferId)->reverse($reversalData);
94 } catch (Exception $e) {
95 $message = $e->getMessage();
96
97 wp_die('<div class="error notice">
98 <p>RAZORPAY ERROR: Reverse Transfer failed with the following message: ' . $message . '</p>
99 </div>');
100 }
101 $this->redirect($pageUrl);
102 }
103
104 function updateTransferSettlement()
105 {
106 $transferId = sanitize_text_field($_POST['transfer_id']);
107 $trfHoldStatus = sanitize_text_field($_POST['on_hold']);
108 $nonce = sanitize_text_field($_POST['nonce']);
109
110 $this->authorizeAndAuthenticate($nonce, 'rzp_settlement_change');
111
112 if ($trfHoldStatus == "on_hold_until") {
113 $trfHoldUntil = sanitize_text_field($_POST['hold_until']);
114 $unixTime = strtotime($trfHoldUntil);
115
116 $trfHoldStatus = true;
117 }
118
119 $pageUrl = admin_url('admin.php?page=razorpayTransfers&id=' . $transferId);
120 try {
121 $updateData = array(
122 'on_hold' => $trfHoldStatus,
123 'on_hold_until' => $unixTime,
124 );
125
126 $url = "transfers/" . $transferId;
127
128 $this->api = $this->fetchRazorpayApiInstance();
129
130 $this->api->request->request("PATCH", $url, $updateData);
131
132 } catch (Exception $e) {
133 $message = $e->getMessage();
134
135 wp_die('<div class="error notice">
136 <p>RAZORPAY ERROR: Change settlement schedule failed with the following message: ' . $message . '</p>
137 </div>');
138 }
139 $this->redirect($pageUrl);
140 }
141
142 function createPaymentTransfer()
143 {
144 $paymentId = sanitize_text_field($_POST['payment_id']);
145 $trfAccount = sanitize_text_field($_POST['pay_trf_account']);
146 $trfAmount = sanitize_text_field($_POST['pay_trf_amount']);
147 $nonce = sanitize_text_field($_POST['nonce']);
148
149 $this->authorizeAndAuthenticate($nonce, 'rzp_payment_transfer');
150
151 $pageUrl = admin_url('admin.php?page=razorpayPaymentsView&id=' . $paymentId);
152
153 $trfHoldStatus = sanitize_text_field($_POST['on_hold']);
154 if ($trfHoldStatus == "on_hold_until") {
155 $trfHoldUntil = sanitize_text_field($_POST['hold_until']);
156 $unixTime = strtotime($trfHoldUntil);
157
158 $trfHoldStatus = true;
159 }
160 try {
161
162 $data = array(
163 'transfers' => array(
164 array(
165 'account' => $trfAccount,
166 'amount' => (int)round($trfAmount * 100),
167 'currency' => 'INR',
168 'on_hold' => $trfHoldStatus,
169 'on_hold_until' => $unixTime,)
170 )
171 );
172
173 $this->api = $this->fetchRazorpayApiInstance();
174
175 $this->api->payment->fetch($paymentId)->transfer($data);
176
177 } catch (Exception $e) {
178 $message = $e->getMessage();
179
180 wp_die('<div class="error notice">
181 <p>RAZORPAY ERROR: Transfers create failed with the following message: ' . $message . '</p>
182 </div>');
183 }
184 $this->redirect($pageUrl);
185 }
186
187 function getOrderTransferData($orderId){
188 $order = wc_get_order($orderId);
189
190 $items = $order->get_items();
191 $orderTransferArr = array();
192
193 foreach ( $items as $item ) {
194 $productId = $item['product_id'];
195 $rzpTransferFrom = get_post_meta($productId, 'rzp_transfer_from', true);
196
197 if($rzpTransferFrom == 'from_order'){
198
199 $LA_number_arr = get_post_meta($productId, 'LA_number', true);
200 $LA_amount_arr = get_post_meta($productId, 'LA_transfer_amount', true);
201 $LA_trf_status_arr = get_post_meta($productId, 'LA_transfer_status', true);
202
203 if(isset($LA_number_arr) && is_array($LA_number_arr) && isset($LA_amount_arr) && is_array($LA_amount_arr)) {
204 $LA_transfer_count = count($LA_number_arr);
205 for($i=0;$i<$LA_transfer_count;$i++){
206 if(!empty($LA_number_arr[$i]) && !empty($LA_amount_arr[$i])){
207 $transferArr = array(
208
209 'account'=> $LA_number_arr[$i],
210 'amount'=> (int) round($LA_amount_arr[$i] * 100),
211 'currency'=> 'INR',
212 'on_hold'=> $LA_trf_status_arr[$i]
213 );
214
215 array_push($orderTransferArr, $transferArr);
216 }
217 }
218 }
219 }
220
221 }
222
223 return $orderTransferArr;
224 }
225
226 function transferFromPayment($orderId, $razorpayPaymentId){
227
228 $order = wc_get_order($orderId);
229
230 $items = $order->get_items();
231 $paymentTransferArr = array();
232
233 foreach ( $items as $item ) {
234 $productId = $item['product_id'];
235 $rzp_transfer_from = get_post_meta($productId, 'rzp_transfer_from', true);
236
237 if($rzp_transfer_from == 'from_payment'){
238
239 $LA_number_arr = get_post_meta($productId, 'LA_number', true);
240 $LA_amount_arr = get_post_meta($productId, 'LA_transfer_amount', true);
241 $LA_trf_status_arr = get_post_meta($productId, 'LA_transfer_status', true);
242
243 if(isset($LA_number_arr) && is_array($LA_number_arr) && isset($LA_amount_arr) && is_array($LA_amount_arr)) {
244 $LA_transfer_count = count($LA_number_arr);
245 for($i=0;$i<$LA_transfer_count;$i++){
246 if(!empty($LA_number_arr[$i]) && !empty($LA_amount_arr[$i])){
247 $transferArr = array(
248
249 'account'=> $LA_number_arr[$i],
250 'amount'=> (int) round($LA_amount_arr[$i] * 100),
251 'currency'=> 'INR',
252 'on_hold'=> $LA_trf_status_arr[$i]
253 );
254 array_push($paymentTransferArr, $transferArr);
255 }
256 }
257 }
258 }
259
260 }
261
262 if(isset($paymentTransferArr) && !empty($paymentTransferArr)){
263
264 $data = array(
265
266 'transfers' => $paymentTransferArr
267 );
268
269 $url = "payments/".$razorpayPaymentId."/transfers";
270
271 $this->api = $this->fetchRazorpayApiInstance();
272
273 $this->api->request->request("POST", $url, $data);
274
275 $this->addRouteAnalyticsScript();
276
277 }
278
279 }
280
281 function addRouteAnalyticsScript() {
282
283 $mod_version = get_plugin_data(PLUGIN_DIR . '/woo-razorpay.php')['Version'];
284 $Wc_Razorpay_Loader = new WC_Razorpay();
285
286 $data = array(
287 'key' => $Wc_Razorpay_Loader->getSetting('key_id'),
288 'name' => get_bloginfo('name'),
289 '_' => array(
290 'x-integration' => 'Woocommerce',
291 'x-integration-module' => 'Route',
292 'x-integration-version' => $mod_version,
293 'x-integration-parent-version' => WOOCOMMERCE_VERSION,
294 ),
295 );
296
297 $Wc_Razorpay_Loader->enqueueCheckoutScripts('routeAnalyticsForm');
298
299 $url = Api::getFullUrl("checkout/embedded");
300
301 $formFields = "";
302 foreach ($data as $fieldKey => $val) {
303 if(in_array($fieldKey, array('prefill', '_')))
304 {
305 foreach ($data[$fieldKey] as $field => $fieldVal) {
306 $formFields .= "<input type='hidden' name='$fieldKey" ."[$field]"."' value='$fieldVal'> \n";
307 }
308 }
309 }
310
311 return '<form method="POST" action="'.$url.'" id="routeAnalyticsForm">
312 <input type="hidden" name="key_id" value="'.$data['key'].'">
313 <input type="hidden" name="name" value="'.$data['name'].'">
314 '. $formFields .'
315 </form>';
316
317 }
318
319 }
320