Persian Woocommerce - Version 3.3.0

Version Description

  • 3.3 PHP 7.2
Download this release

Release Info

Developer Persianscript
Plugin Icon 128x128 Persian Woocommerce
Version 3.3.0
Comparing to
See all releases

Code changes from version 3.2.6.1 to 3.3.0

assets/images/payir.png CHANGED
Binary file
include/persian-woocommerce.php CHANGED
@@ -301,7 +301,7 @@ class Persian_Woocommerce_Plugin {
301
  $this->translate = wp_list_pluck( $result, 'text2', 'text1' );
302
  }
303
 
304
- if( is_array( $this->translate ) && count( is_array( $this->translate ) ) ) {
305
  add_filter( 'gettext_with_context', array( $this, 'pw_gettext' ) );
306
  add_filter( 'ngettext_with_context', array( $this, 'pw_gettext' ) );
307
  add_filter( 'gettext', array( $this, 'pw_gettext' ) );
301
  $this->translate = wp_list_pluck( $result, 'text2', 'text1' );
302
  }
303
 
304
+ if( is_array( $this->translate ) && count( $this->translate ) ) {
305
  add_filter( 'gettext_with_context', array( $this, 'pw_gettext' ) );
306
  add_filter( 'ngettext_with_context', array( $this, 'pw_gettext' ) );
307
  add_filter( 'gettext', array( $this, 'pw_gettext' ) );
include/tools/class-payir.php CHANGED
@@ -1,624 +1,624 @@
1
- <?php
2
-
3
- if( ! defined( 'ABSPATH' ) ) {
4
- die( 'This file cannot be accessed directly' );
5
- }
6
-
7
- function PW_Load_Payir_Gateway() {
8
-
9
- if( class_exists( 'WC_Payment_Gateway' ) && ! class_exists( 'WC_Payir_Gateway' ) && ! function_exists( 'Woocommerce_Add_Payir_Gateway' ) ) {
10
-
11
- add_filter( 'woocommerce_payment_gateways', 'Woocommerce_Add_Payir_Gateway' );
12
-
13
- function Woocommerce_Add_Payir_Gateway( $methods ) {
14
- $methods[] = 'WC_Payir_Gateway';
15
-
16
- return $methods;
17
- }
18
-
19
- add_filter( 'woocommerce_currencies', 'add_payir_currency' );
20
-
21
- function add_payir_currency( $currencies ) {
22
- $currencies['IRR'] = __( 'ریال', 'woocommerce' );
23
- $currencies['IRT'] = __( 'تومان', 'woocommerce' );
24
- $currencies['IRHR'] = __( 'هزار ریال', 'woocommerce' );
25
- $currencies['IRHT'] = __( 'هزار تومان', 'woocommerce' );
26
-
27
- return $currencies;
28
- }
29
-
30
- add_filter( 'woocommerce_currency_symbol', 'add_payir_currency_symbol', 10, 2 );
31
-
32
- function add_payir_currency_symbol( $currency_symbol, $currency ) {
33
- switch( $currency ) {
34
-
35
- case 'IRR':
36
- $currency_symbol = 'ریال';
37
- break;
38
-
39
- case 'IRT':
40
- $currency_symbol = 'تومان';
41
- break;
42
-
43
- case 'IRHR':
44
- $currency_symbol = 'هزار ریال';
45
- break;
46
-
47
- case 'IRHT':
48
- $currency_symbol = 'هزار تومان';
49
- break;
50
- }
51
-
52
- return $currency_symbol;
53
- }
54
-
55
- class WC_Payir_Gateway extends WC_Payment_Gateway {
56
-
57
- public function __construct() {
58
- $this->id = 'payir';
59
- $this->method_title = __( 'درگاه پرداخت و کیف پول الکترونیک Pay.ir', 'woocommerce' );
60
- $this->method_description = __( 'تنظیمات درگاه پرداخت و کیف پول الکترونیک Pay.ir برای افزونه WooCommerce', 'woocommerce' );
61
- $this->icon = apply_filters( 'WC_Payir_logo', plugin_dir_url( __FILE__ ) . '/images/payir.png' );
62
- $this->has_fields = false;
63
-
64
- $this->init_form_fields();
65
- $this->init_settings();
66
-
67
- $this->title = $this->settings['title'];
68
- $this->description = $this->settings['description'];
69
-
70
- $this->api_key = $this->settings['api_key'];
71
-
72
- $this->success_massage = $this->settings['success_massage'];
73
- $this->failed_massage = $this->settings['failed_massage'];
74
-
75
- if( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) ) {
76
-
77
- add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array(
78
- $this,
79
- 'process_admin_options'
80
- ) );
81
-
82
- } else {
83
-
84
- add_action( 'woocommerce_update_options_payment_gateways', array(
85
- $this,
86
- 'process_admin_options'
87
- ) );
88
- }
89
-
90
- add_action( 'woocommerce_receipt_' . $this->id, array( $this, 'Send_to_Payir_Gateway' ) );
91
- add_action( 'woocommerce_api_' . strtolower( get_class( $this ) ) . '', array(
92
- $this,
93
- 'Return_from_Payir_Gateway'
94
- ) );
95
- }
96
-
97
- public function admin_options() {
98
- parent::admin_options();
99
- }
100
-
101
- public function init_form_fields() {
102
- $this->form_fields = apply_filters( 'WC_Payir_Config', array(
103
-
104
- 'base_confing' => array(
105
-
106
- 'title' => __( 'تنظیمات پایه', 'woocommerce' ),
107
- 'type' => 'title',
108
- 'description' => null,
109
- 'desc_tip' => false
110
- ),
111
- 'enabled' => array(
112
-
113
- 'title' => __( 'فعال سازی / غیر فعال سازی', 'woocommerce' ),
114
- 'type' => 'checkbox',
115
- 'label' => __( 'فعال سازی درگاه پرداخت Pay.ir', 'woocommerce' ),
116
- 'description' => __( 'برای فعال سازی درگاه پرداخت Pay.ir باید چک باکس را تیک بزنید', 'woocommerce' ),
117
- 'default' => 'no',
118
- 'desc_tip' => true
119
- ),
120
- 'title' => array(
121
-
122
- 'title' => __( 'عنوان درگاه', 'woocommerce' ),
123
- 'type' => 'text',
124
- 'description' => __( 'عنوانی که برای درگاه در طی مراحل خرید به مشتری نمایش داده میشود', 'woocommerce' ),
125
- 'default' => __( 'درگاه پرداخت و کیف پول الکترونیک Pay.ir', 'woocommerce' ),
126
- 'desc_tip' => true
127
- ),
128
- 'description' => array(
129
-
130
- 'title' => __( 'توضیحات درگاه', 'woocommerce' ),
131
- 'type' => 'text',
132
- 'description' => __( 'توضیحاتی که در مرحله پرداخت برای درگاه نمایش داده خواهد شد', 'woocommerce' ),
133
- 'default' => __( 'پرداخت امن با استفاده از کلیه کارت های عضو شبکه شتاب از طریق درگاه پرداخت و کیف پول الکترونیک Pay.ir', 'woocommerce' ),
134
- 'desc_tip' => true
135
- ),
136
- 'account_confing' => array(
137
-
138
- 'title' => __( 'تنظیمات حساب Pay.ir', 'woocommerce' ),
139
- 'type' => 'title',
140
- 'description' => null,
141
- 'desc_tip' => false
142
- ),
143
- 'api_key' => array(
144
-
145
- 'title' => __( 'کلید API', 'woocommerce' ),
146
- 'type' => 'text',
147
- 'description' => null,
148
- 'default' => null,
149
- 'desc_tip' => false
150
- ),
151
- 'payment_confing' => array(
152
-
153
- 'title' => __( 'تنظیمات عملیات پرداخت', 'woocommerce' ),
154
- 'type' => 'title',
155
- 'description' => null,
156
- 'desc_tip' => false
157
- ),
158
- 'success_massage' => array(
159
-
160
- 'title' => __( 'پیام پرداخت موفق', 'woocommerce' ),
161
- 'type' => 'textarea',
162
- 'description' => __( 'متن پیامی که می خواهید پس از پرداخت موفق به کاربر نمایش داده شود را وارد نمایید.<br/>شما می توانید از شورت کد {transaction_id} برای نمایش شماره پیگیری تراکنش استفاده نمایید.', 'woocommerce' ),
163
- 'default' => __( 'از شما سپاسگزاریم، سفارش شما با موفقیت پرداخت و تایید شد. شماره پیگیری: {transaction_id}', 'woocommerce' ),
164
- 'desc_tip' => false
165
- ),
166
- 'failed_massage' => array(
167
-
168
- 'title' => __( 'پیام پرداخت ناموفق', 'woocommerce' ),
169
- 'type' => 'textarea',
170
- 'description' => __( 'متن پیامی که می خواهید پس از پرداخت ناموفق به کاربر نمایش داده را وارد نمایید.<br/>شما می توانید از شورت کد {fault} برای نمایش دلیل خطای رخ داده استفاده نمایید. این دلیل خطا از سایت Pay.ir ارسال میگردد.', 'woocommerce' ),
171
- 'default' => __( 'متاسفانه پرداخت شما ناموفق بوده است، لطفا مجددا تلاش نمایید یا در صورت بروز اشکال با مدیر سایت تماس بگیرید. شرح خطا: {fault}', 'woocommerce' ),
172
- 'desc_tip' => false
173
- )
174
- ) );
175
- }
176
-
177
- public function process_payment( $order_id ) {
178
- $order = new WC_Order( $order_id );
179
-
180
- return array(
181
-
182
- 'result' => 'success',
183
- 'redirect' => $order->get_checkout_payment_url( true )
184
- );
185
- }
186
-
187
- public function Send_to_Payir_Gateway( $order_id ) {
188
- global $woocommerce;
189
-
190
- $woocommerce->session->order_id_payir = $order_id;
191
-
192
- $order = new WC_Order( $order_id );
193
-
194
- $currency = $order->get_currency();
195
- $currency = apply_filters( 'WC_Payir_Currency', $currency, $order_id );
196
-
197
- $form = '<form id="payir-checkout-form" name="payir-checkout-form" method="post" class="payir-checkout-form">';
198
- $form .= '<input id="payir-payment-button" name="payir_submit" type="submit" class="button alt" value="' . __( 'پرداخت', 'woocommerce' ) . '"/>';
199
- $form .= '<a href="' . $woocommerce->cart->get_checkout_url() . '" class="button cancel">' . __( 'بازگشت', 'woocommerce' ) . '</a>';
200
- $form .= '</form><br/>';
201
-
202
- $form = apply_filters( 'WC_Payir_Form', $form, $order_id, $woocommerce );
203
-
204
- do_action( 'WC_Payir_Gateway_Before_Form', $order_id, $woocommerce );
205
-
206
- echo $form;
207
-
208
- do_action( 'WC_Payir_Gateway_After_Form', $order_id, $woocommerce );
209
-
210
- $amount = intval( $order->get_total() );
211
- $amount = apply_filters( 'woocommerce_order_amount_total_IRANIAN_gateways_before_check_currency', $amount, $currency );
212
-
213
- if( strtolower( $currency ) == strtolower( 'IRT' ) || strtolower( $currency ) == strtolower( 'TOMAN' ) ) {
214
-
215
- $amount = $amount * 10;
216
- }
217
-
218
- if( strtolower( $currency ) == strtolower( 'Iran TOMAN' ) || strtolower( $currency ) == strtolower( 'Iranian TOMAN' ) ) {
219
-
220
- $amount = $amount * 10;
221
- }
222
-
223
- if( strtolower( $currency ) == strtolower( 'Iran-TOMAN' ) || strtolower( $currency ) == strtolower( 'Iranian-TOMAN' ) ) {
224
-
225
- $amount = $amount * 10;
226
- }
227
-
228
- if( strtolower( $currency ) == strtolower( 'Iran_TOMAN' ) || strtolower( $currency ) == strtolower( 'Iranian_TOMAN' ) ) {
229
-
230
- $amount = $amount * 10;
231
- }
232
-
233
- if( strtolower( $currency ) == strtolower( 'تومان' ) || strtolower( $currency ) == strtolower( 'تومان ایران' ) ) {
234
-
235
- $amount = $amount * 10;
236
- }
237
-
238
- if( strtolower( $currency ) == strtolower( 'IRHT' ) ) {
239
-
240
- $amount = $amount * 1000 * 10;
241
- }
242
-
243
- if( strtolower( $currency ) == strtolower( 'IRHR' ) ) {
244
-
245
- $amount = $amount * 1000;
246
- }
247
-
248
- if( strtolower( $currency ) == strtolower( 'IRR' ) ) {
249
-
250
- $amount = $amount;
251
- }
252
-
253
- $amount = apply_filters( 'woocommerce_order_amount_total_IRANIAN_gateways_after_check_currency', $amount, $currency );
254
- $amount = apply_filters( 'woocommerce_order_amount_total_IRANIAN_gateways_irt', $amount, $currency );
255
- $amount = apply_filters( 'woocommerce_order_amount_total_Payir_gateway', $amount, $currency );
256
-
257
- if( extension_loaded( 'curl' ) ) {
258
-
259
- $products = array();
260
- $order_items = $order->get_items();
261
-
262
- foreach( (array) $order_items as $product ) {
263
-
264
- $products[] = $product['name'] . ' (' . $product['qty'] . ') ';
265
- }
266
-
267
- $products = implode( ' - ', $products );
268
-
269
- $description = 'خرید به شماره سفارش: ' . $order->get_order_number();
270
- $mobile = get_post_meta( $order_id, '_billing_phone', true ) ? get_post_meta( $order_id, '_billing_phone', true ) : null;
271
-
272
- $description = apply_filters( 'WC_Payir_Description', $description, $order_id );
273
- $mobile = apply_filters( 'WC_Payir_Mobile', $mobile, $order_id );
274
- $email = apply_filters( 'WC_Payir_Email', $order->get_billing_email(), $order_id );
275
- $paymenter = apply_filters( 'WC_Payir_Paymenter', $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(), $order_id );
276
- $res_number = apply_filters( 'WC_Payir_ResNumber', intval( $order->get_order_number() ), $order_id );
277
-
278
- do_action( 'WC_Payir_Gateway_Payment', $order_id, $description, $mobile );
279
-
280
- $api_key = $this->api_key;
281
- $callback = add_query_arg( 'wc_order', $order_id, WC()->api_request_url( 'WC_Payir_Gateway' ) );
282
- $payresid = '1000000800';
283
- $params = array(
284
-
285
- 'api' => $api_key,
286
- 'amount' => $amount,
287
- 'redirect' => urlencode( $callback ),
288
- 'mobile' => $mobile,
289
- 'resellerId' => $payresid,
290
- 'factorNumber' => $order_id,
291
- 'description' => $description
292
- );
293
-
294
- $result = $this->common( 'https://pay.ir/payment/send', $params );
295
-
296
- if( $result && isset( $result->status ) && $result->status == 1 ) {
297
-
298
- $gateway_url = 'https://pay.ir/payment/gateway/' . $result->transId;
299
-
300
- if( ! headers_sent() ) {
301
-
302
- header( 'Location: ' . $gateway_url );
303
- exit;
304
-
305
- } else {
306
-
307
- echo 'در حال انتقال به درگاه بانکی...';
308
- echo '<script type="text/javascript">window.onload = function(){top.location.href = "' . $gateway_url . '";};</script>';
309
- exit;
310
- }
311
-
312
- } else {
313
-
314
- $message = 'در ارتباط با وب سرویس Pay.ir خطایی رخ داده است';
315
-
316
- $fault = isset( $result->errorCode ) ? $result->errorCode : 'Send';
317
- $message = isset( $result->errorMessage ) ? $result->errorMessage : $message;
318
- }
319
-
320
- } else {
321
-
322
- $fault = 'cUrl';
323
- $message = 'تابع cURL در سرور فعال نمی باشد';
324
- }
325
-
326
- if( ! empty( $message ) && $message ) {
327
-
328
- $note = sprintf( __( 'خطایی رخ داده است: %s', 'woocommerce' ), $message );
329
- $note = apply_filters( 'WC_Payir_Send_to_Gateway_Failed_Note', $note, $order_id, $fault );
330
-
331
- $order->add_order_note( $note );
332
-
333
- $notice = sprintf( __( 'خطایی رخ داده است:<br/>%s', 'woocommerce' ), $message );
334
- $notice = apply_filters( 'WC_Payir_Send_to_Gateway_Failed_Notice', $notice, $order_id, $fault );
335
-
336
- if( $notice ) {
337
-
338
- wc_add_notice( $notice, 'error' );
339
- }
340
-
341
- do_action( 'WC_Payir_Send_to_Gateway_Failed', $order_id, $fault );
342
- }
343
- }
344
-
345
- public function Return_from_Payir_Gateway() {
346
- global $woocommerce;
347
-
348
- $order_id = null;
349
-
350
- $factor_number = isset( $_POST['factorNumber'] ) ? sanitize_text_field( $_POST['factorNumber'] ) : null;
351
- $trans_id = isset( $_POST['transId'] ) ? sanitize_text_field( $_POST['transId'] ) : null;
352
-
353
- if( $trans_id ) {
354
-
355
- update_post_meta( $order_id, '_transaction_id', $trans_id );
356
- }
357
-
358
- if( isset( $_GET['wc_order'] ) ) {
359
-
360
- $order_id = sanitize_text_field( $_GET['wc_order'] );
361
-
362
- } elseif( $factor_number ) {
363
-
364
- $order_id = $factor_number;
365
-
366
- } else {
367
-
368
- $order_id = $woocommerce->session->order_id_payir;
369
-
370
- unset( $woocommerce->session->order_id_payir );
371
- }
372
-
373
- if( $order_id ) {
374
-
375
- $order = new WC_Order( $order_id );
376
- $currency = $order->get_currency();
377
- $currency = apply_filters( 'WC_Payir_Currency', $currency, $order_id );
378
-
379
- if( $order->get_status() != 'completed' && $order->get_status() != 'processing' ) {
380
-
381
- if( isset( $_POST['status'] ) && isset( $_POST['transId'] ) && isset( $_POST['factorNumber'] ) ) {
382
-
383
- $api_key = $this->api_key;
384
-
385
- $payir_status = sanitize_text_field( $_POST['status'] );
386
- $payir_trans_id = sanitize_text_field( $_POST['transId'] );
387
- $payir_factor_number = sanitize_text_field( $_POST['factorNumber'] );
388
- $payir_message = sanitize_text_field( $_POST['message'] );
389
-
390
- if( isset( $payir_status ) && $payir_status == 1 ) {
391
-
392
- $params = array(
393
-
394
- 'api' => $api_key,
395
- 'transId' => $payir_trans_id
396
- );
397
-
398
- $result = $this->common( 'https://pay.ir/payment/verify', $params );
399
-
400
- if( $result && isset( $result->status ) && $result->status == 1 ) {
401
-
402
- $amount = intval( $order->get_total() );
403
- $amount = apply_filters( 'woocommerce_order_amount_total_IRANIAN_gateways_before_check_currency', $amount, $currency );
404
-
405
- if( strtolower( $currency ) == strtolower( 'IRT' ) || strtolower( $currency ) == strtolower( 'TOMAN' ) ) {
406
-
407
- $amount = $amount * 10;
408
- }
409
-
410
- if( strtolower( $currency ) == strtolower( 'Iran TOMAN' ) || strtolower( $currency ) == strtolower( 'Iranian TOMAN' ) ) {
411
-
412
- $amount = $amount * 10;
413
- }
414
-
415
- if( strtolower( $currency ) == strtolower( 'Iran-TOMAN' ) || strtolower( $currency ) == strtolower( 'Iranian-TOMAN' ) ) {
416
-
417
- $amount = $amount * 10;
418
- }
419
-
420
- if( strtolower( $currency ) == strtolower( 'Iran_TOMAN' ) || strtolower( $currency ) == strtolower( 'Iranian_TOMAN' ) ) {
421
-
422
- $amount = $amount * 10;
423
- }
424
-
425
- if( strtolower( $currency ) == strtolower( 'تومان' ) || strtolower( $currency ) == strtolower( 'تومان ایران' ) ) {
426
-
427
- $amount = $amount * 10;
428
- }
429
-
430
- if( strtolower( $currency ) == strtolower( 'IRHT' ) ) {
431
-
432
- $amount = $amount * 1000 * 10;
433
- }
434
-
435
- if( strtolower( $currency ) == strtolower( 'IRHR' ) ) {
436
-
437
- $amount = $amount * 1000;
438
- }
439
-
440
- if( strtolower( $currency ) == strtolower( 'IRR' ) ) {
441
-
442
- $amount = $amount;
443
- }
444
-
445
- $card_number = isset( $_POST['cardNumber'] ) ? sanitize_text_field( $_POST['cardNumber'] ) : 'Null';
446
-
447
- if( $amount == $result->amount ) {
448
-
449
- $status = 'completed';
450
- $fault = null;
451
- $message = null;
452
-
453
- } else {
454
-
455
- $status = 'failed';
456
- $fault = 'Invalid Amount';
457
- $message = 'رقم تراكنش با رقم پرداخت شده مطابقت ندارد';
458
- }
459
-
460
- } else {
461
-
462
- $message = 'در ارتباط با وب سرویس Pay.ir خطایی رخ داده است';
463
-
464
- $status = 'failed';
465
- $fault = isset( $result->errorCode ) ? $result->errorCode : 'Verify';
466
- $message = isset( $result->errorMessage ) ? $result->errorMessage : $message;
467
- }
468
-
469
- } else {
470
-
471
- if( $payir_message ) {
472
-
473
- $status = 'failed';
474
- $fault = 'Invalid Payment';
475
- $message = $payir_message;
476
-
477
- } else {
478
-
479
- $status = 'failed';
480
- $fault = 'Invalid Payment';
481
- $message = 'تراكنش با خطا مواجه شد و یا توسط پرداخت کننده کنسل شده است';
482
- }
483
- }
484
-
485
- } else {
486
-
487
- $status = 'failed';
488
- $fault = 'Invalid Data';
489
- $message = 'اطلاعات ارسال شده مربوط به تایید تراکنش ناقص و یا غیر معتبر است';
490
- }
491
-
492
- if( $status == 'completed' ) {
493
-
494
- $order->payment_complete( $trans_id );
495
- $woocommerce->cart->empty_cart();
496
-
497
- $note = sprintf( __( 'پرداخت موفقیت آمیز بود.<br/>شماره پیگیری: %s', 'woocommerce' ), $trans_id );
498
- $note = apply_filters( 'WC_Payir_Return_from_Gateway_Success_Note', $note, $order_id, $trans_id );
499
-
500
- if( $note ) {
501
-
502
- $order->add_order_note( $note, 1 );
503
- }
504
-
505
- $notice = wpautop( wptexturize( $this->success_massage ) );
506
- $notice = str_replace( '{transaction_id}', $trans_id, $notice );
507
- $notice = apply_filters( 'WC_Payir_Return_from_Gateway_Success_Notice', $notice, $order_id, $trans_id );
508
-
509
- if( $notice ) {
510
-
511
- wc_add_notice( $notice, 'success' );
512
- }
513
-
514
- do_action( 'WC_Payir_Return_from_Gateway_Success', $order_id, $trans_id );
515
-
516
- wp_redirect( add_query_arg( 'wc_status', 'success', $this->get_return_url( $order ) ) );
517
- exit;
518
-
519
- } else {
520
-
521
- $note = sprintf( __( 'خطایی رخ داده است:<br/>شرح خطا: %s<br/>شماره پیگیری: %s', 'woocommerce' ), $message, $trans_id );
522
- $note = apply_filters( 'WC_Payir_Return_from_Gateway_Failed_Note', $note, $order_id, $trans_id, $fault );
523
-
524
- if( $note ) {
525
-
526
- $order->add_order_note( $note, 1 );
527
- }
528
-
529
- $notice = wpautop( wptexturize( $this->failed_massage ) );
530
- $notice = str_replace( '{transaction_id}', $trans_id, $notice );
531
- $notice = str_replace( '{fault}', $message, $notice );
532
- $notice = apply_filters( 'WC_Payir_Return_from_Gateway_Failed_Notice', $notice, $order_id, $trans_id, $fault );
533
-
534
- if( $notice ) {
535
- wc_add_notice( $notice, 'error' );
536
- }
537
-
538
- do_action( 'WC_Payir_Return_from_Gateway_Failed', $order_id, $trans_id, $fault );
539
-
540
- wp_redirect( $woocommerce->cart->get_checkout_url() );
541
- exit;
542
- }
543
-
544
- } else {
545
-
546
- $notice = wpautop( wptexturize( $this->success_massage ) );
547
- $notice = str_replace( '{transaction_id}', $trans_id, $notice );
548
- $notice = apply_filters( 'WC_Payir_Return_from_Gateway_ReSuccess_Notice', $notice, $order_id, $trans_id );
549
-
550
- if( $notice ) {
551
-
552
- wc_add_notice( $notice, 'success' );
553
- }
554
-
555
- do_action( 'WC_Payir_Return_from_Gateway_ReSuccess', $order_id, $trans_id );
556
-
557
- wp_redirect( add_query_arg( 'wc_status', 'success', $this->get_return_url( $order ) ) );
558
- exit;
559
- }
560
-
561
- } else {
562
-
563
- $fault = __( 'شماره سفارش وجود ندارد و یا سفارش منقضی شده است', 'woocommerce' );
564
-
565
- $notice = wpautop( wptexturize( $this->failed_massage ) );
566
- $notice = str_replace( '{fault}', $fault, $notice );
567
- $notice = apply_filters( 'WC_Payir_Return_from_Gateway_No_Order_ID_Notice', $notice, $order_id, $fault );
568
-
569
- if( $notice ) {
570
-
571
- wc_add_notice( $notice, 'error' );
572
- }
573
-
574
- do_action( 'WC_Payir_Return_from_Gateway_No_Order_ID', $order_id, null, $fault );
575
-
576
- wp_redirect( $woocommerce->cart->get_checkout_url() );
577
- exit;
578
- }
579
- }
580
-
581
- private function common( $url, $params ) {
582
- $ch = curl_init();
583
-
584
- curl_setopt( $ch, CURLOPT_URL, $url );
585
- curl_setopt( $ch, CURLOPT_POST, true );
586
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
587
- curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
588
- curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
589
- curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $params ) );
590
-
591
- $response = curl_exec( $ch );
592
- $error = curl_errno( $ch );
593
-
594
- curl_close( $ch );
595
-
596
- $output = $error ? false : json_decode( $response );
597
-
598
- return $output;
599
- }
600
- }
601
- } else {
602
-
603
- if( ! function_exists( 'is_plugin_active' ) ) {
604
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
605
- }
606
-
607
- $plugin = "payir-woocommerce/index.php";
608
-
609
- if( is_plugin_active( $plugin ) ) {
610
- deactivate_plugins( $plugin );
611
- }
612
-
613
- }
614
- }
615
-
616
- add_action( 'plugins_loaded', 'PW_Load_Payir_Gateway', 0 );
617
-
618
- function pw_after_payir_plugin( $plugin_file, $plugin_data, $status ) {
619
- echo '<tr class="inactive"><td>&nbsp;</td><td colspan="2">
620
- <div class="notice inline notice-warning notice-alt"><p>افزونه «<strong>درگاه پرداخت و کیف پول الکترونیک Pay.ir - افزونه WooCommerce</strong>» درون بسته ووکامرس فارسی وجود دارد و نیاز به فعال سازی نیست. به صفحه <a href="' . admin_url('admin.php?page=wc-settings&tab=checkout') . '">پیکربندی تسویه حساب</a> مراجعه کنید.</p></div>
621
- </td></tr>';
622
- }
623
-
624
  add_action( 'after_plugin_row_payir-woocommerce/index.php', 'pw_after_payir_plugin', 10, 3 );
