PluginProbe
Welcart e-Commerce / 2.12.4
Welcart e-Commerce v2.12.4
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / functions / settlement_func.php

settlement_func.php in Welcart e-Commerce 2.12.4, at functions/settlement_func.php

1,371 lines 46.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * 決済直前ログ、決済エラーログ、受注データ復帰関連関数
4 *
5 * @package Welcart
6 */
7
8 /**
9 * 決済直前ログ、決済エラーログ、受注データ復帰関連スクリプト
10 */
11 function usces_order_list_js_settlement_dialog() {
12 ?>
13 settlement_operation = {
14 get_settlement_log: function() {
15 $( "#settlement-log-response" ).html( '<img src="<?php echo esc_url( USCES_PLUGIN_URL ); ?>/images/loading-publish.gif" />' );
16 $.ajax({
17 url: ajaxurl,
18 type: "POST",
19 dataType: "json",
20 data: {
21 'action' : "order_item_ajax",
22 'wc_nonce': "<?php echo esc_js( wp_create_nonce( 'order_list' ) ); ?>",
23 'mode' : "get_settlement_log"
24 }
25 }).done( function( retVal, dataType ) {
26 $( "#settlement-log-response" ).html( "" );
27 if ( retVal.status == "OK" ) {
28 $( "#settlement-log-list" ).html( retVal.result );
29 }
30 }).fail( function( retVal ) {
31 $( "#settlement-log-response" ).html( "" );
32 });
33 return false;
34 },
35
36 get_settlement_log_detail: function( log_key ) {
37 $.ajax({
38 url: ajaxurl,
39 type: "POST",
40 dataType: "json",
41 data: {
42 'action' : "order_item_ajax",
43 'wc_nonce': "<?php echo esc_js( wp_create_nonce( 'order_list' ) ); ?>",
44 'mode' : "get_settlement_log_detail",
45 'log_key' : log_key
46 }
47 }).done( function( retVal, dataType ) {
48 if ( retVal.status == "OK" ) {
49 $( "#settlement-log-detail" ).html( retVal.result );
50 }
51 }).fail( function( retVal ) {
52 });
53 return false;
54 },
55
56 search_settlement_log: function( log_key ) {
57 $.ajax({
58 url: ajaxurl,
59 type: "POST",
60 dataType: "json",
61 data: {
62 'action' : "order_item_ajax",
63 'wc_nonce': "<?php echo esc_js( wp_create_nonce( 'order_list' ) ); ?>",
64 'mode' : "search_settlement_log",
65 'log_key' : log_key
66 }
67 }).done( function( retVal, dataType ) {
68 $( "#settlement-log-response" ).html( "" );
69 if ( retVal.status == "OK" ) {
70 $( "#settlement-log-list" ).html( retVal.result );
71 $( "#searchLogDialog" ).dialog( "close" );
72 }
73 }).fail( function( retVal ) {
74 });
75 return false;
76 },
77
78 delete_settlement_log: function( log_key ) {
79 $.ajax({
80 url: ajaxurl,
81 type: "POST",
82 dataType: "json",
83 data: {
84 'action' : "order_item_ajax",
85 'wc_nonce': "<?php echo esc_js( wp_create_nonce( 'order_list' ) ); ?>",
86 'mode' : "delete_settlement_log",
87 'log_key' : log_key
88 }
89 }).done( function( retVal, dataType ) {
90 if ( retVal.status == "OK" ) {
91 $( "#settlement-log-list" ).html( "" );
92 $( "#settlement-log-list" ).html( retVal.result );
93 }
94 }).fail( function( retVal ) {
95 });
96 return false;
97 },
98
99 delete_settlement_log_all: function() {
100 $.ajax({
101 url: ajaxurl,
102 type: "POST",
103 dataType: "json",
104 data: {
105 'action' : "order_item_ajax",
106 'wc_nonce': "<?php echo esc_js( wp_create_nonce( 'order_list' ) ); ?>",
107 'mode' : "delete_settlement_log_all"
108 }
109 }).done( function( retVal, dataType ) {
110 if ( retVal.status == "OK" ) {
111 $( "#settlement-log-list" ).html( "" );
112 $( "#settlement-log-list" ).html( retVal.result );
113 }
114 }).fail( function( retVal ) {
115 });
116 return false;
117 },
118
119 revival_settlement_data: function( log_key, register_date ) {
120 $.ajax({
121 url: ajaxurl,
122 type: "POST",
123 dataType: "json",
124 data: {
125 'action' : "order_item_ajax",
126 'mode' : "revival_order_data",
127 'wc_nonce' : "<?php echo esc_js( wp_create_nonce( 'order_list' ) ); ?>",
128 'log_key' : log_key,
129 'register_date': register_date
130 }
131 }).done( function( retVal, dataType ) {
132 if ( retVal.status == "OK" ) {
133 alert( "<?php esc_html_e( 'The order data has been updated', 'usces' ); ?>" );
134 $( "#settlementLogDetailDialog" ).dialog( "close" );
135 $( "#settlementLogDialog" ).dialog( "close" );
136 location.reload();
137 }
138 }).fail( function( retVal ) {
139 });
140 return false;
141 },
142
143 get_settlement_error_log: function() {
144 $( "#settlement-error-log-response" ).html( '<img src="<?php echo esc_url( USCES_PLUGIN_URL ); ?>/images/loading-publish.gif" />' );
145 $.ajax({
146 url: ajaxurl,
147 type: "POST",
148 dataType: "json",
149 data: {
150 'action' : "order_item_ajax",
151 'wc_nonce' : "<?php echo esc_js( wp_create_nonce( 'order_list' ) ); ?>",
152 'mode' : "get_settlement_error_log"
153 }
154 }).done( function( retVal, dataType ) {
155 $( "#settlement-error-log-response" ).html( "" );
156 if ( retVal.status == "OK" ) {
157 $( "#settlement-error-log-list" ).html( retVal.result );
158 }
159 }).fail( function( retVal ) {
160 $( "#settlement-error-log-response" ).html( "" );
161 });
162 return false;
163 },
164
165 get_settlement_error_log_detail: function( log_id ) {
166 $.ajax({
167 url: ajaxurl,
168 type: "POST",
169 dataType: "json",
170 data: {
171 'action' : "order_item_ajax",
172 'wc_nonce' : "<?php echo esc_js( wp_create_nonce( 'order_list' ) ); ?>",
173 'mode' : "get_settlement_error_log_detail",
174 'log_id' : log_id
175 }
176 }).done( function( retVal, dataType ) {
177 if ( retVal.status == "OK" ) {
178 $( "#settlement-error-log-detail" ).html( retVal.result );
179 }
180 }).fail( function( retVal ) {
181 });
182 return false;
183 },
184
185 delete_settlement_error_log: function( log_id ) {
186 $.ajax({
187 url: ajaxurl,
188 type: "POST",
189 dataType: "json",
190 data: {
191 'action' : "order_item_ajax",
192 'wc_nonce' : "<?php echo esc_js( wp_create_nonce( 'order_list' ) ); ?>",
193 'mode' : "delete_settlement_error_log",
194 'log_id' : log_id
195 }
196 }).done( function( retVal, dataType ) {
197 if ( retVal.status == "OK" ) {
198 if ( retVal.nodata == "nodata" ) {
199 location.reload();
200 } else {
201 $( "#settlement-error-log-list" ).html( "" );
202 $( "#settlement-error-log-list" ).html( retVal.result );
203 }
204 }
205 }).fail( function( retVal ) {
206 });
207 return false;
208 },
209
210 delete_settlement_error_log_all: function() {
211 $.ajax({
212 url: ajaxurl,
213 type: "POST",
214 dataType: "json",
215 data: {
216 'action' : "order_item_ajax",
217 'wc_nonce' : "<?php echo esc_js( wp_create_nonce( 'order_list' ) ); ?>",
218 'mode' : "delete_settlement_error_log_all"
219 }
220 }).done( function( retVal, dataType ) {
221 if ( retVal.status == "OK" ) {
222 location.reload();
223 }
224 }).fail( function( retVal ) {
225 });
226 return false;
227 },
228
229 output_settlement_error_log: function( log_id ) {
230 location.href = "<?php echo esc_url( USCES_ADMIN_URL ); ?>?page=usces_orderlist&order_action=dlsettlementerrorlog&log_id="+log_id+"&noheader=true&wc_nonce=<?php echo esc_js( wp_create_nonce( 'order_list' ) ); ?>";
231 },
232
233 reset_settlement_notice: function() {
234 $.ajax({
235 url: ajaxurl,
236 type: "POST",
237 dataType: "json",
238 data: {
239 'action' : "order_item_ajax",
240 'wc_nonce' : "<?php echo esc_js( wp_create_nonce( 'order_list' ) ); ?>",
241 'mode' : "reset_settlement_notice"
242 }
243 }).done( function( retVal, dataType ) {
244 }).fail( function( retVal ) {
245 });
246 return false;
247 }
248 };
249
250 $( document ).on( "click", "#settlementlog", function() {
251 $( "#settlementLogDialog" ).dialog( "open" );
252 });
253
254 $( "#settlementLogDialog" ).dialog({
255 bgiframe: true,
256 autoOpen: false,
257 height: 400,
258 width: 800,
259 resizable: true,
260 modal: true,
261 buttons: {
262 "<?php esc_html_e( 'Search log', 'usces' ); ?>": function() {
263 $( "#searchLogDialog" ).dialog( "open" );
264 },
265 "<?php esc_html_e( 'Clear log', 'usces' ); ?>": function() {
266 var log_key = "";
267 $( ".log-check" ).each( function( i ) {
268 if ( $( this ).prop( 'checked' ) ) {
269 log_key += $( this ).val()+':';
270 }
271 });
272 if ( log_key != "" ) {
273 if ( confirm( "<?php esc_html_e( 'Are you sure you want to delete selected log ?', 'usces' ); ?>" ) ) {
274 log_key = log_key.substr( 0, ( log_key.length - 1 ) );
275 settlement_operation.delete_settlement_log( log_key );
276 }
277 } else {
278 if ( confirm( "<?php esc_html_e( 'Are you sure you want to delete all log ?', 'usces' ); ?>" ) ) {
279 settlement_operation.delete_settlement_log_all();
280 }
281 }
282 },
283 "<?php esc_html_e( 'Close' ); ?>": function() {
284 $( this ).dialog( "close" );
285 }
286 },
287 close: function() {
288 },
289 open: function() {
290 $( "#settlement-log-list" ).html( "" );
291 settlement_operation.get_settlement_log();
292 }
293 });
294
295 $( document ).on( "click", ".log-detail", function() {
296 var key = $( this ).attr( "id" );
297 $( "#settlement-log-detail" ).html( "" );
298 settlement_operation.get_settlement_log_detail( key );
299 $( "#settlementLogDetailDialog" ).dialog( "open" );
300 });
301
302 $( "#settlementLogDetailDialog" ).dialog({
303 bgiframe: true,
304 autoOpen: false,
305 height: 600,
306 width: 800,
307 resizable: true,
308 modal: true,
309 buttons: {
310 "<?php esc_html_e( 'Create order data', 'usces' ); ?>": function() {
311 if ( confirm( "<?php esc_html_e( 'Are you sure you want to create the order data ?', 'usces' ); ?>" ) ) {
312 settlement_operation.revival_settlement_data( $( "#log_key" ).val(), $( "input[name='register_date']:checked" ).val() );
313 }
314 },
315 "<?php esc_html_e( 'Close' ); ?>": function() {
316 $( this ).dialog( "close" );
317 }
318 },
319 close: function() {
320 }
321 });
322
323 $( "#searchLogDialog" ).dialog({
324 bgiframe: true,
325 autoOpen: false,
326 height: 210,
327 width: 300,
328 resizable: false,
329 modal: true,
330 buttons: {
331 "<?php esc_html_e( 'Search' ); ?>": function() {
332 var log_key = $( "#search_log_key" ).val();
333 settlement_operation.search_settlement_log( log_key );
334 $( this ).dialog( "close" );
335 },
336 "<?php esc_html_e( 'Close' ); ?>": function() {
337 $( this ).dialog( "close" );
338 }
339 },
340 close: function() {
341 },
342 open: function() {
343 $( "#search_log_key" ).val( "" );
344 }
345 });
346
347 $( document ).on( "click", "#settlement_errorlog", function() {
348 $( "#settlementErrorLogDialog" ).dialog( "open" );
349 });
350
351 $( "#settlementErrorLogDialog" ).dialog({
352 bgiframe: true,
353 autoOpen: false,
354 height: 400,
355 width: 800,
356 resizable: true,
357 modal: true,
358 buttons: {
359 "<?php esc_html_e( 'Output log', 'usces' ); ?>": function() {
360 var log_id = "";
361 $( ".error-log-check" ).each( function( i ) {
362 if ( $( this ).prop( 'checked' ) ) {
363 log_id += $( this ).val()+':';
364 }
365 });
366 if ( log_id != "" ) {
367 log_id = log_id.substr( 0, ( log_id.length - 1 ) );
368 }
369 settlement_operation.output_settlement_error_log( log_id );
370 },
371 "<?php esc_html_e( 'Clear log', 'usces' ); ?>": function() {
372 var log_id = "";
373 $( ".error-log-check" ).each( function( i ) {
374 if ( $( this ).prop( 'checked' ) ) {
375 log_id += $( this ).val() + ':';
376 }
377 });
378 if ( log_id != "" ) {
379 if ( confirm( "<?php esc_html_e( 'Are you sure you want to delete selected log ?', 'usces' ); ?>" ) ) {
380 log_id = log_id.substr( 0, ( log_id.length - 1 ) );
381 settlement_operation.delete_settlement_error_log( log_id );
382 }
383 } else {
384 if ( confirm( "<?php esc_html_e( 'Are you sure you want to delete all log ?', 'usces' ); ?>" ) ) {
385 settlement_operation.delete_settlement_error_log_all();
386 }
387 }
388 },
389 "<?php esc_html_e( 'Close' ); ?>": function() {
390 $( this ).dialog( "close" );
391 }
392 },
393 close: function() {
394 settlement_operation.reset_settlement_notice();
395 },
396 open: function() {
397 $( "#settlement-error-log-list" ).html( "" );
398 settlement_operation.get_settlement_error_log();
399 }
400 });
401
402 $( document ).on( "click", ".error-log-detail", function() {
403 var key = $( this ).attr( "id" );
404 $( "#settlement-error-log-detaily" ).html( "" );
405 settlement_operation.get_settlement_error_log_detail( key );
406 $( "#settlementErrorLogDetailDialog" ).dialog( "open" );
407 });
408
409 $( "#settlementErrorLogDetailDialog" ).dialog({
410 bgiframe: true,
411 autoOpen: false,
412 height: 600,
413 width: 600,
414 resizable: true,
415 modal: true,
416 buttons: {
417 "<?php esc_html_e( 'Output log', 'usces' ); ?>": function() {
418 settlement_operation.output_settlement_error_log( $( "#log_id" ).val() );
419 },
420 "<?php esc_html_e( 'Close' ); ?>": function() {
421 $( this ).dialog( "close" );
422 }
423 },
424 close: function() {
425 }
426 });
427 <?php
428 }
429
430 /**
431 * 決済直前ログダイアログ、決済エラーログダイアログ
432 */
433 function usces_order_list_form_settlement_dialog() {
434 ?>
435 <div id="settlementLogDialog" title="<?php esc_attr_e( 'Settlement previous log list', 'usces' ); ?>" style="display:none;">
436 <div id="settlement-log-response"></div>
437 <fieldset>
438 <div id="settlement-log-list"></div>
439 </fieldset>
440 </div>
441 <div id="settlementLogDetailDialog" title="<?php esc_attr_e( 'Settlement previous log detail', 'usces' ); ?>" style="display:none;">
442 <fieldset>
443 <div id="settlement-log-detail"></div>
444 </fieldset>
445 </div>
446 <div id="searchLogDialog" title="<?php esc_attr_e( 'Search log', 'usces' ); ?>" style="display:none;">
447 <fieldset>
448 <div><?php wel_esc_script_e( __( 'Enter the link key, <br />please click on the "Search" button.', 'usces' ) ); ?></div>
449 <p><input type="text" id="search_log_key" class="text" ></p>
450 </fieldset>
451 </div>
452 <div id="settlementErrorLogDialog" title="<?php esc_attr_e( 'Settlement error log list', 'usces' ); ?>" style="display:none;">
453 <div id="settlement-error-log-response"></div>
454 <fieldset>
455 <div id="settlement-error-log-list"></div>
456 </fieldset>
457 </div>
458 <div id="settlementErrorLogDetailDialog" title="<?php esc_attr_e( 'Settlement error log detail', 'usces' ); ?>" style="display:none;">
459 <fieldset>
460 <div id="settlement-error-log-detail"></div>
461 </fieldset>
462 </div>
463 <?php
464 }
465
466 /**
467 * 決済直前ログ保存
468 *
469 * @param string $key Link key.
470 * @param boolean $mobile Is mobile.
471 * @return mixed
472 */
473 function usces_save_order_acting_data( $key, $mobile = false ) {
474 global $usces, $wpdb;
475
476 $log_table_name = $wpdb->prefix . 'usces_log';
477 $data = array();
478 $data['usces_cart'] = ( isset( $_SESSION['usces_cart'] ) ) ? $_SESSION['usces_cart'] : array();
479 $data['usces_entry'] = ( isset( $_SESSION['usces_entry'] ) ) ? $_SESSION['usces_entry'] : array();
480 $data['usces_member'] = ( isset( $_SESSION['usces_member'] ) ) ? $_SESSION['usces_member'] : array();
481 $data['remote_addr'] = ( isset( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : '';
482 if ( $mobile ) {
483 $data['wcex_mobile'] = $mobile;
484 }
485 $data = apply_filters( 'usces_filter_save_order_acting_data', $data );
486
487 $order_data = usces_get_acting_data( $key );
488 if ( empty( $order_data['datetime'] ) ) {
489 $query = $wpdb->prepare(
490 "INSERT INTO {$log_table_name} ( `datetime`, `log`, `log_type`, `log_key` ) VALUES ( %s, %s, %s, %s )",
491 current_time( 'mysql' ),
492 serialize( $data ),
493 'acting_data',
494 $key
495 );
496 } else {
497 $query = $wpdb->prepare(
498 "UPDATE {$log_table_name} SET `datetime` = %s,`log` = %s WHERE `log_type` = %s AND `log_key` = %s",
499 current_time( 'mysql' ),
500 serialize( $data ),
501 'acting_data',
502 $key
503 );
504 }
505 $res = $wpdb->query( $query );
506 return $res;
507 }
508
509 /**
510 * 決済直前ログ取得
511 *
512 * @param string $key Log key.
513 * @return array
514 */
515 function usces_get_acting_data( $key ) {
516 global $wpdb;
517
518 $log_table_name = $wpdb->prefix . 'usces_log';
519 $query = $wpdb->prepare( "SELECT * FROM {$log_table_name} WHERE `log_type` = %s AND `log_key` = %s", 'acting_data', $key );
520 $data = $wpdb->get_row( $query, ARRAY_A );
521 if ( $data ) {
522 $order_data = wel_safe_unserialize( $data['log'] );
523 $order_data['key'] = $data['log_key'];
524 $order_data['datetime'] = $data['datetime'];
525 } else {
526 $order_data = array(
527 'usces_cart' => array(),
528 'usces_entry' => array(),
529 'usces_member' => array(),
530 'remote_addr' => '',
531 'key' => $key,
532 'datetime' => '',
533 );
534 }
535 return $order_data;
536 }
537
538 /**
539 * 決済直前データ取得
540 *
541 * @param string $key Log key.
542 * @return array
543 */
544 function usces_restore_order_acting_data( $key ) {
545 $order_data = usces_get_acting_data( $key );
546 $_SESSION['usces_cart'] = $order_data['usces_cart'];
547 $_SESSION['usces_entry'] = $order_data['usces_entry'];
548 $_SESSION['usces_member'] = $order_data['usces_member'];
549 do_action( 'usces_action_restore_order_acting_data', $order_data );
550 return $order_data;
551 }
552
553 /**
554 * 決済エラーログ保存
555 *
556 * @param array $log Log data.
557 * @param boolean $mobile Is mobile.
558 * @return mixed
559 */
560 function usces_save_order_acting_error( $log, $mobile = false ) {
561 global $usces, $wpdb;
562
563 $log_table_name = $wpdb->prefix . 'usces_log';
564 $datetime = current_time( 'mysql' );
565 update_option( 'usces_settlement_notice', $datetime );
566
567 do_action( 'usces_action_save_order_acting_error', $log, $datetime );
568
569 $query = $wpdb->prepare( "INSERT INTO {$log_table_name} ( `datetime`, `log`, `log_type`, `log_key` ) VALUES ( %s, %s, %s, %s )",
570 $datetime,
571 serialize( $log ),
572 'acting_error',
573 $log['key']
574 );
575 $res = $wpdb->query( $query );
576 return $res;
577 }
578
579 /**
580 * Escape a settlement log field for HTML output.
581 *
582 * Log fields come from unauthenticated payment-gateway callbacks, so a field
583 * may arrive as an array (e.g. `?rand[]=x`) or as an object. Flatten anything
584 * non-scalar before escaping, because esc_html() cannot take an array.
585 *
586 * Use this for text nodes only. Attribute values need esc_attr().
587 *
588 * @param mixed $value Raw log field.
589 * @return string Escaped, HTML-safe string.
590 */
591 function wel_esc_settlement_log( $value ) {
592 if ( null === $value || is_scalar( $value ) ) {
593 return esc_html( (string) $value );
594 }
595 return esc_html( wp_json_encode( $value ) );
596 }
597
598 /**
599 * 決済直前ログ一覧
600 *
601 * @param string $log_key Log key.
602 * @return void
603 */
604 function usces_get_settlement_log( $log_key = '' ) {
605 global $usces, $wpdb;
606
607 $log_table_name = $wpdb->prefix . 'usces_log';
608 $html = '';
609 if ( ! empty( $log_key ) ) {
610 $query = $wpdb->prepare( "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_data' AND `log_key` = %s ORDER BY datetime DESC", $log_key );
611 } else {
612 $query = "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_data' ORDER BY datetime DESC";
613 }
614 $log_data = $wpdb->get_results( $query, ARRAY_A );
615 if ( $log_data ) {
616 $html = '<table class="list"><tr><th></th><th></th><th>' . __( 'Register date', 'usces' ) . '</th><th>' . __( 'Link key', 'usces' ) . '</th><th>' . __( 'Name', 'usces' ) . '</th><th>' . __( 'Type of payment', 'usces' ) . '</th><th>IP</th></tr>';
617 foreach ( (array) $log_data as $data ) {
618 $log = wel_safe_unserialize( $data['log'] );
619 $name = esc_html( $log['usces_entry']['customer']['name1'] ) . esc_html( $log['usces_entry']['customer']['name2'] );
620 $payment_name = esc_html( $log['usces_entry']['order']['payment_name'] );
621 $payments = usces_get_payments_by_name( $payment_name );
622 $settlement = ( isset( $payments['settlement'] ) ) ? $payments['settlement'] : '';
623 $payment_structure = ( isset( $usces->payment_structure[ $settlement ] ) ) ? '[' . $usces->payment_structure[ $settlement ] . ']' : '';
624 $class = ( ! empty( $log['revival'] ) ) ? ' class="revival"' : '';
625 $ip = ( ! empty( $log['remote_addr'] ) ) ? $log['remote_addr'] : '';
626 $html .= '<tr' . $class . '>
627 <td class="check"><input type="checkbox" class="log-check" value="' . esc_attr( $data['log_key'] ) . '"></td>
628 <td class="detail"><input type="button" class="log-detail button" id="' . esc_attr( $data['log_key'] ) . '" value="' . esc_attr__( 'Detail', 'usces' ) . '"></td>
629 <td class="datetime">' . esc_html( $data['datetime'] ) . '</td>
630 <td class="key">' . esc_html( $data['log_key'] ) . '</td>
631 <td class="name">' . $name . '</td>
632 <td class="payment">' . $payment_name . $payment_structure . '</td>
633 <td class="ip">' . esc_html( $ip ) . '</td>
634 </tr>';
635 }
636 $html .= '</table>';
637 } else {
638 $html = '<div class="nodata">' . __( 'There are no log data . ', 'usces' ) . '</div>';
639 }
640
641 $resdata = array();
642 $resdata['status'] = 'OK';
643 $resdata['result'] = $html;
644 $resdata['nodata'] = ( ! $log_data ) ? 'nodata' : '';
645 wp_send_json( $resdata );
646 }
647
648 /**
649 * 決済直前ログ詳細
650 * from Order item ajax.
651 *
652 * @param string $log_key Log key.
653 */
654 function usces_get_settlement_log_detail( $log_key ) {
655 global $usces;
656
657 $order_data = usces_get_acting_data( $log_key );
658 $usces_entries = $order_data['usces_entry'];
659
660 $html = '<table class="detail-head">';
661 $html .= '<tr><th>' . __( 'Register date', 'usces' ) . '</th><td>' . esc_html( $order_data['datetime'] ) . '</td><td>
662 <label for="register_date_1"><input type="radio" name="register_date" id="register_date_1" value="1" checked="checked" /><span>' . __( 'Set the Registered Date to the Order Date.', 'usces' ) . '</span></label><br />
663 <label for="register_date_0"><input type="radio" name="register_date" id="register_date_0" value="0" /><span>' . __( 'Set the current time to the Order Date.', 'usces' ) . '</span></label></td></tr>';
664 $html .= '<tr><th>' . __( 'Link key', 'usces' ) . '</th><td colspan="2">' . wel_esc_settlement_log( $order_data['key'] ) . '</td></tr>';
665 $html .= '</table>';
666
667 $html .= '<table class="detail-customer">';
668 $html .= '<tr class="title"><td colspan="2"><h3>' . __( 'Customer Information', 'usces' ) . '</h3></td></tr>';
669 $html .= '<tr><th>' . __( 'e-mail adress', 'usces' ) . '</th><td>' . esc_html( $usces_entries['customer']['mailaddress1'] ) . '</td></tr>';
670 $html .= uesces_addressform( 'confirm', $usces_entries );
671 $html .= '</table>';
672
673 $html .= '<table class="detail-other">';
674 $html .= '<tr class="title"><td colspan="2"><h3>' . __( 'Others', 'usces' ) . '</h3></td></tr>';
675 if ( isset( $usces_entries['delivery'] ) ) {
676 $html .= '<tr><th>' . __( 'shipping option', 'usces' ) . '</th><td>' . esc_html( usces_delivery_method_name( $usces_entries['order']['delivery_method'], 'return' ) ) . '</td></tr>';
677 $html .= '<tr><th>' . __( 'Delivery date', 'usces' ) . '</th><td>' . esc_html( $usces_entries['order']['delivery_date'] ) . '</td></tr>';
678 $html .= '<tr><th>' . __( 'Delivery Time', 'usces' ) . '</th><td>' . esc_html( $usces_entries['order']['delivery_time'] ) . '</td></tr>';
679 }
680 $html .= '<tr><th>' . __( 'payment method', 'usces' ) . '</th><td>' . esc_html( $usces_entries['order']['payment_name'] . usces_payment_detail( $usces_entries ) ) . '</td></tr>';
681 $html .= usces_custom_field_info( $usces_entries, 'order', '', 'return' );
682 $html .= '<tr><th>' . __( 'Notes', 'usces' ) . '</th><td>' . esc_html( $usces_entries['order']['note'] ) . '</td></tr>';
683 $html .= '</table>';
684
685 $html .= '<table class="detail-cart">';
686 $html .= '<thead>';
687 $html .= '<tr class="title"><td colspan="4"><h3>' . __( 'Cart', 'usces' ) . '</h3></td></tr>';
688 $html .= '<tr><th>No</th><th>' . __( 'Items', 'usces' ) . '</th><th>' . __( 'Quantity', 'usces' ) . '</th><th>' . __( 'Unit price', 'usces' ) . '</th></tr>';
689 $html .= '</thead><tbody>';
690 $num = 1;
691 foreach ( $order_data['usces_cart'] as $serial => $row ) {
692 $array = wel_safe_unserialize( $serial );
693 $ids = ( is_array( $array ) && ! empty( $array ) ) ? array_keys( $array ) : array();
694 if ( empty( $ids ) || ! is_array( $array[ $ids[0] ] ) || empty( $array[ $ids[0] ] ) ) {
695 /*
696 * The serial key is broken and the item cannot be identified.
697 * When the cart in the session was empty, every posted row was
698 * written to the same empty key and overwrote the previous one,
699 * so the stored quantity and price cannot be attributed to a
700 * particular item. Show the row without those figures.
701 */
702 $html .= '<tr>';
703 $html .= '<td class="num">' . $num . '</td>';
704 $html .= '<td class="item_name">' . esc_html( __( 'The cart data is broken and the item details cannot be restored. The original number of items is also unknown. This line is not included when the order data is recreated.', 'usces' ) ) . '</td>';
705 $html .= '<td class="quantity">-</td>';
706 $html .= '<td class="price">-</td>';
707 $html .= '</tr>';
708 $num++;
709 continue;
710 }
711 $skus = array_keys( $array[ $ids[0] ] );
712 $post_id = $ids[0];
713 $sku = $skus[0];
714 $options = $array[ $ids[0] ][ $skus[0] ];
715 $opt_fields = usces_get_opts( $post_id, 'sort' );
716 $optstr = '';
717 foreach ( (array) $opt_fields as $key => $field ) {
718 $name = urlencode( $field['name'] );
719 $options[ $name ] = ( isset( $options[ $name ] ) ) ? $options[ $name ] : '';
720 if ( ! empty( $name ) ) {
721 $key = urldecode( $name );
722 $value = wel_safe_maybe_unserialize( $options[ $name ] );
723 if ( is_array( $value ) ) {
724 $c = '';
725 $optstr .= esc_html( $key ) . ' : ';
726 foreach ( $value as $v ) {
727 $optstr .= $c . nl2br( esc_html( urldecode( $v ) ) );
728 $c = ', ';
729 }
730 $optstr .= '<br />';
731 } else {
732 $optstr .= esc_html( $key ) . ' : ' . nl2br( esc_html( urldecode( $value ) ) ) . '<br />';
733 }
734 }
735 }
736 $quantity = ( isset( $row['quant'] ) ) ? $row['quant'] : 0;
737 $price = ( isset( $row['price'] ) ) ? $row['price'] : 0;
738 $cart_item_name = $usces->getCartItemName( $post_id, $sku );
739
740 $html .= '<tr>';
741 $html .= '<td class="num">' . $num . '</td>';
742 $html .= '<td class="item_name">' . esc_html( urldecode( $cart_item_name ) ) . '<br />' . $optstr . '</td>';
743 $html .= '<td class="quantity">' . $quantity . '</td>';
744 $html .= '<td class="price">' . usces_crform( $price, true, false, 'return' ) . '</td>';
745 $html .= '</tr>';
746 $num++;
747 }
748 $html .= '</tbody><tfoot>';
749 $html .= '<tr><th colspan="3">' . __( 'total items', 'usces' ) . '</th><td class="total_items_price">' . usces_crform( $usces_entries['order']['total_items_price'], true, false, 'return' ) . '</td></tr>';
750 if ( ! empty( $usces_entries['order']['discount'] ) ) {
751 $html .= '<tr><th colspan="3">' . apply_filters( 'usces_confirm_discount_label', __( 'Campaign discount', 'usces' ) ) . '</th><td class="discount">' . usces_crform( $usces_entries['order']['discount'], true, false, 'return' ) . '</td></tr>';
752 }
753 if ( usces_is_tax_display() && 'products' === usces_get_tax_target() ) {
754 $html .= '<tr><th colspan="3">' . usces_tax_label( array(), 'return' ) . '</th><td class="tax">' . usces_tax( $usces_entries, 'return' ) . '</td></tr>';
755 }
756 $html .= '<tr><th colspan="3">' . __( 'Shipping', 'usces' ) . '</th><td class="shipping_charge">' . usces_crform( $usces_entries['order']['shipping_charge'], true, false, 'return' ) . '</td></tr>';
757 $payment = usces_get_payments_by_name( $usces_entries['order']['payment_name'] );
758 if ( 'COD' === $payment['settlement'] ) {
759 $html .= '<tr><th colspan="3">' . apply_filters( 'usces_filter_cod_label', __( 'COD fee', 'usces' ) ) . '</th><td class="cod_fee">' . usces_crform( $usces_entries['order']['cod_fee'], true, false, 'return' ) . '</td></tr>';
760 }
761 if ( usces_is_tax_display() && 'all' === usces_get_tax_target() ) {
762 $html .= '<tr><th colspan="3">' . usces_tax_label( array(), 'return' ) . '</th><td class="tax">' . usces_tax( $usces_entries, 'return' ) . '</td></tr>';
763 }
764 if ( usces_is_member_system() && usces_is_member_system_point() && ! empty( $usces_entries['order']['usedpoint'] ) ) {
765 $html .= '<tr><th colspan="3">' . __( 'Used points', 'usces' ) . '</th><td class="usedpoint">' . number_format( $usces_entries['order']['usedpoint'] ) . '</td></tr>';
766 }
767 $html .= '<tr><th colspan="3">' . __( 'Payment amount', 'usces' ) . '</th><td class="total_full_price">' . usces_crform( $usces_entries['order']['total_full_price'], true, false, 'return' ) . '</td></tr>';
768 $html .= '</tfoot></table>';
769 $html .= '<input type="hidden" id="log_key" value="' . esc_attr( $order_data['key'] ) . '" />';
770
771 $resdata = array();
772 $resdata['status'] = 'OK';
773 $resdata['result'] = $html;
774 wp_send_json( $resdata );
775 }
776
777 /**
778 * 決済直前ログ削除
779 *
780 * @param string $log_key Log key.
781 * @return mixed
782 */
783 function usces_delete_settlement_log( $log_key = '' ) {
784 global $wpdb;
785
786 $log_table_name = $wpdb->prefix . 'usces_log';
787 if ( '' !== $log_key ) {
788 $keys = explode( ':', $log_key );
789 $query = $wpdb->prepare( "DELETE FROM {$log_table_name} WHERE `log_type` = 'acting_data' AND `log_key` IN( %s )", implode( "','", $keys ) );
790 $query = stripslashes( $query );
791 } else {
792 $query = "DELETE FROM {$log_table_name} WHERE `log_type` = 'acting_data'";
793 }
794 $res = $wpdb->query( $query );
795 return $res;
796 }
797
798 /**
799 * 受注データ再作成
800 *
801 * @param string $log_key Log key.
802 * @param int $register_date 0:受注日時に現在の時刻を設定 1:受注日時に登録日を設定.
803 * @return void
804 */
805 function usces_revival_order_data( $log_key, $register_date = 0 ) {
806 global $usces;
807
808 $order_data = usces_restore_order_acting_data( $log_key );
809 $results = array();
810 if ( 1 === (int) $register_date ) {
811 $results['order_date'] = $order_data['datetime'];
812 }
813 $order_id = usces_reg_orderdata( $results );
814
815 $payments = $usces->getPayments( $order_data['usces_entry']['order']['payment_name'] );
816 $acting = ( 'acting' === $payments['settlement'] ) ? $payments['module'] : $payments['settlement'];
817 $data = array();
818 switch ( $acting ) {
819 case 'paypal.php':
820 $usces->set_order_meta_value( 'settlement_id', $log_key, $order_id );
821 break;
822
823 case 'epsilon.php':
824 $usces->set_order_meta_value( 'settlement_id', $log_key, $order_id );
825 break;
826
827 case 'acting_remise_card':
828 case 'acting_remise_conv':
829 $usces->set_order_meta_value( 'settlement_id', $log_key, $order_id );
830 break;
831
832 case 'acting_jpayment_card':
833 case 'acting_jpayment_conv':
834 case 'acting_jpayment_bank':
835 $usces->set_order_meta_value( 'settlement_id', $log_key, $order_id );
836 break;
837
838 case 'acting_paypal_ec':
839 break;
840
841 case 'acting_paypal_wpp':
842 $data['custom'] = $log_key;
843 $usces->set_order_meta_value( $acting, serialize( $data ), $order_id );
844 break;
845
846 case 'acting_telecom_card':
847 case 'acting_telecom_edy':
848 $data['option'] = $log_key;
849 $usces->set_order_meta_value( $acting, serialize( $data ), $order_id );
850 break;
851
852 case 'acting_digitalcheck_card':
853 case 'acting_digitalcheck_conv':
854 $data['SID'] = $log_key;
855 $usces->set_order_meta_value( $acting, serialize( $data ), $order_id );
856 $usces->set_order_meta_value( 'SID', $log_key, $order_id );
857 break;
858
859 case 'acting_mizuho_card':
860 case 'acting_mizuho_conv1':
861 case 'acting_mizuho_conv2':
862 $data['stran'] = $log_key;
863 $usces->set_order_meta_value( $acting, serialize( $data ), $order_id );
864 $usces->set_order_meta_value( 'stran', $log_key, $order_id );
865 break;
866
867 case 'acting_anotherlane_card':
868 $data['LINK_KEY'] = $log_key;
869 $usces->set_order_meta_value( $acting, serialize( $data ), $order_id );
870 break;
871
872 case 'acting_veritrans_card':
873 case 'acting_veritrans_conv':
874 $data['orderId'] = $log_key;
875 $usces->set_order_meta_value( $acting, serialize( $data ), $order_id );
876 $usces->set_order_meta_value( 'orderId', $log_key, $order_id );
877 break;
878 }
879
880 usces_already_revival_order_data( $order_data );
881 do_action( 'usces_action_revival_order_data', $order_id, $log_key, $acting );
882
883 $resdata = array();
884 $resdata['status'] = 'OK';
885 $resdata['order_id'] = $order_id;
886 wp_send_json( $resdata );
887 }
888
889 /**
890 * 受注データ再作成済み
891 *
892 * @param array $order_data Order data.
893 */
894 function usces_already_revival_order_data( $order_data ) {
895 global $wpdb;
896
897 $log_table_name = $wpdb->prefix . 'usces_log';
898 $order_data['revival'] = 'done';
899 $query = $wpdb->prepare( "UPDATE {$log_table_name} SET `log` = %s WHERE `datetime` = %s AND `log_type` = %s AND `log_key` = %s", serialize( $order_data ), $order_data['datetime'], 'acting_data', $order_data['key'] );
900 $res = $wpdb->query( $query );
901 }
902
903 /**
904 * 決済エラーログ一覧
905 */
906 function usces_get_settlement_error_log() {
907 global $usces, $wpdb;
908
909 $log_table_name = $wpdb->prefix . 'usces_log';
910 $html = '';
911 $query = "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_error' ORDER BY datetime DESC";
912 $log_data = $wpdb->get_results( $query, ARRAY_A );
913 if ( $log_data ) {
914 $html = '<table class="list"><tr><th></th><th></th><th>' . __( 'Register date', 'usces' ) . '</th><th>' . __( 'Link key', 'usces' ) . '</th><th>' . __( 'Type of payment', 'usces' ) . '</th><th>' . __( 'Status', 'usces' ) . '</th></tr>';
915 foreach ( (array) $log_data as $data ) {
916 $log = wel_safe_unserialize( $data['log'] );
917 $result = ( ! empty( $log['result'] ) ) ? $log['result'] : '';
918 $acting = ( ! empty( $log['acting'] ) ) ? $log['acting'] : '';
919 $html .= '<tr>
920 <td class="check"><input type="checkbox" class="error-log-check" value="' . esc_attr( $data['ID'] ) . '"></td>
921 <td class="detail"><input type="button" class="error-log-detail button" id="' . esc_attr( $data['ID'] ) . '" value="' . esc_attr__( 'Detail', 'usces' ) . '"></td>
922 <td class="datetime">' . esc_html( $data['datetime'] ) . '</td>
923 <td class="key">' . esc_html( $data['log_key'] ) . '</td>
924 <td class="payment">' . wel_esc_settlement_log( $acting ) . '</td>
925 <td class="status">' . wel_esc_settlement_log( $result ) . '</td>
926 </tr>';
927 }
928 $html .= '</table>';
929 } else {
930 $html = '<div class="nodata">' . __( 'There are no log data . ', 'usces' ) . '</div>';
931 usces_reset_settlement_notice();
932 }
933
934 $resdata = array();
935 $resdata['status'] = 'OK';
936 $resdata['result'] = $html;
937 $resdata['nodata'] = ( ! $log_data ) ? 'nodata' : '';
938 wp_send_json( $resdata );
939 }
940
941 /**
942 * 決済エラーログ付加�
943
944 *
945 * @return array
946 */
947 function usces_get_settlement_error_log_exemption() {
948 $exemption = array( 'uscesid', 'acting', 'acting_return', 'purchase', 'purchase_ali', 'purchase_jpayment', 'page_id', 'CardNo' );
949 return $exemption;
950 }
951
952 /**
953 * 決済エラーログ詳細
954 *
955 * @param string $log_id Log ID.
956 * @return void
957 */
958 function usces_get_settlement_error_log_detail( $log_id ) {
959 global $usces, $wpdb;
960
961 $log_table_name = $wpdb->prefix . 'usces_log';
962 $exemption = usces_get_settlement_error_log_exemption();
963 $html = '';
964 $query = $wpdb->prepare( "SELECT * FROM {$log_table_name} WHERE `log_type` = %s AND `ID` = %s", 'acting_error', $log_id );
965 $data = $wpdb->get_row( $query, ARRAY_A );
966 if ( $data ) {
967 $log = wel_safe_unserialize( $data['log'] );
968 $html = '<table class="detail">';
969 $html .= '<tr><th>' . __( 'Register date', 'usces' ) . '</th><td>' . esc_html( $data['datetime'] ) . '</td></tr>';
970 $html .= '<tr><th>' . __( 'Link key', 'usces' ) . '</th><td>' . wel_esc_settlement_log( $log['key'] ) . '</td></tr>';
971 $html .= '<tr><th>' . __( 'Result', 'usces' ) . '</th><td>' . wel_esc_settlement_log( $log['result'] ) . '</td></tr>';
972 foreach ( (array) $log['data'] as $key => $value ) {
973 if ( in_array( $key, $exemption ) ) {
974 continue;
975 }
976 if ( is_array( $value ) ) {
977 foreach ( $value as $key2 => $value2 ) {
978 if ( in_array( $key2, $exemption ) ) {
979 continue;
980 }
981 if ( is_array( $value2 ) ) {
982 $html .= '<tr><th>' . esc_html( $key ) . ':' . esc_html( $key2 ) . '</th><td>' . esc_html( serialize( $value2 ) ) . '</td></tr>';
983 } else {
984 $html .= '<tr><th>' . esc_html( $key ) . ':' . esc_html( $key2 ) . '</th><td>' . esc_html( $value2 ) . '</td></tr>';
985 }
986 }
987 } else {
988 $html .= '<tr><th>' . esc_html( $key ) . '</th><td>' . esc_html( $value ) . '</td></tr>';
989 }
990 }
991 $html .= '</table>';
992 $html .= '<input type="hidden" id="log_id" value="' . esc_attr( $data['ID'] ) . '" />';
993 }
994
995 $resdata = array();
996 $resdata['status'] = 'OK';
997 $resdata['result'] = $html;
998 wp_send_json( $resdata );
999 }
1000
1001 /**
1002 * 決済エラーログ削除
1003 *
1004 * @param string $log_id Log ID.
1005 * @return mixed
1006 */
1007 function usces_delete_settlement_error_log( $log_id = '' ) {
1008 global $usces, $wpdb;
1009
1010 $log_table_name = $wpdb->prefix . 'usces_log';
1011 if ( '' !== $log_id ) {
1012 $ids = explode( ':', $log_id );
1013 $query = $wpdb->prepare( "DELETE FROM {$log_table_name} WHERE `log_type` = 'acting_error' AND `ID` IN( %s )", implode( "','", $ids ) );
1014 $query = stripslashes( $query );
1015 } else {
1016 $query = "DELETE FROM {$log_table_name} WHERE `log_type` = 'acting_error'";
1017 }
1018 $res = $wpdb->query( $query );
1019 return $res;
1020 }
1021
1022 /**
1023 * 決済エラー通知リセット
1024 */
1025 function usces_reset_settlement_notice() {
1026 global $wpdb;
1027
1028 $log_table_name = $wpdb->prefix . 'usces_log';
1029 $query = "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_error'";
1030 $log_data = $wpdb->get_results( $query, ARRAY_A );
1031 if ( ! $log_data ) {
1032 update_option( 'usces_settlement_notice', false );
1033 }
1034
1035 $resdata = array();
1036 $resdata['status'] = 'OK';
1037 wp_send_json( $resdata );
1038 }
1039
1040 /**
1041 * 決済エラー通知
1042 */
1043 function usces_display_settlement_notice() {
1044 if ( ! current_user_can( 'wel_manage_order' ) ) {
1045 return false;
1046 }
1047 $datetime = get_option( 'usces_settlement_notice' );
1048 echo '<div class="message error"><p>' . wp_kses_post(
1049 sprintf(
1050 /* translators: %s: date and time when the settlement error occurred */
1051 __( 'Settlement error has occurred. Please check <a href="admin.php?page=usces_orderlist&order_action=settlement_notice">the settlement error log</a>. The date of occurrence:[ %s ]', 'usces' ),
1052 $datetime
1053 )
1054 ) . '</p></div>';
1055 }
1056
1057 /**
1058 * 決済エラーログダウンロード
1059 */
1060 function usces_download_settlement_error_log() {
1061 global $usces, $wpdb;
1062
1063 $log_table_name = $wpdb->prefix . 'usces_log';
1064 $exemption = usces_get_settlement_error_log_exemption();
1065 $line = '';
1066 if ( ! empty( $_GET['log_id'] ) ) {
1067 $ids = explode( ':', wp_unslash( $_GET['log_id'] ) );
1068 $query = $wpdb->prepare( "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_error' AND `ID` IN( %s )", implode( "','", $ids ) );
1069 $query = stripslashes( $query );
1070 } else {
1071 $query = "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_error' ORDER BY datetime DESC";
1072 }
1073 $log_data = $wpdb->get_results( $query, ARRAY_A );
1074 foreach ( (array) $log_data as $data ) {
1075 $log = wel_safe_unserialize( $data['log'] );
1076 $line .= __( 'Register date', 'usces' ) . ' = ' . $data['datetime'] . "\r\n";
1077 $line .= __( 'Link key', 'usces' ) . ' = ' . $log['key'] . "\r\n";
1078 $line .= __( 'Result', 'usces' ) . ' = ' . $log['result'] . "\r\n";
1079 foreach ( (array) $log['data'] as $key => $value ) {
1080 if ( in_array( $key, $exemption ) ) {
1081 continue;
1082 }
1083 if ( is_array( $value ) ) {
1084 $line .= $key . ' = ' . esc_html( print_r( $value, true ) ) . "\r\n"; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
1085 } else {
1086 $line .= $key . ' = ' . esc_html( $value ) . "\r\n";
1087 }
1088 }
1089 $line .= "--------------------------------------------------\r\n\r\n";
1090 }
1091 $line = mb_convert_encoding( $line, 'SJIS-win', 'UTF-8' );
1092
1093 $filename = 'settlement_error_' . wp_date( 'YmdHis' ) . '.log';
1094 header( 'Content-type: text/plain;charset=Shift_JIS' );
1095 header( "Content-Disposition: attachment; filename=$filename" );
1096 print( $line );
1097 exit();
1098 }
1099
1100 /**
1101 * Verify that the card information update action is correct.
1102 * Members who request renewal more than 10 times an hour
1103 * will be locked and will not be able to renew their card information
1104 * until the administrator unlocks it.
1105 *
1106 * @since 2.5.8
1107 *
1108 * @param int $member_id Member ID.
1109 * @return boolean Return true if there is no problem, false otherwise.
1110 */
1111 function wel_verify_update_settlement( $member_id ) {
1112 global $usces;
1113
1114 $rightfulness = true;
1115 if ( 1 === USCES_CREDITCARD_SECURITY::$option['active'] ) {
1116 $is_lock = $usces->get_member_meta_value( 'settlement_action_lock', $member_id );
1117 // wel_log_card_update_action( $member_id );
1118
1119 // $number_limit = apply_filters( 'usces_filter_update_settlement_number_limit', 10 );
1120
1121 if ( $is_lock ) {
1122 $rightfulness = false;
1123 } else {
1124 $number_limit = apply_filters( 'usces_filter_update_settlement_number_limit', USCES_CREDITCARD_SECURITY::$option['set_count'] );
1125 $action_num = wel_count_card_update_action( $member_id );
1126 if ( $number_limit > $action_num ) {
1127 $rightfulness = true;
1128 wel_log_card_update_action( $member_id );
1129 } else {
1130 $usces->set_member_meta_value( 'settlement_action_lock', current_time( 'mysql' ), $member_id );
1131 $rightfulness = false;
1132 }
1133 }
1134 }
1135 return $rightfulness;
1136 }
1137
1138 /**
1139 * Log card information update action.
1140 *
1141 * @since 2.5.8
1142 *
1143 * @param int $member_id Member ID.
1144 */
1145 function wel_log_card_update_action( $member_id ) {
1146 global $wpdb;
1147
1148 $table_name = $wpdb->prefix . 'usces_log';
1149 $wpdb->query(
1150 $wpdb->prepare(
1151 "INSERT INTO $table_name ( `datetime`, `log_type`, `log_key` ) VALUES ( %s, %s, %s )",
1152 current_time( 'Y-m-d H:i:s' ),
1153 'card_update_action',
1154 $member_id
1155 )
1156 );
1157 }
1158
1159 /**
1160 * Count card information update action.
1161 *
1162 * @since 2.5.8
1163 *
1164 * @param int $member_id Member ID.
1165 * @return int Return number of action.
1166 */
1167 function wel_count_card_update_action( $member_id ) {
1168 global $wpdb;
1169
1170 $table_name = $wpdb->prefix . 'usces_log';
1171 // $due_time = (int) current_time( 'timestamp' ) - 3600;
1172 $time_frame = USCES_CREDITCARD_SECURITY::$option['time_frame'];
1173 $due_time = (int) current_time( 'timestamp' ) - ( $time_frame * 60 );
1174 $res = $wpdb->get_var(
1175 $wpdb->prepare(
1176 "SELECT COUNT( `ID` ) FROM $table_name WHERE `datetime` > %s AND `log_type` = %s AND `log_key` = %s",
1177 date_i18n( 'Y-m-d H:i:s', $due_time ),
1178 'card_update_action',
1179 $member_id
1180 )
1181 );
1182 return (int) $res;
1183 }
1184
1185 /**
1186 * Release the card information update lock.
1187 *
1188 * @since 2.5.8
1189 *
1190 * @param int $member_id Member ID.
1191 */
1192 function wel_release_card_update_lock( $member_id ) {
1193 global $wpdb, $usces;
1194
1195 $usces->del_member_meta( 'settlement_action_lock', $member_id );
1196
1197 $table_name = $wpdb->prefix . 'usces_log';
1198 $wpdb->query(
1199 $wpdb->prepare(
1200 "DELETE FROM $table_name WHERE `log_type` = %s AND `log_key` = %s",
1201 'card_update_action',
1202 $member_id
1203 )
1204 );
1205 }
1206
1207 /**
1208 * All credit security unlocked.
1209 */
1210 function wel_all_unlock() {
1211 global $wpdb;
1212
1213 $member_meta_table = usces_get_tablename( 'usces_member_meta' );
1214 $wpdb->query(
1215 $wpdb->prepare(
1216 "DELETE FROM {$member_meta_table} WHERE `meta_key` = %s",
1217 'settlement_action_lock'
1218 )
1219 );
1220 $wpdb->query(
1221 $wpdb->prepare(
1222 "DELETE FROM {$wpdb->prefix}usces_log WHERE `log_type` = %s",
1223 'card_update_action'
1224 )
1225 );
1226 }
1227
1228 /**
1229 * Is lockout credit card input per terminal.
1230 *
1231 * @param string $remote_addr IP address.
1232 * @return bool
1233 */
1234 function wel_is_lockout_credit_input( $remote_addr ) {
1235 global $wpdb;
1236
1237 $lockout = false;
1238
1239 $count = $wpdb->get_var(
1240 $wpdb->prepare(
1241 "SELECT COUNT(`ID`) FROM {$wpdb->prefix}usces_log WHERE `log` IS NOT NULL AND `log` > %s AND `log_type` = %s AND `log_key` = %s",
1242 current_time( 'Y-m-d H:i:s' ),
1243 'card_update_action',
1244 $remote_addr
1245 )
1246 );
1247 if ( 0 < $count ) {
1248 $lockout = true;
1249 }
1250 return $lockout;
1251 }
1252
1253 /**
1254 * Count credit card input per terminal.
1255 *
1256 * @param string $remote_addr IP address.
1257 * @return int
1258 */
1259 function wel_count_credit_input( $remote_addr ) {
1260 global $wpdb;
1261
1262 $time_frame = USCES_CREDITCARD_SECURITY::$option['time_frame'];
1263 $due_time = (int) current_time( 'timestamp' ) - ( $time_frame * 60 );
1264 $count = $wpdb->get_var(
1265 $wpdb->prepare(
1266 "SELECT COUNT(`ID`) FROM {$wpdb->prefix}usces_log WHERE `datetime` > %s AND `log_type` = %s AND `log_key` = %s",
1267 date_i18n( 'Y-m-d H:i:s', $due_time ),
1268 'card_update_action',
1269 $remote_addr
1270 )
1271 );
1272 return (int) $count;
1273 }
1274
1275 /**
1276 * Log credit card input per terminal.
1277 *
1278 * @param string $remote_addr IP address.
1279 */
1280 function wel_log_credit_input( $remote_addr ) {
1281 global $wpdb;
1282
1283 $wpdb->query(
1284 $wpdb->prepare(
1285 "INSERT INTO {$wpdb->prefix}usces_log ( `datetime`, `log_type`, `log_key` ) VALUES ( %s, %s, %s )",
1286 current_time( 'Y-m-d H:i:s' ),
1287 'card_update_action',
1288 $remote_addr
1289 )
1290 );
1291 }
1292
1293 /**
1294 * Log credit card lockout per terminal.
1295 *
1296 * @param string $remote_addr IP address.
1297 */
1298 function wel_lockout_credit_input( $remote_addr ) {
1299 global $wpdb;
1300
1301 $lockout_time = USCES_CREDITCARD_SECURITY::$option['lockout_time'];
1302 $due_time = (int) current_time( 'timestamp' ) + ( $lockout_time * 60 * 60 );
1303 $wpdb->query(
1304 $wpdb->prepare(
1305 "UPDATE {$wpdb->prefix}usces_log SET `log` = %s WHERE `log_type` = %s AND `log_key` = %s",
1306 date_i18n( 'Y-m-d H:i:s', $due_time ),
1307 'card_update_action',
1308 $remote_addr
1309 )
1310 );
1311 }
1312
1313 /**
1314 * Check credit security.
1315 *
1316 * @return bool
1317 */
1318 function wel_check_credit_security() {
1319 global $usces;
1320
1321 $check = true;
1322 if ( 1 === USCES_CREDITCARD_SECURITY::$option['active'] ) {
1323 if ( $usces->is_member_logged_in() ) {
1324 $member = $usces->get_member();
1325 $is_lock = $usces->get_member_meta_value( 'settlement_action_lock', $member['ID'] );
1326 if ( $is_lock ) {
1327 $check = false;
1328 }
1329 }
1330 if ( $check ) {
1331 $remote_addr = ( isset( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : '';
1332 if ( empty( $remote_addr ) ) {
1333 $check = false;
1334 } else {
1335 if ( wel_is_lockout_credit_input( $remote_addr ) ) {
1336 $check = false;
1337 } else {
1338 $count = wel_count_credit_input( $remote_addr );
1339 if ( USCES_CREDITCARD_SECURITY::$option['set_count'] > $count ) {
1340 wel_log_credit_input( $remote_addr );
1341 } else {
1342 wel_lockout_credit_input( $remote_addr );
1343 $check = false;
1344 }
1345 }
1346 }
1347 }
1348 }
1349 return $check;
1350 }
1351
1352 /**
1353 * Credit card input log clearup.
1354 */
1355 function wel_clearup_log_credit_input() {
1356 global $wpdb;
1357
1358 if ( 1 === USCES_CREDITCARD_SECURITY::$option['active'] ) {
1359 $time_frame = USCES_CREDITCARD_SECURITY::$option['time_frame'];
1360 $due_time = (int) current_time( 'timestamp' ) - ( $time_frame * 60 );
1361 $wpdb->query(
1362 $wpdb->prepare(
1363 "DELETE FROM {$wpdb->prefix}usces_log WHERE `datetime` < %s AND ( `log` IS NULL OR `log` < %s ) AND `log_type` = %s",
1364 date_i18n( 'Y-m-d H:i:s', $due_time ),
1365 current_time( 'Y-m-d H:i:s' ),
1366 'card_update_action'
1367 )
1368 );
1369 }
1370 }
1371