PluginProbe
Welcart e-Commerce / 2.12.1
Welcart e-Commerce v2.12.1
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.1, at functions/settlement_func.php

1,346 lines 45.0 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 = 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 * 決済直前ログ一覧
581 *
582 * @param string $log_key Log key.
583 * @return void
584 */
585 function usces_get_settlement_log( $log_key = '' ) {
586 global $usces, $wpdb;
587
588 $log_table_name = $wpdb->prefix . 'usces_log';
589 $html = '';
590 if ( ! empty( $log_key ) ) {
591 $query = $wpdb->prepare( "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_data' AND `log_key` = %s ORDER BY datetime DESC", $log_key );
592 } else {
593 $query = "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_data' ORDER BY datetime DESC";
594 }
595 $log_data = $wpdb->get_results( $query, ARRAY_A );
596 if ( $log_data ) {
597 $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>';
598 foreach ( (array) $log_data as $data ) {
599 $log = unserialize( $data['log'] );
600 $name = esc_html( $log['usces_entry']['customer']['name1'] ) . esc_html( $log['usces_entry']['customer']['name2'] );
601 $payment_name = esc_html( $log['usces_entry']['order']['payment_name'] );
602 $payments = usces_get_payments_by_name( $payment_name );
603 $settlement = ( isset( $payments['settlement'] ) ) ? $payments['settlement'] : '';
604 $payment_structure = ( isset( $usces->payment_structure[ $settlement ] ) ) ? '[' . $usces->payment_structure[ $settlement ] . ']' : '';
605 $class = ( ! empty( $log['revival'] ) ) ? ' class="revival"' : '';
606 $ip = ( ! empty( $log['remote_addr'] ) ) ? $log['remote_addr'] : '';
607 $html .= '<tr' . $class . '>
608 <td class="check"><input type="checkbox" class="log-check" value="' . $data['log_key'] . '"></td>
609 <td class="detail"><input type="button" class="log-detail button" id="' . $data['log_key'] . '" value="' . __( 'Detail', 'usces' ) . '"></td>
610 <td class="datetime">' . $data['datetime'] . '</td>
611 <td class="key">' . $data['log_key'] . '</td>
612 <td class="name">' . $name . '</td>
613 <td class="payment">' . $payment_name . $payment_structure . '</td>
614 <td class="ip">' . $ip . '</td>
615 </tr>';
616 }
617 $html .= '</table>';
618 } else {
619 $html = '<div class="nodata">' . __( 'There are no log data . ', 'usces' ) . '</div>';
620 }
621
622 $resdata = array();
623 $resdata['status'] = 'OK';
624 $resdata['result'] = $html;
625 $resdata['nodata'] = ( ! $log_data ) ? 'nodata' : '';
626 wp_send_json( $resdata );
627 }
628
629 /**
630 * 決済直前ログ詳細
631 * from Order item ajax.
632 *
633 * @param string $log_key Log key.
634 */
635 function usces_get_settlement_log_detail( $log_key ) {
636 global $usces;
637
638 $order_data = usces_get_acting_data( $log_key );
639 $usces_entries = $order_data['usces_entry'];
640
641 $html = '<table class="detail-head">';
642 $html .= '<tr><th>' . __( 'Register date', 'usces' ) . '</th><td>' . $order_data['datetime'] . '</td><td>
643 <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 />
644 <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>';
645 $html .= '<tr><th>' . __( 'Link key', 'usces' ) . '</th><td colspan="2">' . $order_data['key'] . '</td></tr>';
646 $html .= '</table>';
647
648 $html .= '<table class="detail-customer">';
649 $html .= '<tr class="title"><td colspan="2"><h3>' . __( 'Customer Information', 'usces' ) . '</h3></td></tr>';
650 $html .= '<tr><th>' . __( 'e-mail adress', 'usces' ) . '</th><td>' . esc_html( $usces_entries['customer']['mailaddress1'] ) . '</td></tr>';
651 $html .= uesces_addressform( 'confirm', $usces_entries );
652 $html .= '</table>';
653
654 $html .= '<table class="detail-other">';
655 $html .= '<tr class="title"><td colspan="2"><h3>' . __( 'Others', 'usces' ) . '</h3></td></tr>';
656 if ( isset( $usces_entries['delivery'] ) ) {
657 $html .= '<tr><th>' . __( 'shipping option', 'usces' ) . '</th><td>' . esc_html( usces_delivery_method_name( $usces_entries['order']['delivery_method'], 'return' ) ) . '</td></tr>';
658 $html .= '<tr><th>' . __( 'Delivery date', 'usces' ) . '</th><td>' . esc_html( $usces_entries['order']['delivery_date'] ) . '</td></tr>';
659 $html .= '<tr><th>' . __( 'Delivery Time', 'usces' ) . '</th><td>' . esc_html( $usces_entries['order']['delivery_time'] ) . '</td></tr>';
660 }
661 $html .= '<tr><th>' . __( 'payment method', 'usces' ) . '</th><td>' . esc_html( $usces_entries['order']['payment_name'] . usces_payment_detail( $usces_entries ) ) . '</td></tr>';
662 $html .= usces_custom_field_info( $usces_entries, 'order', '', 'return' );
663 $html .= '<tr><th>' . __( 'Notes', 'usces' ) . '</th><td>' . esc_html( $usces_entries['order']['note'] ) . '</td></tr>';
664 $html .= '</table>';
665
666 $html .= '<table class="detail-cart">';
667 $html .= '<thead>';
668 $html .= '<tr class="title"><td colspan="4"><h3>' . __( 'Cart', 'usces' ) . '</h3></td></tr>';
669 $html .= '<tr><th>No</th><th>' . __( 'Items', 'usces' ) . '</th><th>' . __( 'Quantity', 'usces' ) . '</th><th>' . __( 'Unit price', 'usces' ) . '</th></tr>';
670 $html .= '</thead><tbody>';
671 $num = 1;
672 foreach ( $order_data['usces_cart'] as $serial => $row ) {
673 $array = @unserialize( $serial );
674 $ids = ( is_array( $array ) && ! empty( $array ) ) ? array_keys( $array ) : array();
675 if ( empty( $ids ) || ! is_array( $array[ $ids[0] ] ) || empty( $array[ $ids[0] ] ) ) {
676 /*
677 * The serial key is broken and the item cannot be identified.
678 * When the cart in the session was empty, every posted row was
679 * written to the same empty key and overwrote the previous one,
680 * so the stored quantity and price cannot be attributed to a
681 * particular item. Show the row without those figures.
682 */
683 $html .= '<tr>';
684 $html .= '<td class="num">' . $num . '</td>';
685 $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>';
686 $html .= '<td class="quantity">-</td>';
687 $html .= '<td class="price">-</td>';
688 $html .= '</tr>';
689 $num++;
690 continue;
691 }
692 $skus = array_keys( $array[ $ids[0] ] );
693 $post_id = $ids[0];
694 $sku = $skus[0];
695 $options = $array[ $ids[0] ][ $skus[0] ];
696 $opt_fields = usces_get_opts( $post_id, 'sort' );
697 $optstr = '';
698 foreach ( (array) $opt_fields as $key => $field ) {
699 $name = urlencode( $field['name'] );
700 $options[ $name ] = ( isset( $options[ $name ] ) ) ? $options[ $name ] : '';
701 if ( ! empty( $name ) ) {
702 $key = urldecode( $name );
703 $value = maybe_unserialize( $options[ $name ] );
704 if ( is_array( $value ) ) {
705 $c = '';
706 $optstr .= esc_html( $key ) . ' : ';
707 foreach ( $value as $v ) {
708 $optstr .= $c . nl2br( esc_html( urldecode( $v ) ) );
709 $c = ', ';
710 }
711 $optstr .= '<br />';
712 } else {
713 $optstr .= esc_html( $key ) . ' : ' . nl2br( esc_html( urldecode( $value ) ) ) . '<br />';
714 }
715 }
716 }
717 $quantity = ( isset( $row['quant'] ) ) ? $row['quant'] : 0;
718 $price = ( isset( $row['price'] ) ) ? $row['price'] : 0;
719 $cart_item_name = $usces->getCartItemName( $post_id, $sku );
720
721 $html .= '<tr>';
722 $html .= '<td class="num">' . $num . '</td>';
723 $html .= '<td class="item_name">' . esc_html( urldecode( $cart_item_name ) ) . '<br />' . $optstr . '</td>';
724 $html .= '<td class="quantity">' . $quantity . '</td>';
725 $html .= '<td class="price">' . usces_crform( $price, true, false, 'return' ) . '</td>';
726 $html .= '</tr>';
727 $num++;
728 }
729 $html .= '</tbody><tfoot>';
730 $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>';
731 if ( ! empty( $usces_entries['order']['discount'] ) ) {
732 $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>';
733 }
734 if ( usces_is_tax_display() && 'products' === usces_get_tax_target() ) {
735 $html .= '<tr><th colspan="3">' . usces_tax_label( array(), 'return' ) . '</th><td class="tax">' . usces_tax( $usces_entries, 'return' ) . '</td></tr>';
736 }
737 $html .= '<tr><th colspan="3">' . __( 'Shipping', 'usces' ) . '</th><td class="shipping_charge">' . usces_crform( $usces_entries['order']['shipping_charge'], true, false, 'return' ) . '</td></tr>';
738 $payment = usces_get_payments_by_name( $usces_entries['order']['payment_name'] );
739 if ( 'COD' === $payment['settlement'] ) {
740 $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>';
741 }
742 if ( usces_is_tax_display() && 'all' === usces_get_tax_target() ) {
743 $html .= '<tr><th colspan="3">' . usces_tax_label( array(), 'return' ) . '</th><td class="tax">' . usces_tax( $usces_entries, 'return' ) . '</td></tr>';
744 }
745 if ( usces_is_member_system() && usces_is_member_system_point() && ! empty( $usces_entries['order']['usedpoint'] ) ) {
746 $html .= '<tr><th colspan="3">' . __( 'Used points', 'usces' ) . '</th><td class="usedpoint">' . number_format( $usces_entries['order']['usedpoint'] ) . '</td></tr>';
747 }
748 $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>';
749 $html .= '</tfoot></table>';
750 $html .= '<input type="hidden" id="log_key" value="' . $order_data['key'] . '" />';
751
752 $resdata = array();
753 $resdata['status'] = 'OK';
754 $resdata['result'] = $html;
755 wp_send_json( $resdata );
756 }
757
758 /**
759 * 決済直前ログ削除
760 *
761 * @param string $log_key Log key.
762 * @return mixed
763 */
764 function usces_delete_settlement_log( $log_key = '' ) {
765 global $wpdb;
766
767 $log_table_name = $wpdb->prefix . 'usces_log';
768 if ( '' !== $log_key ) {
769 $keys = explode( ':', $log_key );
770 $query = $wpdb->prepare( "DELETE FROM {$log_table_name} WHERE `log_type` = 'acting_data' AND `log_key` IN( %s )", implode( "','", $keys ) );
771 $query = stripslashes( $query );
772 } else {
773 $query = "DELETE FROM {$log_table_name} WHERE `log_type` = 'acting_data'";
774 }
775 $res = $wpdb->query( $query );
776 return $res;
777 }
778
779 /**
780 * 受注データ再作成
781 *
782 * @param string $log_key Log key.
783 * @param int $register_date 0:受注日時に現在の時刻を設定 1:受注日時に登録日を設定.
784 * @return void
785 */
786 function usces_revival_order_data( $log_key, $register_date = 0 ) {
787 global $usces;
788
789 $order_data = usces_restore_order_acting_data( $log_key );
790 $results = array();
791 if ( 1 === (int) $register_date ) {
792 $results['order_date'] = $order_data['datetime'];
793 }
794 $order_id = usces_reg_orderdata( $results );
795
796 $payments = $usces->getPayments( $order_data['usces_entry']['order']['payment_name'] );
797 $acting = ( 'acting' === $payments['settlement'] ) ? $payments['module'] : $payments['settlement'];
798 $data = array();
799 switch ( $acting ) {
800 case 'paypal.php':
801 $usces->set_order_meta_value( 'settlement_id', $log_key, $order_id );
802 break;
803
804 case 'epsilon.php':
805 $usces->set_order_meta_value( 'settlement_id', $log_key, $order_id );
806 break;
807
808 case 'acting_remise_card':
809 case 'acting_remise_conv':
810 $usces->set_order_meta_value( 'settlement_id', $log_key, $order_id );
811 break;
812
813 case 'acting_jpayment_card':
814 case 'acting_jpayment_conv':
815 case 'acting_jpayment_bank':
816 $usces->set_order_meta_value( 'settlement_id', $log_key, $order_id );
817 break;
818
819 case 'acting_paypal_ec':
820 break;
821
822 case 'acting_paypal_wpp':
823 $data['custom'] = $log_key;
824 $usces->set_order_meta_value( $acting, serialize( $data ), $order_id );
825 break;
826
827 case 'acting_telecom_card':
828 case 'acting_telecom_edy':
829 $data['option'] = $log_key;
830 $usces->set_order_meta_value( $acting, serialize( $data ), $order_id );
831 break;
832
833 case 'acting_digitalcheck_card':
834 case 'acting_digitalcheck_conv':
835 $data['SID'] = $log_key;
836 $usces->set_order_meta_value( $acting, serialize( $data ), $order_id );
837 $usces->set_order_meta_value( 'SID', $log_key, $order_id );
838 break;
839
840 case 'acting_mizuho_card':
841 case 'acting_mizuho_conv1':
842 case 'acting_mizuho_conv2':
843 $data['stran'] = $log_key;
844 $usces->set_order_meta_value( $acting, serialize( $data ), $order_id );
845 $usces->set_order_meta_value( 'stran', $log_key, $order_id );
846 break;
847
848 case 'acting_anotherlane_card':
849 $data['LINK_KEY'] = $log_key;
850 $usces->set_order_meta_value( $acting, serialize( $data ), $order_id );
851 break;
852
853 case 'acting_veritrans_card':
854 case 'acting_veritrans_conv':
855 $data['orderId'] = $log_key;
856 $usces->set_order_meta_value( $acting, serialize( $data ), $order_id );
857 $usces->set_order_meta_value( 'orderId', $log_key, $order_id );
858 break;
859 }
860
861 usces_already_revival_order_data( $order_data );
862 do_action( 'usces_action_revival_order_data', $order_id, $log_key, $acting );
863
864 $resdata = array();
865 $resdata['status'] = 'OK';
866 $resdata['order_id'] = $order_id;
867 wp_send_json( $resdata );
868 }
869
870 /**
871 * 受注データ再作成済み
872 *
873 * @param array $order_data Order data.
874 */
875 function usces_already_revival_order_data( $order_data ) {
876 global $wpdb;
877
878 $log_table_name = $wpdb->prefix . 'usces_log';
879 $order_data['revival'] = 'done';
880 $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'] );
881 $res = $wpdb->query( $query );
882 }
883
884 /**
885 * 決済エラーログ一覧
886 */
887 function usces_get_settlement_error_log() {
888 global $usces, $wpdb;
889
890 $log_table_name = $wpdb->prefix . 'usces_log';
891 $html = '';
892 $query = "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_error' ORDER BY datetime DESC";
893 $log_data = $wpdb->get_results( $query, ARRAY_A );
894 if ( $log_data ) {
895 $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>';
896 foreach ( (array) $log_data as $data ) {
897 $log = unserialize( $data['log'] );
898 $result = ( ! empty( $log['result'] ) ) ? $log['result'] : '';
899 $acting = ( ! empty( $log['acting'] ) ) ? $log['acting'] : '';
900 $html .= '<tr>
901 <td class="check"><input type="checkbox" class="error-log-check" value="' . $data['ID'] . '"></td>
902 <td class="detail"><input type="button" class="error-log-detail button" id="' . $data['ID'] . '" value="' . __( 'Detail', 'usces' ) . '"></td>
903 <td class="datetime">' . $data['datetime'] . '</td>
904 <td class="key">' . $data['log_key'] . '</td>
905 <td class="payment">' . $acting . '</td>
906 <td class="status">' . $result . '</td>
907 </tr>';
908 }
909 $html .= '</table>';
910 } else {
911 $html = '<div class="nodata">' . __( 'There are no log data . ', 'usces' ) . '</div>';
912 usces_reset_settlement_notice();
913 }
914
915 $resdata = array();
916 $resdata['status'] = 'OK';
917 $resdata['result'] = $html;
918 $resdata['nodata'] = ( ! $log_data ) ? 'nodata' : '';
919 wp_send_json( $resdata );
920 }
921
922 /**
923 * 決済エラーログ付加�
924
925 *
926 * @return array
927 */
928 function usces_get_settlement_error_log_exemption() {
929 $exemption = array( 'uscesid', 'acting', 'acting_return', 'purchase', 'purchase_ali', 'purchase_jpayment', 'page_id', 'CardNo' );
930 return $exemption;
931 }
932
933 /**
934 * 決済エラーログ詳細
935 *
936 * @param string $log_id Log ID.
937 * @return void
938 */
939 function usces_get_settlement_error_log_detail( $log_id ) {
940 global $usces, $wpdb;
941
942 $log_table_name = $wpdb->prefix . 'usces_log';
943 $exemption = usces_get_settlement_error_log_exemption();
944 $html = '';
945 $query = $wpdb->prepare( "SELECT * FROM {$log_table_name} WHERE `log_type` = %s AND `ID` = %s", 'acting_error', $log_id );
946 $data = $wpdb->get_row( $query, ARRAY_A );
947 if ( $data ) {
948 $log = unserialize( $data['log'] );
949 $html = '<table class="detail">';
950 $html .= '<tr><th>' . __( 'Register date', 'usces' ) . '</th><td>' . $data['datetime'] . '</td></tr>';
951 $html .= '<tr><th>' . __( 'Link key', 'usces' ) . '</th><td>' . $log['key'] . '</td></tr>';
952 $html .= '<tr><th>' . __( 'Result', 'usces' ) . '</th><td>' . $log['result'] . '</td></tr>';
953 foreach ( (array) $log['data'] as $key => $value ) {
954 if ( in_array( $key, $exemption ) ) {
955 continue;
956 }
957 if ( is_array( $value ) ) {
958 foreach ( $value as $key2 => $value2 ) {
959 if ( in_array( $key2, $exemption ) ) {
960 continue;
961 }
962 if ( is_array( $value2 ) ) {
963 $html .= '<tr><th>' . $key . ':' . $key2 . '</th><td>' . esc_html( serialize( $value2 ) ) . '</td></tr>';
964 } else {
965 $html .= '<tr><th>' . $key . ':' . $key2 . '</th><td>' . esc_html( $value2 ) . '</td></tr>';
966 }
967 }
968 } else {
969 $html .= '<tr><th>' . $key . '</th><td>' . esc_html( $value ) . '</td></tr>';
970 }
971 }
972 $html .= '</table>';
973 $html .= '<input type="hidden" id="log_id" value="' . $data['ID'] . '" />';
974 }
975
976 $resdata = array();
977 $resdata['status'] = 'OK';
978 $resdata['result'] = $html;
979 wp_send_json( $resdata );
980 }
981
982 /**
983 * 決済エラーログ削除
984 *
985 * @param string $log_id Log ID.
986 * @return mixed
987 */
988 function usces_delete_settlement_error_log( $log_id = '' ) {
989 global $usces, $wpdb;
990
991 $log_table_name = $wpdb->prefix . 'usces_log';
992 if ( '' !== $log_id ) {
993 $ids = explode( ':', $log_id );
994 $query = $wpdb->prepare( "DELETE FROM {$log_table_name} WHERE `log_type` = 'acting_error' AND `ID` IN( %s )", implode( "','", $ids ) );
995 $query = stripslashes( $query );
996 } else {
997 $query = "DELETE FROM {$log_table_name} WHERE `log_type` = 'acting_error'";
998 }
999 $res = $wpdb->query( $query );
1000 return $res;
1001 }
1002
1003 /**
1004 * 決済エラー通知リセット
1005 */
1006 function usces_reset_settlement_notice() {
1007 global $wpdb;
1008
1009 $log_table_name = $wpdb->prefix . 'usces_log';
1010 $query = "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_error'";
1011 $log_data = $wpdb->get_results( $query, ARRAY_A );
1012 if ( ! $log_data ) {
1013 update_option( 'usces_settlement_notice', false );
1014 }
1015
1016 $resdata = array();
1017 $resdata['status'] = 'OK';
1018 wp_send_json( $resdata );
1019 }
1020
1021 /**
1022 * 決済エラー通知
1023 */
1024 function usces_display_settlement_notice() {
1025 if ( ! current_user_can( 'wel_manage_order' ) ) {
1026 return false;
1027 }
1028 $datetime = get_option( 'usces_settlement_notice' );
1029 echo '<div class="message error"><p>' . sprintf( __( "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' ), $datetime ) . '</p></div>';
1030 }
1031
1032 /**
1033 * 決済エラーログダウンロード
1034 */
1035 function usces_download_settlement_error_log() {
1036 global $usces, $wpdb;
1037
1038 $log_table_name = $wpdb->prefix . 'usces_log';
1039 $exemption = usces_get_settlement_error_log_exemption();
1040 $line = '';
1041 if ( ! empty( $_GET['log_id'] ) ) {
1042 $ids = explode( ':', wp_unslash( $_GET['log_id'] ) );
1043 $query = $wpdb->prepare( "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_error' AND `ID` IN( %s )", implode( "','", $ids ) );
1044 $query = stripslashes( $query );
1045 } else {
1046 $query = "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_error' ORDER BY datetime DESC";
1047 }
1048 $log_data = $wpdb->get_results( $query, ARRAY_A );
1049 foreach ( (array) $log_data as $data ) {
1050 $log = unserialize( $data['log'] );
1051 $line .= __( 'Register date', 'usces' ) . ' = ' . $data['datetime'] . "\r\n";
1052 $line .= __( 'Link key', 'usces' ) . ' = ' . $log['key'] . "\r\n";
1053 $line .= __( 'Result', 'usces' ) . ' = ' . $log['result'] . "\r\n";
1054 foreach ( (array) $log['data'] as $key => $value ) {
1055 if ( in_array( $key, $exemption ) ) {
1056 continue;
1057 }
1058 if ( is_array( $value ) ) {
1059 $line .= $key . ' = ' . esc_html( print_r( $value, true ) ) . "\r\n"; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
1060 } else {
1061 $line .= $key . ' = ' . esc_html( $value ) . "\r\n";
1062 }
1063 }
1064 $line .= "--------------------------------------------------\r\n\r\n";
1065 }
1066 $line = mb_convert_encoding( $line, 'SJIS-win', 'UTF-8' );
1067
1068 $filename = 'settlement_error_' . wp_date( 'YmdHis' ) . '.log';
1069 header( 'Content-type: text/plain;charset=Shift_JIS' );
1070 header( "Content-Disposition: attachment; filename=$filename" );
1071 print( $line );
1072 exit();
1073 }
1074
1075 /**
1076 * Verify that the card information update action is correct.
1077 * Members who request renewal more than 10 times an hour
1078 * will be locked and will not be able to renew their card information
1079 * until the administrator unlocks it.
1080 *
1081 * @since 2.5.8
1082 *
1083 * @param int $member_id Member ID.
1084 * @return boolean Return true if there is no problem, false otherwise.
1085 */
1086 function wel_verify_update_settlement( $member_id ) {
1087 global $usces;
1088
1089 $rightfulness = true;
1090 if ( 1 === USCES_CREDITCARD_SECURITY::$option['active'] ) {
1091 $is_lock = $usces->get_member_meta_value( 'settlement_action_lock', $member_id );
1092 // wel_log_card_update_action( $member_id );
1093
1094 // $number_limit = apply_filters( 'usces_filter_update_settlement_number_limit', 10 );
1095
1096 if ( $is_lock ) {
1097 $rightfulness = false;
1098 } else {
1099 $number_limit = apply_filters( 'usces_filter_update_settlement_number_limit', USCES_CREDITCARD_SECURITY::$option['set_count'] );
1100 $action_num = wel_count_card_update_action( $member_id );
1101 if ( $number_limit > $action_num ) {
1102 $rightfulness = true;
1103 wel_log_card_update_action( $member_id );
1104 } else {
1105 $usces->set_member_meta_value( 'settlement_action_lock', current_time( 'mysql' ), $member_id );
1106 $rightfulness = false;
1107 }
1108 }
1109 }
1110 return $rightfulness;
1111 }
1112
1113 /**
1114 * Log card information update action.
1115 *
1116 * @since 2.5.8
1117 *
1118 * @param int $member_id Member ID.
1119 */
1120 function wel_log_card_update_action( $member_id ) {
1121 global $wpdb;
1122
1123 $table_name = $wpdb->prefix . 'usces_log';
1124 $wpdb->query(
1125 $wpdb->prepare(
1126 "INSERT INTO $table_name ( `datetime`, `log_type`, `log_key` ) VALUES ( %s, %s, %s )",
1127 current_time( 'Y-m-d H:i:s' ),
1128 'card_update_action',
1129 $member_id
1130 )
1131 );
1132 }
1133
1134 /**
1135 * Count card information update action.
1136 *
1137 * @since 2.5.8
1138 *
1139 * @param int $member_id Member ID.
1140 * @return int Return number of action.
1141 */
1142 function wel_count_card_update_action( $member_id ) {
1143 global $wpdb;
1144
1145 $table_name = $wpdb->prefix . 'usces_log';
1146 // $due_time = (int) current_time( 'timestamp' ) - 3600;
1147 $time_frame = USCES_CREDITCARD_SECURITY::$option['time_frame'];
1148 $due_time = (int) current_time( 'timestamp' ) - ( $time_frame * 60 );
1149 $res = $wpdb->get_var(
1150 $wpdb->prepare(
1151 "SELECT COUNT( `ID` ) FROM $table_name WHERE `datetime` > %s AND `log_type` = %s AND `log_key` = %s",
1152 date_i18n( 'Y-m-d H:i:s', $due_time ),
1153 'card_update_action',
1154 $member_id
1155 )
1156 );
1157 return (int) $res;
1158 }
1159
1160 /**
1161 * Release the card information update lock.
1162 *
1163 * @since 2.5.8
1164 *
1165 * @param int $member_id Member ID.
1166 */
1167 function wel_release_card_update_lock( $member_id ) {
1168 global $wpdb, $usces;
1169
1170 $usces->del_member_meta( 'settlement_action_lock', $member_id );
1171
1172 $table_name = $wpdb->prefix . 'usces_log';
1173 $wpdb->query(
1174 $wpdb->prepare(
1175 "DELETE FROM $table_name WHERE `log_type` = %s AND `log_key` = %s",
1176 'card_update_action',
1177 $member_id
1178 )
1179 );
1180 }
1181
1182 /**
1183 * All credit security unlocked.
1184 */
1185 function wel_all_unlock() {
1186 global $wpdb;
1187
1188 $member_meta_table = usces_get_tablename( 'usces_member_meta' );
1189 $wpdb->query(
1190 $wpdb->prepare(
1191 "DELETE FROM {$member_meta_table} WHERE `meta_key` = %s",
1192 'settlement_action_lock'
1193 )
1194 );
1195 $wpdb->query(
1196 $wpdb->prepare(
1197 "DELETE FROM {$wpdb->prefix}usces_log WHERE `log_type` = %s",
1198 'card_update_action'
1199 )
1200 );
1201 }
1202
1203 /**
1204 * Is lockout credit card input per terminal.
1205 *
1206 * @param string $remote_addr IP address.
1207 * @return bool
1208 */
1209 function wel_is_lockout_credit_input( $remote_addr ) {
1210 global $wpdb;
1211
1212 $lockout = false;
1213
1214 $count = $wpdb->get_var(
1215 $wpdb->prepare(
1216 "SELECT COUNT(`ID`) FROM {$wpdb->prefix}usces_log WHERE `log` IS NOT NULL AND `log` > %s AND `log_type` = %s AND `log_key` = %s",
1217 current_time( 'Y-m-d H:i:s' ),
1218 'card_update_action',
1219 $remote_addr
1220 )
1221 );
1222 if ( 0 < $count ) {
1223 $lockout = true;
1224 }
1225 return $lockout;
1226 }
1227
1228 /**
1229 * Count credit card input per terminal.
1230 *
1231 * @param string $remote_addr IP address.
1232 * @return int
1233 */
1234 function wel_count_credit_input( $remote_addr ) {
1235 global $wpdb;
1236
1237 $time_frame = USCES_CREDITCARD_SECURITY::$option['time_frame'];
1238 $due_time = (int) current_time( 'timestamp' ) - ( $time_frame * 60 );
1239 $count = $wpdb->get_var(
1240 $wpdb->prepare(
1241 "SELECT COUNT(`ID`) FROM {$wpdb->prefix}usces_log WHERE `datetime` > %s AND `log_type` = %s AND `log_key` = %s",
1242 date_i18n( 'Y-m-d H:i:s', $due_time ),
1243 'card_update_action',
1244 $remote_addr
1245 )
1246 );
1247 return (int) $count;
1248 }
1249
1250 /**
1251 * Log credit card input per terminal.
1252 *
1253 * @param string $remote_addr IP address.
1254 */
1255 function wel_log_credit_input( $remote_addr ) {
1256 global $wpdb;
1257
1258 $wpdb->query(
1259 $wpdb->prepare(
1260 "INSERT INTO {$wpdb->prefix}usces_log ( `datetime`, `log_type`, `log_key` ) VALUES ( %s, %s, %s )",
1261 current_time( 'Y-m-d H:i:s' ),
1262 'card_update_action',
1263 $remote_addr
1264 )
1265 );
1266 }
1267
1268 /**
1269 * Log credit card lockout per terminal.
1270 *
1271 * @param string $remote_addr IP address.
1272 */
1273 function wel_lockout_credit_input( $remote_addr ) {
1274 global $wpdb;
1275
1276 $lockout_time = USCES_CREDITCARD_SECURITY::$option['lockout_time'];
1277 $due_time = (int) current_time( 'timestamp' ) + ( $lockout_time * 60 * 60 );
1278 $wpdb->query(
1279 $wpdb->prepare(
1280 "UPDATE {$wpdb->prefix}usces_log SET `log` = %s WHERE `log_type` = %s AND `log_key` = %s",
1281 date_i18n( 'Y-m-d H:i:s', $due_time ),
1282 'card_update_action',
1283 $remote_addr
1284 )
1285 );
1286 }
1287
1288 /**
1289 * Check credit security.
1290 *
1291 * @return bool
1292 */
1293 function wel_check_credit_security() {
1294 global $usces;
1295
1296 $check = true;
1297 if ( 1 === USCES_CREDITCARD_SECURITY::$option['active'] ) {
1298 if ( $usces->is_member_logged_in() ) {
1299 $member = $usces->get_member();
1300 $is_lock = $usces->get_member_meta_value( 'settlement_action_lock', $member['ID'] );
1301 if ( $is_lock ) {
1302 $check = false;
1303 }
1304 }
1305 if ( $check ) {
1306 $remote_addr = ( isset( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : '';
1307 if ( empty( $remote_addr ) ) {
1308 $check = false;
1309 } else {
1310 if ( wel_is_lockout_credit_input( $remote_addr ) ) {
1311 $check = false;
1312 } else {
1313 $count = wel_count_credit_input( $remote_addr );
1314 if ( USCES_CREDITCARD_SECURITY::$option['set_count'] > $count ) {
1315 wel_log_credit_input( $remote_addr );
1316 } else {
1317 wel_lockout_credit_input( $remote_addr );
1318 $check = false;
1319 }
1320 }
1321 }
1322 }
1323 }
1324 return $check;
1325 }
1326
1327 /**
1328 * Credit card input log clearup.
1329 */
1330 function wel_clearup_log_credit_input() {
1331 global $wpdb;
1332
1333 if ( 1 === USCES_CREDITCARD_SECURITY::$option['active'] ) {
1334 $time_frame = USCES_CREDITCARD_SECURITY::$option['time_frame'];
1335 $due_time = (int) current_time( 'timestamp' ) - ( $time_frame * 60 );
1336 $wpdb->query(
1337 $wpdb->prepare(
1338 "DELETE FROM {$wpdb->prefix}usces_log WHERE `datetime` < %s AND ( `log` IS NULL OR `log` < %s ) AND `log_type` = %s",
1339 date_i18n( 'Y-m-d H:i:s', $due_time ),
1340 current_time( 'Y-m-d H:i:s' ),
1341 'card_update_action'
1342 )
1343 );
1344 }
1345 }
1346