';
$html .= '';
$num = 1;
foreach ( $order_data['usces_cart'] as $serial => $row ) {
$array = wel_safe_unserialize( $serial );
$ids = ( is_array( $array ) && ! empty( $array ) ) ? array_keys( $array ) : array();
if ( empty( $ids ) || ! is_array( $array[ $ids[0] ] ) || empty( $array[ $ids[0] ] ) ) {
/*
* The serial key is broken and the item cannot be identified.
* When the cart in the session was empty, every posted row was
* written to the same empty key and overwrote the previous one,
* so the stored quantity and price cannot be attributed to a
* particular item. Show the row without those figures.
*/
$html .= '
';
$html .= '
' . $num . '
';
$html .= '
' . 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' ) ) . '
' . wp_kses_post(
sprintf(
/* translators: %s: date and time when the settlement error occurred */
__( 'Settlement error has occurred. Please check the settlement error log. The date of occurrence:[ %s ]', 'usces' ),
$datetime
)
) . '
';
}
/**
* 決済エラーログダウンロード
*/
function usces_download_settlement_error_log() {
global $usces, $wpdb;
$log_table_name = $wpdb->prefix . 'usces_log';
$exemption = usces_get_settlement_error_log_exemption();
$line = '';
if ( ! empty( $_GET['log_id'] ) ) {
$ids = explode( ':', wp_unslash( $_GET['log_id'] ) );
$query = $wpdb->prepare( "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_error' AND `ID` IN( %s )", implode( "','", $ids ) );
$query = stripslashes( $query );
} else {
$query = "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_error' ORDER BY datetime DESC";
}
$log_data = $wpdb->get_results( $query, ARRAY_A );
foreach ( (array) $log_data as $data ) {
$log = wel_safe_unserialize( $data['log'] );
$line .= __( 'Register date', 'usces' ) . ' = ' . $data['datetime'] . "\r\n";
$line .= __( 'Link key', 'usces' ) . ' = ' . $log['key'] . "\r\n";
$line .= __( 'Result', 'usces' ) . ' = ' . $log['result'] . "\r\n";
foreach ( (array) $log['data'] as $key => $value ) {
if ( in_array( $key, $exemption ) ) {
continue;
}
if ( is_array( $value ) ) {
$line .= $key . ' = ' . esc_html( print_r( $value, true ) ) . "\r\n"; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
} else {
$line .= $key . ' = ' . esc_html( $value ) . "\r\n";
}
}
$line .= "--------------------------------------------------\r\n\r\n";
}
$line = mb_convert_encoding( $line, 'SJIS-win', 'UTF-8' );
$filename = 'settlement_error_' . wp_date( 'YmdHis' ) . '.log';
header( 'Content-type: text/plain;charset=Shift_JIS' );
header( "Content-Disposition: attachment; filename=$filename" );
print( $line );
exit();
}
/**
* Verify that the card information update action is correct.
* Members who request renewal more than 10 times an hour
* will be locked and will not be able to renew their card information
* until the administrator unlocks it.
*
* @since 2.5.8
*
* @param int $member_id Member ID.
* @return boolean Return true if there is no problem, false otherwise.
*/
function wel_verify_update_settlement( $member_id ) {
global $usces;
$rightfulness = true;
if ( 1 === USCES_CREDITCARD_SECURITY::$option['active'] ) {
$is_lock = $usces->get_member_meta_value( 'settlement_action_lock', $member_id );
// wel_log_card_update_action( $member_id );
// $number_limit = apply_filters( 'usces_filter_update_settlement_number_limit', 10 );
if ( $is_lock ) {
$rightfulness = false;
} else {
$number_limit = apply_filters( 'usces_filter_update_settlement_number_limit', USCES_CREDITCARD_SECURITY::$option['set_count'] );
$action_num = wel_count_card_update_action( $member_id );
if ( $number_limit > $action_num ) {
$rightfulness = true;
wel_log_card_update_action( $member_id );
} else {
$usces->set_member_meta_value( 'settlement_action_lock', current_time( 'mysql' ), $member_id );
$rightfulness = false;
}
}
}
return $rightfulness;
}
/**
* Log card information update action.
*
* @since 2.5.8
*
* @param int $member_id Member ID.
*/
function wel_log_card_update_action( $member_id ) {
global $wpdb;
$table_name = $wpdb->prefix . 'usces_log';
$wpdb->query(
$wpdb->prepare(
"INSERT INTO $table_name ( `datetime`, `log_type`, `log_key` ) VALUES ( %s, %s, %s )",
current_time( 'Y-m-d H:i:s' ),
'card_update_action',
$member_id
)
);
}
/**
* Count card information update action.
*
* @since 2.5.8
*
* @param int $member_id Member ID.
* @return int Return number of action.
*/
function wel_count_card_update_action( $member_id ) {
global $wpdb;
$table_name = $wpdb->prefix . 'usces_log';
// $due_time = (int) current_time( 'timestamp' ) - 3600;
$time_frame = USCES_CREDITCARD_SECURITY::$option['time_frame'];
$due_time = (int) current_time( 'timestamp' ) - ( $time_frame * 60 );
$res = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT( `ID` ) FROM $table_name WHERE `datetime` > %s AND `log_type` = %s AND `log_key` = %s",
date_i18n( 'Y-m-d H:i:s', $due_time ),
'card_update_action',
$member_id
)
);
return (int) $res;
}
/**
* Release the card information update lock.
*
* @since 2.5.8
*
* @param int $member_id Member ID.
*/
function wel_release_card_update_lock( $member_id ) {
global $wpdb, $usces;
$usces->del_member_meta( 'settlement_action_lock', $member_id );
$table_name = $wpdb->prefix . 'usces_log';
$wpdb->query(
$wpdb->prepare(
"DELETE FROM $table_name WHERE `log_type` = %s AND `log_key` = %s",
'card_update_action',
$member_id
)
);
}
/**
* All credit security unlocked.
*/
function wel_all_unlock() {
global $wpdb;
$member_meta_table = usces_get_tablename( 'usces_member_meta' );
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$member_meta_table} WHERE `meta_key` = %s",
'settlement_action_lock'
)
);
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->prefix}usces_log WHERE `log_type` = %s",
'card_update_action'
)
);
}
/**
* Is lockout credit card input per terminal.
*
* @param string $remote_addr IP address.
* @return bool
*/
function wel_is_lockout_credit_input( $remote_addr ) {
global $wpdb;
$lockout = false;
$count = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(`ID`) FROM {$wpdb->prefix}usces_log WHERE `log` IS NOT NULL AND `log` > %s AND `log_type` = %s AND `log_key` = %s",
current_time( 'Y-m-d H:i:s' ),
'card_update_action',
$remote_addr
)
);
if ( 0 < $count ) {
$lockout = true;
}
return $lockout;
}
/**
* Count credit card input per terminal.
*
* @param string $remote_addr IP address.
* @return int
*/
function wel_count_credit_input( $remote_addr ) {
global $wpdb;
$time_frame = USCES_CREDITCARD_SECURITY::$option['time_frame'];
$due_time = (int) current_time( 'timestamp' ) - ( $time_frame * 60 );
$count = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(`ID`) FROM {$wpdb->prefix}usces_log WHERE `datetime` > %s AND `log_type` = %s AND `log_key` = %s",
date_i18n( 'Y-m-d H:i:s', $due_time ),
'card_update_action',
$remote_addr
)
);
return (int) $count;
}
/**
* Log credit card input per terminal.
*
* @param string $remote_addr IP address.
*/
function wel_log_credit_input( $remote_addr ) {
global $wpdb;
$wpdb->query(
$wpdb->prepare(
"INSERT INTO {$wpdb->prefix}usces_log ( `datetime`, `log_type`, `log_key` ) VALUES ( %s, %s, %s )",
current_time( 'Y-m-d H:i:s' ),
'card_update_action',
$remote_addr
)
);
}
/**
* Log credit card lockout per terminal.
*
* @param string $remote_addr IP address.
*/
function wel_lockout_credit_input( $remote_addr ) {
global $wpdb;
$lockout_time = USCES_CREDITCARD_SECURITY::$option['lockout_time'];
$due_time = (int) current_time( 'timestamp' ) + ( $lockout_time * 60 * 60 );
$wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->prefix}usces_log SET `log` = %s WHERE `log_type` = %s AND `log_key` = %s",
date_i18n( 'Y-m-d H:i:s', $due_time ),
'card_update_action',
$remote_addr
)
);
}
/**
* Check credit security.
*
* @return bool
*/
function wel_check_credit_security() {
global $usces;
$check = true;
if ( 1 === USCES_CREDITCARD_SECURITY::$option['active'] ) {
if ( $usces->is_member_logged_in() ) {
$member = $usces->get_member();
$is_lock = $usces->get_member_meta_value( 'settlement_action_lock', $member['ID'] );
if ( $is_lock ) {
$check = false;
}
}
if ( $check ) {
$remote_addr = ( isset( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : '';
if ( empty( $remote_addr ) ) {
$check = false;
} else {
if ( wel_is_lockout_credit_input( $remote_addr ) ) {
$check = false;
} else {
$count = wel_count_credit_input( $remote_addr );
if ( USCES_CREDITCARD_SECURITY::$option['set_count'] > $count ) {
wel_log_credit_input( $remote_addr );
} else {
wel_lockout_credit_input( $remote_addr );
$check = false;
}
}
}
}
}
return $check;
}
/**
* Credit card input log clearup.
*/
function wel_clearup_log_credit_input() {
global $wpdb;
if ( 1 === USCES_CREDITCARD_SECURITY::$option['active'] ) {
$time_frame = USCES_CREDITCARD_SECURITY::$option['time_frame'];
$due_time = (int) current_time( 'timestamp' ) - ( $time_frame * 60 );
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->prefix}usces_log WHERE `datetime` < %s AND ( `log` IS NULL OR `log` < %s ) AND `log_type` = %s",
date_i18n( 'Y-m-d H:i:s', $due_time ),
current_time( 'Y-m-d H:i:s' ),
'card_update_action'
)
);
}
}