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