1
+ <?php
2
+
3
+ if( ! defined( 'ABSPATH' ) ) {
4
+ die( 'This file cannot be accessed directly' );
5
+ }
6
+
7
+ function PW_Load_Payir_Gateway() {
8
+
9
+ if( class_exists( 'WC_Payment_Gateway' ) && ! class_exists( 'WC_Payir_Gateway' ) && ! function_exists( 'Woocommerce_Add_Payir_Gateway' ) ) {
10
+
11
+ add_filter( 'woocommerce_payment_gateways', 'Woocommerce_Add_Payir_Gateway' );
12
+
13
+ function Woocommerce_Add_Payir_Gateway( $methods ) {
14
+ $methods[] = 'WC_Payir_Gateway';
15
+
16
+ return $methods;
17
+ }
18
+
19
+ add_filter( 'woocommerce_currencies', 'add_payir_currency' );
20
+
21
+ function add_payir_currency( $currencies ) {
22
+ $currencies['IRR'] = __( 'ریال', 'woocommerce' );
23
+ $currencies['IRT'] = __( 'تومان', 'woocommerce' );
24
+ $currencies['IRHR'] = __( 'هزار ریال', 'woocommerce' );
25
+ $currencies['IRHT'] = __( 'هزار تومان', 'woocommerce' );
26
+
27
+ return $currencies;
28
+ }
29
+
30
+ add_filter( 'woocommerce_currency_symbol', 'add_payir_currency_symbol', 10, 2 );
31
+
32
+ function add_payir_currency_symbol( $currency_symbol, $currency ) {
33
+ switch( $currency ) {
34
+
35
+ case 'IRR':
36
+ $currency_symbol = 'ریال';
37
+ break;
38
+
39
+ case 'IRT':
40
+ $currency_symbol = 'تومان';
41
+ break;
42
+
43
+ case 'IRHR':
44
+ $currency_symbol = 'هزار ریال';
45
+ break;
46
+
47
+ case 'IRHT':
48
+ $currency_symbol = 'هزار تومان';
49
+ break;
50
+ }
51
+
52
+ return $currency_symbol;
53
+ }
54
+
55
+ class WC_Payir_Gateway extends WC_Payment_Gateway {
56
+
57
+ public function __construct() {
58
+ $this->id = 'payir';
59
+ $this->method_title = __( 'درگاه پرداخت و کیف پول الکترونیک Pay.ir', 'woocommerce' );
60
+ $this->method_description = __( 'تنظیمات درگاه پرداخت و کیف پول الکترونیک Pay.ir برای افزونه WooCommerce', 'woocommerce' );
61
+ $this->icon = apply_filters( 'WC_Payir_logo', PW()->plugin_url( 'assets/images/payir.png' ) );
62
+ $this->has_fields = false;
63
+
64
+ $this->init_form_fields();
65
+ $this->init_settings();
66
+
67
+ $this->title = $this->settings['title'];
68
+ $this->description = $this->settings['description'];
69
+
70
+ $this->api_key = $this->settings['api_key'];
71
+
72
+ $this->success_massage = $this->settings['success_massage'];
73
+ $this->failed_massage = $this->settings['failed_massage'];
74
+
75
+ if( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) ) {
76
+
77
+ add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array(
78
+ $this,
79
+ 'process_admin_options'
80
+ ) );
81
+
82
+ } else {
83
+
84
+ add_action( 'woocommerce_update_options_payment_gateways', array(
85
+ $this,
86
+ 'process_admin_options'
87
+ ) );
88
+ }
89
+
90
+ add_action( 'woocommerce_receipt_' . $this->id, array( $this, 'Send_to_Payir_Gateway' ) );
91
+ add_action( 'woocommerce_api_' . strtolower( get_class( $this ) ) . '', array(
92
+ $this,
93
+ 'Return_from_Payir_Gateway'
94
+ ) );
95
+ }
96
+
97
+ public function admin_options() {
98
+ parent::admin_options();
99
+ }
100
+
101
+ public function init_form_fields() {
102
+ $this->form_fields = apply_filters( 'WC_Payir_Config', array(
103
+
104
+ 'base_confing' => array(
105
+
106
+ 'title' => __( 'تنظیمات پایه', 'woocommerce' ),
107
+ 'type' => 'title',
108
+ 'description' => null,
109
+ 'desc_tip' => false
110
+ ),
111
+ 'enabled' => array(
112
+
113
+ 'title' => __( 'فعال سازی / غیر فعال سازی', 'woocommerce' ),
114
+ 'type' => 'checkbox',
115
+ 'label' => __( 'فعال سازی درگاه پرداخت Pay.ir', 'woocommerce' ),
116
+ 'description' => __( 'برای فعال سازی درگاه پرداخت Pay.ir باید چک باکس را تیک بزنید', 'woocommerce' ),
117
+ 'default' => 'no',
118
+ 'desc_tip' => true
119
+ ),
120
+ 'title' => array(
121
+
122
+ 'title' => __( 'عنوان درگاه', 'woocommerce' ),
123
+ 'type' => 'text',
124
+ 'description' => __( 'عنوانی که برای درگاه در طی مراحل خرید به مشتری نمایش داده میشود', 'woocommerce' ),
125
+ 'default' => __( 'درگاه پرداخت و کیف پول الکترونیک Pay.ir', 'woocommerce' ),
126
+ 'desc_tip' => true
127
+ ),
128
+ 'description' => array(
129
+
130
+ 'title' => __( 'توضیحات درگاه', 'woocommerce' ),
131
+ 'type' => 'text',
132
+ 'description' => __( 'توضیحاتی که در مرحله پرداخت برای درگاه نمایش داده خواهد شد', 'woocommerce' ),
133
+ 'default' => __( 'پرداخت امن با استفاده از کلیه کارت های عضو شبکه شتاب از طریق درگاه پرداخت و کیف پول الکترونیک Pay.ir', 'woocommerce' ),
134
+ 'desc_tip' => true
135
+ ),
136
+ 'account_confing' => array(
137
+
138
+ 'title' => __( 'تنظیمات حساب Pay.ir', 'woocommerce' ),
139
+ 'type' => 'title',
140
+ 'description' => null,
141
+ 'desc_tip' => false
142
+ ),
143
+ 'api_key' => array(
144
+
145
+ 'title' => __( 'کلید API', 'woocommerce' ),
146
+ 'type' => 'text',
147
+ 'description' => null,
148
+ 'default' => null,
149
+ 'desc_tip' => false
150
+ ),
151
+ 'payment_confing' => array(
152
+
153
+ 'title' => __( 'تنظیمات عملیات پرداخت', 'woocommerce' ),
154
+ 'type' => 'title',
155
+ 'description' => null,
156
+ 'desc_tip' => false
157
+ ),
158
+ 'success_massage' => array(
159
+
160
+ 'title' => __( 'پیام پرداخت موفق', 'woocommerce' ),
161
+ 'type' => 'textarea',
162
+ 'description' => __( 'متن پیامی که می خواهید پس از پرداخت موفق به کاربر نمایش داده شود را وارد نمایید.<br/>شما می توانید از شورت کد {transaction_id} برای نمایش شماره پیگیری تراکنش استفاده نمایید.', 'woocommerce' ),
163
+ 'default' => __( 'از شما سپاسگزاریم، سفارش شما با موفقیت پرداخت و تایید شد. شماره پیگیری: {transaction_id}', 'woocommerce' ),
164
+ 'desc_tip' => false
165
+ ),
166
+ 'failed_massage' => array(
167
+
168
+ 'title' => __( 'پیام پرداخت ناموفق', 'woocommerce' ),
169
+ 'type' => 'textarea',
170
+ 'description' => __( 'متن پیامی که می خواهید پس از پرداخت ناموفق به کاربر نمایش داده را وارد نمایید.<br/>شما می توانید از شورت کد {fault} برای نمایش دلیل خطای رخ داده استفاده نمایید. این دلیل خطا از سایت Pay.ir ارسال میگردد.', 'woocommerce' ),
171
+ 'default' => __( 'متاسفانه پرداخت شما ناموفق بوده است، لطفا مجددا تلاش نمایید یا در صورت بروز اشکال با مدیر سایت تماس بگیرید. شرح خطا: {fault}', 'woocommerce' ),
172
+ 'desc_tip' => false
173
+ )
174
+ ) );
175
+ }
176
+
177
+ public function process_payment( $order_id ) {
178
+ $order = new WC_Order( $order_id );
179
+
180
+ return array(
181
+
182
+ 'result' => 'success',
183
+ 'redirect' => $order->get_checkout_payment_url( true )
184
+ );
185
+ }
186
+
187
+ public function Send_to_Payir_Gateway( $order_id ) {
188
+ global $woocommerce;
189
+
190
+ $woocommerce->session->order_id_payir = $order_id;
191
+
192
+ $order = new WC_Order( $order_id );
193
+
194
+ $currency = $order->get_currency();
195
+ $currency = apply_filters( 'WC_Payir_Currency', $currency, $order_id );
196
+
197
+ $form = '<form id="payir-checkout-form" name="payir-checkout-form" method="post" class="payir-checkout-form">';
198
+ $form .= '<input id="payir-payment-button" name="payir_submit" type="submit" class="button alt" value="' . __( 'پرداخت', 'woocommerce' ) . '"/>';
199
+ $form .= '<a href="' . $woocommerce->cart->get_checkout_url() . '" class="button cancel">' . __( 'بازگشت', 'woocommerce' ) . '</a>';
200
+ $form .= '</form><br/>';
201
+
202
+ $form = apply_filters( 'WC_Payir_Form', $form, $order_id, $woocommerce );
203
+
204
+ do_action( 'WC_Payir_Gateway_Before_Form', $order_id, $woocommerce );
205
+
206
+ echo $form;
207
+
208
+ do_action( 'WC_Payir_Gateway_After_Form', $order_id, $woocommerce );
209
+
210
+ $amount = intval( $order->get_total() );
211
+ $amount = apply_filters( 'woocommerce_order_amount_total_IRANIAN_gateways_before_check_currency', $amount, $currency );
212
+
213
+ if( strtolower( $currency ) == strtolower( 'IRT' ) || strtolower( $currency ) == strtolower( 'TOMAN' ) ) {
214
+
215
+ $amount = $amount * 10;
216
+ }
217
+
218
+ if( strtolower( $currency ) == strtolower( 'Iran TOMAN' ) || strtolower( $currency ) == strtolower( 'Iranian TOMAN' ) ) {
219
+
220
+ $amount = $amount * 10;
221
+ }
222
+
223
+ if( strtolower( $currency ) == strtolower( 'Iran-TOMAN' ) || strtolower( $currency ) == strtolower( 'Iranian-TOMAN' ) ) {
224
+
225
+ $amount = $amount * 10;
226
+ }
227
+
228
+ if( strtolower( $currency ) == strtolower( 'Iran_TOMAN' ) || strtolower( $currency ) == strtolower( 'Iranian_TOMAN' ) ) {
229
+
230
+ $amount = $amount * 10;
231
+ }
232
+
233
+ if( strtolower( $currency ) == strtolower( 'تومان' ) || strtolower( $currency ) == strtolower( 'تومان ایران' ) ) {
234
+
235
+ $amount = $amount * 10;
236
+ }
237
+
238
+ if( strtolower( $currency ) == strtolower( 'IRHT' ) ) {
239
+
240
+ $amount = $amount * 1000 * 10;
241
+ }
242
+
243
+ if( strtolower( $currency ) == strtolower( 'IRHR' ) ) {
244
+
245
+ $amount = $amount * 1000;
246
+ }
247
+
248
+ if( strtolower( $currency ) == strtolower( 'IRR' ) ) {
249
+
250
+ $amount = $amount;
251
+ }
252
+
253
+ $amount = apply_filters( 'woocommerce_order_amount_total_IRANIAN_gateways_after_check_currency', $amount, $currency );
254
+ $amount = apply_filters( 'woocommerce_order_amount_total_IRANIAN_gateways_irt', $amount, $currency );
255
+ $amount = apply_filters( 'woocommerce_order_amount_total_Payir_gateway', $amount, $currency );
256
+
257
+ if( extension_loaded( 'curl' ) ) {
258
+
259
+ $products = array();
260
+ $order_items = $order->get_items();
261
+
262
+ foreach( (array) $order_items as $product ) {
263
+
264
+ $products[] = $product['name'] . ' (' . $product['qty'] . ') ';
265
+ }
266
+
267
+ $products = implode( ' - ', $products );
268
+
269
+ $description = 'خرید به شماره سفارش: ' . $order->get_order_number();
270
+ $mobile = get_post_meta( $order_id, '_billing_phone', true ) ? get_post_meta( $order_id, '_billing_phone', true ) : null;
271
+
272
+ $description = apply_filters( 'WC_Payir_Description', $description, $order_id );
273
+ $mobile = apply_filters( 'WC_Payir_Mobile', $mobile, $order_id );
274
+ $email = apply_filters( 'WC_Payir_Email', $order->get_billing_email(), $order_id );
275
+ $paymenter = apply_filters( 'WC_Payir_Paymenter', $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(), $order_id );
276
+ $res_number = apply_filters( 'WC_Payir_ResNumber', intval( $order->get_order_number() ), $order_id );
277
+
278
+ do_action( 'WC_Payir_Gateway_Payment', $order_id, $description, $mobile );
279
+
280
+ $api_key = $this->api_key;
281
+ $callback = add_query_arg( 'wc_order', $order_id, WC()->api_request_url( 'WC_Payir_Gateway' ) );
282
+ $payresid = '1000000800';
283
+ $params = array(
284
+
285
+ 'api' => $api_key,
286
+ 'amount' => $amount,
287
+ 'redirect' => urlencode( $callback ),
288
+ 'mobile' => $mobile,
289
+ 'resellerId' => $payresid,
290
+ 'factorNumber' => $order_id,
291
+ 'description' => $description
292
+ );
293
+
294
+ $result = $this->common( 'https://pay.ir/payment/send', $params );
295
+
296
+ if( $result && isset( $result->status ) && $result->status == 1 ) {
297
+
298
+ $gateway_url = 'https://pay.ir/payment/gateway/' . $result->transId;
299
+
300
+ if( ! headers_sent() ) {
301
+
302
+ header( 'Location: ' . $gateway_url );
303
+ exit;
304
+
305
+ } else {
306
+
307
+ echo 'در حال انتقال به درگاه بانکی...';
308
+ echo '<script type="text/javascript">window.onload = function(){top.location.href = "' . $gateway_url . '";};</script>';
309
+ exit;
310
+ }
311
+
312
+ } else {
313
+
314
+ $message = 'در ارتباط با وب سرویس Pay.ir خطایی رخ داده است';
315
+
316
+ $fault = isset( $result->errorCode ) ? $result->errorCode : 'Send';
317
+ $message = isset( $result->errorMessage ) ? $result->errorMessage : $message;
318
+ }
319
+
320
+ } else {
321
+
322
+ $fault = 'cUrl';
323
+ $message = 'تابع cURL در سرور فعال نمی باشد';
324
+ }
325
+
326
+ if( ! empty( $message ) && $message ) {
327
+
328
+ $note = sprintf( __( 'خطایی رخ داده است: %s', 'woocommerce' ), $message );
329
+ $note = apply_filters( 'WC_Payir_Send_to_Gateway_Failed_Note', $note, $order_id, $fault );
330
+
331
+ $order->add_order_note( $note );
332
+
333
+ $notice = sprintf( __( 'خطایی رخ داده است:<br/>%s', 'woocommerce' ), $message );
334
+ $notice = apply_filters( 'WC_Payir_Send_to_Gateway_Failed_Notice', $notice, $order_id, $fault );
335
+
336
+ if( $notice ) {
337
+
338
+ wc_add_notice( $notice, 'error' );
339
+ }
340
+
341
+ do_action( 'WC_Payir_Send_to_Gateway_Failed', $order_id, $fault );
342
+ }
343
+ }
344
+
345
+ public function Return_from_Payir_Gateway() {
346
+ global $woocommerce;
347
+
348
+ $order_id = null;
349
+
350
+ $factor_number = isset( $_POST['factorNumber'] ) ? sanitize_text_field( $_POST['factorNumber'] ) : null;
351
+ $trans_id = isset( $_POST['transId'] ) ? sanitize_text_field( $_POST['transId'] ) : null;
352
+
353
+ if( $trans_id ) {
354
+
355
+ update_post_meta( $order_id, '_transaction_id', $trans_id );
356
+ }
357
+
358
+ if( isset( $_GET['wc_order'] ) ) {
359
+
360
+ $order_id = sanitize_text_field( $_GET['wc_order'] );
361
+
362
+ } elseif( $factor_number ) {
363
+
364
+ $order_id = $factor_number;
365
+
366
+ } else {
367
+
368
+ $order_id = $woocommerce->session->order_id_payir;
369
+
370
+ unset( $woocommerce->session->order_id_payir );
371
+ }
372
+
373
+ if( $order_id ) {
374
+
375
+ $order = new WC_Order( $order_id );
376
+ $currency = $order->get_currency();
377
+ $currency = apply_filters( 'WC_Payir_Currency', $currency, $order_id );
378
+
379
+ if( $order->get_status() != 'completed' && $order->get_status() != 'processing' ) {
380
+
381
+ if( isset( $_POST['status'] ) && isset( $_POST['transId'] ) && isset( $_POST['factorNumber'] ) ) {
382
+
383
+ $api_key = $this->api_key;
384
+
385
+ $payir_status = sanitize_text_field( $_POST['status'] );
386
+ $payir_trans_id = sanitize_text_field( $_POST['transId'] );
387
+ $payir_factor_number = sanitize_text_field( $_POST['factorNumber'] );
388
+ $payir_message = sanitize_text_field( $_POST['message'] );
389
+
390
+ if( isset( $payir_status ) && $payir_status == 1 ) {
391
+
392
+ $params = array(
393
+
394
+ 'api' => $api_key,
395
+ 'transId' => $payir_trans_id
396
+ );
397
+
398
+ $result = $this->common( 'https://pay.ir/payment/verify', $params );
399
+
400
+ if( $result && isset( $result->status ) && $result->status == 1 ) {
401
+
402
+ $amount = intval( $order->get_total() );
403
+ $amount = apply_filters( 'woocommerce_order_amount_total_IRANIAN_gateways_before_check_currency', $amount, $currency );
404
+
405
+ if( strtolower( $currency ) == strtolower( 'IRT' ) || strtolower( $currency ) == strtolower( 'TOMAN' ) ) {
406
+
407
+ $amount = $amount * 10;
408
+ }
409
+
410
+ if( strtolower( $currency ) == strtolower( 'Iran TOMAN' ) || strtolower( $currency ) == strtolower( 'Iranian TOMAN' ) ) {
411
+
412
+ $amount = $amount * 10;
413
+ }
414
+
415
+ if( strtolower( $currency ) == strtolower( 'Iran-TOMAN' ) || strtolower( $currency ) == strtolower( 'Iranian-TOMAN' ) ) {
416
+
417
+ $amount = $amount * 10;
418
+ }
419
+
420
+ if( strtolower( $currency ) == strtolower( 'Iran_TOMAN' ) || strtolower( $currency ) == strtolower( 'Iranian_TOMAN' ) ) {
421
+
422
+ $amount = $amount * 10;
423
+ }
424
+
425
+ if( strtolower( $currency ) == strtolower( 'تومان' ) || strtolower( $currency ) == strtolower( 'تومان ایران' ) ) {
426
+
427
+ $amount = $amount * 10;
428
+ }
429
+
430
+ if( strtolower( $currency ) == strtolower( 'IRHT' ) ) {
431
+
432
+ $amount = $amount * 1000 * 10;
433
+ }
434
+
435
+ if( strtolower( $currency ) == strtolower( 'IRHR' ) ) {
436
+
437
+ $amount = $amount * 1000;
438
+ }
439
+
440
+ if( strtolower( $currency ) == strtolower( 'IRR' ) ) {
441
+
442
+ $amount = $amount;
443
+ }
444
+
445
+ $card_number = isset( $_POST['cardNumber'] ) ? sanitize_text_field( $_POST['cardNumber'] ) : 'Null';
446
+
447
+ if( $amount == $result->amount ) {
448
+
449
+ $status = 'completed';
450
+ $fault = null;
451
+ $message = null;
452
+
453
+ } else {
454
+
455
+ $status = 'failed';
456
+ $fault = 'Invalid Amount';
457
+ $message = 'رقم تراكنش با رقم پرداخت شده مطابقت ندارد';
458
+ }
459
+
460
+ } else {
461
+
462
+ $message = 'در ارتباط با وب سرویس Pay.ir خطایی رخ داده است';
463
+
464
+ $status = 'failed';
465
+ $fault = isset( $result->errorCode ) ? $result->errorCode : 'Verify';
466
+ $message = isset( $result->errorMessage ) ? $result->errorMessage : $message;
467
+ }
468
+
469
+ } else {
470
+
471
+ if( $payir_message ) {
472
+
473
+ $status = 'failed';
474
+ $fault = 'Invalid Payment';
475
+ $message = $payir_message;
476
+
477
+ } else {
478
+
479
+ $status = 'failed';
480
+ $fault = 'Invalid Payment';
481
+ $message = 'تراكنش با خطا مواجه شد و یا توسط پرداخت کننده کنسل شده است';
482
+ }
483
+ }
484
+
485
+ } else {
486
+
487
+ $status = 'failed';
488
+ $fault = 'Invalid Data';
489
+ $message = 'اطلاعات ارسال شده مربوط به تایید تراکنش ناقص و یا غیر معتبر است';
490
+ }
491
+
492
+ if( $status == 'completed' ) {
493
+
494
+ $order->payment_complete( $trans_id );
495
+ $woocommerce->cart->empty_cart();
496
+
497
+ $note = sprintf( __( 'پرداخت موفقیت آمیز بود.<br/>شماره پیگیری: %s', 'woocommerce' ), $trans_id );
498
+ $note = apply_filters( 'WC_Payir_Return_from_Gateway_Success_Note', $note, $order_id, $trans_id );
499
+
500
+ if( $note ) {
501
+
502
+ $order->add_order_note( $note, 1 );
503
+ }
504
+
505
+ $notice = wpautop( wptexturize( $this->success_massage ) );
506
+ $notice = str_replace( '{transaction_id}', $trans_id, $notice );
507
+ $notice = apply_filters( 'WC_Payir_Return_from_Gateway_Success_Notice', $notice, $order_id, $trans_id );
508
+
509
+ if( $notice ) {
510
+
511
+ wc_add_notice( $notice, 'success' );
512
+ }
513
+
514
+ do_action( 'WC_Payir_Return_from_Gateway_Success', $order_id, $trans_id );
515
+
516
+ wp_redirect( add_query_arg( 'wc_status', 'success', $this->get_return_url( $order ) ) );
517
+ exit;
518
+
519
+ } else {
520
+
521
+ $note = sprintf( __( 'خطایی رخ داده است:<br/>شرح خطا: %s<br/>شماره پیگیری: %s', 'woocommerce' ), $message, $trans_id );
522
+ $note = apply_filters( 'WC_Payir_Return_from_Gateway_Failed_Note', $note, $order_id, $trans_id, $fault );
523
+
524
+ if( $note ) {
525
+
526
+ $order->add_order_note( $note, 1 );
527
+ }
528
+
529
+ $notice = wpautop( wptexturize( $this->failed_massage ) );
530
+ $notice = str_replace( '{transaction_id}', $trans_id, $notice );
531
+ $notice = str_replace( '{fault}', $message, $notice );
532
+ $notice = apply_filters( 'WC_Payir_Return_from_Gateway_Failed_Notice', $notice, $order_id, $trans_id, $fault );
533
+
534
+ if( $notice ) {
535
+ wc_add_notice( $notice, 'error' );
536
+ }
537
+
538
+ do_action( 'WC_Payir_Return_from_Gateway_Failed', $order_id, $trans_id, $fault );
539
+
540
+ wp_redirect( $woocommerce->cart->get_checkout_url() );
541
+ exit;
542
+ }
543
+
544
+ } else {
545
+
546
+ $notice = wpautop( wptexturize( $this->success_massage ) );
547
+ $notice = str_replace( '{transaction_id}', $trans_id, $notice );
548
+ $notice = apply_filters( 'WC_Payir_Return_from_Gateway_ReSuccess_Notice', $notice, $order_id, $trans_id );
549
+
550
+ if( $notice ) {
551
+
552
+ wc_add_notice( $notice, 'success' );
553
+ }
554
+
555
+ do_action( 'WC_Payir_Return_from_Gateway_ReSuccess', $order_id, $trans_id );
556
+
557
+ wp_redirect( add_query_arg( 'wc_status', 'success', $this->get_return_url( $order ) ) );
558
+ exit;
559
+ }
560
+
561
+ } else {
562
+
563
+ $fault = __( 'شماره سفارش وجود ندارد و یا سفارش منقضی شده است', 'woocommerce' );
564
+
565
+ $notice = wpautop( wptexturize( $this->failed_massage ) );
566
+ $notice = str_replace( '{fault}', $fault, $notice );
567
+ $notice = apply_filters( 'WC_Payir_Return_from_Gateway_No_Order_ID_Notice', $notice, $order_id, $fault );
568
+
569
+ if( $notice ) {
570
+
571
+ wc_add_notice( $notice, 'error' );
572
+ }
573
+
574
+ do_action( 'WC_Payir_Return_from_Gateway_No_Order_ID', $order_id, null, $fault );
575
+
576
+ wp_redirect( $woocommerce->cart->get_checkout_url() );
577
+ exit;
578
+ }
579
+ }
580
+
581
+ private function common( $url, $params ) {
582
+ $ch = curl_init();
583
+
584
+ curl_setopt( $ch, CURLOPT_URL, $url );
585
+ curl_setopt( $ch, CURLOPT_POST, true );
586
+ curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
587
+ curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
588
+ curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
589
+ curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $params ) );
590
+
591
+ $response = curl_exec( $ch );
592
+ $error = curl_errno( $ch );
593
+
594
+ curl_close( $ch );
595
+
596
+ $output = $error ? false : json_decode( $response );
597
+
598
+ return $output;
599
+ }
600
+ }
601
+ } else {
602
+
603
+ if( ! function_exists( 'is_plugin_active' ) ) {
604
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
605
+ }
606
+
607
+ $plugin = "payir-woocommerce/index.php";
608
+
609
+ if( is_plugin_active( $plugin ) ) {
610
+ deactivate_plugins( $plugin );
611
+ }
612
+
613
+ }
614
+ }
615
+
616
+ add_action( 'plugins_loaded', 'PW_Load_Payir_Gateway', 0 );
617
+
618
+ function pw_after_payir_plugin( $plugin_file, $plugin_data, $status ) {
619
+ echo '<tr class="inactive"><td>&nbsp;</td><td colspan="2">
620
+ <div class="notice inline notice-warning notice-alt"><p>افزونه «<strong>درگاه پرداخت و کیف پول الکترونیک Pay.ir - افزونه WooCommerce</strong>» درون بسته ووکامرس فارسی وجود دارد و نیاز به فعال سازی نیست. به صفحه <a href="' . admin_url('admin.php?page=wc-settings&tab=checkout') . '">پیکربندی تسویه حساب</a> مراجعه کنید.</p></div>
621
+ </td></tr>';
622
+ }
623
+
624
  add_action( 'after_plugin_row_payir-woocommerce/index.php', 'pw_after_payir_plugin', 10, 3 );
