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

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