PluginProbe
Welcart e-Commerce / 2.12.4
Welcart e-Commerce v2.12.4
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / classes / paymentSBPS.main.class.php

paymentSBPS.main.class.php in Welcart e-Commerce 2.12.4, at classes/paymentSBPS.main.class.php

2,021 lines 75.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Settlement Class.
4 * SB Payment Service
5 *
6 * @package Welcart
7 * @author Collne Inc.
8 * @version 1.0.0
9 * @since 1.9.16
10 */
11
12 /**
13 * SB Payment Service Main Class
14 */
15 class SBPS_MAIN {
16
17 /**
18 * 各種通知の送信�
19 �IP許可リスト(本番環境)
20 *
21 * @var array
22 */
23 const ACTING_NOTICE_IPADDRS_PUBLIC = array( '61.215.213.20' );
24
25 /**
26 * 各種通知の送信�
27 �IP許可リスト(テスト環境・接続支援サイト)
28 *
29 * @var array
30 */
31 const ACTING_NOTICE_IPADDRS_TEST = array( '61.215.213.47' );
32
33 /**
34 * 決済代行会社ID
35 *
36 * @var string
37 */
38 protected $paymod_id;
39
40 /**
41 * 決済種別
42 *
43 * @var string
44 */
45 protected $pay_method;
46
47 /**
48 * 決済代行会社略称
49 *
50 * @var string
51 */
52 protected $acting_name;
53
54 /**
55 * 決済代行会社正式名称
56 *
57 * @var string
58 */
59 protected $acting_formal_name;
60
61 /**
62 * 併用不可決済モジュール
63 *
64 * @var array
65 */
66 protected $unavailable_method;
67
68 /**
69 * クレジットカード決済
70 * ex) 'sbps_card'
71 *
72 * @var string
73 */
74 protected $acting_card;
75
76 /**
77 * コンビニ決済
78 * ex) 'sbps_conv'
79 *
80 * @var string
81 */
82 protected $acting_conv;
83
84 /**
85 * Pay-easy(ペイジー)決済
86 * ex) 'sbps_payeasy'
87 *
88 * @var string
89 */
90 protected $acting_payeasy;
91
92 /**
93 * ウォレット決済
94 * ex) 'sbps_wallet'
95 *
96 * @var string
97 */
98 protected $acting_wallet;
99
100 /**
101 * キャリア決済
102 * ex) 'sbps_mobile'
103 *
104 * @var string
105 */
106 protected $acting_mobile;
107
108 /**
109 * PayPay オンライン決済
110 * ex) 'sbps_paypay'
111 *
112 * @var string
113 */
114 protected $acting_paypay;
115
116 /**
117 * クレジットカード決済フラグ
118 * ex) 'acting_sbps_card'
119 *
120 * @var string
121 */
122 protected $acting_flg_card;
123
124 /**
125 * コンビニ決済フラグ
126 * ex) 'acting_sbps_conv'
127 *
128 * @var string
129 */
130 protected $acting_flg_conv;
131
132 /**
133 * Pay-easy(ペイジー)決済フラグ
134 * ex) 'acting_sbps_payeasy'
135 *
136 * @var string
137 */
138 protected $acting_flg_payeasy;
139
140 /**
141 * ウォレット決済フラグ
142 * ex) 'acting_sbps_wallet'
143 *
144 * @var string
145 */
146 protected $acting_flg_wallet;
147
148 /**
149 * キャリア決済フラグ
150 * ex) 'acting_sbps_mobile'
151 *
152 * @var string
153 */
154 protected $acting_flg_mobile;
155
156 /**
157 * PayPay オンライン決済フラグ
158 * ex) 'acting_sbps_paypay'
159 *
160 * @var string
161 */
162 protected $acting_flg_paypay;
163
164 /**
165 * エラーメッセージ
166 *
167 * @var string
168 */
169 protected $error_mes;
170
171 /**
172 * Construct.
173 *
174 * @param string $mode 'sbps'|'dsk'.
175 */
176 public function __construct( $mode ) {
177
178 $this->paymod_id = $mode;
179
180 if ( $this->is_activate_conv() ) {
181 add_filter( 'usces_filter_noreceipt_status', array( $this, 'noreceipt_status' ) );
182 }
183
184 if ( is_admin() ) {
185 add_action( 'admin_print_footer_scripts', array( $this, 'admin_scripts' ) );
186 add_action( 'usces_action_admin_settlement_update', array( $this, 'settlement_update' ) );
187 add_action( 'usces_action_settlement_tab_title', array( $this, 'settlement_tab_title' ) );
188 add_action( 'usces_action_settlement_tab_body', array( $this, 'settlement_tab_body' ) );
189 }
190
191 if ( $this->is_validity_acting() ) {
192 add_action( 'plugins_loaded', array( $this, 'acting_construct' ), 11 );
193 add_action( 'usces_after_cart_instant', array( $this, 'acting_transaction' ), 9 );
194 add_filter( 'usces_filter_order_confirm_mail_payment', array( $this, 'order_confirm_mail_payment' ), 10, 5 );
195 add_filter( 'usces_filter_is_complete_settlement', array( $this, 'is_complete_settlement' ), 10, 3 );
196 add_filter( 'usces_filter_get_link_key', array( $this, 'get_link_key' ), 10, 2 );
197 add_action( 'usces_action_revival_order_data', array( $this, 'revival_orderdata' ), 10, 3 );
198 if ( is_admin() ) {
199 add_filter( 'usces_filter_settle_info_field_meta_keys', array( $this, 'settlement_info_field_meta_keys' ) );
200 add_filter( 'usces_filter_settle_info_field_keys', array( $this, 'settlement_info_field_keys' ), 10, 2 );
201 add_filter( 'usces_filter_settle_info_field_value', array( $this, 'settlement_info_field_value' ), 10, 3 );
202 } else {
203 add_filter( 'usces_filter_payment_detail', array( $this, 'payment_detail' ), 10, 2 );
204 add_filter( 'usces_filter_payments_str', array( $this, 'payments_str' ), 10, 2 );
205 add_filter( 'usces_filter_payments_arr', array( $this, 'payments_arr' ), 10, 2 );
206 // add_filter( 'usces_filter_delivery_check', array( $this, 'delivery_check' ), 15 );
207 add_filter( 'usces_filter_confirm_inform', array( $this, 'confirm_inform' ), 10, 5 );
208 add_action( 'usces_action_confirm_page_point_inform', array( $this, 'e_point_inform' ), 10, 5 );
209 add_filter( 'usces_filter_confirm_point_inform', array( $this, 'point_inform' ), 10, 5 );
210 if ( defined( 'WCEX_COUPON' ) ) {
211 add_filter( 'wccp_filter_coupon_inform', array( $this, 'point_inform' ), 10, 5 );
212 }
213 add_action( 'usces_action_acting_processing', array( $this, 'acting_processing' ), 10, 2 );
214 add_filter( 'usces_filter_check_acting_return_results', array( $this, 'acting_return' ) );
215 add_filter( 'usces_filter_check_acting_return_duplicate', array( $this, 'check_acting_return_duplicate' ), 10, 2 );
216 add_action( 'usces_action_reg_orderdata', array( $this, 'register_orderdata' ) );
217 // add_filter( 'usces_filter_get_error_settlement', array( $this, 'error_page_message' ) );
218 add_filter( 'usces_filter_completion_settlement_message', array( $this, 'completion_settlement_message' ), 10, 2 );
219 }
220 }
221
222 if ( $this->is_validity_acting( 'card' ) ) {
223 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
224 add_action( 'wp_print_footer_scripts', array( $this, 'footer_scripts' ), 9 );
225 add_filter( 'usces_filter_delivery_check', array( $this, 'delivery_check' ), 15 );
226 add_filter( 'usces_filter_delivery_secure_form_loop', array( $this, 'delivery_secure_form_loop' ), 10, 2 );
227 add_action( 'usces_action_pre_delete_memberdata', array( $this, 'delete_member' ) );
228 add_filter( 'usces_filter_get_error_settlement', array( $this, 'error_page_message' ) );
229 if ( is_admin() ) {
230 add_action( 'usces_action_admin_member_info', array( $this, 'admin_member_info' ), 10, 3 );
231 add_action( 'usces_action_post_update_memberdata', array( $this, 'admin_update_memberdata' ), 10, 2 );
232 }
233 }
234 }
235
236 /**
237 * Initialize.
238 */
239 public function initialize_data() {
240
241 }
242
243 /**
244 * 決済有効判定
245 * 引数が指定されたとき、支払方法で使用している場合に「有効」とする
246 *
247 * @param string|NULL $type Payment type.
248 * @return boolean
249 */
250 public function is_validity_acting( $type = '' ) {
251 $acting_opts = $this->get_acting_settings();
252 if ( empty( $acting_opts ) ) {
253 return false;
254 }
255
256 $payment_method = usces_get_system_option( 'usces_payment_method', 'sort' );
257 $method = false;
258
259 switch ( $type ) {
260 case 'card':
261 foreach ( $payment_method as $payment ) {
262 if ( $this->acting_flg_card === $payment['settlement'] && 'activate' === $payment['use'] ) {
263 $method = true;
264 break;
265 }
266 }
267 if ( $method && $this->is_activate_card() ) {
268 return true;
269 } else {
270 return false;
271 }
272 break;
273
274 case 'conv':
275 foreach ( $payment_method as $payment ) {
276 if ( $this->acting_flg_conv === $payment['settlement'] && 'activate' === $payment['use'] ) {
277 $method = true;
278 break;
279 }
280 }
281 if ( $method && $this->is_activate_conv() ) {
282 return true;
283 } else {
284 return false;
285 }
286 break;
287
288 case 'payeasy':
289 foreach ( $payment_method as $payment ) {
290 if ( $this->acting_flg_payeasy === $payment['settlement'] && 'activate' === $payment['use'] ) {
291 $method = true;
292 break;
293 }
294 }
295 if ( $method && $this->is_activate_payeasy() ) {
296 return true;
297 } else {
298 return false;
299 }
300 break;
301
302 case 'wallet':
303 foreach ( $payment_method as $payment ) {
304 if ( $this->acting_flg_wallet === $payment['settlement'] && 'activate' === $payment['use'] ) {
305 $method = true;
306 break;
307 }
308 }
309 if ( $method && $this->is_activate_wallet() ) {
310 return true;
311 } else {
312 return false;
313 }
314 break;
315
316 case 'mobile':
317 foreach ( $payment_method as $payment ) {
318 if ( $this->acting_flg_mobile === $payment['settlement'] && 'activate' === $payment['use'] ) {
319 $method = true;
320 break;
321 }
322 }
323 if ( $method && $this->is_activate_mobile() ) {
324 return true;
325 } else {
326 return false;
327 }
328 break;
329
330 case 'paypay':
331 foreach ( $payment_method as $payment ) {
332 if ( $this->acting_flg_paypay === $payment['settlement'] && 'activate' === $payment['use'] ) {
333 $method = true;
334 break;
335 }
336 }
337 if ( $method && $this->is_activate_paypay() ) {
338 return true;
339 } else {
340 return false;
341 }
342 break;
343
344 default:
345 if ( isset( $acting_opts['activate'] ) && 'on' === $acting_opts['activate'] ) {
346 return true;
347 } else {
348 return false;
349 }
350 }
351 }
352
353 /**
354 * クレジットカード決済有効判定
355 *
356 * @return boolean
357 */
358 public function is_activate_card() {
359 $acting_opts = $this->get_acting_settings();
360 if ( ( isset( $acting_opts['activate'] ) && 'on' === $acting_opts['activate'] ) &&
361 ( isset( $acting_opts['card_activate'] ) && ( 'on' === $acting_opts['card_activate'] || 'token' === $acting_opts['card_activate'] ) ) ) {
362 $res = true;
363 } else {
364 $res = false;
365 }
366 return $res;
367 }
368
369 /**
370 * コンビニ決済有効判定
371 *
372 * @return boolean
373 */
374 public function is_activate_conv() {
375 $acting_opts = $this->get_acting_settings();
376 if ( ( isset( $acting_opts['activate'] ) && 'on' === $acting_opts['activate'] ) &&
377 ( isset( $acting_opts['conv_activate'] ) && 'on' === $acting_opts['conv_activate'] ) ) {
378 $res = true;
379 } else {
380 $res = false;
381 }
382 return $res;
383 }
384
385 /**
386 * ペイジー決済有効判定
387 *
388 * @return boolean
389 */
390 public function is_activate_payeasy() {
391 $acting_opts = $this->get_acting_settings();
392 if ( ( isset( $acting_opts['activate'] ) && 'on' === $acting_opts['activate'] ) &&
393 ( isset( $acting_opts['payeasy_activate'] ) && 'on' === $acting_opts['payeasy_activate'] ) ) {
394 $res = true;
395 } else {
396 $res = false;
397 }
398 return $res;
399 }
400
401 /**
402 * ウォレット決済有効判定
403 *
404 * @return boolean
405 */
406 public function is_activate_wallet() {
407 $acting_opts = $this->get_acting_settings();
408 if ( ( isset( $acting_opts['activate'] ) && 'on' === $acting_opts['activate'] ) &&
409 ( isset( $acting_opts['wallet_activate'] ) && 'on' === $acting_opts['wallet_activate'] ) ) {
410 $res = true;
411 } else {
412 $res = false;
413 }
414 return $res;
415 }
416
417 /**
418 * キャリア決済有効判定
419 *
420 * @return boolean
421 */
422 public function is_activate_mobile() {
423 $acting_opts = $this->get_acting_settings();
424 if ( ( isset( $acting_opts['activate'] ) && 'on' === $acting_opts['activate'] ) &&
425 ( isset( $acting_opts['mobile_activate'] ) && 'on' === $acting_opts['mobile_activate'] ) ) {
426 $res = true;
427 } else {
428 $res = false;
429 }
430 return $res;
431 }
432
433 /**
434 * PayPay オンライン決済有効判定
435 *
436 * @return boolean
437 */
438 public function is_activate_paypay() {
439 $acting_opts = $this->get_acting_settings();
440 if ( ( isset( $acting_opts['activate'] ) && 'on' === $acting_opts['activate'] ) &&
441 ( isset( $acting_opts['paypay_activate'] ) && 'on' === $acting_opts['paypay_activate'] ) ) {
442 $res = true;
443 } else {
444 $res = false;
445 }
446 return $res;
447 }
448
449 /**
450 * 決済オプション取得
451 *
452 * @return array
453 */
454 protected function get_acting_settings() {
455 global $usces;
456
457 $acting_settings = ( isset( $usces->options['acting_settings'][ $this->paymod_id ] ) ) ? $usces->options['acting_settings'][ $this->paymod_id ] : array();
458 return $acting_settings;
459 }
460
461 /**
462 * 動作環境ごとの接続�
463 �取得
464 *
465 * @return array
466 */
467 protected function get_connection() {
468 $connection = array();
469 $acting_opts = $this->get_acting_settings();
470 if ( 'public' === $acting_opts['ope'] ) {
471 $connection['send_url'] = ( isset( $acting_opts['send_url'] ) ) ? $acting_opts['send_url'] : '';
472 $connection['token_url'] = ( isset( $acting_opts['token_url'] ) ) ? $acting_opts['token_url'] : '';
473 $connection['api_url'] = ( isset( $acting_opts['api_url'] ) ) ? $acting_opts['api_url'] : '';
474 $connection['cust_url'] = ( isset( $acting_opts['cust_url'] ) ) ? $acting_opts['cust_url'] : '';
475 } elseif ( 'test' === $acting_opts['ope'] ) {
476 $connection['send_url'] = ( isset( $acting_opts['send_url_test'] ) ) ? $acting_opts['send_url_test'] : '';
477 $connection['token_url'] = ( isset( $acting_opts['token_url_test'] ) ) ? $acting_opts['token_url_test'] : '';
478 $connection['api_url'] = ( isset( $acting_opts['api_url_test'] ) ) ? $acting_opts['api_url_test'] : '';
479 $connection['cust_url'] = ( isset( $acting_opts['cust_url_test'] ) ) ? $acting_opts['cust_url_test'] : '';
480 } else {
481 $connection['send_url'] = ( isset( $acting_opts['send_url_check'] ) ) ? $acting_opts['send_url_check'] : '';
482 $connection['token_url'] = ( isset( $acting_opts['token_url_test'] ) ) ? $acting_opts['token_url_test'] : '';
483 $connection['api_url'] = ( isset( $acting_opts['api_url_test'] ) ) ? $acting_opts['api_url_test'] : '';
484 $connection['cust_url'] = ( isset( $acting_opts['cust_url_test'] ) ) ? $acting_opts['cust_url_test'] : '';
485 }
486 return $connection;
487 }
488
489 /**
490 * 未�
491 �金ステータス
492 * usces_filter_noreceipt_status
493 *
494 * @param array $noreceipt_status Receive payment notification.
495 * @return array
496 */
497 public function noreceipt_status( $noreceipt_status ) {
498 if ( ! in_array( 'acting_' . $this->paymod_id . '_conv', $noreceipt_status ) || ! in_array( 'acting_' . $this->paymod_id . '_payeasy', $noreceipt_status ) ) {
499 $noreceipt_status[] = 'acting_' . $this->paymod_id . '_conv';
500 $noreceipt_status[] = 'acting_' . $this->paymod_id . '_payeasy';
501 update_option( 'usces_noreceipt_status', $noreceipt_status );
502 }
503 return $noreceipt_status;
504 }
505
506 /**
507 * 決済オプション登録・更新
508 * usces_action_admin_settlement_update
509 */
510 public function settlement_update() {
511
512 }
513
514 /**
515 * クレジット決済設定画面タブ
516 * usces_action_settlement_tab_title
517 */
518 public function settlement_tab_title() {
519 $settlement_selected = get_option( 'usces_settlement_selected', array() );
520 if ( in_array( $this->paymod_id, (array) $settlement_selected ) ) {
521 echo '<li><a href="#uscestabs_' . esc_html( $this->paymod_id ) . '">' . esc_html( $this->acting_formal_name ) . '</a></li>';
522 }
523 }
524
525 /**
526 * クレジット決済設定画面フォーム
527 * usces_action_settlement_tab_body
528 */
529 public function settlement_tab_body() {
530
531 }
532
533 /**
534 * 結果通知前処理
535 * usces_construct
536 */
537 public function acting_construct() {
538 if ( isset( $_POST['res_result'] ) && isset( $_POST['res_pay_method'] ) && isset( $_POST['order_id'] ) ) {
539 $post_data = wp_unslash( $_POST );
540 $rand = $post_data['order_id'];
541 $acting_flg = ( isset( $post_data['free1'] ) ) ? $post_data['free1'] : '';
542 if ( in_array( $acting_flg, $this->pay_method ) ) {
543 usces_restore_order_acting_data( $rand );
544 }
545 // usces_log( $this->acting_name . ' construct : ' . $rand, 'acting_transaction.log' );
546 }
547 }
548
549 /**
550 * 各種通知の送信�
551 �IPを検証する
552 *
553 * 許可IP以外からのリクエストはエラーログを残して処理を終了する
554 * �
555 �金状�
556 �を変更するサーバー間通知でのみ呼び出すこと
557 *
558 * @param array $data Notification data.
559 * @return void
560 */
561 private function acting_notice_ip_guard( $data ) {
562 $acting_opts = $this->get_acting_settings();
563 $allowed_ips = ( isset( $acting_opts['ope'] ) && 'public' === $acting_opts['ope'] ) ? self::ACTING_NOTICE_IPADDRS_PUBLIC : self::ACTING_NOTICE_IPADDRS_TEST;
564 $remote_addr = ( isset( $_SERVER['REMOTE_ADDR'] ) ) ? wp_unslash( $_SERVER['REMOTE_ADDR'] ) : '';
565 if ( usces_acting_notice_ip_allowed( $remote_addr, $allowed_ips ) ) {
566 return;
567 }
568 $log = array(
569 'acting' => $this->paymod_id,
570 'key' => ( isset( $data['res_tracking_id'] ) ) ? $data['res_tracking_id'] : '',
571 'result' => 'IP ADDRESS NOT ALLOWED: ' . $remote_addr,
572 'data' => $data,
573 );
574 usces_save_order_acting_error( $log );
575 usces_log( $this->acting_name . ' notice denied ip : ' . $remote_addr, 'acting_transaction.log' );
576 die( 'NG,ip address error' );
577 }
578
579 /**
580 * 結果通知処理
581 * usces_after_cart_instant
582 */
583 public function acting_transaction() {
584 global $usces;
585
586 if ( ! isset( $_GET['acting_return'] ) && isset( $_POST['res_result'] ) && isset( $_POST['res_pay_method'] ) ) {
587 $post_data = wp_unslash( $_POST );
588 foreach ( $post_data as $key => $value ) {
589 $data[ $key ] = mb_convert_encoding( $value, 'UTF-8', 'SJIS' );
590 }
591 $acting_flg = ( isset( $data['free1'] ) ) ? $data['free1'] : '';
592
593 /* マイページからの会員登録・会員変更 */
594 if ( $acting_flg === $this->acting_flg_card && isset( $_GET['acting'] ) ) {
595 return;
596 } elseif ( $acting_flg === $this->acting_flg_card && ! isset( $data['res_tracking_id'] ) ) {
597 if ( 'OK' === $data['res_result'] ) {
598 die( 'OK,' );
599 } else {
600 die( 'NG,card update error' );
601 }
602 }
603
604 $acting = substr( $acting_flg, 7 );
605 $_GET['acting'] = $acting;
606 switch ( $data['res_result'] ) {
607 case 'OK': /* 決済処理OK */
608 $this->acting_notice_ip_guard( $data );
609 $order_id = $this->get_order_id( $data['res_tracking_id'] );
610 if ( ! $order_id ) {
611 $res = $usces->order_processing( $data );
612 if ( 'ordercompletion' === $res ) {
613 // $usces->set_order_meta_value( 'wc_trans_id', $data['res_tracking_id'], $order_id );
614 } else {
615 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' order processing error : ' . print_r( $data, true ), 'acting_transaction.log' );
616 die( 'NG,order processing error' );
617 }
618 }
619 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [OK] transaction : ' . $data['res_tracking_id'], 'acting_transaction.log' );
620 die( 'OK,' );
621 break;
622
623 case 'PY': /* �
624 �金結果通知 */
625 $this->acting_notice_ip_guard( $data );
626 $order_id = $this->get_order_id( $data['res_tracking_id'] );
627 if ( ! $order_id ) {
628 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [PY] error1 : ' . print_r( $data, true ), 'acting_transaction.log' );
629 die( 'NG,order_id error' );
630 }
631
632 $order_status = $this->get_order_status( $order_id );
633 if ( $usces->is_status( 'receipted', $order_status ) ) {
634 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [PY] second transaction : ' . $order_id, 'acting_transaction.log' );
635 die( 'OK,' );
636 }
637
638 $res = usces_change_order_receipt( $order_id, 'receipted' );
639 if ( false === $res ) {
640 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [PY] error2 : ' . print_r( $data, true ), 'acting_transaction.log' );
641 die( 'NG,usces_order update error' );
642 }
643
644 $res = $usces->set_order_meta_value( $acting_flg, serialize( $data ), $order_id );
645 if ( false === $res ) {
646 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [PY] error3 : ' . print_r( $data, true ), 'acting_transaction.log' );
647 die( 'NG,usces_order_meta update error' );
648 }
649
650 usces_action_acting_getpoint( $order_id );
651 do_action( 'usces_action_' . $this->paymod_id . '_payment_completion', $data, $order_id );
652
653 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [PY] transaction : ' . $order_id, 'acting_transaction.log' );
654 die( 'OK,' );
655 break;
656
657 case 'CN': /* 期限切通知 */
658 $this->acting_notice_ip_guard( $data );
659 $order_id = $this->get_order_id( $data['res_tracking_id'] );
660 if ( ! $order_id ) {
661 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [CN] error1 : ' . print_r( $data, true ), 'acting_transaction.log' );
662 die( 'NG,order_id error' );
663 }
664
665 $res = usces_change_order_receipt( $order_id, 'noreceipt' );
666 if ( false === $res ) {
667 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [CN] error2 : ' . print_r( $data, true ), 'acting_transaction.log' );
668 die( 'NG,usces_order update error' );
669 }
670
671 $res = $usces->set_order_meta_value( $acting_flg, serialize( $data ), $order_id );
672 if ( false === $res ) {
673 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [CN] error3 : ' . print_r( $data, true ), 'acting_transaction.log' );
674 die( 'NG,usces_order_meta update error' );
675 }
676
677 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [CN] transaction : ' . $order_id, 'acting_transaction.log' );
678 die( 'OK,' );
679 break;
680
681 case 'NG': /* 要求NG */
682 $log = array(
683 'acting' => $acting,
684 'key' => $data['res_tracking_id'],
685 'result' => $data['res_result'],
686 'data' => $data,
687 );
688 usces_save_order_acting_error( $log );
689 die( 'NG,' );
690 break;
691
692 default:
693 if ( empty( $data['res_result'] ) ) {
694 return;
695 }
696 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [' . $data['res_result'] . '] : ' . print_r( $data, true ), 'acting_transaction.log' );
697 die( 'OK,' );
698 }
699 }
700 }
701
702 /**
703 * 管理画面送信メール
704 * usces_filter_order_confirm_mail_payment
705 *
706 * @param string $msg_payment Default payment message.
707 * @param int $order_id Order number.
708 * @param array $payment Payment information.
709 * @param array $cart Cart data.
710 * @param array $data Order data.
711 * @return string
712 */
713 public function order_confirm_mail_payment( $msg_payment, $order_id, $payment, $cart, $data ) {
714 return $msg_payment;
715 }
716
717 /**
718 * ポイント即時付与
719 * usces_filter_is_complete_settlement
720 *
721 * @param boolean $complete Payment completion flag.
722 * @param string $payment_name Payment name.
723 * @param string $status Status.
724 * @return boolean
725 */
726 public function is_complete_settlement( $complete, $payment_name, $status ) {
727 $payment = usces_get_payments_by_name( $payment_name );
728 if ( $this->acting_flg_card === $payment['settlement'] || $this->acting_flg_wallet === $payment['settlement'] || $this->acting_flg_mobile === $payment['settlement'] || $this->acting_flg_paypay === $payment['settlement'] ) {
729 $complete = true;
730 }
731 return $complete;
732 }
733
734 /**
735 * 決済リンクキー
736 * usces_filter_get_link_key
737 *
738 * @param string $linkkey Settlement link key.
739 * @param array $results Response data.
740 * @return string
741 */
742 public function get_link_key( $linkkey, $results ) {
743 if ( isset( $_REQUEST['res_tracking_id'] ) ) {
744 $linkkey = wp_unslash( $_REQUEST['res_tracking_id'] );
745 }
746 return $linkkey;
747 }
748
749 /**
750 * 受注データ復旧処理
751 * usces_action_revival_order_data
752 *
753 * @param int $order_id Order number.
754 * @param string $log_key Link key.
755 * @param string $acting_flg Payment type.
756 */
757 public function revival_orderdata( $order_id, $log_key, $acting_flg ) {
758 global $usces;
759
760 if ( ! in_array( $acting_flg, $this->pay_method ) ) {
761 return;
762 }
763
764 $data = array();
765 $data['LINK_KEY'] = $log_key;
766 $usces->set_order_meta_value( $acting_flg, serialize( $data ), $order_id );
767 $usces->set_order_meta_value( 'res_tracking_id', $log_key, $order_id );
768 }
769
770 /**
771 * 受注データから取得する決済�
772 報のキー
773 * usces_filter_settle_info_field_meta_keys
774 *
775 * @param array $keys Settlement information key.
776 * @return array
777 */
778 public function settlement_info_field_meta_keys( $keys ) {
779 $keys = array_merge( $keys, array( 'acting', 'trans_id' ) );
780 return $keys;
781 }
782
783 /**
784 * 受注編集画面に表示する決済�
785 報のキー
786 * usces_filter_settle_info_field_keys
787 *
788 * @param array $keys Settlement information keys.
789 * @param array $fields Settlement information fields.
790 * @return array
791 */
792 public function settlement_info_field_keys( $keys, $fields ) {
793 if ( isset( $fields['acting'] ) && isset( $fields['res_tracking_id'] ) ) {
794 switch ( $fields['acting'] ) {
795 case $this->acting_card:
796 case $this->acting_conv:
797 case $this->acting_payeasy:
798 case $this->acting_wallet:
799 case $this->acting_mobile:
800 case $this->acting_paypay:
801 $keys = array( 'acting', 'res_tracking_id', 'trans_id' );
802 break;
803 }
804 }
805 return $keys;
806 }
807
808 /**
809 * 受注編集画面に表示する決済�
810 報の値整形
811 * usces_filter_settle_info_field_value
812 *
813 * @param string $value Value.
814 * @param string $key Key.
815 * @param string $acting Acting type.
816 * @return string
817 */
818 public function settlement_info_field_value( $value, $key, $acting ) {
819 if ( 'acting' === $key ) {
820 if ( $this->acting_card === $value ) {
821 $value = $this->acting_name . ' カード決済';
822 } elseif ( $this->acting_conv === $value ) {
823 $value = $this->acting_name . ' コンビニ決済';
824 } elseif ( $this->acting_payeasy === $value ) {
825 $value = $this->acting_name . ' ペイジー決済';
826 } elseif ( $this->acting_wallet === $value ) {
827 $value = $this->acting_name . ' ウォレット決済';
828 } elseif ( $this->acting_mobile === $value ) {
829 $value = $this->acting_name . ' キャリア決済';
830 } elseif ( $this->acting_paypay === $value ) {
831 $value = $this->acting_name . ' PayPay オンライン決済';
832 }
833 }
834 return $value;
835 }
836
837 /**
838 * 支払方法説明
839 * usces_filter_payment_detail
840 *
841 * @param string $str Payment method description.
842 * @param array $usces_entries Entry data.
843 * @return string
844 */
845 public function payment_detail( $str, $usces_entries ) {
846 $payment = usces_get_payments_by_name( $usces_entries['order']['payment_name'] );
847 if ( isset( $payment['settlement'] ) && $this->acting_flg_conv === $payment['settlement'] ) {
848 $acting_opts = $this->get_acting_settings();
849 if ( ! empty( $acting_opts['conv_limit'] ) ) {
850 $payment_detail = __( '(', 'usces' ) . sprintf( __( 'Payment is valid for %s days from the date of order.', 'usces' ), $acting_opts['conv_limit'] ) . __( ')', 'usces' );
851 $str = apply_filters( 'usces_filter_sbps_payment_limit_conv', $payment_detail, $acting_opts['conv_limit'] );
852 }
853 }
854 return $str;
855 }
856
857 /**
858 * 支払方法 JavaScript 用決済名追加
859 * usces_filter_payments_str
860 *
861 * @param string $payments_str Payments.
862 * @param array $payment Selected payment.
863 * @return string
864 */
865 public function payments_str( $payments_str, $payment ) {
866 if ( $this->acting_flg_card === $payment['settlement'] ) {
867 if ( $this->is_activate_card() ) {
868 $payments_str .= "'" . $payment['name'] . "': '" . $this->paymod_id . "_form', ";
869 }
870 }
871 return $payments_str;
872 }
873
874 /**
875 * 支払方法 JavaScript 用決済追加
876 * usces_filter_payments_arr
877 *
878 * @param array $payments_arr Payments.
879 * @param array $payment Selected payment.
880 * @return array
881 */
882 public function payments_arr( $payments_arr, $payment ) {
883 if ( $this->acting_flg_card === $payment['settlement'] ) {
884 if ( $this->is_activate_card() ) {
885 $payments_arr[] = $this->paymod_id . '_form';
886 }
887 }
888 return $payments_arr;
889 }
890
891 /**
892 * �
893 容確認ページ [注文する] ボタン
894 * usces_filter_confirm_inform
895 *
896 * @param string $html Purchase post form.
897 * @param array $payments Payment method info.
898 * @param string $acting_flg Payment type.
899 * @param string $rand Welcart transaction key.
900 * @param string $purchase_disabled Disable purchase button.
901 * @return string
902 */
903 public function confirm_inform( $html, $payments, $acting_flg, $rand, $purchase_disabled ) {
904 global $usces;
905
906 if ( ! in_array( $acting_flg, $this->pay_method ) ) {
907 return $html;
908 }
909
910 $usces_entries = $usces->cart->get_entry();
911 $cart = $usces->cart->get_cart();
912 if ( ! $usces_entries || ! $cart ) {
913 return $html;
914 }
915 if ( ! $usces_entries['order']['total_full_price'] ) {
916 return $html;
917 }
918 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
919
920 $acting_opts = $this->get_acting_settings();
921 $usces->save_order_acting_data( $rand );
922 usces_save_order_acting_data( $rand );
923
924 $member = $usces->get_member();
925 $cust_code = ( empty( $member['ID'] ) ) ? str_replace( '-', '', mb_convert_kana( $usces_entries['customer']['tel'], 'a', 'UTF-8' ) ) : $member['ID'];
926 // $item_id = $cart[0]['post_id'];
927 $item_id = mb_convert_kana( $usces->getItemCode( $cart[0]['post_id'] ), 'a', 'UTF-8' );
928 $item_name = $usces->getItemName( $cart[0]['post_id'] );
929 if ( 1 < $cart_count ) {
930 $item_name .= ' ' . __( 'Others', 'usces' );
931 }
932 if ( 36 < mb_strlen( $item_name, 'UTF-8' ) ) {
933 $item_name = mb_substr( $item_name, 0, 30, 'UTF-8' ) . '...';
934 }
935 $item_name = esc_attr( $item_name );
936 $amount = usces_crform( $usces_entries['order']['total_full_price'], false, false, 'return', false );
937 $free1 = $acting_flg;
938 $limit_second = '600';
939
940 if ( $this->acting_flg_card === $acting_flg && isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) {
941 $cust_quick = ( isset( $_POST['cust_quick'] ) ) ? $_POST['cust_quick'] : 'off';
942 $cust_manage = ( isset( $_POST['cust_manage'] ) ) ? $_POST['cust_manage'] : 'off';
943 $token = ( isset( $_POST['token'] ) ) ? $_POST['token'] : '';
944 $token_key = ( isset( $_POST['tokenKey'] ) ) ? $_POST['tokenKey'] : '';
945 $html = '<form id="purchase_form" action="' . USCES_CART_URL . '" method="post" onKeyDown="if (event.keyCode == 13){return false;}">';
946 // if ( ! empty( $token ) && ! empty( $token_key ) ) {
947 $html .= '
948 <input type="hidden" name="cust_quick" value="' . esc_attr( $cust_quick ) . '" />
949 <input type="hidden" name="cust_manage" value="' . esc_attr( $cust_manage ) . '" />
950 <input type="hidden" name="cust_code" value="' . $cust_code . '" />
951 <input type="hidden" name="order_id" value="' . $rand . '" />
952 <input type="hidden" name="item_id" value="' . $item_id . '" />
953 <input type="hidden" name="item_name" value="' . $item_name . '" />
954 <input type="hidden" name="tax" value="" />
955 <input type="hidden" name="amount" value="' . $amount . '" />
956 <input type="hidden" name="free1" value="' . $free1 . '" />
957 <input type="hidden" name="free2" value="" />
958 <input type="hidden" name="free3" value="" />
959 <input type="hidden" name="token" value="' . esc_attr( $token ) . '" />
960 <input type="hidden" name="token_key" value="' . esc_attr( $token_key ) . '" />
961 <input type="hidden" name="limit_second" value="' . $limit_second . '" />';
962 // }
963 $html .= '<div class="send">
964 ' . apply_filters( 'usces_filter_confirm_before_backbutton', null, $payments, $acting_flg, $rand ) . '
965 <input name="backDelivery" type="submit" id="back_button" class="back_to_delivery_button" value="' . __( 'Back', 'usces' ) . '"' . apply_filters( 'usces_filter_confirm_prebutton', null ) . ' />
966 <input name="purchase" type="submit" id="purchase_button" class="checkout_button" value="' . apply_filters( 'usces_filter_confirm_checkout_button_value', __( 'Checkout', 'usces' ) ) . '"' . apply_filters( 'usces_filter_confirm_nextbutton', null ) . $purchase_disabled . ' /></div>
967 <input type="hidden" name="_nonce" value="' . wp_create_nonce( $acting_flg ) . '">';
968
969 } else {
970 $connection = $this->get_connection();
971 $sps_cust_no = '';
972 $sps_payment_no = '';
973 if ( $this->acting_flg_card === $acting_flg ) {
974 $pay_method = ( 'on' === $acting_opts['3d_secure'] ) ? 'credit3d2' : 'credit';
975 $acting = $this->acting_card;
976 $free_csv = '';
977 } elseif ( $this->acting_flg_conv === $acting_flg ) {
978 $pay_method = 'webcvs';
979 $acting = $this->acting_conv;
980 $conv_limit = ( isset( $acting_opts['conv_limit'] ) ) ? $acting_opts['conv_limit'] : '';
981 $free_csv = $this->set_free_csv( $usces_entries['customer'], $conv_limit );
982 } elseif ( $this->acting_flg_payeasy === $acting_flg ) {
983 $pay_method = 'payeasy';
984 $acting = $this->acting_payeasy;
985 $free_csv = $this->set_free_csv( $usces_entries['customer'] );
986 } elseif ( $this->acting_flg_wallet === $acting_flg ) {
987 $pay_method = '';
988 if ( 'on' === $acting_opts['wallet_yahoowallet'] ) {
989 $pay_method .= ',yahoowallet';
990 }
991 if ( 'on' === $acting_opts['wallet_rakutenv2'] ) {
992 $pay_method .= ',rakutenv2';
993 } elseif ( 'on' === $acting_opts['wallet_rakuten'] ) {
994 $pay_method .= ',rakuten';
995 }
996 if ( 'on' === $acting_opts['wallet_paypal'] ) {
997 $pay_method .= ',paypal';
998 }
999 if ( 'on' === $acting_opts['wallet_alipay'] ) {
1000 $pay_method .= ',alipay';
1001 }
1002 $pay_method = ltrim( $pay_method, ',' );
1003 $acting = $this->acting_wallet;
1004 $free_csv = '';
1005 } elseif ( $this->acting_flg_mobile === $acting_flg ) {
1006 $pay_method = '';
1007 if ( 'on' === $acting_opts['mobile_docomo'] ) {
1008 $pay_method .= ',docomo';
1009 }
1010 if ( 'on' === $acting_opts['mobile_auone'] ) {
1011 $pay_method .= ',auone';
1012 }
1013 if ( 'on' === $acting_opts['mobile_softbank2'] ) {
1014 $pay_method .= ',softbank2';
1015 }
1016 $pay_method = ltrim( $pay_method, ',' );
1017 $acting = $this->acting_mobile;
1018 $free_csv = '';
1019 } elseif ( $this->acting_flg_paypay === $acting_flg ) {
1020 $pay_method = 'paypay';
1021 $acting = $this->acting_paypay;
1022 $free_csv = $this->set_free_csv( $usces_entries['customer'] );
1023 }
1024 $pay_type = '0';
1025 $auto_charge_type = '';
1026 $service_type = '0';
1027 $div_settle = '';
1028 $last_charge_month = '';
1029 $camp_type = '';
1030 $terminal_type = '0';
1031 $success_url = USCES_CART_URL . $usces->delim . 'acting=' . $acting . '&acting_return=1';
1032 $cancel_url = USCES_CART_URL . $usces->delim . 'acting=' . $acting . '&confirm=1';
1033 $error_url = USCES_CART_URL . $usces->delim . 'acting=' . $acting . '&acting_return=0';
1034 $pagecon_url = apply_filters( 'usces_filter_' . $this->paymod_id . '_pagecon_url', USCES_CART_URL );
1035 $request_date = wp_date( 'YmdHis' );
1036 $sps_hashcode = $pay_method . $acting_opts['merchant_id'] . $acting_opts['service_id'] . $cust_code . $sps_cust_no . $sps_payment_no . $rand . $item_id . $item_name . $amount . $pay_type . $auto_charge_type . $service_type . $div_settle . $last_charge_month . $camp_type . $terminal_type . $success_url . $cancel_url . $error_url . $pagecon_url . $free1 . $free_csv . $request_date . $limit_second . $acting_opts['hash_key'];
1037 $sps_hashcode = sha1( $sps_hashcode );
1038
1039 $html = '<form id="purchase_form" name="purchase_form" action="' . $connection['send_url'] . '" method="post" onKeyDown="if (event.keyCode == 13){return false;}" accept-charset="Shift_JIS">
1040 <input type="hidden" name="pay_method" value="' . $pay_method . '" />
1041 <input type="hidden" name="merchant_id" value="' . $acting_opts['merchant_id'] . '" />
1042 <input type="hidden" name="service_id" value="' . $acting_opts['service_id'] . '" />
1043 <input type="hidden" name="cust_code" value="' . $cust_code . '" />
1044 <input type="hidden" name="sps_cust_no" value="' . $sps_cust_no . '" />
1045 <input type="hidden" name="sps_payment_no" value="' . $sps_payment_no . '" />
1046 <input type="hidden" name="order_id" value="' . $rand . '" />
1047 <input type="hidden" name="item_id" value="' . $item_id . '" />
1048 <input type="hidden" name="pay_item_id" value="" />
1049 <input type="hidden" name="item_name" value="' . $item_name . '" />
1050 <input type="hidden" name="tax" value="" />
1051 <input type="hidden" name="amount" value="' . $amount . '" />
1052 <input type="hidden" name="pay_type" value="' . $pay_type . '" />
1053 <input type="hidden" name="auto_charge_type" value="' . $auto_charge_type . '" />
1054 <input type="hidden" name="service_type" value="' . $service_type . '" />
1055 <input type="hidden" name="div_settle" value="' . $div_settle . '" />
1056 <input type="hidden" name="last_charge_month" value="' . $last_charge_month . '" />
1057 <input type="hidden" name="camp_type" value="' . $camp_type . '" />
1058 <input type="hidden" name="terminal_type" value="' . $terminal_type . '" />
1059 <input type="hidden" name="success_url" value="' . $success_url . '" />
1060 <input type="hidden" name="cancel_url" value="' . $cancel_url . '" />
1061 <input type="hidden" name="error_url" value="' . $error_url . '" />
1062 <input type="hidden" name="pagecon_url" value="' . $pagecon_url . '" />
1063 <input type="hidden" name="free1" value="' . $free1 . '" />
1064 <input type="hidden" name="free2" value="" />
1065 <input type="hidden" name="free3" value="" />
1066 <input type="hidden" name="free_csv" value="' . $free_csv . '" />
1067 <input type="hidden" name="request_date" value="' . $request_date . '" />
1068 <input type="hidden" name="limit_second" value="' . $limit_second . '" />
1069 <input type="hidden" name="sps_hashcode" value="' . $sps_hashcode . '" />';
1070 $html .= '<input type="hidden" name="dummy" value="&#65533;" />';
1071 $html .= '<div class="send"><input name="purchase" type="submit" id="purchase_button" class="checkout_button" value="' . apply_filters( 'usces_filter_confirm_checkout_button_value', __( 'Checkout', 'usces' ) ) . '"' . apply_filters( 'usces_filter_confirm_nextbutton', ' onClick="document.charset=\'Shift_JIS\';"' ) . $purchase_disabled . ' /></div>';
1072 $html .= '</form>';
1073 $html .= '<form action="' . USCES_CART_URL . '" method="post" onKeyDown="if (event.keyCode == 13){return false;}">
1074 <div class="send">
1075 ' . apply_filters( 'usces_filter_confirm_before_backbutton', null, $payments, $acting_flg, $rand ) . '
1076 <input name="backDelivery" type="submit" id="back_button" class="back_to_delivery_button" value="' . __( 'Back', 'usces' ) . '"' . apply_filters( 'usces_filter_confirm_prebutton', null ) . ' />
1077 </div>';
1078 }
1079 return $html;
1080 }
1081
1082 /**
1083 * Encode free_csv
1084 *
1085 * @param array $customer Customer data.
1086 * @param string $conv_limit Convenience store payment deadline.
1087 */
1088 public function set_free_csv( $customer, $conv_limit = '' ) {
1089 $free_csv = '';
1090 if ( ! WCUtils::is_blank( $customer['name1'] ) ) {
1091 $free_csv = 'LAST_NAME=' . mb_convert_encoding( $customer['name1'], 'SJIS', 'UTF-8' ) . ',FIRST_NAME=' . mb_convert_encoding( $customer['name2'], 'SJIS', 'UTF-8' ) . ',TEL=' . str_replace( '-', '', $customer['tel'] ) . ',MAIL=' . $customer['mailaddress1'];
1092 if ( ! empty( $conv_limit ) ) {
1093 $days = sprintf( '+%d day', $conv_limit );
1094 $bill_date = wp_date( 'Ymd', strtotime( $days ) );
1095 $free_csv .= ',BILL_DATE=' . $bill_date;
1096 }
1097 $acting_opts = $this->get_acting_settings();
1098 if ( ! empty( $acting_opts['3des_key'] ) && ! empty( $acting_opts['3desinit_key'] ) ) {
1099 $free_csv = openssl_encrypt( $free_csv, 'des-ede3-cbc', $acting_opts['3des_key'], OPENSSL_RAW_DATA, $acting_opts['3desinit_key'] );
1100 }
1101 $free_csv = base64_encode( $free_csv );
1102 }
1103 return $free_csv;
1104 }
1105
1106 /**
1107 * �
1108 容確認ページ ポイントフォーム
1109 * usces_action_confirm_page_point_inform
1110 */
1111 public function e_point_inform() {
1112 $html = $this->point_inform( '' );
1113 wel_esc_script_e( $html );
1114 }
1115
1116 /**
1117 * �
1118 容確認ページ ポイントフォーム
1119 * usces_filter_confirm_point_inform
1120 *
1121 * @param string $html Input point form.
1122 * @return string
1123 */
1124 public function point_inform( $html ) {
1125 global $usces;
1126
1127 $usces_entries = $usces->cart->get_entry();
1128 $payment = usces_get_payments_by_name( $usces_entries['order']['payment_name'] );
1129 if ( $this->acting_flg_card !== $payment['settlement'] ) {
1130 return $html;
1131 }
1132
1133 $acting_opts = $this->get_acting_settings();
1134 if ( isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) {
1135 $html .= '
1136 <input type="hidden" name="token" value="' . esc_attr( $_POST['token'] ) . '">
1137 <input type="hidden" name="tokenKey" value="' . esc_attr( $_POST['tokenKey'] ) . '">';
1138 if ( isset( $_POST['cust_quick'] ) ) {
1139 $html .= '
1140 <input type="hidden" name="cust_quick" value="' . esc_attr( $_POST['cust_quick'] ) . '">';
1141 }
1142 if ( isset( $_POST['cust_manage'] ) ) {
1143 $html .= '
1144 <input type="hidden" name="cust_manage" value="' . esc_attr( $_POST['cust_manage'] ) . '">';
1145 }
1146 }
1147 return $html;
1148 }
1149
1150 /**
1151 * 決済処理
1152 * usces_action_acting_processing
1153 *
1154 * @param string $acting_flg Acting type.
1155 * @param array $post_query Post data.
1156 */
1157 public function acting_processing( $acting_flg, $post_query ) {
1158 global $usces;
1159
1160 if ( ! in_array( $acting_flg, $this->pay_method ) ) {
1161 return;
1162 }
1163 $usces_entries = $usces->cart->get_entry();
1164 $cart = $usces->cart->get_cart();
1165 if ( ! $usces_entries || ! $cart ) {
1166 wp_redirect( USCES_CART_URL );
1167 exit;
1168 }
1169 if ( ! wp_verify_nonce( $_REQUEST['_nonce'], $acting_flg ) ) {
1170 wp_redirect( USCES_CART_URL );
1171 exit;
1172 }
1173
1174 $usces->error_message = $usces->zaiko_check();
1175 if ( '' !== $usces->error_message || 0 === $usces->cart->num_row() ) {
1176 wp_redirect( USCES_CART_URL );
1177 exit();
1178 }
1179
1180 $acting_opts = $this->get_acting_settings();
1181 parse_str( $post_query, $post_data );
1182 $connection = $this->get_connection();
1183
1184 if ( $this->acting_flg_card === $acting_flg && isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) {
1185 $item_name = trim( mb_convert_encoding( $post_data['item_name'], 'SJIS', 'UTF-8' ) );
1186 $free1 = trim( $post_data['free1'] );
1187 $order_rowno = '1';
1188 if ( isset( $post_data['cust_quick'] ) ) {
1189 if ( 'quick' === $post_data['cust_quick'] ) {
1190 $token = '';
1191 $token_key = '';
1192 $cust_manage_flg = '0';
1193 } else {
1194 $token = trim( $post_data['token'] );
1195 $token_key = trim( $post_data['token_key'] );
1196 $cust_manage_flg = ( 'save' === $post_data['cust_manage'] || 'change' === $post_data['cust_manage'] ) ? '1' : '0';
1197 }
1198 } else {
1199 $token = trim( $post_data['token'] );
1200 $token_key = trim( $post_data['token_key'] );
1201 $cust_manage_flg = ( isset( $post_data['cust_manage'] ) && 'save' === $post_data['cust_manage'] ) ? '1' : '0';
1202 }
1203 $cardbrand_return_flg = '0';
1204 $encrypted_flg = '1';
1205 $request_date = wp_date( 'YmdHis' );
1206 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . trim( $post_data['cust_code'] ) . trim( $post_data['order_id'] ) . trim( $post_data['item_id'] ) . $item_name . trim( $post_data['amount'] ) . $free1 . $order_rowno . trim( $post_data['token'] ) . trim( $post_data['token_key'] ) . $cust_manage_flg . $cardbrand_return_flg . $encrypted_flg . $request_date . trim( $post_data['limit_second'] ) . $acting_opts['hash_key'];
1207 $sps_hashcode = sha1( $sps_hashcode );
1208
1209 /* 決済要求 */
1210 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
1211 <sps-api-request id="ST01-00131-101">
1212 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
1213 <service_id>' . $acting_opts['service_id'] . '</service_id>
1214 <cust_code>' . trim( $post_data['cust_code'] ) . '</cust_code>
1215 <order_id>' . trim( $post_data['order_id'] ) . '</order_id>
1216 <item_id>' . trim( $post_data['item_id'] ) . '</item_id>
1217 <item_name>' . base64_encode( $item_name ) . '</item_name>
1218 <amount>' . trim( $post_data['amount'] ) . '</amount>
1219 <free1>' . base64_encode( $free1 ) . '</free1>
1220 <order_rowno>' . $order_rowno . '</order_rowno>
1221 <pay_option_manage>
1222 <token>' . $token . '</token>
1223 <token_key>' . $token_key . '</token_key>
1224 <cust_manage_flg>' . $cust_manage_flg . '</cust_manage_flg>
1225 <cardbrand_return_flg>' . $cardbrand_return_flg . '</cardbrand_return_flg>
1226 </pay_option_manage>
1227 <encrypted_flg>' . $encrypted_flg . '</encrypted_flg>
1228 <request_date>' . $request_date . '</request_date>
1229 <limit_second>' . trim( $post_data['limit_second'] ) . '</limit_second>
1230 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
1231 </sps-api-request>';
1232 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
1233 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_card, $encrypted_flg );
1234 if ( isset( $response_settlement['res_result'] ) && 'OK' === $response_settlement['res_result'] ) {
1235 $sps_transaction_id = $response_settlement['res_sps_transaction_id'];
1236 $tracking_id = $response_settlement['res_tracking_id'];
1237 $request_date = wp_date( 'YmdHis' );
1238 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $sps_transaction_id . $tracking_id . $request_date . trim( $post_data['limit_second'] ) . $acting_opts['hash_key'];
1239 $sps_hashcode = sha1( $sps_hashcode );
1240
1241 /* 確定要求 */
1242 $request_credit = '<?xml version="1.0" encoding="Shift_JIS"?>
1243 <sps-api-request id="ST02-00101-101">
1244 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
1245 <service_id>' . $acting_opts['service_id'] . '</service_id>
1246 <sps_transaction_id>' . $sps_transaction_id . '</sps_transaction_id>
1247 <tracking_id>' . $tracking_id . '</tracking_id>
1248 <processing_datetime></processing_datetime>
1249 <request_date>' . $request_date . '</request_date>
1250 <limit_second>' . trim( $post_data['limit_second'] ) . '</limit_second>
1251 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
1252 </sps-api-request>';
1253 $xml_credit = $this->get_xml_response( $connection['api_url'], $request_credit );
1254 $response_credit = $this->xml2assoc( $xml_credit, $this->acting_card );
1255 if ( isset( $response_credit['res_result'] ) && 'OK' === $response_credit['res_result'] ) {
1256 if ( isset( $acting_opts['sales'] ) && 'auto' === $acting_opts['sales'] ) {
1257 $process_date = $response_credit['res_process_date'];
1258 $request_date = wp_date( 'YmdHis' );
1259 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $sps_transaction_id . $tracking_id . $process_date . trim( $post_data['amount'] ) . $request_date . trim( $post_data['limit_second'] ) . $acting_opts['hash_key'];
1260 $sps_hashcode = sha1( $sps_hashcode );
1261
1262 /* 売上要求(自動売上)*/
1263 $request_sales = '<?xml version="1.0" encoding="Shift_JIS"?>
1264 <sps-api-request id="ST02-00201-101">
1265 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
1266 <service_id>' . $acting_opts['service_id'] . '</service_id>
1267 <sps_transaction_id>' . $sps_transaction_id . '</sps_transaction_id>
1268 <tracking_id>' . $tracking_id . '</tracking_id>
1269 <processing_datetime>' . $process_date . '</processing_datetime>
1270 <pay_option_manage>
1271 <amount>' . trim( $post_data['amount'] ) . '</amount>
1272 </pay_option_manage>
1273 <request_date>' . $request_date . '</request_date>
1274 <limit_second>' . trim( $post_data['limit_second'] ) . '</limit_second>
1275 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
1276 </sps-api-request>';
1277 $xml_sales = $this->get_xml_response( $connection['api_url'], $request_sales );
1278 $response_sales = $this->xml2assoc( $xml_sales, $this->acting_card );
1279 if ( isset( $response_sales['res_result'] ) && 'OK' === $response_sales['res_result'] ) {
1280 $result_data = array(
1281 'acting' => $this->acting_card,
1282 'acting_return' => 1,
1283 'res_result' => $response_sales['res_result'],
1284 'res_tracking_id' => $tracking_id,
1285 'res_sps_transaction_id' => $response_sales['res_sps_transaction_id'],
1286 'res_process_date' => $response_sales['res_process_date'],
1287 'res_pay_method' => 'sales',
1288 'trans_id' => $post_data['order_id'],
1289 );
1290 wp_redirect( add_query_arg( $result_data, USCES_CART_URL ) );
1291 exit;
1292
1293 } else {
1294 $res_err_code = ( isset( $response_sales['res_err_code'] ) ) ? $response_sales['res_err_code'] : 'ST02-00201-101 Error';
1295 $data = ( ! empty( $response_sales ) ) ? $response_sales : $xml_sales;
1296 $log = array(
1297 'acting' => $this->acting_card,
1298 'key' => $post_data['order_id'],
1299 'result' => $res_err_code,
1300 'data' => $data,
1301 );
1302 usces_save_order_acting_error( $log );
1303 $result_data = array(
1304 'acting' => $this->acting_card,
1305 'acting_return' => 0,
1306 'res_err_code' => $res_err_code,
1307 );
1308 wp_redirect( add_query_arg( $result_data, USCES_CART_URL ) );
1309 exit;
1310 }
1311
1312 } else {
1313 /* 指定売上 */
1314 $result_data = array(
1315 'acting' => $this->acting_card,
1316 'acting_return' => 1,
1317 'res_result' => $response_credit['res_result'],
1318 'res_tracking_id' => $tracking_id,
1319 'res_sps_transaction_id' => $response_credit['res_sps_transaction_id'],
1320 'res_process_date' => $response_credit['res_process_date'],
1321 'res_pay_method' => 'manual',
1322 'trans_id' => $post_data['order_id'],
1323 );
1324 wp_redirect( add_query_arg( $result_data, USCES_CART_URL ) );
1325 exit;
1326 }
1327
1328 } else {
1329 $res_err_code = ( isset( $response_credit['res_err_code'] ) ) ? $response_credit['res_err_code'] : 'ST02-00101-101 Error';
1330 $data = ( ! empty( $response_credit ) ) ? $response_credit : $xml_credit;
1331 $log = array(
1332 'acting' => $this->acting_card,
1333 'key' => $post_data['order_id'],
1334 'result' => $res_err_code,
1335 'data' => $data,
1336 );
1337 usces_save_order_acting_error( $log );
1338 $result_data = array(
1339 'acting' => $this->acting_card,
1340 'acting_return' => 0,
1341 'res_err_code' => $res_err_code,
1342 );
1343 wp_redirect( add_query_arg( $result_data, USCES_CART_URL ) );
1344 exit;
1345 }
1346
1347 } else {
1348 $res_err_code = ( isset( $response_settlement['res_err_code'] ) ) ? $response_settlement['res_err_code'] : 'ST01-00131-101 Error';
1349 $data = ( ! empty( $response_settlement ) ) ? $response_settlement : $xml_settlement;
1350 $log = array(
1351 'acting' => $this->acting_card,
1352 'key' => $post_data['order_id'],
1353 'result' => $res_err_code,
1354 'data' => $data,
1355 );
1356 usces_save_order_acting_error( $log );
1357 $result_data = array(
1358 'acting' => $this->acting_card,
1359 'acting_return' => 0,
1360 'res_err_code' => $res_err_code,
1361 );
1362 wp_redirect( add_query_arg( $result_data, USCES_CART_URL ) );
1363 exit;
1364 }
1365
1366 exit;
1367 }
1368 }
1369
1370 /**
1371 * Get XML response
1372 *
1373 * @param string $url Send URL.
1374 * @param array $data Send data.
1375 * @return string
1376 */
1377 protected function get_xml_response( $url, $data ) {
1378 $acting_opts = $this->get_acting_settings();
1379 $interface = parse_url( $url );
1380
1381 $header = 'POST ' . $url . " HTTP/1.1\r\n";
1382 $header .= 'Host: ' . $interface['host'] . "\r\n";
1383 $header .= 'Authorization: Basic ' . base64_encode( $acting_opts['basic_id'] . ':' . $acting_opts['basic_password'] ) . "\r\n";
1384 $header .= "User-Agent: PHP Script\r\n";
1385 $header .= "Content-Type: text/xml\r\n";
1386 $header .= 'Content-Length: ' . strlen( $data ) . "\r\n";
1387 $header .= "Connection: close\r\n\r\n";
1388 $header .= $data;
1389
1390 $fp = @stream_socket_client( 'tlsv1.2://' . $interface['host'] . ':443', $errno, $errstr, 30 );
1391 if ( ! $fp ) {
1392 // usces_log( $this->paymod_id . ' API : TLS(v1.2) Error', 'acting_transaction.log' );
1393 }
1394
1395 $xml = '';
1396 if ( $fp ) {
1397 fwrite( $fp, $header );
1398 while ( ! feof( $fp ) ) {
1399 $code = fgets( $fp, 1024 );
1400 if ( false !== strpos( $code, '>' ) ) {
1401 $xml .= $code;
1402 }
1403 }
1404 fclose( $fp );
1405 }
1406 return $xml;
1407 }
1408
1409 /**
1410 * XML to Associative Array
1411 *
1412 * @param object $xml_data XML data.
1413 * @param string $acting Acting type.
1414 * @param int $encrypted_flg Encrypted flag.
1415 * @return array
1416 */
1417 protected function xml2assoc( $xml_data, $acting, $encrypted_flg = 0 ) {
1418 $array_data = array();
1419 if ( $this->is_valid_xml( $xml_data, $acting ) ) {
1420 $object_data = simplexml_load_string( $xml_data );
1421 $json_data = json_encode( $object_data );
1422 $array_data = json_decode( $json_data, true );
1423 if ( 1 === (int) $encrypted_flg ) {
1424 $acting_opts = $this->get_acting_settings();
1425 if ( isset( $array_data['res_pay_method_info'] ) && ! empty( $acting_opts['3des_key'] ) && ! empty( $acting_opts['3desinit_key'] ) ) {
1426 foreach ( $array_data['res_pay_method_info'] as $info => $value ) {
1427 $value = base64_decode( $value );
1428 $value = openssl_decrypt( $value, 'des-ede3-cbc', $acting_opts['3des_key'], OPENSSL_NO_PADDING, $acting_opts['3desinit_key'] );
1429 $array_data['res_pay_method_info'][ $info ] = trim( $value );
1430 }
1431 }
1432 if ( isset( $array_data['pay_method_info'] ) && ! empty( $acting_opts['3des_key'] ) && ! empty( $acting_opts['3desinit_key'] ) ) {
1433 foreach ( $array_data['pay_method_info'] as $info => $value ) {
1434 $value = base64_decode( $value );
1435 $value = openssl_decrypt( $value, 'des-ede3-cbc', $acting_opts['3des_key'], OPENSSL_NO_PADDING, $acting_opts['3desinit_key'] );
1436 $array_data['pay_method_info'][ $info ] = trim( $value );
1437 }
1438 }
1439 }
1440 }
1441 return $array_data;
1442 }
1443
1444 /**
1445 * XML Validator.
1446 *
1447 * @param object $xml_data XML data.
1448 * @param string $acting Acting type.
1449 * @return boolean
1450 */
1451 private function is_valid_xml( $xml_data, $acting ) {
1452 if ( ! empty( $xml_data ) ) {
1453 if ( stripos( $xml_data, '<?xml version=' ) !== false ) {
1454 return true;
1455 }
1456 }
1457 $log = array(
1458 'acting' => $acting,
1459 'key' => '(empty)',
1460 'result' => 'XML validation error',
1461 'data' => array( 'response' => $xml_data ),
1462 );
1463 usces_save_order_acting_error( $log );
1464 return false;
1465 }
1466
1467 /**
1468 * 決済完了ページ制御
1469 * usces_filter_check_acting_return_results
1470 *
1471 * @param array $results Result data.
1472 * @return array
1473 */
1474 public function acting_return( $results ) {
1475 if ( ! in_array( 'acting_' . $results['acting'], $this->pay_method ) ) {
1476 return $results;
1477 }
1478 if ( isset( $results['acting_return'] ) && 1 !== (int) $results['acting_return'] ) {
1479 return $results;
1480 }
1481
1482 if ( isset( $_REQUEST['cancel'] ) ) {
1483 $results[0] = 0;
1484 $results['reg_order'] = false;
1485 } else {
1486 $acting_opts = $this->get_acting_settings();
1487 if ( isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) {
1488 if ( isset( $_REQUEST['res_result'] ) && 'OK' === $_REQUEST['res_result'] ) {
1489 $results[0] = 1;
1490 $results['reg_order'] = true;
1491 } else {
1492 $results[0] = 0;
1493 $results['reg_order'] = false;
1494 }
1495 } else {
1496 if ( isset( $_REQUEST['res_result'] ) && 'OK' === $_REQUEST['res_result'] ) {
1497 $results[0] = 1;
1498 } else {
1499 $results[0] = 0;
1500 }
1501 $results['reg_order'] = false;
1502 }
1503 }
1504 return $results;
1505 }
1506
1507 /**
1508 * 重複オーダー禁止処理
1509 * usces_filter_check_acting_return_duplicate
1510 *
1511 * @param string $trans_id Transaction ID.
1512 * @param array $results Result data.
1513 * @return string
1514 */
1515 public function check_acting_return_duplicate( $trans_id, $results ) {
1516 global $usces;
1517
1518 $acting = ( isset( $_GET['acting'] ) ) ? wp_unslash( $_GET['acting'] ) : '';
1519 $acting_flg = 'acting_' . $acting;
1520 if ( in_array( $acting_flg, $this->pay_method ) ) {
1521 if ( isset( $_REQUEST['order_id'] ) ) {
1522 $trans_id = wp_unslash( $_REQUEST['order_id'] );
1523 }
1524 }
1525 return $trans_id;
1526 }
1527
1528 /**
1529 * 受注データ登録
1530 * usces_action_reg_orderdata
1531 *
1532 * @param string $args {
1533 * The array of Order related data.
1534 * @type array $cart Cart data.
1535 * @type array $entry Entry data.
1536 * @type int $order_id Order ID.
1537 * @type int $member_id Member ID.
1538 * @type array $payments Payment data.
1539 * @type int $charging_type Charging type.
1540 * @type array $results Results data.
1541 * }
1542 */
1543 public function register_orderdata( $args ) {
1544 global $usces;
1545 extract( $args );
1546
1547 $acting_flg = $payments['settlement'];
1548 if ( ! in_array( $acting_flg, $this->pay_method ) ) {
1549 return;
1550 }
1551 if ( ! $entry['order']['total_full_price'] ) {
1552 return;
1553 }
1554
1555 if ( isset( $results['res_tracking_id'] ) ) {
1556 $usces->set_order_meta_value( 'res_tracking_id', $results['res_tracking_id'], $order_id );
1557 $usces->set_order_meta_value( 'wc_trans_id', $results['res_tracking_id'], $order_id );
1558 if ( isset( $results['order_id'] ) ) {
1559 $usces->set_order_meta_value( 'trans_id', $results['order_id'], $order_id );
1560 } elseif ( isset( $results['trans_id'] ) ) {
1561 $usces->set_order_meta_value( 'trans_id', $results['trans_id'], $order_id );
1562 }
1563 if ( ! isset( $results['acting'] ) ) {
1564 $results['acting'] = substr( $acting_flg, 7 );
1565 }
1566 if ( isset( $results['acting_return'] ) ) {
1567 unset( $results['acting_return'] );
1568 unset( $results['page_id'] );
1569 unset( $results['0'] );
1570 unset( $results['reg_order'] );
1571 }
1572 $usces->set_order_meta_value( $acting_flg, usces_serialize( $results ), $order_id );
1573 }
1574 }
1575
1576 /**
1577 * 会員データ削除
1578 * usces_action_pre_delete_memberdata
1579 *
1580 * @param string $member_id Member ID.
1581 */
1582 public function delete_member( $member_id ) {
1583 $this->api_customer_delete( $member_id );
1584 }
1585
1586 /**
1587 * 決済エラーメッセージ
1588 * usces_filter_get_error_settlement
1589 *
1590 * @param string $html Credit card number error.
1591 * @return string Credit card number re-entry message.
1592 */
1593 public function error_page_message( $html ) {
1594 if ( isset( $_REQUEST['acting'] ) && $this->acting_card === $_REQUEST['acting'] ) {
1595 if ( isset( $_GET['res_err_code'] ) && '101' === substr( $_GET['res_err_code'], 0, 3 ) ) {
1596 $html .= '<div class="support_box">
1597 クレジットカード�
1598 報に誤りがあります。<br />カード番号を再�
1599 �力する場合は、こちらをクリックしてください。<br /><br />
1600 <p class="return_settlement"><a href="' . add_query_arg( array( 'backDelivery' => $this->acting_card, 're-enter' => 1 ), USCES_CUSTOMER_URL ) . '">カード番号の再�
1601 �力</a></p>
1602 </div>';
1603 }
1604 }
1605 return $html;
1606 }
1607
1608 /**
1609 * 購�
1610 �完了メッセージ
1611 * usces_filter_completion_settlement_message
1612 *
1613 * @param string $html Purchase complete message.
1614 * @param array $usces_entries Entry data.
1615 * @return string
1616 */
1617 public function completion_settlement_message( $html, $usces_entries ) {
1618 if ( isset( $_REQUEST['acting'] ) && ( $this->acting_conv === $_REQUEST['acting'] || $this->acting_payeasy === $_REQUEST['acting'] ) ) {
1619 $title = ( $this->acting_conv === $_REQUEST['acting'] ) ? 'コンビニ決済' : 'ペイジー決済';
1620 $html .= '<div id="status_table"><h5>' . $this->acting_formal_name . ' ' . $title . '</h5>';
1621 $html .= '<p>' . sprintf( __( 'Information on payment will be mailed to %s.', 'usces' ), esc_html( $usces_entries['customer']['mailaddress1'] ) ) . '</p>';
1622 $html .= '</div>';
1623 }
1624 return $html;
1625 }
1626
1627 /**
1628 * フロントスクリプト
1629 * wp_enqueue_scripts
1630 */
1631 public function enqueue_scripts() {
1632 global $usces;
1633
1634 /* 発送・支払方法ページ */
1635 if ( ! is_admin() && 'delivery' === $usces->page && $this->is_validity_acting( 'card' ) ) :
1636 $acting_opts = $this->get_acting_settings();
1637 if ( isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) :
1638 $connection = $this->get_connection();
1639 ?>
1640 <script type="text/javascript" src="<?php echo esc_url( $connection['token_url'] ); ?>"></script>
1641 <?php
1642 endif;
1643 endif;
1644 }
1645
1646 /**
1647 * フロントスクリプト
1648 * wp_print_footer_scripts
1649 */
1650 public function footer_scripts() {
1651 global $usces;
1652
1653 /* 発送・支払方法ページ */
1654 if ( $this->is_validity_acting( 'card' ) && $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) && 'delivery' === $usces->page ) {
1655 $acting_opts = $this->get_acting_settings();
1656 if ( isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) {
1657 wp_register_style( 'sbps-token-style', USCES_FRONT_PLUGIN_URL . '/css/sbps_token.css' );
1658 wp_enqueue_style( 'sbps-token-style' );
1659 wp_register_script( 'usces_cart_sbps', USCES_FRONT_PLUGIN_URL . '/js/cart_sbps.js', array( 'jquery' ), USCES_VERSION, true );
1660 $sbps_params = array();
1661 $sbps_params['sbps_merchantId'] = $acting_opts['merchant_id'];
1662 $sbps_params['sbps_serviceId'] = $acting_opts['service_id'];
1663 $sbps_params['message'] = array(
1664 'error_token' => __( 'Credit card information is not appropriate.', 'usces' ),
1665 'error_card_number' => __( 'The card number is not a valid credit card number.', 'usces' ),
1666 'error_card_expym' => __( 'The card\'s expiration date is invalid.', 'usces' ),
1667 'error_card_seccd' => __( 'The card\'s security code is invalid.', 'usces' ),
1668 );
1669 wp_localize_script( 'usces_cart_sbps', 'sbps_params', $sbps_params );
1670 wp_enqueue_script( 'usces_cart_sbps' );
1671 }
1672 }
1673 }
1674
1675 /**
1676 * カード�
1677 報�
1678 �力チェック
1679 * usces_filter_delivery_check
1680 *
1681 * @param string $mes Validation check message.
1682 * @return string
1683 */
1684 public function delivery_check( $mes ) {
1685 global $usces;
1686
1687 if ( ! isset( $_POST['offer']['payment_name'] ) ) {
1688 return $mes;
1689 }
1690
1691 if ( ! empty( $mes ) ) {
1692 return $mes;
1693 }
1694
1695 $payment = $usces->getPayments( $_POST['offer']['payment_name'] );
1696 if ( $this->acting_flg_card === $payment['settlement'] ) {
1697 $acting_opts = $this->get_acting_settings();
1698 if ( isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) {
1699 if ( isset( $_POST['cust_quick'] ) && 'quick' === $_POST['cust_quick'] ) {
1700 } else {
1701 if ( ( isset( $_POST['token'] ) && empty( $_POST['token'] ) ) &&
1702 ( isset( $_POST['tokenKey'] ) && empty( $_POST['tokenKey'] ) ) ) {
1703 $mes .= __( 'Please enter the card information correctly.', 'usces' ) . '<br />';
1704 } else {
1705 if ( ! wel_check_credit_security() ) {
1706 $mes .= __( 'Update has been locked. Please contact the store administrator.', 'usces' ) . '<br />';
1707 }
1708 }
1709 }
1710 }
1711 }
1712 return $mes;
1713 }
1714
1715 /**
1716 * 支払方法ページ用�
1717 �力フォーム
1718 * usces_filter_delivery_secure_form_loop
1719 *
1720 * @param string $nouse Empty.
1721 * @param array $payment Payment data.
1722 * @return string
1723 */
1724 public function delivery_secure_form_loop( $nouse, $payment ) {
1725 global $usces;
1726
1727 $html = '';
1728 if ( $this->acting_flg_card === $payment['settlement'] ) {
1729 $acting_opts = $this->get_acting_settings();
1730 if ( ( ! isset( $acting_opts['activate'] ) || 'on' !== $acting_opts['activate'] ) ||
1731 ( ! isset( $acting_opts['card_activate'] ) || 'token' !== $acting_opts['card_activate'] ) ||
1732 'activate' !== $payment['use'] ) {
1733 return $html;
1734 }
1735
1736 $re_enter = ( isset( $_REQUEST['re_enter'] ) && false !== strpos( $_REQUEST['re_enter'], $this->paymod_id . '_card' ) ) ? true : false;
1737
1738 $cust_code = '';
1739 if ( usces_is_login() ) {
1740 $member = $usces->get_member();
1741 $cust_code = $member['ID'];
1742 }
1743
1744 $cust_ref = array();
1745 if ( 'on' === $acting_opts['cust_manage'] || 'choice' === $acting_opts['cust_manage'] ) {
1746 if ( ! empty( $cust_code ) ) {
1747 $cust_ref = $this->api_customer_reference( $cust_code );
1748 }
1749 }
1750
1751 $html .= '<table class="customer_form" id="' . $this->paymod_id . '_form">';
1752 $html .= '<tr><th scope="row">' . __( 'Credit card information', 'usces' ) . '</th><td>';
1753
1754 if ( 'off' !== $acting_opts['cust_manage'] && ! empty( $cust_ref['cc_number'] ) ) {
1755 $cardlast4 = substr( $cust_ref['cc_number'], -4 );
1756 $html .= '<p><label><input type="radio" name="cust_quick" class="cust_quick" id="cust_quick_use" value="quick"><span>登録済みのクレジットカードを使う</span></label></p>';
1757 $html .= '<div class="sbps_registerd_card_area">';
1758 $html .= '<div>登録済みのカード番号下4桁<span class="cc_cardlast4">' . $cardlast4 . '</span></div>';
1759 $html .= '</div>';
1760 $html .= '<p><label><input type="radio" name="cust_quick" class="cust_quick" id="cust_quick_new" value="new"><span>新しいクレジットカードを使う</span></label></p>';
1761 }
1762
1763 $html .= '<div class="sbps_new_card_area">';
1764 $html .= '<dl>';
1765 $html .= '<dt>' . __( 'card number', 'usces' ) . '</dt>
1766 <dd><input type="tel" class="cc_number" id="cc_number" maxlength="16" value=""></dd>';
1767
1768 if ( 'off' !== $acting_opts['cust_manage'] ) {
1769 if ( usces_have_regular_order() || usces_have_continue_charge() ) {
1770 $html .= '<input type="hidden" name="cust_manage" value="save" />';
1771 } elseif ( 'on' === $acting_opts['cust_manage'] ) {
1772 $html .= '<input type="hidden" name="cust_manage" value="save" />';
1773 } elseif ( 'choice' === $acting_opts['cust_manage'] ) {
1774 if ( ! empty( $cust_ref['cc_number'] ) ) {
1775 $html .= '<dd><label><input type="checkbox" name="cust_manage" id="cust_manage" value="change"><span id="cust_manage_label">登録済のカードを変更して購�
1776 �する</span></label></dd>';
1777 } else {
1778 $html .= '<dd><label><input type="checkbox" name="cust_manage" id="cust_manage" value="save"><span id="cust_manage_label">クレジットカードを登録して購�
1779 �する</span></label></dd>';
1780 }
1781 }
1782 }
1783 $cardno_attention = apply_filters( 'usces_filter_cardno_attention', '<dd><div class="attention">' . __( '* Please do not enter symbols or letters other than numbers such as space (blank), hyphen (-) between numbers.', 'usces' ) . '</div></dd>' );
1784 $html .= $cardno_attention;
1785
1786 $html .= '<dt>' . __( 'Card expiration', 'usces' ) . '</dt>
1787 <dd><select class="cc_expmm" id="cc_expmm">
1788 <option value="">--</option>';
1789 for ( $i = 1; $i <= 12; $i++ ) {
1790 $html .= '
1791 <option value="' . sprintf( '%02d', $i ) . '">' . sprintf( '%02d', $i ) . '</option>';
1792 }
1793 $html .= '
1794 </select>' . __( 'month', 'usces' ) . '&nbsp;
1795 <select class="cc_expyy" id="cc_expyy">
1796 <option value="">----</option>';
1797 for ( $i = 0; $i <= 15; $i++ ) {
1798 $year = wp_date( 'Y' ) + $i;
1799 $html .= '
1800 <option value="' . $year . '">' . $year . '</option>';
1801 }
1802 $html .= '
1803 </select>' . __( 'year', 'usces' ) . '</dd>
1804 <dt>' . __( 'security code', 'usces' ) . '</dt>
1805 <dd><input type="tel" class="cc_seccd" id="cc_seccd" maxlength="4" value=""></dd>';
1806 $seccd_attention = apply_filters( 'usces_filter_seccd_attention', '' );
1807 $html .= $seccd_attention;
1808 $html .= '
1809 </dl>
1810 </div>';
1811 $html .= '
1812 <input type="hidden" name="acting" value="' . $this->paymod_id . '" />
1813 <input type="hidden" name="confirm" value="confirm" />
1814 <input type="hidden" name="token" id="token" value="" />
1815 <input type="hidden" name="tokenKey" id="tokenKey" value="" />';
1816 $html .= '</td></tr>';
1817 $html .= '</table>';
1818 }
1819 return $html;
1820 }
1821
1822 /**
1823 * 会員データ編集画面 カード�
1824 報登録�
1825
1826 * usces_action_admin_member_info
1827 *
1828 * @param array $member Member data.
1829 * @param array $member_metas Member meta data.
1830 * @param array $usces_member_history Member's history order data.
1831 */
1832 public function admin_member_info( $member, $member_metas, $usces_member_history ) {
1833 if ( 0 < count( $usces_member_history ) ) :
1834 $acting_opts = $this->get_acting_settings();
1835 if ( isset( $acting_opts['card_activate'] ) ) :
1836 $cust_ref = $this->api_customer_reference( $member['ID'] );
1837 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) :
1838 $cardlast4 = substr( $cust_ref['cc_number'], -4 );
1839 $expyy = substr( $cust_ref['cc_expiration'], 0, 4 );
1840 $expmm = substr( $cust_ref['cc_expiration'], 4, 2 );
1841 ?>
1842 <tr>
1843 <td class="label"><?php esc_html_e( 'Lower 4 digits', 'usces' ); ?></td>
1844 <td><div class="rod_left shortm"><?php echo esc_html( $cardlast4 ); ?></div></td>
1845 </tr>
1846 <tr>
1847 <td class="label"><?php esc_html_e( 'Expiration date', 'usces' ); ?></td>
1848 <td><div class="rod_left shortm"><?php echo esc_html( $expyy . '/' . $expmm ); ?></div></td>
1849 </tr>
1850 <tr>
1851 <td class="label">カード�
1852 </td>
1853 <td><div class="rod_left shortm"><?php esc_html_e( 'Registered', 'usces' ); ?></div></td>
1854 </tr>
1855 <?php
1856 if ( ! usces_have_member_continue_order( $member['ID'] ) && ! usces_have_member_regular_order( $member['ID'] ) ) :
1857 ?>
1858 <tr>
1859 <td class="label"><input type="checkbox" name="sbps_quick" id="sbps-quick-release" value="release"></td>
1860 <td><label for="sbps-quick-release">カード�
1861 報の登録を解除する</label></td>
1862 </tr>
1863 <?php
1864 endif;
1865 endif;
1866 endif;
1867 endif;
1868 }
1869
1870 /**
1871 * 会員データ編集画面 カード�
1872 報登録解除
1873 * usces_action_post_update_memberdata
1874 *
1875 * @param string $member_id Member ID.
1876 * @param boolean $res Deletable.
1877 */
1878 public function admin_update_memberdata( $member_id, $res ) {
1879 if ( ! $this->is_activate_card() || false === $res ) {
1880 return;
1881 }
1882 if ( isset( $_POST['sbps_quick'] ) && 'release' === $_POST['sbps_quick'] ) {
1883 $this->api_customer_delete( $member_id );
1884 }
1885 }
1886
1887 /**
1888 * Get order_id by meta_data
1889 *
1890 * @param string $res_tracking_id Tracking ID.
1891 * @return int
1892 */
1893 protected function get_order_id( $res_tracking_id ) {
1894 global $wpdb;
1895
1896 $order_meta_table_name = $wpdb->prefix . 'usces_order_meta';
1897 $query = $wpdb->prepare( "SELECT `order_id` FROM $order_meta_table_name WHERE `meta_key` = %s AND `meta_value` = %s", 'res_tracking_id', $res_tracking_id );
1898 $order_id = $wpdb->get_var( $query );
1899 return $order_id;
1900 }
1901
1902 /**
1903 * Get order_status by order data
1904 *
1905 * @param int $order_id Order number.
1906 * @return string
1907 */
1908 protected function get_order_status( $order_id ) {
1909 global $wpdb;
1910
1911 $order_table_name = $wpdb->prefix . 'usces_order';
1912 $query = $wpdb->prepare( "SELECT `order_status` FROM $order_table_name WHERE `ID` = %d", $order_id );
1913 $order_status = $wpdb->get_var( $query );
1914 return $order_status;
1915 }
1916
1917 /**
1918 * Get customers card data
1919 *
1920 * @param string $cust_code Member ID.
1921 * @return array
1922 */
1923 protected function api_customer_reference( $cust_code ) {
1924 global $wpdb;
1925
1926 $cust_ref = array();
1927 $acting_opts = $this->get_acting_settings();
1928 if ( empty( $acting_opts['3des_key'] ) || empty( $acting_opts['3desinit_key'] ) ) {
1929 return $cust_ref;
1930 }
1931 $connection = $this->get_connection();
1932
1933 $sps_cust_info_return_flg = '1';
1934 $response_info_type = '2';
1935 $cardbrand_return_flg = '0';
1936 $encrypted_flg = '1';
1937 $request_date = wp_date( 'YmdHis' );
1938 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $cust_code . $sps_cust_info_return_flg . $response_info_type . $cardbrand_return_flg . $encrypted_flg . $request_date . $acting_opts['hash_key'];
1939 $sps_hashcode = sha1( $sps_hashcode );
1940
1941 /* クレジットカード�
1942 報参�
1943 �要求 */
1944 $request_cust_ref = '<?xml version="1.0" encoding="Shift_JIS"?>
1945 <sps-api-request id="MG02-00104-101">
1946 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
1947 <service_id>' . $acting_opts['service_id'] . '</service_id>
1948 <cust_code>' . $cust_code . '</cust_code>
1949 <sps_cust_info_return_flg>' . $sps_cust_info_return_flg . '</sps_cust_info_return_flg>
1950 <response_info_type>' . $response_info_type . '</response_info_type>
1951 <pay_option_manage>
1952 <cardbrand_return_flg>' . $cardbrand_return_flg . '</cardbrand_return_flg>
1953 </pay_option_manage>
1954 <encrypted_flg>' . $encrypted_flg . '</encrypted_flg>
1955 <request_date>' . $request_date . '</request_date>
1956 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
1957 </sps-api-request>';
1958 $xml_cust_ref = $this->get_xml_response( $connection['api_url'], $request_cust_ref );
1959 $response_cust_ref = $this->xml2assoc( $xml_cust_ref, $this->acting_card );
1960 if ( isset( $response_cust_ref['res_result'] ) ) {
1961 $cust_ref['result'] = $response_cust_ref['res_result'];
1962 if ( 'OK' === $response_cust_ref['res_result'] ) {
1963 if ( isset( $response_cust_ref['res_pay_method_info']['cc_number'] ) && ! empty( $acting_opts['3des_key'] ) && ! empty( $acting_opts['3desinit_key'] ) ) {
1964 $cc_number = base64_decode( $response_cust_ref['res_pay_method_info']['cc_number'] );
1965 $cust_ref['cc_number'] = openssl_decrypt( $cc_number, 'des-ede3-cbc', $acting_opts['3des_key'], OPENSSL_NO_PADDING, $acting_opts['3desinit_key'] );
1966 }
1967 if ( isset( $response_cust_ref['res_pay_method_info']['cc_expiration'] ) && ! empty( $acting_opts['3des_key'] ) && ! empty( $acting_opts['3desinit_key'] ) ) {
1968 $cc_expiration = base64_decode( $response_cust_ref['res_pay_method_info']['cc_expiration'] );
1969 $cust_ref['cc_expiration'] = openssl_decrypt( $cc_expiration, 'des-ede3-cbc', $acting_opts['3des_key'], OPENSSL_NO_PADDING, $acting_opts['3desinit_key'] );
1970 }
1971 if ( isset( $response_cust_ref['res_sps_info']['cc_number'] ) ) {
1972 $cust_ref['sps_cust_no'] = $response_cust_ref['res_sps_info']['res_sps_cust_no'];
1973 }
1974 } else {
1975 if ( isset( $response_cust_ref['res_err_code'] ) ) {
1976 $cust_ref['err_code'] = $response_cust_ref['res_err_code'];
1977 }
1978 }
1979 }
1980 return $cust_ref;
1981 }
1982
1983 /**
1984 * Delete customers card data
1985 *
1986 * @param string $cust_code Member ID.
1987 * @return boolean
1988 */
1989 protected function api_customer_delete( $cust_code ) {
1990 $res = false;
1991 $cust_ref = $this->api_customer_reference( $cust_code );
1992 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) {
1993 $acting_opts = $this->get_acting_settings();
1994 $connection = $this->get_connection();
1995
1996 $sps_cust_info_return_flg = '0';
1997 $request_date = wp_date( 'YmdHis' );
1998 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $cust_code . $sps_cust_info_return_flg . $request_date . $acting_opts['hash_key'];
1999 $sps_hashcode = sha1( $sps_hashcode );
2000
2001 /* クレジットカード�
2002 報削除要求 */
2003 $request_cust_del = '<?xml version="1.0" encoding="Shift_JIS"?>
2004 <sps-api-request id="MG02-00103-101">
2005 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
2006 <service_id>' . $acting_opts['service_id'] . '</service_id>
2007 <cust_code>' . $cust_code . '</cust_code>
2008 <sps_cust_info_return_flg>' . $sps_cust_info_return_flg . '</sps_cust_info_return_flg>
2009 <request_date>' . $request_date . '</request_date>
2010 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
2011 </sps-api-request>';
2012 $xml_cust_del = $this->get_xml_response( $connection['api_url'], $request_cust_del );
2013 $response_cust_del = $this->xml2assoc( $xml_cust_del, $this->acting_card );
2014 if ( isset( $response_cust_del['res_result'] ) && 'OK' === $response_cust_del['res_result'] ) {
2015 $res = true;
2016 }
2017 }
2018 return $res;
2019 }
2020 }
2021