readme.txt CHANGED
@@ -44,6 +44,8 @@ This plugin extends the WooCommerce shop plugin with complete Persian(Farsi) lan
44
  You can read complete documentations on the [woocommerce.ir](http://www.woocommerce.ir)
45
 
46
  == Changelog ==
 
 
47
  = 3.2.6.1 =
48
  * some bug fixed
49
  = 3.2.6 =
@@ -120,8 +122,8 @@ You can read complete documentations on the [woocommerce.ir](http://www.woocomme
120
  * نسخه اولیه
121
 
122
  == Upgrade Notice ==
123
- = 3.2.6.1 =
124
- * رفع مشکل تصویر Pay.ir
125
 
126
  == Traducciones ==
127
  You can read complete documentations on the [woocommerce.ir](http://www.woocommerce.ir)
44
  You can read complete documentations on the [woocommerce.ir](http://www.woocommerce.ir)
45
 
46
  == Changelog ==
47
+ = 3.3.0 =
48
+ * پشتیبانی از ووکامرس 3.3 و سازگاری با PHP 7.2
49
  = 3.2.6.1 =
50
  * some bug fixed
51
  = 3.2.6 =
122
  * نسخه اولیه
123
 
124
  == Upgrade Notice ==
125
+ = 3.3.0 =
126
+ * پشتیبانی از ووکامرس 3.3 و سازگاری با PHP 7.2
127
 
128
  == Traducciones ==
129
  You can read complete documentations on the [woocommerce.ir](http://www.woocommerce.ir)
woocommerce-persian.php CHANGED
@@ -3,11 +3,11 @@
3
  Plugin Name: ووکامرس فارسی
4
  Plugin URI: http://woocommerce.ir
5
  Description: بسته فارسی ساز ووکامرس پارسی به راحتی سیستم فروشگاه ساز ووکامرس را فارسی می کند. با فعال سازی افزونه ، واحد پولی ریال و تومان ایران و همچنین لیست استان های ایران به افزونه افزوده می شوند. پشتیبانی در <a href="http://www.woocommerce.ir/" target="_blank">ووکامرس پارسی</a>.
6
- Version: 3.2.6.1
7
  Author: ووکامرس فارسی
8
  Author URI: http://woocommerce.ir
9
  WC requires at least: 3.0.0
10
- WC tested up to: 3.2.6
11
  */
12
 
13
  if( !defined( 'ABSPATH' ) ) {
3
  Plugin Name: ووکامرس فارسی
4
  Plugin URI: http://woocommerce.ir
5
  Description: بسته فارسی ساز ووکامرس پارسی به راحتی سیستم فروشگاه ساز ووکامرس را فارسی می کند. با فعال سازی افزونه ، واحد پولی ریال و تومان ایران و همچنین لیست استان های ایران به افزونه افزوده می شوند. پشتیبانی در <a href="http://www.woocommerce.ir/" target="_blank">ووکامرس پارسی</a>.
6
+ Version: 3.3.0
7
  Author: ووکامرس فارسی
8
  Author URI: http://woocommerce.ir
9
  WC requires at least: 3.0.0
10
+ WC tested up to: 3.3.1
11
  */
12
 
13
  if( !defined( 'ABSPATH' ) ) {