settlement_operation = { get_settlement_log: function() { $( "#settlement-log-response" ).html( '' ); $.ajax({ url: ajaxurl, type: "POST", dataType: "json", data: { 'action' : "order_item_ajax", 'wc_nonce': "", 'mode' : "get_settlement_log" } }).done( function( retVal, dataType ) { $( "#settlement-log-response" ).html( "" ); if ( retVal.status == "OK" ) { $( "#settlement-log-list" ).html( retVal.result ); } }).fail( function( retVal ) { $( "#settlement-log-response" ).html( "" ); }); return false; }, get_settlement_log_detail: function( log_key ) { $.ajax({ url: ajaxurl, type: "POST", dataType: "json", data: { 'action' : "order_item_ajax", 'wc_nonce': "", 'mode' : "get_settlement_log_detail", 'log_key' : log_key } }).done( function( retVal, dataType ) { if ( retVal.status == "OK" ) { $( "#settlement-log-detail" ).html( retVal.result ); } }).fail( function( retVal ) { }); return false; }, search_settlement_log: function( log_key ) { $.ajax({ url: ajaxurl, type: "POST", dataType: "json", data: { 'action' : "order_item_ajax", 'wc_nonce': "", 'mode' : "search_settlement_log", 'log_key' : log_key } }).done( function( retVal, dataType ) { $( "#settlement-log-response" ).html( "" ); if ( retVal.status == "OK" ) { $( "#settlement-log-list" ).html( retVal.result ); $( "#searchLogDialog" ).dialog( "close" ); } }).fail( function( retVal ) { }); return false; }, delete_settlement_log: function( log_key ) { $.ajax({ url: ajaxurl, type: "POST", dataType: "json", data: { 'action' : "order_item_ajax", 'wc_nonce': "", 'mode' : "delete_settlement_log", 'log_key' : log_key } }).done( function( retVal, dataType ) { if ( retVal.status == "OK" ) { $( "#settlement-log-list" ).html( "" ); $( "#settlement-log-list" ).html( retVal.result ); } }).fail( function( retVal ) { }); return false; }, delete_settlement_log_all: function() { $.ajax({ url: ajaxurl, type: "POST", dataType: "json", data: { 'action' : "order_item_ajax", 'wc_nonce': "", 'mode' : "delete_settlement_log_all" } }).done( function( retVal, dataType ) { if ( retVal.status == "OK" ) { $( "#settlement-log-list" ).html( "" ); $( "#settlement-log-list" ).html( retVal.result ); } }).fail( function( retVal ) { }); return false; }, revival_settlement_data: function( log_key, register_date ) { $.ajax({ url: ajaxurl, type: "POST", dataType: "json", data: { 'action' : "order_item_ajax", 'mode' : "revival_order_data", 'wc_nonce' : "", 'log_key' : log_key, 'register_date': register_date } }).done( function( retVal, dataType ) { if ( retVal.status == "OK" ) { alert( "" ); $( "#settlementLogDetailDialog" ).dialog( "close" ); $( "#settlementLogDialog" ).dialog( "close" ); location.reload(); } }).fail( function( retVal ) { }); return false; }, get_settlement_error_log: function() { $( "#settlement-error-log-response" ).html( '' ); $.ajax({ url: ajaxurl, type: "POST", dataType: "json", data: { 'action' : "order_item_ajax", 'wc_nonce' : "", 'mode' : "get_settlement_error_log" } }).done( function( retVal, dataType ) { $( "#settlement-error-log-response" ).html( "" ); if ( retVal.status == "OK" ) { $( "#settlement-error-log-list" ).html( retVal.result ); } }).fail( function( retVal ) { $( "#settlement-error-log-response" ).html( "" ); }); return false; }, get_settlement_error_log_detail: function( log_id ) { $.ajax({ url: ajaxurl, type: "POST", dataType: "json", data: { 'action' : "order_item_ajax", 'wc_nonce' : "", 'mode' : "get_settlement_error_log_detail", 'log_id' : log_id } }).done( function( retVal, dataType ) { if ( retVal.status == "OK" ) { $( "#settlement-error-log-detail" ).html( retVal.result ); } }).fail( function( retVal ) { }); return false; }, delete_settlement_error_log: function( log_id ) { $.ajax({ url: ajaxurl, type: "POST", dataType: "json", data: { 'action' : "order_item_ajax", 'wc_nonce' : "", 'mode' : "delete_settlement_error_log", 'log_id' : log_id } }).done( function( retVal, dataType ) { if ( retVal.status == "OK" ) { if ( retVal.nodata == "nodata" ) { location.reload(); } else { $( "#settlement-error-log-list" ).html( "" ); $( "#settlement-error-log-list" ).html( retVal.result ); } } }).fail( function( retVal ) { }); return false; }, delete_settlement_error_log_all: function() { $.ajax({ url: ajaxurl, type: "POST", dataType: "json", data: { 'action' : "order_item_ajax", 'wc_nonce' : "", 'mode' : "delete_settlement_error_log_all" } }).done( function( retVal, dataType ) { if ( retVal.status == "OK" ) { location.reload(); } }).fail( function( retVal ) { }); return false; }, output_settlement_error_log: function( log_id ) { location.href = "?page=usces_orderlist&order_action=dlsettlementerrorlog&log_id="+log_id+"&noheader=true&wc_nonce="; }, reset_settlement_notice: function() { $.ajax({ url: ajaxurl, type: "POST", dataType: "json", data: { 'action' : "order_item_ajax", 'wc_nonce' : "", 'mode' : "reset_settlement_notice" } }).done( function( retVal, dataType ) { }).fail( function( retVal ) { }); return false; } }; $( document ).on( "click", "#settlementlog", function() { $( "#settlementLogDialog" ).dialog( "open" ); }); $( "#settlementLogDialog" ).dialog({ bgiframe: true, autoOpen: false, height: 400, width: 800, resizable: true, modal: true, buttons: { "": function() { $( "#searchLogDialog" ).dialog( "open" ); }, "": function() { var log_key = ""; $( ".log-check" ).each( function( i ) { if ( $( this ).prop( 'checked' ) ) { log_key += $( this ).val()+':'; } }); if ( log_key != "" ) { if ( confirm( "" ) ) { log_key = log_key.substr( 0, ( log_key.length - 1 ) ); settlement_operation.delete_settlement_log( log_key ); } } else { if ( confirm( "" ) ) { settlement_operation.delete_settlement_log_all(); } } }, "": function() { $( this ).dialog( "close" ); } }, close: function() { }, open: function() { $( "#settlement-log-list" ).html( "" ); settlement_operation.get_settlement_log(); } }); $( document ).on( "click", ".log-detail", function() { var key = $( this ).attr( "id" ); $( "#settlement-log-detail" ).html( "" ); settlement_operation.get_settlement_log_detail( key ); $( "#settlementLogDetailDialog" ).dialog( "open" ); }); $( "#settlementLogDetailDialog" ).dialog({ bgiframe: true, autoOpen: false, height: 600, width: 800, resizable: true, modal: true, buttons: { "": function() { if ( confirm( "" ) ) { settlement_operation.revival_settlement_data( $( "#log_key" ).val(), $( "input[name='register_date']:checked" ).val() ); } }, "": function() { $( this ).dialog( "close" ); } }, close: function() { } }); $( "#searchLogDialog" ).dialog({ bgiframe: true, autoOpen: false, height: 210, width: 300, resizable: false, modal: true, buttons: { "": function() { var log_key = $( "#search_log_key" ).val(); settlement_operation.search_settlement_log( log_key ); $( this ).dialog( "close" ); }, "": function() { $( this ).dialog( "close" ); } }, close: function() { }, open: function() { $( "#search_log_key" ).val( "" ); } }); $( document ).on( "click", "#settlement_errorlog", function() { $( "#settlementErrorLogDialog" ).dialog( "open" ); }); $( "#settlementErrorLogDialog" ).dialog({ bgiframe: true, autoOpen: false, height: 400, width: 800, resizable: true, modal: true, buttons: { "": function() { var log_id = ""; $( ".error-log-check" ).each( function( i ) { if ( $( this ).prop( 'checked' ) ) { log_id += $( this ).val()+':'; } }); if ( log_id != "" ) { log_id = log_id.substr( 0, ( log_id.length - 1 ) ); } settlement_operation.output_settlement_error_log( log_id ); }, "": function() { var log_id = ""; $( ".error-log-check" ).each( function( i ) { if ( $( this ).prop( 'checked' ) ) { log_id += $( this ).val() + ':'; } }); if ( log_id != "" ) { if ( confirm( "" ) ) { log_id = log_id.substr( 0, ( log_id.length - 1 ) ); settlement_operation.delete_settlement_error_log( log_id ); } } else { if ( confirm( "" ) ) { settlement_operation.delete_settlement_error_log_all(); } } }, "": function() { $( this ).dialog( "close" ); } }, close: function() { settlement_operation.reset_settlement_notice(); }, open: function() { $( "#settlement-error-log-list" ).html( "" ); settlement_operation.get_settlement_error_log(); } }); $( document ).on( "click", ".error-log-detail", function() { var key = $( this ).attr( "id" ); $( "#settlement-error-log-detaily" ).html( "" ); settlement_operation.get_settlement_error_log_detail( key ); $( "#settlementErrorLogDetailDialog" ).dialog( "open" ); }); $( "#settlementErrorLogDetailDialog" ).dialog({ bgiframe: true, autoOpen: false, height: 600, width: 600, resizable: true, modal: true, buttons: { "": function() { settlement_operation.output_settlement_error_log( $( "#log_id" ).val() ); }, "": function() { $( this ).dialog( "close" ); } }, close: function() { } }); prefix . 'usces_log'; $data = array(); $data['usces_cart'] = ( isset( $_SESSION['usces_cart'] ) ) ? $_SESSION['usces_cart'] : array(); $data['usces_entry'] = ( isset( $_SESSION['usces_entry'] ) ) ? $_SESSION['usces_entry'] : array(); $data['usces_member'] = ( isset( $_SESSION['usces_member'] ) ) ? $_SESSION['usces_member'] : array(); $data['remote_addr'] = ( isset( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : ''; if ( $mobile ) { $data['wcex_mobile'] = $mobile; } $data = apply_filters( 'usces_filter_save_order_acting_data', $data ); $order_data = usces_get_acting_data( $key ); if ( empty( $order_data['datetime'] ) ) { $query = $wpdb->prepare( "INSERT INTO {$log_table_name} ( `datetime`, `log`, `log_type`, `log_key` ) VALUES ( %s, %s, %s, %s )", current_time( 'mysql' ), serialize( $data ), 'acting_data', $key ); } else { $query = $wpdb->prepare( "UPDATE {$log_table_name} SET `datetime` = %s,`log` = %s WHERE `log_type` = %s AND `log_key` = %s", current_time( 'mysql' ), serialize( $data ), 'acting_data', $key ); } $res = $wpdb->query( $query ); return $res; } /** * 決済直前ログ取得 * * @param string $key Log key. * @return array */ function usces_get_acting_data( $key ) { global $wpdb; $log_table_name = $wpdb->prefix . 'usces_log'; $query = $wpdb->prepare( "SELECT * FROM {$log_table_name} WHERE `log_type` = %s AND `log_key` = %s", 'acting_data', $key ); $data = $wpdb->get_row( $query, ARRAY_A ); if ( $data ) { $order_data = unserialize( $data['log'] ); $order_data['key'] = $data['log_key']; $order_data['datetime'] = $data['datetime']; } else { $order_data = array( 'usces_cart' => array(), 'usces_entry' => array(), 'usces_member' => array(), 'remote_addr' => '', 'key' => $key, 'datetime' => '', ); } return $order_data; } /** * 決済直前データ取得 * * @param string $key Log key. * @return array */ function usces_restore_order_acting_data( $key ) { $order_data = usces_get_acting_data( $key ); $_SESSION['usces_cart'] = $order_data['usces_cart']; $_SESSION['usces_entry'] = $order_data['usces_entry']; $_SESSION['usces_member'] = $order_data['usces_member']; do_action( 'usces_action_restore_order_acting_data', $order_data ); return $order_data; } /** * 決済エラーログ保存 * * @param array $log Log data. * @param boolean $mobile Is mobile. * @return mixed */ function usces_save_order_acting_error( $log, $mobile = false ) { global $usces, $wpdb; $log_table_name = $wpdb->prefix . 'usces_log'; $datetime = current_time( 'mysql' ); update_option( 'usces_settlement_notice', $datetime ); do_action( 'usces_action_save_order_acting_error', $log, $datetime ); $query = $wpdb->prepare( "INSERT INTO {$log_table_name} ( `datetime`, `log`, `log_type`, `log_key` ) VALUES ( %s, %s, %s, %s )", $datetime, serialize( $log ), 'acting_error', $log['key'] ); $res = $wpdb->query( $query ); return $res; } /** * 決済直前ログ一覧 * * @param string $log_key Log key. * @return void */ function usces_get_settlement_log( $log_key = '' ) { global $usces, $wpdb; $log_table_name = $wpdb->prefix . 'usces_log'; $html = ''; if ( ! empty( $log_key ) ) { $query = $wpdb->prepare( "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_data' AND `log_key` = %s ORDER BY datetime DESC", $log_key ); } else { $query = "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_data' ORDER BY datetime DESC"; } $log_data = $wpdb->get_results( $query, ARRAY_A ); if ( $log_data ) { $html = ''; foreach ( (array) $log_data as $data ) { $log = unserialize( $data['log'] ); $name = esc_html( $log['usces_entry']['customer']['name1'] ) . esc_html( $log['usces_entry']['customer']['name2'] ); $payment_name = esc_html( $log['usces_entry']['order']['payment_name'] ); $payments = usces_get_payments_by_name( $payment_name ); $settlement = ( isset( $payments['settlement'] ) ) ? $payments['settlement'] : ''; $payment_structure = ( isset( $usces->payment_structure[ $settlement ] ) ) ? '[' . $usces->payment_structure[ $settlement ] . ']' : ''; $class = ( ! empty( $log['revival'] ) ) ? ' class="revival"' : ''; $ip = ( ! empty( $log['remote_addr'] ) ) ? $log['remote_addr'] : ''; $html .= ' '; } $html .= '
' . __( 'Register date', 'usces' ) . '' . __( 'Link key', 'usces' ) . '' . __( 'Name', 'usces' ) . '' . __( 'Type of payment', 'usces' ) . 'IP
' . $data['datetime'] . ' ' . $data['log_key'] . ' ' . $name . ' ' . $payment_name . $payment_structure . ' ' . $ip . '
'; } else { $html = '
' . __( 'There are no log data . ', 'usces' ) . '
'; } $resdata = array(); $resdata['status'] = 'OK'; $resdata['result'] = $html; $resdata['nodata'] = ( ! $log_data ) ? 'nodata' : ''; wp_send_json( $resdata ); } /** * 決済直前ログ詳細 * from Order item ajax. * * @param string $log_key Log key. */ function usces_get_settlement_log_detail( $log_key ) { global $usces; $order_data = usces_get_acting_data( $log_key ); $usces_entries = $order_data['usces_entry']; $html = ''; $html .= ''; $html .= ''; $html .= '
' . __( 'Register date', 'usces' ) . '' . $order_data['datetime'] . '
' . __( 'Link key', 'usces' ) . '' . $order_data['key'] . '
'; $html .= ''; $html .= ''; $html .= ''; $html .= uesces_addressform( 'confirm', $usces_entries ); $html .= '

' . __( 'Customer Information', 'usces' ) . '

' . __( 'e-mail adress', 'usces' ) . '' . esc_html( $usces_entries['customer']['mailaddress1'] ) . '
'; $html .= ''; $html .= ''; if ( isset( $usces_entries['delivery'] ) ) { $html .= ''; $html .= ''; $html .= ''; } $html .= ''; $html .= usces_custom_field_info( $usces_entries, 'order', '', 'return' ); $html .= ''; $html .= '

' . __( 'Others', 'usces' ) . '

' . __( 'shipping option', 'usces' ) . '' . esc_html( usces_delivery_method_name( $usces_entries['order']['delivery_method'], 'return' ) ) . '
' . __( 'Delivery date', 'usces' ) . '' . esc_html( $usces_entries['order']['delivery_date'] ) . '
' . __( 'Delivery Time', 'usces' ) . '' . esc_html( $usces_entries['order']['delivery_time'] ) . '
' . __( 'payment method', 'usces' ) . '' . esc_html( $usces_entries['order']['payment_name'] . usces_payment_detail( $usces_entries ) ) . '
' . __( 'Notes', 'usces' ) . '' . esc_html( $usces_entries['order']['note'] ) . '
'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $num = 1; foreach ( $order_data['usces_cart'] as $serial => $row ) { $array = @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 .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $num++; continue; } $skus = array_keys( $array[ $ids[0] ] ); $post_id = $ids[0]; $sku = $skus[0]; $options = $array[ $ids[0] ][ $skus[0] ]; $opt_fields = usces_get_opts( $post_id, 'sort' ); $optstr = ''; foreach ( (array) $opt_fields as $key => $field ) { $name = urlencode( $field['name'] ); $options[ $name ] = ( isset( $options[ $name ] ) ) ? $options[ $name ] : ''; if ( ! empty( $name ) ) { $key = urldecode( $name ); $value = maybe_unserialize( $options[ $name ] ); if ( is_array( $value ) ) { $c = ''; $optstr .= esc_html( $key ) . ' : '; foreach ( $value as $v ) { $optstr .= $c . nl2br( esc_html( urldecode( $v ) ) ); $c = ', '; } $optstr .= '
'; } else { $optstr .= esc_html( $key ) . ' : ' . nl2br( esc_html( urldecode( $value ) ) ) . '
'; } } } $quantity = ( isset( $row['quant'] ) ) ? $row['quant'] : 0; $price = ( isset( $row['price'] ) ) ? $row['price'] : 0; $cart_item_name = $usces->getCartItemName( $post_id, $sku ); $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $num++; } $html .= ''; $html .= ''; if ( ! empty( $usces_entries['order']['discount'] ) ) { $html .= ''; } if ( usces_is_tax_display() && 'products' === usces_get_tax_target() ) { $html .= ''; } $html .= ''; $payment = usces_get_payments_by_name( $usces_entries['order']['payment_name'] ); if ( 'COD' === $payment['settlement'] ) { $html .= ''; } if ( usces_is_tax_display() && 'all' === usces_get_tax_target() ) { $html .= ''; } if ( usces_is_member_system() && usces_is_member_system_point() && ! empty( $usces_entries['order']['usedpoint'] ) ) { $html .= ''; } $html .= ''; $html .= '

' . __( 'Cart', 'usces' ) . '

No' . __( 'Items', 'usces' ) . '' . __( 'Quantity', 'usces' ) . '' . __( 'Unit price', 'usces' ) . '
' . $num . '' . 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' ) ) . '--
' . $num . '' . esc_html( urldecode( $cart_item_name ) ) . '
' . $optstr . '
' . $quantity . '' . usces_crform( $price, true, false, 'return' ) . '
' . __( 'total items', 'usces' ) . '' . usces_crform( $usces_entries['order']['total_items_price'], true, false, 'return' ) . '
' . apply_filters( 'usces_confirm_discount_label', __( 'Campaign discount', 'usces' ) ) . '' . usces_crform( $usces_entries['order']['discount'], true, false, 'return' ) . '
' . usces_tax_label( array(), 'return' ) . '' . usces_tax( $usces_entries, 'return' ) . '
' . __( 'Shipping', 'usces' ) . '' . usces_crform( $usces_entries['order']['shipping_charge'], true, false, 'return' ) . '
' . apply_filters( 'usces_filter_cod_label', __( 'COD fee', 'usces' ) ) . '' . usces_crform( $usces_entries['order']['cod_fee'], true, false, 'return' ) . '
' . usces_tax_label( array(), 'return' ) . '' . usces_tax( $usces_entries, 'return' ) . '
' . __( 'Used points', 'usces' ) . '' . number_format( $usces_entries['order']['usedpoint'] ) . '
' . __( 'Payment amount', 'usces' ) . '' . usces_crform( $usces_entries['order']['total_full_price'], true, false, 'return' ) . '
'; $html .= ''; $resdata = array(); $resdata['status'] = 'OK'; $resdata['result'] = $html; wp_send_json( $resdata ); } /** * 決済直前ログ削除 * * @param string $log_key Log key. * @return mixed */ function usces_delete_settlement_log( $log_key = '' ) { global $wpdb; $log_table_name = $wpdb->prefix . 'usces_log'; if ( '' !== $log_key ) { $keys = explode( ':', $log_key ); $query = $wpdb->prepare( "DELETE FROM {$log_table_name} WHERE `log_type` = 'acting_data' AND `log_key` IN( %s )", implode( "','", $keys ) ); $query = stripslashes( $query ); } else { $query = "DELETE FROM {$log_table_name} WHERE `log_type` = 'acting_data'"; } $res = $wpdb->query( $query ); return $res; } /** * 受注データ再作成 * * @param string $log_key Log key. * @param int $register_date 0:受注日時に現在の時刻を設定 1:受注日時に登録日を設定. * @return void */ function usces_revival_order_data( $log_key, $register_date = 0 ) { global $usces; $order_data = usces_restore_order_acting_data( $log_key ); $results = array(); if ( 1 === (int) $register_date ) { $results['order_date'] = $order_data['datetime']; } $order_id = usces_reg_orderdata( $results ); $payments = $usces->getPayments( $order_data['usces_entry']['order']['payment_name'] ); $acting = ( 'acting' === $payments['settlement'] ) ? $payments['module'] : $payments['settlement']; $data = array(); switch ( $acting ) { case 'paypal.php': $usces->set_order_meta_value( 'settlement_id', $log_key, $order_id ); break; case 'epsilon.php': $usces->set_order_meta_value( 'settlement_id', $log_key, $order_id ); break; case 'acting_remise_card': case 'acting_remise_conv': $usces->set_order_meta_value( 'settlement_id', $log_key, $order_id ); break; case 'acting_jpayment_card': case 'acting_jpayment_conv': case 'acting_jpayment_bank': $usces->set_order_meta_value( 'settlement_id', $log_key, $order_id ); break; case 'acting_paypal_ec': break; case 'acting_paypal_wpp': $data['custom'] = $log_key; $usces->set_order_meta_value( $acting, serialize( $data ), $order_id ); break; case 'acting_telecom_card': case 'acting_telecom_edy': $data['option'] = $log_key; $usces->set_order_meta_value( $acting, serialize( $data ), $order_id ); break; case 'acting_digitalcheck_card': case 'acting_digitalcheck_conv': $data['SID'] = $log_key; $usces->set_order_meta_value( $acting, serialize( $data ), $order_id ); $usces->set_order_meta_value( 'SID', $log_key, $order_id ); break; case 'acting_mizuho_card': case 'acting_mizuho_conv1': case 'acting_mizuho_conv2': $data['stran'] = $log_key; $usces->set_order_meta_value( $acting, serialize( $data ), $order_id ); $usces->set_order_meta_value( 'stran', $log_key, $order_id ); break; case 'acting_anotherlane_card': $data['LINK_KEY'] = $log_key; $usces->set_order_meta_value( $acting, serialize( $data ), $order_id ); break; case 'acting_veritrans_card': case 'acting_veritrans_conv': $data['orderId'] = $log_key; $usces->set_order_meta_value( $acting, serialize( $data ), $order_id ); $usces->set_order_meta_value( 'orderId', $log_key, $order_id ); break; } usces_already_revival_order_data( $order_data ); do_action( 'usces_action_revival_order_data', $order_id, $log_key, $acting ); $resdata = array(); $resdata['status'] = 'OK'; $resdata['order_id'] = $order_id; wp_send_json( $resdata ); } /** * 受注データ再作成済み * * @param array $order_data Order data. */ function usces_already_revival_order_data( $order_data ) { global $wpdb; $log_table_name = $wpdb->prefix . 'usces_log'; $order_data['revival'] = 'done'; $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'] ); $res = $wpdb->query( $query ); } /** * 決済エラーログ一覧 */ function usces_get_settlement_error_log() { global $usces, $wpdb; $log_table_name = $wpdb->prefix . 'usces_log'; $html = ''; $query = "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_error' ORDER BY datetime DESC"; $log_data = $wpdb->get_results( $query, ARRAY_A ); if ( $log_data ) { $html = ''; foreach ( (array) $log_data as $data ) { $log = unserialize( $data['log'] ); $result = ( ! empty( $log['result'] ) ) ? $log['result'] : ''; $acting = ( ! empty( $log['acting'] ) ) ? $log['acting'] : ''; $html .= ''; } $html .= '
' . __( 'Register date', 'usces' ) . '' . __( 'Link key', 'usces' ) . '' . __( 'Type of payment', 'usces' ) . '' . __( 'Status', 'usces' ) . '
' . $data['datetime'] . ' ' . $data['log_key'] . ' ' . $acting . ' ' . $result . '
'; } else { $html = '
' . __( 'There are no log data . ', 'usces' ) . '
'; usces_reset_settlement_notice(); } $resdata = array(); $resdata['status'] = 'OK'; $resdata['result'] = $html; $resdata['nodata'] = ( ! $log_data ) ? 'nodata' : ''; wp_send_json( $resdata ); } /** * 決済エラーログ付加情報 * * @return array */ function usces_get_settlement_error_log_exemption() { $exemption = array( 'uscesid', 'acting', 'acting_return', 'purchase', 'purchase_ali', 'purchase_jpayment', 'page_id', 'CardNo' ); return $exemption; } /** * 決済エラーログ詳細 * * @param string $log_id Log ID. * @return void */ function usces_get_settlement_error_log_detail( $log_id ) { global $usces, $wpdb; $log_table_name = $wpdb->prefix . 'usces_log'; $exemption = usces_get_settlement_error_log_exemption(); $html = ''; $query = $wpdb->prepare( "SELECT * FROM {$log_table_name} WHERE `log_type` = %s AND `ID` = %s", 'acting_error', $log_id ); $data = $wpdb->get_row( $query, ARRAY_A ); if ( $data ) { $log = unserialize( $data['log'] ); $html = ''; $html .= ''; $html .= ''; $html .= ''; foreach ( (array) $log['data'] as $key => $value ) { if ( in_array( $key, $exemption ) ) { continue; } if ( is_array( $value ) ) { foreach ( $value as $key2 => $value2 ) { if ( in_array( $key2, $exemption ) ) { continue; } if ( is_array( $value2 ) ) { $html .= ''; } else { $html .= ''; } } } else { $html .= ''; } } $html .= '
' . __( 'Register date', 'usces' ) . '' . $data['datetime'] . '
' . __( 'Link key', 'usces' ) . '' . $log['key'] . '
' . __( 'Result', 'usces' ) . '' . $log['result'] . '
' . $key . ':' . $key2 . '' . esc_html( serialize( $value2 ) ) . '
' . $key . ':' . $key2 . '' . esc_html( $value2 ) . '
' . $key . '' . esc_html( $value ) . '
'; $html .= ''; } $resdata = array(); $resdata['status'] = 'OK'; $resdata['result'] = $html; wp_send_json( $resdata ); } /** * 決済エラーログ削除 * * @param string $log_id Log ID. * @return mixed */ function usces_delete_settlement_error_log( $log_id = '' ) { global $usces, $wpdb; $log_table_name = $wpdb->prefix . 'usces_log'; if ( '' !== $log_id ) { $ids = explode( ':', $log_id ); $query = $wpdb->prepare( "DELETE FROM {$log_table_name} WHERE `log_type` = 'acting_error' AND `ID` IN( %s )", implode( "','", $ids ) ); $query = stripslashes( $query ); } else { $query = "DELETE FROM {$log_table_name} WHERE `log_type` = 'acting_error'"; } $res = $wpdb->query( $query ); return $res; } /** * 決済エラー通知リセット */ function usces_reset_settlement_notice() { global $wpdb; $log_table_name = $wpdb->prefix . 'usces_log'; $query = "SELECT * FROM {$log_table_name} WHERE `log_type` = 'acting_error'"; $log_data = $wpdb->get_results( $query, ARRAY_A ); if ( ! $log_data ) { update_option( 'usces_settlement_notice', false ); } $resdata = array(); $resdata['status'] = 'OK'; wp_send_json( $resdata ); } /** * 決済エラー通知 */ function usces_display_settlement_notice() { if ( ! current_user_can( 'wel_manage_order' ) ) { return false; } $datetime = get_option( 'usces_settlement_notice' ); echo '

' . sprintf( __( "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 = 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' ) ); } }