-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpayping.php
2435 lines (2024 loc) · 115 KB
/
payping.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
register_activation_hook( __FILE__, array( 'GFPersian_Gateway_payping', "add_permissions" ) );
add_action( 'init', array( 'GFPersian_Gateway_payping', 'init' ) );
require_once( 'database.php' );
require_once( 'chart.php' );
class GFPersian_Gateway_payping {
//Dont Change this Parameter if you are legitimate !!!
public static $author = "HANNANStd";
// -------------------------------------------------
private static $version = "2.3.0";
private static $min_gravityforms_version = "1.9.10";
private static $config = null;
// -------------------------------------------------
public static function init() {
if ( ! class_exists( "GFPersian_Payments" ) || ! defined( 'GF_PERSIAN_VERSION' ) || version_compare( GF_PERSIAN_VERSION, '2.3.1', '<' ) ) {
add_action( 'admin_notices', array( __CLASS__, 'admin_notice_persian_gf' ) );
return false;
}
if ( ! self::is_gravityforms_supported() ) {
add_action( 'admin_notices', array( __CLASS__, 'admin_notice_gf_support' ) );
return false;
}
add_filter( 'members_get_capabilities', array( __CLASS__, "members_get_capabilities" ) );
if ( is_admin() && self::has_access() ) {
add_filter( 'gform_tooltips', array( __CLASS__, 'tooltips' ) );
add_filter( 'gform_addon_navigation', array( __CLASS__, 'menu' ) );
add_action( 'gform_entry_info', array( __CLASS__, 'payment_entry_detail' ), 4, 2 );
add_action( 'gform_after_update_entry', array( __CLASS__, 'update_payment_entry' ), 4, 2 );
if ( get_option( "ppgf_payping_configured" ) ) {
add_filter( 'gform_form_settings_menu', array( __CLASS__, 'toolbar' ), 10, 2 );
add_action( 'gform_form_settings_page_payping', array( __CLASS__, 'feed_page' ) );
}
if ( rgget( "page" ) == "gf_settings" ) {
RGForms::add_settings_page( array(
'name' => 'gravityforms_payping',
'tab_label' => esc_html__( 'درگاه پیپینگ', 'payping-gravityforms' ),
'title' => esc_html__( 'تنظیمات درگاه پیپینگ', 'payping-gravityforms' ),
'handler' => array( __CLASS__, 'settings_page' ),
)
);
}
if ( self::is_payping_page() ) {
wp_enqueue_script( array( "sack" ) );
self::setup();
}
add_action( 'wp_ajax_gf_payping_update_feed_active', array( __CLASS__, 'update_feed_active' ) );
}
if ( get_option( "ppgf_payping_configured" ) ) {
add_filter( "gform_disable_post_creation", array( __CLASS__, "delay_posts" ), 10, 3 );
add_filter( "gform_is_delayed_pre_process_feed", array( __CLASS__, "delay_addons" ), 10, 4 );
add_filter( "gform_confirmation", array( __CLASS__, "Request" ), 1000, 4 );
add_action( 'wp', array( __CLASS__, 'Verify' ), 5 );
}
add_filter( "gform_logging_supported", array( __CLASS__, "set_logging_supported" ) );
// --------------------------------------------------------------------------------------------
add_filter( 'gf_payment_gateways', array( __CLASS__, 'gravityformspayping' ), 2 );
do_action( 'gravityforms_gateways' );
do_action( 'gravityforms_payping' );
// --------------------------------------------------------------------------------------------
}
// -------------------------------------------------
public static function admin_notice_persian_gf() {
$class_safe = 'notice notice-error';
$message_safe = sprintf( esc_html__( "برای استفاده از نسخه جدید درگاه های پرداخت گرویتی فرم نصب بسته فارسی ساز نسخه 2.3.1 به بالا الزامی است. برای نصب فارسی ساز %sکلیک کنید%s.", "payping-gravityforms" ), '<a href="' . admin_url( "plugin-install.php?tab=plugin-information&plugin=persian-gravity-forms&TB_iframe=true&width=772&height=884" ) . '">', '</a>' );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class_safe ), wp_kses_post( $message_safe ) );
}
// -------------------------------------------------
public static function admin_notice_gf_support() {
$class_safe = 'notice notice-error';
$message_safe = sprintf( esc_html__( "درگاه پیپینگ نیاز به گرویتی فرم نسخه %s به بالا دارد. برای بروز رسانی هسته گرویتی فرم به %sسایت گرویتی فرم فارسی%s مراجعه نمایید .", "payping-gravityforms" ), self::$min_gravityforms_version, "<a href='http:///11378' target='_blank'>", "</a>" );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class_safe ), wp_kses_post( $message_safe ) );
}
// #1
// -------------------------------------------------
public static function gravityformspayping( $form, $entry ) {
$payping = array(
'class' => ( __CLASS__ . '|' . self::$author ),
'title' => esc_html__( 'پیپینگ', 'payping-gravityforms' ),
'param' => array(
'email' => esc_html__( 'ایمیل', 'payping-gravityforms' ),
'mobile' => esc_html__( 'موبایل', 'payping-gravityforms' ),
'desc' => esc_html__( 'توضیحات', 'payping-gravityforms' )
)
);
return apply_filters( self::$author . '_gf_payping_detail', apply_filters( self::$author . '_gf_gateway_detail', $payping, $form, $entry ), $form, $entry );
}
// -------------------------------------------------
public static function add_permissions() {
global $wp_roles;
$editable_roles = get_editable_roles();
foreach ( (array) $editable_roles as $role => $details ) {
if ( $role == 'administrator' || in_array( 'gravityforms_edit_forms', $details['capabilities'] ) ) {
$wp_roles->add_cap( $role, 'gravityforms_payping' );
$wp_roles->add_cap( $role, 'gravityforms_payping_uninstall' );
}
}
}
// -------------------------------------------------
public static function members_get_capabilities( $caps ) {
return array_merge( $caps, array( "gravityforms_payping", "gravityforms_payping_uninstall" ) );
}
// -------------------------------------------------
private static function setup() {
if ( get_option( "ppgf_payping_version" ) != self::$version ) {
GFPersian_DB_payping::update_table();
update_option( "ppgf_payping_version", self::$version );
}
}
// -------------------------------------------------
public static function tooltips( $tooltips ) {
$tooltips["gateway_name"] = esc_html__( "تذکر مهم : این قسمت برای نمایش به بازدید کننده می باشد و لطفا جهت جلوگیری از مشکل و تداخل آن را فقط یکبار تنظیم نمایید و از تنظیم مکرر آن خود داری نمایید .", "payping-gravityforms" );
return $tooltips;
}
// -------------------------------------------------
public static function menu( $menus ) {
$permission = "gravityforms_payping";
if ( ! empty( $permission ) ) {
$menus[] = array(
"name" => "gravityforms_payping",
"label" => esc_html__( "پیپینگ", "payping-gravityforms" ),
"callback" => array( __CLASS__, "payping_page" ),
"permission" => $permission
);
}
return $menus;
}
// -------------------------------------------------
public static function toolbar( $menu_items ) {
$menu_items[] = array(
'name' => 'payping',
'label' => esc_html__( 'پیپینگ', 'payping-gravityforms' )
);
return $menu_items;
}
// -------------------------------------------------
private static function is_gravityforms_supported() {
if ( class_exists( "GFCommon" ) ) {
$is_correct_version = version_compare( GFCommon::$version, self::$min_gravityforms_version, ">=" );
return $is_correct_version;
} else {
return false;
}
}
// -------------------------------------------------
protected static function has_access( $required_permission = 'gravityforms_payping' ) {
if ( ! function_exists( 'wp_get_current_user' ) ) {
include( ABSPATH . "wp-includes/pluggable.php" );
}
return GFCommon::current_user_can_any( $required_permission );
}
// -------------------------------------------------
protected static function get_base_url() {
return plugins_url( null, __FILE__ );
}
// -------------------------------------------------
protected static function get_base_path() {
$folder = basename( dirname( __FILE__ ) );
return WP_PLUGIN_DIR . "/" . $folder;
}
// -------------------------------------------------
public static function set_logging_supported( $plugins ) {
$plugins[ basename( dirname( __FILE__ ) ) ] = "payping";
return $plugins;
}
// -------------------------------------------------
public static function uninstall() {
if ( ! self::has_access( "gravityforms_payping_uninstall" ) ) {
die( esc_html__( "شما مجوز کافی برای این کار را ندارید . سطح دسترسی شما پایین تر از حد مجاز است . ", "payping-gravityforms" ) );
}
GFPersian_DB_payping::drop_tables();
delete_option( "ppgf_payping_settings" );
delete_option( "ppgf_payping_configured" );
delete_option( "ppgf_payping_version" );
update_option( 'payping_gf_recently_activated', array( $plugin => time() ) + (array) get_option( 'payping_gf_recently_activated' ) );
}
// -------------------------------------------------
private static function is_payping_page() {
$current_page = in_array( trim( strtolower( rgget( "page" ) ) ), array( 'gravityforms_payping', 'payping' ) );
$current_view = in_array( trim( strtolower( rgget( "view" ) ) ), array( 'gravityforms_payping', 'payping' ) );
$current_subview = in_array( trim( strtolower( rgget( "subview" ) ) ), array( 'gravityforms_payping', 'payping' ) );
return $current_page || $current_view || $current_subview;
}
// -------------------------------------------------
public static function feed_page() {
GFFormSettings::page_header(); ?>
<h3>
<span><i class="fa fa-credit-card"></i> <?php esc_html_e( 'پیپینگ', 'payping-gravityforms' ) ?>
<a id="add-new-confirmation" class="add-new-h2"
href="<?php echo esc_url( admin_url( 'admin.php?page=gravityforms_payping&view=edit&fid=' . absint( rgget( "id" ) ) ) ) ?>"><?php esc_html_e( 'افزودن فید جدید', 'payping-gravityforms' ) ?></a></span>
<a class="add-new-h2"
href="admin.php?page=gravityforms_payping&view=stats&id=<?php echo absint( rgget( 'id' ) ); ?>"><?php esc_html_e( "نمودار ها", "payping-gravityforms" ) ?></a>
</h3>
<?php self::list_page( 'per-form' ); ?>
<?php GFFormSettings::page_footer();
}
// -------------------------------------------------
public static function has_payping_condition( $form, $config ) {
if ( empty( $config['meta'] ) ) {
return false;
}
if ( empty( $config['meta']['payping_conditional_enabled'] ) ) {
return true;
}
if ( ! empty( $config['meta']['payping_conditional_field_id'] ) ) {
$condition_field_ids = $config['meta']['payping_conditional_field_id'];
if ( ! is_array( $condition_field_ids ) ) {
$condition_field_ids = array( '1' => $condition_field_ids );
}
} else {
return true;
}
if ( ! empty( $config['meta']['payping_conditional_value'] ) ) {
$condition_values = $config['meta']['payping_conditional_value'];
if ( ! is_array( $condition_values ) ) {
$condition_values = array( '1' => $condition_values );
}
} else {
$condition_values = array( '1' => '' );
}
if ( ! empty( $config['meta']['payping_conditional_operator'] ) ) {
$condition_operators = $config['meta']['payping_conditional_operator'];
if ( ! is_array( $condition_operators ) ) {
$condition_operators = array( '1' => $condition_operators );
}
} else {
$condition_operators = array( '1' => 'is' );
}
$type = ! empty( $config['meta']['payping_conditional_type'] ) ? strtolower( $config['meta']['payping_conditional_type'] ) : '';
$type = $type == 'all' ? 'all' : 'any';
foreach ( $condition_field_ids as $i => $field_id ) {
if ( empty( $field_id ) ) {
continue;
}
$field = RGFormsModel::get_field( $form, $field_id );
if ( empty( $field ) ) {
continue;
}
$value = ! empty( $condition_values[ '' . $i . '' ] ) ? $condition_values[ '' . $i . '' ] : '';
$operator = ! empty( $condition_operators[ '' . $i . '' ] ) ? $condition_operators[ '' . $i . '' ] : 'is';
$is_visible = ! RGFormsModel::is_field_hidden( $form, $field, array() );
$field_value = RGFormsModel::get_field_value( $field, array() );
$is_value_match = RGFormsModel::is_value_match( $field_value, $value, $operator );
$check = $is_value_match && $is_visible;
if ( $type == 'any' && $check ) {
return true;
} else if ( $type == 'all' && ! $check ) {
return false;
}
}
if ( $type == 'any' ) {
return false;
} else {
return true;
}
}
// -------------------------------------------------
public static function get_config_by_entry( $entry ) {
$feed_id = gform_get_meta( $entry["id"], "payping_feed_id" );
$feed = ! empty( $feed_id ) ? GFPersian_DB_payping::get_feed( $feed_id ) : '';
$return = ! empty( $feed ) ? $feed : false;
return apply_filters( self::$author . '_gf_payping_get_config_by_entry', apply_filters( self::$author . '_gf_gateway_get_config_by_entry', $return, $entry ), $entry );
}
// -------------------------------------------------
public static function delay_posts( $is_disabled, $form, $entry ) {
$config = self::get_active_config( $form );
if ( ! empty( $config ) && is_array( $config ) && $config ) {
return true;
}
return $is_disabled;
}
// -------------------------------------------------
public static function delay_addons( $is_delayed, $form, $entry, $slug ) {
$config = self::get_active_config( $form );
if ( ! empty( $config["meta"] ) && is_array( $config["meta"] ) && $config = $config["meta"] ) {
$user_registration_slug = apply_filters( 'ppgf_user_registration_slug', 'gravityformsuserregistration' );
if ( $slug != $user_registration_slug && ! empty( $config["addon"] ) && $config["addon"] == 'true' ) {
$flag = true;
} elseif ( $slug == $user_registration_slug && ! empty( $config["type"] ) && $config["type"] == "subscription" ) {
$flag = true;
}
if ( ! empty( $flag ) ) {
$fulfilled = gform_get_meta( $entry['id'], $slug . '_is_fulfilled' );
$processed = gform_get_meta( $entry['id'], 'processed_feeds' );
$is_delayed = empty( $fulfilled ) && rgempty( $slug, $processed );
}
}
return $is_delayed;
}
// -------------------------------------------------
private static function redirect_confirmation( $url, $ajax ) {
if ( headers_sent() || $ajax ) {
$confirmation = array( 'redirect' => $url );
} else {
$confirmation = array( 'redirect' => $url );
}
return $confirmation;
}
// -------------------------------------------------
public static function get_active_config( $form ) {
if ( ! empty( self::$config ) ) {
return self::$config;
}
$configs = GFPersian_DB_payping::get_feed_by_form( $form["id"], true );
$configs = apply_filters( self::$author . '_gf_payping_get_active_configs', apply_filters( self::$author . '_gf_gateway_get_active_configs', $configs, $form ), $form );
$return = false;
if ( ! empty( $configs ) && is_array( $configs ) ) {
foreach ( $configs as $config ) {
if ( self::has_payping_condition( $form, $config ) ) {
$return = $config;
}
break;
}
}
self::$config = apply_filters( self::$author . '_gf_payping_get_active_config', apply_filters( self::$author . '_gf_gateway_get_active_config', $return, $form ), $form );
return self::$config;
}
// -------------------------------------------------
public static function payping_page() {
$view = rgget( "view" );
if ( $view == "edit" ) {
self::config_page();
} else if ( $view == "stats" ) {
GFPersian_Chart_payping::stats_page();
} else {
self::list_page( '' );
}
}
// -------------------------------------------------
private static function list_page( $arg ) {
if ( ! self::is_gravityforms_supported() ) {
die( sprintf( esc_html__( "درگاه پیپینگ نیاز به گرویتی فرم نسخه %s دارد. برای بروز رسانی هسته گرویتی فرم به %sسایت گرویتی فرم فارسی%s مراجعه نمایید .", "payping-gravityforms" ), self::$min_gravityforms_version, "<a href='http:///11378' target='_blank'>", "</a>" ) );
}
if ( rgpost( 'action' ) == "delete" ) {
check_admin_referer( "list_action", "gf_payping_list" );
$id = absint( rgpost( "action_argument" ) );
GFPersian_DB_payping::delete_feed( $id );
?>
<div class="updated fade"
style="padding:6px"><?php esc_html_e( "فید حذف شد", "payping-gravityforms" ) ?></div><?php
} else if ( ! empty( $_POST["bulk_action"] ) ) {
check_admin_referer( "list_action", "gf_payping_list" );
$selected_feeds = rgpost( "feed" );
if ( is_array( $selected_feeds ) ) {
foreach ( $selected_feeds as $feed_id ) {
GFPersian_DB_payping::delete_feed( $feed_id );
}
}
?>
<div class="updated fade"
style="padding:6px"><?php esc_html_e( "فید ها حذف شدند", "payping-gravityforms" ) ?></div>
<?php
}
?>
<div class="wrap">
<?php if ( $arg != 'per-form' ) { ?>
<h2>
<?php esc_html_e( "فیدهای درگاه پیپینگ", "payping-gravityforms" );
if ( get_option( "ppgf_payping_configured" ) ) { ?>
<a class="add-new-h2"
href="admin.php?page=gravityforms_payping&view=edit"><?php esc_html_e( "افزودن جدید", "payping-gravityforms" ) ?></a>
<?php
} ?>
</h2>
<?php } ?>
<form id="confirmation_list_form" method="post">
<?php wp_nonce_field( 'list_action', 'gf_payping_list' ) ?>
<input type="hidden" id="action" name="action"/>
<input type="hidden" id="action_argument" name="action_argument"/>
<div class="tablenav">
<div class="alignleft actions" style="padding:8px 0 7px 0;">
<label class="hidden"
for="bulk_action"><?php esc_html_e( "اقدام دسته جمعی", "payping-gravityforms" ) ?></label>
<select name="bulk_action" id="bulk_action">
<option value=''> <?php esc_html_e( "اقدامات دسته جمعی", "payping-gravityforms" ) ?> </option>
<option value='delete'><?php esc_html_e( "حذف", "payping-gravityforms" ) ?></option>
</select>
<?php
echo '<input type="submit" class="button" value="' . esc_html__( "اعمال", "payping-gravityforms" ) . '" onclick="if( jQuery(\'#bulk_action\').val() == \'delete\' && !confirm(\'' . esc_html__( "فید حذف شود ؟ ", "payping-gravityforms" ) . esc_html__( "\'Cancel\' برای منصرف شدن, \'OK\' برای حذف کردن", "payping-gravityforms" ) . '\')) { return false; } return true;"/>';
?>
<a class="button button-primary"
href="admin.php?page=gf_settings&subview=gravityforms_payping"><?php esc_html_e( 'تنظیمات حساب پیپینگ', 'payping-gravityforms' ) ?></a>
</div>
</div>
<table class="wp-list-table widefat fixed striped toplevel_page_gf_edit_forms" cellspacing="0">
<thead>
<tr>
<th scope="col" id="cb" class="manage-column column-cb check-column"
style="padding:13px 3px;width:30px"><input type="checkbox"/></th>
<th scope="col" id="active" class="manage-column"
style="width:<?php echo esc_attr($arg !== 'per-form' ? '50px' : '20px'); ?>"><?php echo esc_html($arg != 'per-form') ? esc_html__( 'وضعیت', 'payping-gravityforms' ) : '' ?></th>
<th scope="col" class="manage-column"
style="width:<?php echo esc_attr($arg != 'per-form' ? '65px' : '30%'); ?>"><?php esc_html_e( " آیدی فید", "payping-gravityforms" ) ?></th>
<?php if ( $arg != 'per-form' ) { ?>
<th scope="col"
class="manage-column"><?php esc_html_e( "فرم متصل به درگاه", "payping-gravityforms" ) ?></th>
<?php } ?>
<th scope="col" class="manage-column"><?php esc_html_e( "نوع تراکنش", "payping-gravityforms" ) ?></th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="col" id="cb" class="manage-column column-cb check-column" style="padding:13px 3px;">
<input type="checkbox"/></th>
<th scope="col" id="active"
class="manage-column"><?php echo esc_html($arg != 'per-form') ? esc_html__( 'وضعیت', 'payping-gravityforms' ) : '' ?></th>
<th scope="col" class="manage-column"><?php esc_html_e( "آیدی فید", "payping-gravityforms" ) ?></th>
<?php if ( $arg != 'per-form' ) { ?>
<th scope="col"
class="manage-column"><?php esc_html_e( "فرم متصل به درگاه", "payping-gravityforms" ) ?></th>
<?php } ?>
<th scope="col" class="manage-column"><?php esc_html_e( "نوع تراکنش", "payping-gravityforms" ) ?></th>
</tr>
</tfoot>
<tbody class="list:user user-list">
<?php
if ( $arg != 'per-form' ) {
$settings = GFPersian_DB_payping::get_feeds();
} else {
$settings = GFPersian_DB_payping::get_feed_by_form( rgget( 'id' ), false );
}
if ( ! get_option( "ppgf_payping_configured" ) ) {
?>
<tr>
<td colspan="5" style="padding:20px;">
<?php echo sprintf( esc_html__( "برای شروع باید درگاه را فعال نمایید . به %sتنظیمات پیپینگ%s بروید . ", "payping-gravityforms" ), '<a href="admin.php?page=gf_settings&subview=gravityforms_payping">', "</a>" ); ?>
</td>
</tr>
<?php
} else if ( is_array( $settings ) && sizeof( $settings ) > 0 ) {
foreach ( $settings as $setting ) {
?>
<tr class='author-self status-inherit' valign="top">
<th scope="row" class="check-column"><input type="checkbox" name="feed[]" value="<?php echo esc_html($setting["id"]) ?>"/></th>
<td>
<img style="cursor:pointer;width:25px"
src="<?php echo esc_url( GFCommon::get_base_url() ) ?>/images/active<?php echo esc_attr( intval( $setting["is_active"] ) ) ?>.png"
alt="<?php echo esc_attr( $setting["is_active"] ? esc_html__( "درگاه فعال است", "payping-gravityforms" ) : esc_html__( "درگاه غیر فعال است", "payping-gravityforms" ) ); ?>"
title="<?php echo esc_attr( $setting["is_active"] ? esc_html__( "درگاه فعال است", "payping-gravityforms" ) : esc_html__( "درگاه غیر فعال است", "payping-gravityforms" ) ); ?>"
onclick="ToggleActive(this, <?php echo esc_attr( $setting['id'] ) ?>);"
/>
</td>
<td><?php echo esc_html($setting["id"]) ?>
<?php if ( $arg == 'per-form' ) { ?>
<div class="row-actions">
<span class="edit">
<a title="<?php esc_html_e( "ویرایش فید", "payping-gravityforms" ) ?>"
href="admin.php?page=gravityforms_payping&view=edit&id=<?php echo esc_html($setting["id"]) ?>"><?php esc_html_e( "ویرایش فید", "payping-gravityforms" ) ?></a>
|
</span>
<span class="trash">
<a title="<?php esc_html_e( "حذف", "payping-gravityforms" ) ?>"
href="javascript: if(confirm('<?php esc_html_e( "فید حذف شود؟ ", "payping-gravityforms" ) ?> <?php esc_html_e( "\'Cancel\' برای انصراف, \'OK\' برای حذف کردن.", "payping-gravityforms" ) ?>')){ DeleteSetting(<?php echo esc_html($setting["id"]) ?>);}"><?php esc_html_e( "حذف", "payping-gravityforms" ) ?></a>
</span>
</div>
<?php } ?>
</td>
<?php if ( $arg != 'per-form' ) { ?>
<td class="column-title">
<strong><a class="row-title"
href="admin.php?page=gravityforms_payping&view=edit&id=<?php echo esc_html($setting["id"]) ?>"
title="<?php esc_html_e( "تنظیم مجدد درگاه", "payping-gravityforms" ) ?>"><?php echo esc_html($setting["form_title"]) ?></a></strong>
<div class="row-actions">
<span class="edit">
<a title="<?php esc_html_e( "ویرایش فید", "payping-gravityforms" ) ?>"
href="admin.php?page=gravityforms_payping&view=edit&id=<?php echo esc_html($setting["id"]) ?>"><?php esc_html_e( "ویرایش فید", "payping-gravityforms" ) ?></a>
|
</span>
<span class="trash">
<a title="<?php esc_html_e( "حذف فید", "payping-gravityforms" ) ?>"
href="javascript: if(confirm('<?php esc_html_e( "فید حذف شود؟ ", "payping-gravityforms" ) ?> <?php esc_html_e( "\'Cancel\' برای انصراف, \'OK\' برای حذف کردن.", "payping-gravityforms" ) ?>')){ DeleteSetting(<?php echo esc_html($setting["id"]) ?>);}"><?php esc_html_e( "حذف", "payping-gravityforms" ) ?></a>
|
</span>
<span class="view">
<a title="<?php esc_html_e( "ویرایش فرم", "payping-gravityforms" ) ?>"
href="admin.php?page=gf_edit_forms&id=<?php echo esc_html($setting["form_id"]) ?>"><?php esc_html_e( "ویرایش فرم", "payping-gravityforms" ) ?></a>
|
</span>
<span class="view">
<a title="<?php esc_html_e( "مشاهده صندوق ورودی", "payping-gravityforms" ) ?>"
href="admin.php?page=gf_entries&view=entries&id=<?php echo esc_html($setting["form_id"]) ?>"><?php esc_html_e( "صندوق ورودی", "payping-gravityforms" ) ?></a>
|
</span>
<span class="view">
<a title="<?php esc_html_e( "نمودارهای فرم", "payping-gravityforms" ) ?>"
href="admin.php?page=gravityforms_payping&view=stats&id=<?php echo esc_html($setting["form_id"]) ?>"><?php esc_html_e( "نمودارهای فرم", "payping-gravityforms" ) ?></a>
</span>
</div>
</td>
<?php } ?>
<td class="column-date">
<?php
if ( isset( $setting["meta"]["type"] ) && $setting["meta"]["type"] == 'subscription' ) {
esc_html_e( "عضویت", "payping-gravityforms" );
} else {
esc_html_e( "محصول معمولی یا فرم ارسال پست", "payping-gravityforms" );
}
?>
</td>
</tr>
<?php
}
} else {
?>
<tr>
<td colspan="5" style="padding:20px;">
<?php
if ( $arg == 'per-form' ) {
echo sprintf( esc_html__( "شما هیچ فید پیپینگی ندارید . %sیکی بسازید%s .", "payping-gravityforms" ), '<a href="admin.php?page=gravityforms_payping&view=edit&fid=' . absint( rgget( "id" ) ) . '">', "</a>" );
} else {
echo sprintf( esc_html__( "شما هیچ فید پیپینگی ندارید . %sیکی بسازید%s .", "payping-gravityforms" ), '<a href="admin.php?page=gravityforms_payping&view=edit">', "</a>" );
}
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</form>
</div>
<?php
}
// -------------------------------------------------
public static function update_feed_active() {
check_ajax_referer( 'gf_payping_update_feed_active', 'gf_payping_update_feed_active' );
$id = absint( rgpost( 'feed_id' ) ); // Sanitize as an integer
$feed = GFPersian_DB_payping::get_feed( $id );
$form_id = intval( $feed["form_id"] ); // Sanitize as an integer
$is_active = isset( $_POST["is_active"] ) ? intval( $_POST["is_active"] ) : 0; // Sanitize as an integer, default to 0 if not set
$meta = esc_sql( $feed["meta"] ); // Escape SQL data
GFPersian_DB_payping::update_feed( $id, $form_id, $is_active, $meta );
}
// -------------------------------------------------
private static function Return_URL( $form_id, $entry_id ) {
$pageURL = GFCommon::is_ssl() ? 'https://' : 'http://';
// Sanitize SERVER_NAME
if (isset($_SERVER['SERVER_NAME'])) {
$pageURL .= sanitize_text_field($_SERVER['SERVER_NAME']);
}
// Check if HTTPS is on and prepend 'https://' if true
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
$pageURL = 'https://' . $pageURL;
} else {
$pageURL = 'http://' . $pageURL;
}
// Sanitize SERVER_PORT
if (isset($_SERVER['SERVER_PORT']) && is_numeric($_SERVER['SERVER_PORT'])) {
// Add port number if not the default HTTP port (80)
if ($_SERVER['SERVER_PORT'] != '80') {
$pageURL .= ':' . absint($_SERVER['SERVER_PORT']);
}
}
// Sanitize REQUEST_URI
if (isset($_SERVER['REQUEST_URI'])) {
$pageURL .= esc_url_raw($_SERVER['REQUEST_URI']);
}
$arr_params = array( 'id', 'entry', 'no', 'Authority', 'Status' );
$pageURL = esc_url( remove_query_arg( $arr_params, $pageURL ) );
$pageURL = str_replace( '#038;', '&', add_query_arg( array(
'id' => $form_id,
'entry' => $entry_id
), $pageURL ) );
$returnUrl = str_replace('https://https://', 'https://', $pageURL);
return apply_filters( self::$author . '_payping_return_url', apply_filters( self::$author . '_gateway_return_url', $returnUrl, $form_id, $entry_id, __CLASS__ ), $form_id, $entry_id, __CLASS__ );
}
// -------------------------------------------------
public static function get_order_total( $form, $entry ) {
$total = GFCommon::get_order_total( $form, $entry );
$total = ( ! empty( $total ) && $total > 0 ) ? $total : 0;
return apply_filters( self::$author . '_payping_get_order_total', apply_filters( self::$author . '_gateway_get_order_total', $total, $form, $entry ), $form, $entry );
}
// -------------------------------------------------
private static function get_mapped_field_list( $field_name, $selected_field, $fields ) {
$str_escaped = "<select name='" . esc_attr($field_name) . "' id='" . esc_attr($field_name) . "'><option value=''></option>";
if (is_array($fields)) {
foreach ($fields as $field) {
$field_id = $field[0];
$field_label = esc_html(GFCommon::truncate_middle($field[1], 40));
$selected = $field_id == $selected_field ? "selected='selected'" : "";
$str_escaped .= "<option value='" . esc_attr($field_id) . "' " . $selected . ">" . esc_html($field_label) . "</option>";
}
}
$str_escaped .= "</select>";
echo $str_escaped;
}
// -------------------------------------------------
private static function get_form_fields( $form ) {
$fields = array();
if ( is_array( $form["fields"] ) ) {
foreach ( $form["fields"] as $field ) {
if ( isset( $field["inputs"] ) && is_array( $field["inputs"] ) ) {
foreach ( $field["inputs"] as $input ) {
$fields[] = array( $input["id"], GFCommon::get_label( $field, $input["id"] ) );
}
} else if ( ! rgar( $field, 'displayOnly' ) ) {
$fields[] = array( $field["id"], GFCommon::get_label( $field ) );
}
}
}
return $fields;
}
// ---------------------------------------------------------------------------------------------
//desc
private static function get_customer_information_desc( $form, $config = null ) {
$form_fields = self::get_form_fields( $form );
$selected_field = ! empty( $config["meta"]["customer_fields_desc"] ) ? $config["meta"]["customer_fields_desc"] : '';
return self::get_mapped_field_list( 'payping_customer_field_desc', $selected_field, $form_fields );
}
//email
private static function get_customer_information_email( $form, $config = null ) {
$form_fields = self::get_form_fields( $form );
$selected_field = ! empty( $config["meta"]["customer_fields_email"] ) ? $config["meta"]["customer_fields_email"] : '';
return self::get_mapped_field_list( 'payping_customer_field_email', $selected_field, $form_fields );
}
//mobile
private static function get_customer_information_mobile( $form, $config = null ) {
$form_fields = self::get_form_fields( $form );
$selected_field = ! empty( $config["meta"]["customer_fields_mobile"] ) ? $config["meta"]["customer_fields_mobile"] : '';
return self::get_mapped_field_list( 'payping_customer_field_mobile', $selected_field, $form_fields );
}
// ------------------------------------------------------------------------------------------------------------
// -------------------------------------------------
public static function payment_entry_detail( $form_id, $entry ) {
$payment_gateway = rgar( $entry, "payment_method" );
if ( ! empty( $payment_gateway ) && $payment_gateway == "payping" ) {
do_action( 'ppgf_gateway_entry_detail' );
?>
<hr/>
<strong>
<?php esc_html_e( 'اطلاعات تراکنش :', 'payping-gravityforms' ) ?>
</strong>
<br/>
<br/>
<?php
$transaction_type = rgar( $entry, "transaction_type" );
$payment_status = rgar( $entry, "payment_status" );
$payment_amount = rgar( $entry, "payment_amount" );
if ( empty( $payment_amount ) ) {
$form = RGFormsModel::get_form_meta( $form_id );
$payment_amount = self::get_order_total( $form, $entry );
}
$transaction_id = rgar( $entry, "transaction_id" );
$payment_date = rgar( $entry, "payment_date" );
$date = new DateTime( $payment_date );
$tzb = get_option( 'gmt_offset' );
$tzn = abs( $tzb ) * 3600;
$tzh = intval( gmdate( "H", $tzn ) );
$tzm = intval( gmdate( "i", $tzn ) );
if ( intval( $tzb ) < 0 ) {
$date->sub( new DateInterval( 'P0DT' . $tzh . 'H' . $tzm . 'M' ) );
} else {
$date->add( new DateInterval( 'P0DT' . $tzh . 'H' . $tzm . 'M' ) );
}
$payment_date = $date->format( 'Y-m-d H:i:s' );
$payment_date = GF_jdate( 'Y-m-d H:i:s', strtotime( $payment_date ), '', date_default_timezone_get(), 'en' );
if ( $payment_status == 'Paid' ) {
$payment_status_persian = esc_html__( 'موفق', 'payping-gravityforms' );
}
if ( $payment_status == 'Active' ) {
$payment_status_persian = esc_html__( 'موفق', 'payping-gravityforms' );
}
if ( $payment_status == 'Cancelled' ) {
$payment_status_persian = esc_html__( 'منصرف شده', 'payping-gravityforms' );
}
if ( $payment_status == 'Failed' ) {
$payment_status_persian = esc_html__( 'ناموفق', 'payping-gravityforms' );
}
if ( $payment_status == 'Processing' ) {
$payment_status_persian = esc_html__( 'معلق', 'payping-gravityforms' );
}
if ( ! strtolower( rgpost( "save" ) ) || RGForms::post( "screen_mode" ) != "edit" ) {
echo esc_html__( 'وضعیت پرداخت : ', 'payping-gravityforms' ) . esc_html( $payment_status_persian ) . '<br/><br/>';
echo esc_html__( 'تاریخ پرداخت : ', 'payping-gravityforms' ) . '<span style="">' . esc_html( $payment_date ) . '</span><br/><br/>';
echo esc_html__( 'مبلغ پرداختی : ', 'payping-gravityforms' ) . esc_html( GFCommon::to_money( $payment_amount, rgar( $entry, "currency" ) ) ) . '<br/><br/>';
echo esc_html__( 'کد رهگیری : ', 'payping-gravityforms' ) . esc_html( $transaction_id ) . '<br/><br/>';
echo esc_html__( 'درگاه پرداخت : پیپینگ', 'payping-gravityforms' );
} else {
$payment_string = '';
$payment_string .= '<select id="payment_status" name="payment_status">';
$payment_string .= '<option value="' . $payment_status . '" selected>' . $payment_status_persian . '</option>';
if ( $transaction_type == 1 ) {
if ( $payment_status != "Paid" ) {
$payment_string .= '<option value="Paid">' . esc_html__( 'موفق', 'payping-gravityforms' ) . '</option>';
}
}
if ( $transaction_type == 2 ) {
if ( $payment_status != "Active" ) {
$payment_string .= '<option value="Active">' . esc_html__( 'موفق', 'payping-gravityforms' ) . '</option>';
}
}
if ( ! $transaction_type ) {
if ( $payment_status != "Paid" ) {
$payment_string .= '<option value="Paid">' . esc_html__( 'موفق', 'payping-gravityforms' ) . '</option>';
}
if ( $payment_status != "Active" ) {
$payment_string .= '<option value="Active">' . esc_html__( 'موفق', 'payping-gravityforms' ) . '</option>';
}
}
if ( $payment_status != "Failed" ) {
$payment_string .= '<option value="Failed">' . esc_html__( 'ناموفق', 'payping-gravityforms' ) . '</option>';
}
if ( $payment_status != "Cancelled" ) {
$payment_string .= '<option value="Cancelled">' . esc_html__( 'منصرف شده', 'payping-gravityforms' ) . '</option>';
}
if ( $payment_status != "Processing" ) {
$payment_string .= '<option value="Processing">' . esc_html__( 'معلق', 'payping-gravityforms' ) . '</option>';
}
$payment_string .= '</select>';
echo esc_html__( 'وضعیت پرداخت :', 'payping-gravityforms' ) . esc_html( $payment_string ) . '<br/><br/>';
?>
<div id="edit_payment_status_details" style="display:block">
<table>
<tr>
<td><?php esc_html_e( 'تاریخ پرداخت :', 'payping-gravityforms' ) ?></td>
<td><input type="text" id="payment_date" name="payment_date"
value="<?php echo esc_html($payment_date) ?>"></td>
</tr>
<tr>
<td><?php esc_html_e( 'مبلغ پرداخت :', 'payping-gravityforms' ) ?></td>
<td><input type="text" id="payment_amount" name="payment_amount"
value="<?php echo esc_html($payment_amount) ?>"></td>
</tr>
<tr>
<td><?php esc_html_e( 'شماره تراکنش :', 'payping-gravityforms' ) ?></td>
<td><input type="text" id="payping_transaction_id" name="payping_transaction_id"
value="<?php echo esc_html($transaction_id) ?>"></td>
</tr>
</table>
<br/>
</div>
<?php
echo esc_html__( 'درگاه پرداخت : پیپینگ (غیر قابل ویرایش)', 'payping-gravityforms' );
}
}
}
// -------------------------------------------------
public static function update_payment_entry( $form, $entry_id ) {
check_admin_referer( 'gforms_save_entry', 'gforms_save_entry' );
do_action( 'ppgf_gateway_update_entry' );
$entry = GFPersian_Payments::get_entry( $entry_id );
$payment_gateway = rgar( $entry, "payment_method" );
if ( empty( $payment_gateway ) ) {
return;
}
if ( $payment_gateway != "payping" ) {
return;
}
$payment_status = rgpost( "payment_status" );
if ( empty( $payment_status ) ) {
$payment_status = rgar( $entry, "payment_status" );
}
$payment_amount = rgpost( "payment_amount" );
$payment_transaction = rgpost( "payping_transaction_id" );
$payment_date_Checker = $payment_date = rgpost( "payment_date" );
list( $date, $time ) = explode( " ", $payment_date );
list( $Y, $m, $d ) = explode( "-", $date );
list( $H, $i, $s ) = explode( ":", $time );
$miladi = GF_jalali_to_gregorian( $Y, $m, $d );
$date = new DateTime( "$miladi[0]-$miladi[1]-$miladi[2] $H:$i:$s" );
$payment_date = $date->format( 'Y-m-d H:i:s' );
if ( empty( $payment_date_Checker ) ) {
if ( ! empty( $entry["payment_date"] ) ) {
$payment_date = $entry["payment_date"];
} else {
$payment_date = rgar( $entry, "date_created" );
}
} else {
$payment_date = date( "Y-m-d H:i:s", strtotime( $payment_date ) );
$date = new DateTime( $payment_date );
$tzb = get_option( 'gmt_offset' );
$tzn = abs( $tzb ) * 3600;
$tzh = intval( gmdate( "H", $tzn ) );
$tzm = intval( gmdate( "i", $tzn ) );
if ( intval( $tzb ) < 0 ) {
$date->add( new DateInterval( 'P0DT' . $tzh . 'H' . $tzm . 'M' ) );
} else {
$date->sub( new DateInterval( 'P0DT' . $tzh . 'H' . $tzm . 'M' ) );
}
$payment_date = $date->format( 'Y-m-d H:i:s' );
}
global $current_user;
$user_id = 0;
$user_name = esc_html__( "مهمان", 'payping-gravityforms' );
if ( $current_user && $user_data = get_userdata( $current_user->ID ) ) {
$user_id = $current_user->ID;
$user_name = $user_data->display_name;
}
$entry["payment_status"] = $payment_status;
$entry["payment_amount"] = $payment_amount;
$entry["payment_date"] = $payment_date;
$entry["transaction_id"] = $payment_transaction;
if ( $payment_status == 'Paid' || $payment_status == 'Active' ) {
$entry["is_fulfilled"] = 1;
} else {
$entry["is_fulfilled"] = 0;
}
GFAPI::update_entry( $entry );
$new_status = '';
switch ( rgar( $entry, "payment_status" ) ) {
case "Active" :
$new_status = esc_html__( 'موفق', 'payping-gravityforms' );
break;
case "Paid" :
$new_status = esc_html__( 'موفق', 'payping-gravityforms' );
break;
case "Cancelled" :
$new_status = esc_html__( 'منصرف شده', 'payping-gravityforms' );
break;
case "Failed" :
$new_status = esc_html__( 'ناموفق', 'payping-gravityforms' );
break;
case "Processing" :
$new_status = esc_html__( 'معلق', 'payping-gravityforms' );
break;
}