PluginProbe
Welcart e-Commerce / 2.11.35
Welcart e-Commerce v2.11.35
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.11.35, at classes/paymentSBPS.main.class.php

2,020 lines 75.0 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 $order_id = $this->get_order_id( $data['res_tracking_id'] );
609 if ( ! $order_id ) {
610 $res = $usces->order_processing( $data );
611 if ( 'ordercompletion' === $res ) {
612 // $usces->set_order_meta_value( 'wc_trans_id', $data['res_tracking_id'], $order_id );
613 } else {
614 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' order processing error : ' . print_r( $data, true ), 'acting_transaction.log' );
615 die( 'NG,order processing error' );
616 }
617 }
618 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [OK] transaction : ' . $data['res_tracking_id'], 'acting_transaction.log' );
619 die( 'OK,' );
620 break;
621
622 case 'PY': /* �
623 �金結果通知 */
624 $this->acting_notice_ip_guard( $data );
625 $order_id = $this->get_order_id( $data['res_tracking_id'] );
626 if ( ! $order_id ) {
627 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [PY] error1 : ' . print_r( $data, true ), 'acting_transaction.log' );
628 die( 'NG,order_id error' );
629 }
630
631 $order_status = $this->get_order_status( $order_id );
632 if ( $usces->is_status( 'receipted', $order_status ) ) {
633 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [PY] second transaction : ' . $order_id, 'acting_transaction.log' );
634 die( 'OK,' );
635 }
636
637 $res = usces_change_order_receipt( $order_id, 'receipted' );
638 if ( false === $res ) {
639 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [PY] error2 : ' . print_r( $data, true ), 'acting_transaction.log' );
640 die( 'NG,usces_order update error' );
641 }
642
643 $res = $usces->set_order_meta_value( $acting_flg, serialize( $data ), $order_id );
644 if ( false === $res ) {
645 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [PY] error3 : ' . print_r( $data, true ), 'acting_transaction.log' );
646 die( 'NG,usces_order_meta update error' );
647 }
648
649 usces_action_acting_getpoint( $order_id );
650 do_action( 'usces_action_' . $this->paymod_id . '_payment_completion', $data, $order_id );
651
652 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [PY] transaction : ' . $order_id, 'acting_transaction.log' );
653 die( 'OK,' );
654 break;
655
656 case 'CN': /* 期限切通知 */
657 $this->acting_notice_ip_guard( $data );
658 $order_id = $this->get_order_id( $data['res_tracking_id'] );
659 if ( ! $order_id ) {
660 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [CN] error1 : ' . print_r( $data, true ), 'acting_transaction.log' );
661 die( 'NG,order_id error' );
662 }
663
664 $res = usces_change_order_receipt( $order_id, 'noreceipt' );
665 if ( false === $res ) {
666 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [CN] error2 : ' . print_r( $data, true ), 'acting_transaction.log' );
667 die( 'NG,usces_order update error' );
668 }
669
670 $res = $usces->set_order_meta_value( $acting_flg, serialize( $data ), $order_id );
671 if ( false === $res ) {
672 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [CN] error3 : ' . print_r( $data, true ), 'acting_transaction.log' );
673 die( 'NG,usces_order_meta update error' );
674 }
675
676 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [CN] transaction : ' . $order_id, 'acting_transaction.log' );
677 die( 'OK,' );
678 break;
679
680 case 'NG': /* 要求NG */
681 $log = array(
682 'acting' => $acting,
683 'key' => $data['res_tracking_id'],
684 'result' => $data['res_result'],
685 'data' => $data,
686 );
687 usces_save_order_acting_error( $log );
688 die( 'NG,' );
689 break;
690
691 default:
692 if ( empty( $data['res_result'] ) ) {
693 return;
694 }
695 // usces_log( $this->acting_name . ' ' . $data['res_pay_method'] . ' [' . $data['res_result'] . '] : ' . print_r( $data, true ), 'acting_transaction.log' );
696 die( 'OK,' );
697 }
698 }
699 }
700
701 /**
702 * 管理画面送信メール
703 * usces_filter_order_confirm_mail_payment
704 *
705 * @param string $msg_payment Default payment message.
706 * @param int $order_id Order number.
707 * @param array $payment Payment information.
708 * @param array $cart Cart data.
709 * @param array $data Order data.
710 * @return string
711 */
712 public function order_confirm_mail_payment( $msg_payment, $order_id, $payment, $cart, $data ) {
713 return $msg_payment;
714 }
715
716 /**
717 * ポイント即時付与
718 * usces_filter_is_complete_settlement
719 *
720 * @param boolean $complete Payment completion flag.
721 * @param string $payment_name Payment name.
722 * @param string $status Status.
723 * @return boolean
724 */
725 public function is_complete_settlement( $complete, $payment_name, $status ) {
726 $payment = usces_get_payments_by_name( $payment_name );
727 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'] ) {
728 $complete = true;
729 }
730 return $complete;
731 }
732
733 /**
734 * 決済リンクキー
735 * usces_filter_get_link_key
736 *
737 * @param string $linkkey Settlement link key.
738 * @param array $results Response data.
739 * @return string
740 */
741 public function get_link_key( $linkkey, $results ) {
742 if ( isset( $_REQUEST['res_tracking_id'] ) ) {
743 $linkkey = wp_unslash( $_REQUEST['res_tracking_id'] );
744 }
745 return $linkkey;
746 }
747
748 /**
749 * 受注データ復旧処理
750 * usces_action_revival_order_data
751 *
752 * @param int $order_id Order number.
753 * @param string $log_key Link key.
754 * @param string $acting_flg Payment type.
755 */
756 public function revival_orderdata( $order_id, $log_key, $acting_flg ) {
757 global $usces;
758
759 if ( ! in_array( $acting_flg, $this->pay_method ) ) {
760 return;
761 }
762
763 $data = array();
764 $data['LINK_KEY'] = $log_key;
765 $usces->set_order_meta_value( $acting_flg, serialize( $data ), $order_id );
766 $usces->set_order_meta_value( 'res_tracking_id', $log_key, $order_id );
767 }
768
769 /**
770 * 受注データから取得する決済�
771 報のキー
772 * usces_filter_settle_info_field_meta_keys
773 *
774 * @param array $keys Settlement information key.
775 * @return array
776 */
777 public function settlement_info_field_meta_keys( $keys ) {
778 $keys = array_merge( $keys, array( 'acting', 'trans_id' ) );
779 return $keys;
780 }
781
782 /**
783 * 受注編集画面に表示する決済�
784 報のキー
785 * usces_filter_settle_info_field_keys
786 *
787 * @param array $keys Settlement information keys.
788 * @param array $fields Settlement information fields.
789 * @return array
790 */
791 public function settlement_info_field_keys( $keys, $fields ) {
792 if ( isset( $fields['acting'] ) && isset( $fields['res_tracking_id'] ) ) {
793 switch ( $fields['acting'] ) {
794 case $this->acting_card:
795 case $this->acting_conv:
796 case $this->acting_payeasy:
797 case $this->acting_wallet:
798 case $this->acting_mobile:
799 case $this->acting_paypay:
800 $keys = array( 'acting', 'res_tracking_id', 'trans_id' );
801 break;
802 }
803 }
804 return $keys;
805 }
806
807 /**
808 * 受注編集画面に表示する決済�
809 報の値整形
810 * usces_filter_settle_info_field_value
811 *
812 * @param string $value Value.
813 * @param string $key Key.
814 * @param string $acting Acting type.
815 * @return string
816 */
817 public function settlement_info_field_value( $value, $key, $acting ) {
818 if ( 'acting' === $key ) {
819 if ( $this->acting_card === $value ) {
820 $value = $this->acting_name . ' カード決済';
821 } elseif ( $this->acting_conv === $value ) {
822 $value = $this->acting_name . ' コンビニ決済';
823 } elseif ( $this->acting_payeasy === $value ) {
824 $value = $this->acting_name . ' ペイジー決済';
825 } elseif ( $this->acting_wallet === $value ) {
826 $value = $this->acting_name . ' ウォレット決済';
827 } elseif ( $this->acting_mobile === $value ) {
828 $value = $this->acting_name . ' キャリア決済';
829 } elseif ( $this->acting_paypay === $value ) {
830 $value = $this->acting_name . ' PayPay オンライン決済';
831 }
832 }
833 return $value;
834 }
835
836 /**
837 * 支払方法説明
838 * usces_filter_payment_detail
839 *
840 * @param string $str Payment method description.
841 * @param array $usces_entries Entry data.
842 * @return string
843 */
844 public function payment_detail( $str, $usces_entries ) {
845 $payment = usces_get_payments_by_name( $usces_entries['order']['payment_name'] );
846 if ( isset( $payment['settlement'] ) && $this->acting_flg_conv === $payment['settlement'] ) {
847 $acting_opts = $this->get_acting_settings();
848 if ( ! empty( $acting_opts['conv_limit'] ) ) {
849 $payment_detail = __( '(', 'usces' ) . sprintf( __( 'Payment is valid for %s days from the date of order.', 'usces' ), $acting_opts['conv_limit'] ) . __( ')', 'usces' );
850 $str = apply_filters( 'usces_filter_sbps_payment_limit_conv', $payment_detail, $acting_opts['conv_limit'] );
851 }
852 }
853 return $str;
854 }
855
856 /**
857 * 支払方法 JavaScript 用決済名追加
858 * usces_filter_payments_str
859 *
860 * @param string $payments_str Payments.
861 * @param array $payment Selected payment.
862 * @return string
863 */
864 public function payments_str( $payments_str, $payment ) {
865 if ( $this->acting_flg_card === $payment['settlement'] ) {
866 if ( $this->is_activate_card() ) {
867 $payments_str .= "'" . $payment['name'] . "': '" . $this->paymod_id . "_form', ";
868 }
869 }
870 return $payments_str;
871 }
872
873 /**
874 * 支払方法 JavaScript 用決済追加
875 * usces_filter_payments_arr
876 *
877 * @param array $payments_arr Payments.
878 * @param array $payment Selected payment.
879 * @return array
880 */
881 public function payments_arr( $payments_arr, $payment ) {
882 if ( $this->acting_flg_card === $payment['settlement'] ) {
883 if ( $this->is_activate_card() ) {
884 $payments_arr[] = $this->paymod_id . '_form';
885 }
886 }
887 return $payments_arr;
888 }
889
890 /**
891 * �
892 容確認ページ [注文する] ボタン
893 * usces_filter_confirm_inform
894 *
895 * @param string $html Purchase post form.
896 * @param array $payments Payment method info.
897 * @param string $acting_flg Payment type.
898 * @param string $rand Welcart transaction key.
899 * @param string $purchase_disabled Disable purchase button.
900 * @return string
901 */
902 public function confirm_inform( $html, $payments, $acting_flg, $rand, $purchase_disabled ) {
903 global $usces;
904
905 if ( ! in_array( $acting_flg, $this->pay_method ) ) {
906 return $html;
907 }
908
909 $usces_entries = $usces->cart->get_entry();
910 $cart = $usces->cart->get_cart();
911 if ( ! $usces_entries || ! $cart ) {
912 return $html;
913 }
914 if ( ! $usces_entries['order']['total_full_price'] ) {
915 return $html;
916 }
917 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
918
919 $acting_opts = $this->get_acting_settings();
920 $usces->save_order_acting_data( $rand );
921 usces_save_order_acting_data( $rand );
922
923 $member = $usces->get_member();
924 $cust_code = ( empty( $member['ID'] ) ) ? str_replace( '-', '', mb_convert_kana( $usces_entries['customer']['tel'], 'a', 'UTF-8' ) ) : $member['ID'];
925 // $item_id = $cart[0]['post_id'];
926 $item_id = mb_convert_kana( $usces->getItemCode( $cart[0]['post_id'] ), 'a', 'UTF-8' );
927 $item_name = $usces->getItemName( $cart[0]['post_id'] );
928 if ( 1 < $cart_count ) {
929 $item_name .= ' ' . __( 'Others', 'usces' );
930 }
931 if ( 36 < mb_strlen( $item_name, 'UTF-8' ) ) {
932 $item_name = mb_substr( $item_name, 0, 30, 'UTF-8' ) . '...';
933 }
934 $item_name = esc_attr( $item_name );
935 $amount = usces_crform( $usces_entries['order']['total_full_price'], false, false, 'return', false );
936 $free1 = $acting_flg;
937 $limit_second = '600';
938
939 if ( $this->acting_flg_card === $acting_flg && isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) {
940 $cust_quick = ( isset( $_POST['cust_quick'] ) ) ? $_POST['cust_quick'] : 'off';
941 $cust_manage = ( isset( $_POST['cust_manage'] ) ) ? $_POST['cust_manage'] : 'off';
942 $token = ( isset( $_POST['token'] ) ) ? $_POST['token'] : '';
943 $token_key = ( isset( $_POST['tokenKey'] ) ) ? $_POST['tokenKey'] : '';
944 $html = '<form id="purchase_form" action="' . USCES_CART_URL . '" method="post" onKeyDown="if (event.keyCode == 13){return false;}">';
945 // if ( ! empty( $token ) && ! empty( $token_key ) ) {
946 $html .= '
947 <input type="hidden" name="cust_quick" value="' . esc_attr( $cust_quick ) . '" />
948 <input type="hidden" name="cust_manage" value="' . esc_attr( $cust_manage ) . '" />
949 <input type="hidden" name="cust_code" value="' . $cust_code . '" />
950 <input type="hidden" name="order_id" value="' . $rand . '" />
951 <input type="hidden" name="item_id" value="' . $item_id . '" />
952 <input type="hidden" name="item_name" value="' . $item_name . '" />
953 <input type="hidden" name="tax" value="" />
954 <input type="hidden" name="amount" value="' . $amount . '" />
955 <input type="hidden" name="free1" value="' . $free1 . '" />
956 <input type="hidden" name="free2" value="" />
957 <input type="hidden" name="free3" value="" />
958 <input type="hidden" name="token" value="' . esc_attr( $token ) . '" />
959 <input type="hidden" name="token_key" value="' . esc_attr( $token_key ) . '" />
960 <input type="hidden" name="limit_second" value="' . $limit_second . '" />';
961 // }
962 $html .= '<div class="send">
963 ' . apply_filters( 'usces_filter_confirm_before_backbutton', null, $payments, $acting_flg, $rand ) . '
964 <input name="backDelivery" type="submit" id="back_button" class="back_to_delivery_button" value="' . __( 'Back', 'usces' ) . '"' . apply_filters( 'usces_filter_confirm_prebutton', null ) . ' />
965 <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>
966 <input type="hidden" name="_nonce" value="' . wp_create_nonce( $acting_flg ) . '">';
967
968 } else {
969 $connection = $this->get_connection();
970 $sps_cust_no = '';
971 $sps_payment_no = '';
972 if ( $this->acting_flg_card === $acting_flg ) {
973 $pay_method = ( 'on' === $acting_opts['3d_secure'] ) ? 'credit3d2' : 'credit';
974 $acting = $this->acting_card;
975 $free_csv = '';
976 } elseif ( $this->acting_flg_conv === $acting_flg ) {
977 $pay_method = 'webcvs';
978 $acting = $this->acting_conv;
979 $conv_limit = ( isset( $acting_opts['conv_limit'] ) ) ? $acting_opts['conv_limit'] : '';
980 $free_csv = $this->set_free_csv( $usces_entries['customer'], $conv_limit );
981 } elseif ( $this->acting_flg_payeasy === $acting_flg ) {
982 $pay_method = 'payeasy';
983 $acting = $this->acting_payeasy;
984 $free_csv = $this->set_free_csv( $usces_entries['customer'] );
985 } elseif ( $this->acting_flg_wallet === $acting_flg ) {
986 $pay_method = '';
987 if ( 'on' === $acting_opts['wallet_yahoowallet'] ) {
988 $pay_method .= ',yahoowallet';
989 }
990 if ( 'on' === $acting_opts['wallet_rakutenv2'] ) {
991 $pay_method .= ',rakutenv2';
992 } elseif ( 'on' === $acting_opts['wallet_rakuten'] ) {
993 $pay_method .= ',rakuten';
994 }
995 if ( 'on' === $acting_opts['wallet_paypal'] ) {
996 $pay_method .= ',paypal';
997 }
998 if ( 'on' === $acting_opts['wallet_alipay'] ) {
999 $pay_method .= ',alipay';
1000 }
1001 $pay_method = ltrim( $pay_method, ',' );
1002 $acting = $this->acting_wallet;
1003 $free_csv = '';
1004 } elseif ( $this->acting_flg_mobile === $acting_flg ) {
1005 $pay_method = '';
1006 if ( 'on' === $acting_opts['mobile_docomo'] ) {
1007 $pay_method .= ',docomo';
1008 }
1009 if ( 'on' === $acting_opts['mobile_auone'] ) {
1010 $pay_method .= ',auone';
1011 }
1012 if ( 'on' === $acting_opts['mobile_softbank2'] ) {
1013 $pay_method .= ',softbank2';
1014 }
1015 $pay_method = ltrim( $pay_method, ',' );
1016 $acting = $this->acting_mobile;
1017 $free_csv = '';
1018 } elseif ( $this->acting_flg_paypay === $acting_flg ) {
1019 $pay_method = 'paypay';
1020 $acting = $this->acting_paypay;
1021 $free_csv = $this->set_free_csv( $usces_entries['customer'] );
1022 }
1023 $pay_type = '0';
1024 $auto_charge_type = '';
1025 $service_type = '0';
1026 $div_settle = '';
1027 $last_charge_month = '';
1028 $camp_type = '';
1029 $terminal_type = '0';
1030 $success_url = USCES_CART_URL . $usces->delim . 'acting=' . $acting . '&acting_return=1';
1031 $cancel_url = USCES_CART_URL . $usces->delim . 'acting=' . $acting . '&confirm=1';
1032 $error_url = USCES_CART_URL . $usces->delim . 'acting=' . $acting . '&acting_return=0';
1033 $pagecon_url = apply_filters( 'usces_filter_' . $this->paymod_id . '_pagecon_url', USCES_CART_URL );
1034 $request_date = wp_date( 'YmdHis' );
1035 $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'];
1036 $sps_hashcode = sha1( $sps_hashcode );
1037
1038 $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">
1039 <input type="hidden" name="pay_method" value="' . $pay_method . '" />
1040 <input type="hidden" name="merchant_id" value="' . $acting_opts['merchant_id'] . '" />
1041 <input type="hidden" name="service_id" value="' . $acting_opts['service_id'] . '" />
1042 <input type="hidden" name="cust_code" value="' . $cust_code . '" />
1043 <input type="hidden" name="sps_cust_no" value="' . $sps_cust_no . '" />
1044 <input type="hidden" name="sps_payment_no" value="' . $sps_payment_no . '" />
1045 <input type="hidden" name="order_id" value="' . $rand . '" />
1046 <input type="hidden" name="item_id" value="' . $item_id . '" />
1047 <input type="hidden" name="pay_item_id" value="" />
1048 <input type="hidden" name="item_name" value="' . $item_name . '" />
1049 <input type="hidden" name="tax" value="" />
1050 <input type="hidden" name="amount" value="' . $amount . '" />
1051 <input type="hidden" name="pay_type" value="' . $pay_type . '" />
1052 <input type="hidden" name="auto_charge_type" value="' . $auto_charge_type . '" />
1053 <input type="hidden" name="service_type" value="' . $service_type . '" />
1054 <input type="hidden" name="div_settle" value="' . $div_settle . '" />
1055 <input type="hidden" name="last_charge_month" value="' . $last_charge_month . '" />
1056 <input type="hidden" name="camp_type" value="' . $camp_type . '" />
1057 <input type="hidden" name="terminal_type" value="' . $terminal_type . '" />
1058 <input type="hidden" name="success_url" value="' . $success_url . '" />
1059 <input type="hidden" name="cancel_url" value="' . $cancel_url . '" />
1060 <input type="hidden" name="error_url" value="' . $error_url . '" />
1061 <input type="hidden" name="pagecon_url" value="' . $pagecon_url . '" />
1062 <input type="hidden" name="free1" value="' . $free1 . '" />
1063 <input type="hidden" name="free2" value="" />
1064 <input type="hidden" name="free3" value="" />
1065 <input type="hidden" name="free_csv" value="' . $free_csv . '" />
1066 <input type="hidden" name="request_date" value="' . $request_date . '" />
1067 <input type="hidden" name="limit_second" value="' . $limit_second . '" />
1068 <input type="hidden" name="sps_hashcode" value="' . $sps_hashcode . '" />';
1069 $html .= '<input type="hidden" name="dummy" value="&#65533;" />';
1070 $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>';
1071 $html .= '</form>';
1072 $html .= '<form action="' . USCES_CART_URL . '" method="post" onKeyDown="if (event.keyCode == 13){return false;}">
1073 <div class="send">
1074 ' . apply_filters( 'usces_filter_confirm_before_backbutton', null, $payments, $acting_flg, $rand ) . '
1075 <input name="backDelivery" type="submit" id="back_button" class="back_to_delivery_button" value="' . __( 'Back', 'usces' ) . '"' . apply_filters( 'usces_filter_confirm_prebutton', null ) . ' />
1076 </div>';
1077 }
1078 return $html;
1079 }
1080
1081 /**
1082 * Encode free_csv
1083 *
1084 * @param array $customer Customer data.
1085 * @param string $conv_limit Convenience store payment deadline.
1086 */
1087 public function set_free_csv( $customer, $conv_limit = '' ) {
1088 $free_csv = '';
1089 if ( ! WCUtils::is_blank( $customer['name1'] ) ) {
1090 $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'];
1091 if ( ! empty( $conv_limit ) ) {
1092 $days = sprintf( '+%d day', $conv_limit );
1093 $bill_date = wp_date( 'Ymd', strtotime( $days ) );
1094 $free_csv .= ',BILL_DATE=' . $bill_date;
1095 }
1096 $acting_opts = $this->get_acting_settings();
1097 if ( ! empty( $acting_opts['3des_key'] ) && ! empty( $acting_opts['3desinit_key'] ) ) {
1098 $free_csv = openssl_encrypt( $free_csv, 'des-ede3-cbc', $acting_opts['3des_key'], OPENSSL_RAW_DATA, $acting_opts['3desinit_key'] );
1099 }
1100 $free_csv = base64_encode( $free_csv );
1101 }
1102 return $free_csv;
1103 }
1104
1105 /**
1106 * �
1107 容確認ページ ポイントフォーム
1108 * usces_action_confirm_page_point_inform
1109 */
1110 public function e_point_inform() {
1111 $html = $this->point_inform( '' );
1112 wel_esc_script_e( $html );
1113 }
1114
1115 /**
1116 * �
1117 容確認ページ ポイントフォーム
1118 * usces_filter_confirm_point_inform
1119 *
1120 * @param string $html Input point form.
1121 * @return string
1122 */
1123 public function point_inform( $html ) {
1124 global $usces;
1125
1126 $usces_entries = $usces->cart->get_entry();
1127 $payment = usces_get_payments_by_name( $usces_entries['order']['payment_name'] );
1128 if ( $this->acting_flg_card !== $payment['settlement'] ) {
1129 return $html;
1130 }
1131
1132 $acting_opts = $this->get_acting_settings();
1133 if ( isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) {
1134 $html .= '
1135 <input type="hidden" name="token" value="' . esc_attr( $_POST['token'] ) . '">
1136 <input type="hidden" name="tokenKey" value="' . esc_attr( $_POST['tokenKey'] ) . '">';
1137 if ( isset( $_POST['cust_quick'] ) ) {
1138 $html .= '
1139 <input type="hidden" name="cust_quick" value="' . esc_attr( $_POST['cust_quick'] ) . '">';
1140 }
1141 if ( isset( $_POST['cust_manage'] ) ) {
1142 $html .= '
1143 <input type="hidden" name="cust_manage" value="' . esc_attr( $_POST['cust_manage'] ) . '">';
1144 }
1145 }
1146 return $html;
1147 }
1148
1149 /**
1150 * 決済処理
1151 * usces_action_acting_processing
1152 *
1153 * @param string $acting_flg Acting type.
1154 * @param array $post_query Post data.
1155 */
1156 public function acting_processing( $acting_flg, $post_query ) {
1157 global $usces;
1158
1159 if ( ! in_array( $acting_flg, $this->pay_method ) ) {
1160 return;
1161 }
1162 $usces_entries = $usces->cart->get_entry();
1163 $cart = $usces->cart->get_cart();
1164 if ( ! $usces_entries || ! $cart ) {
1165 wp_redirect( USCES_CART_URL );
1166 exit;
1167 }
1168 if ( ! wp_verify_nonce( $_REQUEST['_nonce'], $acting_flg ) ) {
1169 wp_redirect( USCES_CART_URL );
1170 exit;
1171 }
1172
1173 $usces->error_message = $usces->zaiko_check();
1174 if ( '' !== $usces->error_message || 0 === $usces->cart->num_row() ) {
1175 wp_redirect( USCES_CART_URL );
1176 exit();
1177 }
1178
1179 $acting_opts = $this->get_acting_settings();
1180 parse_str( $post_query, $post_data );
1181 $connection = $this->get_connection();
1182
1183 if ( $this->acting_flg_card === $acting_flg && isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) {
1184 $item_name = trim( mb_convert_encoding( $post_data['item_name'], 'SJIS', 'UTF-8' ) );
1185 $free1 = trim( $post_data['free1'] );
1186 $order_rowno = '1';
1187 if ( isset( $post_data['cust_quick'] ) ) {
1188 if ( 'quick' === $post_data['cust_quick'] ) {
1189 $token = '';
1190 $token_key = '';
1191 $cust_manage_flg = '0';
1192 } else {
1193 $token = trim( $post_data['token'] );
1194 $token_key = trim( $post_data['token_key'] );
1195 $cust_manage_flg = ( 'save' === $post_data['cust_manage'] || 'change' === $post_data['cust_manage'] ) ? '1' : '0';
1196 }
1197 } else {
1198 $token = trim( $post_data['token'] );
1199 $token_key = trim( $post_data['token_key'] );
1200 $cust_manage_flg = ( isset( $post_data['cust_manage'] ) && 'save' === $post_data['cust_manage'] ) ? '1' : '0';
1201 }
1202 $cardbrand_return_flg = '0';
1203 $encrypted_flg = '1';
1204 $request_date = wp_date( 'YmdHis' );
1205 $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'];
1206 $sps_hashcode = sha1( $sps_hashcode );
1207
1208 /* 決済要求 */
1209 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
1210 <sps-api-request id="ST01-00131-101">
1211 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
1212 <service_id>' . $acting_opts['service_id'] . '</service_id>
1213 <cust_code>' . trim( $post_data['cust_code'] ) . '</cust_code>
1214 <order_id>' . trim( $post_data['order_id'] ) . '</order_id>
1215 <item_id>' . trim( $post_data['item_id'] ) . '</item_id>
1216 <item_name>' . base64_encode( $item_name ) . '</item_name>
1217 <amount>' . trim( $post_data['amount'] ) . '</amount>
1218 <free1>' . base64_encode( $free1 ) . '</free1>
1219 <order_rowno>' . $order_rowno . '</order_rowno>
1220 <pay_option_manage>
1221 <token>' . $token . '</token>
1222 <token_key>' . $token_key . '</token_key>
1223 <cust_manage_flg>' . $cust_manage_flg . '</cust_manage_flg>
1224 <cardbrand_return_flg>' . $cardbrand_return_flg . '</cardbrand_return_flg>
1225 </pay_option_manage>
1226 <encrypted_flg>' . $encrypted_flg . '</encrypted_flg>
1227 <request_date>' . $request_date . '</request_date>
1228 <limit_second>' . trim( $post_data['limit_second'] ) . '</limit_second>
1229 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
1230 </sps-api-request>';
1231 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
1232 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_card, $encrypted_flg );
1233 if ( isset( $response_settlement['res_result'] ) && 'OK' === $response_settlement['res_result'] ) {
1234 $sps_transaction_id = $response_settlement['res_sps_transaction_id'];
1235 $tracking_id = $response_settlement['res_tracking_id'];
1236 $request_date = wp_date( 'YmdHis' );
1237 $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'];
1238 $sps_hashcode = sha1( $sps_hashcode );
1239
1240 /* 確定要求 */
1241 $request_credit = '<?xml version="1.0" encoding="Shift_JIS"?>
1242 <sps-api-request id="ST02-00101-101">
1243 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
1244 <service_id>' . $acting_opts['service_id'] . '</service_id>
1245 <sps_transaction_id>' . $sps_transaction_id . '</sps_transaction_id>
1246 <tracking_id>' . $tracking_id . '</tracking_id>
1247 <processing_datetime></processing_datetime>
1248 <request_date>' . $request_date . '</request_date>
1249 <limit_second>' . trim( $post_data['limit_second'] ) . '</limit_second>
1250 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
1251 </sps-api-request>';
1252 $xml_credit = $this->get_xml_response( $connection['api_url'], $request_credit );
1253 $response_credit = $this->xml2assoc( $xml_credit, $this->acting_card );
1254 if ( isset( $response_credit['res_result'] ) && 'OK' === $response_credit['res_result'] ) {
1255 if ( isset( $acting_opts['sales'] ) && 'auto' === $acting_opts['sales'] ) {
1256 $process_date = $response_credit['res_process_date'];
1257 $request_date = wp_date( 'YmdHis' );
1258 $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'];
1259 $sps_hashcode = sha1( $sps_hashcode );
1260
1261 /* 売上要求(自動売上)*/
1262 $request_sales = '<?xml version="1.0" encoding="Shift_JIS"?>
1263 <sps-api-request id="ST02-00201-101">
1264 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
1265 <service_id>' . $acting_opts['service_id'] . '</service_id>
1266 <sps_transaction_id>' . $sps_transaction_id . '</sps_transaction_id>
1267 <tracking_id>' . $tracking_id . '</tracking_id>
1268 <processing_datetime>' . $process_date . '</processing_datetime>
1269 <pay_option_manage>
1270 <amount>' . trim( $post_data['amount'] ) . '</amount>
1271 </pay_option_manage>
1272 <request_date>' . $request_date . '</request_date>
1273 <limit_second>' . trim( $post_data['limit_second'] ) . '</limit_second>
1274 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
1275 </sps-api-request>';
1276 $xml_sales = $this->get_xml_response( $connection['api_url'], $request_sales );
1277 $response_sales = $this->xml2assoc( $xml_sales, $this->acting_card );
1278 if ( isset( $response_sales['res_result'] ) && 'OK' === $response_sales['res_result'] ) {
1279 $result_data = array(
1280 'acting' => $this->acting_card,
1281 'acting_return' => 1,
1282 'res_result' => $response_sales['res_result'],
1283 'res_tracking_id' => $tracking_id,
1284 'res_sps_transaction_id' => $response_sales['res_sps_transaction_id'],
1285 'res_process_date' => $response_sales['res_process_date'],
1286 'res_pay_method' => 'sales',
1287 'trans_id' => $post_data['order_id'],
1288 );
1289 wp_redirect( add_query_arg( $result_data, USCES_CART_URL ) );
1290 exit;
1291
1292 } else {
1293 $res_err_code = ( isset( $response_sales['res_err_code'] ) ) ? $response_sales['res_err_code'] : 'ST02-00201-101 Error';
1294 $data = ( ! empty( $response_sales ) ) ? $response_sales : $xml_sales;
1295 $log = array(
1296 'acting' => $this->acting_card,
1297 'key' => $post_data['order_id'],
1298 'result' => $res_err_code,
1299 'data' => $data,
1300 );
1301 usces_save_order_acting_error( $log );
1302 $result_data = array(
1303 'acting' => $this->acting_card,
1304 'acting_return' => 0,
1305 'res_err_code' => $res_err_code,
1306 );
1307 wp_redirect( add_query_arg( $result_data, USCES_CART_URL ) );
1308 exit;
1309 }
1310
1311 } else {
1312 /* 指定売上 */
1313 $result_data = array(
1314 'acting' => $this->acting_card,
1315 'acting_return' => 1,
1316 'res_result' => $response_credit['res_result'],
1317 'res_tracking_id' => $tracking_id,
1318 'res_sps_transaction_id' => $response_credit['res_sps_transaction_id'],
1319 'res_process_date' => $response_credit['res_process_date'],
1320 'res_pay_method' => 'manual',
1321 'trans_id' => $post_data['order_id'],
1322 );
1323 wp_redirect( add_query_arg( $result_data, USCES_CART_URL ) );
1324 exit;
1325 }
1326
1327 } else {
1328 $res_err_code = ( isset( $response_credit['res_err_code'] ) ) ? $response_credit['res_err_code'] : 'ST02-00101-101 Error';
1329 $data = ( ! empty( $response_credit ) ) ? $response_credit : $xml_credit;
1330 $log = array(
1331 'acting' => $this->acting_card,
1332 'key' => $post_data['order_id'],
1333 'result' => $res_err_code,
1334 'data' => $data,
1335 );
1336 usces_save_order_acting_error( $log );
1337 $result_data = array(
1338 'acting' => $this->acting_card,
1339 'acting_return' => 0,
1340 'res_err_code' => $res_err_code,
1341 );
1342 wp_redirect( add_query_arg( $result_data, USCES_CART_URL ) );
1343 exit;
1344 }
1345
1346 } else {
1347 $res_err_code = ( isset( $response_settlement['res_err_code'] ) ) ? $response_settlement['res_err_code'] : 'ST01-00131-101 Error';
1348 $data = ( ! empty( $response_settlement ) ) ? $response_settlement : $xml_settlement;
1349 $log = array(
1350 'acting' => $this->acting_card,
1351 'key' => $post_data['order_id'],
1352 'result' => $res_err_code,
1353 'data' => $data,
1354 );
1355 usces_save_order_acting_error( $log );
1356 $result_data = array(
1357 'acting' => $this->acting_card,
1358 'acting_return' => 0,
1359 'res_err_code' => $res_err_code,
1360 );
1361 wp_redirect( add_query_arg( $result_data, USCES_CART_URL ) );
1362 exit;
1363 }
1364
1365 exit;
1366 }
1367 }
1368
1369 /**
1370 * Get XML response
1371 *
1372 * @param string $url Send URL.
1373 * @param array $data Send data.
1374 * @return string
1375 */
1376 protected function get_xml_response( $url, $data ) {
1377 $acting_opts = $this->get_acting_settings();
1378 $interface = parse_url( $url );
1379
1380 $header = 'POST ' . $url . " HTTP/1.1\r\n";
1381 $header .= 'Host: ' . $interface['host'] . "\r\n";
1382 $header .= 'Authorization: Basic ' . base64_encode( $acting_opts['basic_id'] . ':' . $acting_opts['basic_password'] ) . "\r\n";
1383 $header .= "User-Agent: PHP Script\r\n";
1384 $header .= "Content-Type: text/xml\r\n";
1385 $header .= 'Content-Length: ' . strlen( $data ) . "\r\n";
1386 $header .= "Connection: close\r\n\r\n";
1387 $header .= $data;
1388
1389 $fp = @stream_socket_client( 'tlsv1.2://' . $interface['host'] . ':443', $errno, $errstr, 30 );
1390 if ( ! $fp ) {
1391 // usces_log( $this->paymod_id . ' API : TLS(v1.2) Error', 'acting_transaction.log' );
1392 }
1393
1394 $xml = '';
1395 if ( $fp ) {
1396 fwrite( $fp, $header );
1397 while ( ! feof( $fp ) ) {
1398 $code = fgets( $fp, 1024 );
1399 if ( false !== strpos( $code, '>' ) ) {
1400 $xml .= $code;
1401 }
1402 }
1403 fclose( $fp );
1404 }
1405 return $xml;
1406 }
1407
1408 /**
1409 * XML to Associative Array
1410 *
1411 * @param object $xml_data XML data.
1412 * @param string $acting Acting type.
1413 * @param int $encrypted_flg Encrypted flag.
1414 * @return array
1415 */
1416 protected function xml2assoc( $xml_data, $acting, $encrypted_flg = 0 ) {
1417 $array_data = array();
1418 if ( $this->is_valid_xml( $xml_data, $acting ) ) {
1419 $object_data = simplexml_load_string( $xml_data );
1420 $json_data = json_encode( $object_data );
1421 $array_data = json_decode( $json_data, true );
1422 if ( 1 === (int) $encrypted_flg ) {
1423 $acting_opts = $this->get_acting_settings();
1424 if ( isset( $array_data['res_pay_method_info'] ) && ! empty( $acting_opts['3des_key'] ) && ! empty( $acting_opts['3desinit_key'] ) ) {
1425 foreach ( $array_data['res_pay_method_info'] as $info => $value ) {
1426 $value = base64_decode( $value );
1427 $value = openssl_decrypt( $value, 'des-ede3-cbc', $acting_opts['3des_key'], OPENSSL_NO_PADDING, $acting_opts['3desinit_key'] );
1428 $array_data['res_pay_method_info'][ $info ] = trim( $value );
1429 }
1430 }
1431 if ( isset( $array_data['pay_method_info'] ) && ! empty( $acting_opts['3des_key'] ) && ! empty( $acting_opts['3desinit_key'] ) ) {
1432 foreach ( $array_data['pay_method_info'] as $info => $value ) {
1433 $value = base64_decode( $value );
1434 $value = openssl_decrypt( $value, 'des-ede3-cbc', $acting_opts['3des_key'], OPENSSL_NO_PADDING, $acting_opts['3desinit_key'] );
1435 $array_data['pay_method_info'][ $info ] = trim( $value );
1436 }
1437 }
1438 }
1439 }
1440 return $array_data;
1441 }
1442
1443 /**
1444 * XML Validator.
1445 *
1446 * @param object $xml_data XML data.
1447 * @param string $acting Acting type.
1448 * @return boolean
1449 */
1450 private function is_valid_xml( $xml_data, $acting ) {
1451 if ( ! empty( $xml_data ) ) {
1452 if ( stripos( $xml_data, '<?xml version=' ) !== false ) {
1453 return true;
1454 }
1455 }
1456 $log = array(
1457 'acting' => $acting,
1458 'key' => '(empty)',
1459 'result' => 'XML validation error',
1460 'data' => array( 'response' => $xml_data ),
1461 );
1462 usces_save_order_acting_error( $log );
1463 return false;
1464 }
1465
1466 /**
1467 * 決済完了ページ制御
1468 * usces_filter_check_acting_return_results
1469 *
1470 * @param array $results Result data.
1471 * @return array
1472 */
1473 public function acting_return( $results ) {
1474 if ( ! in_array( 'acting_' . $results['acting'], $this->pay_method ) ) {
1475 return $results;
1476 }
1477 if ( isset( $results['acting_return'] ) && 1 !== (int) $results['acting_return'] ) {
1478 return $results;
1479 }
1480
1481 if ( isset( $_REQUEST['cancel'] ) ) {
1482 $results[0] = 0;
1483 $results['reg_order'] = false;
1484 } else {
1485 $acting_opts = $this->get_acting_settings();
1486 if ( isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) {
1487 if ( isset( $_REQUEST['res_result'] ) && 'OK' === $_REQUEST['res_result'] ) {
1488 $results[0] = 1;
1489 $results['reg_order'] = true;
1490 } else {
1491 $results[0] = 0;
1492 $results['reg_order'] = false;
1493 }
1494 } else {
1495 if ( isset( $_REQUEST['res_result'] ) && 'OK' === $_REQUEST['res_result'] ) {
1496 $results[0] = 1;
1497 } else {
1498 $results[0] = 0;
1499 }
1500 $results['reg_order'] = false;
1501 }
1502 }
1503 return $results;
1504 }
1505
1506 /**
1507 * 重複オーダー禁止処理
1508 * usces_filter_check_acting_return_duplicate
1509 *
1510 * @param string $trans_id Transaction ID.
1511 * @param array $results Result data.
1512 * @return string
1513 */
1514 public function check_acting_return_duplicate( $trans_id, $results ) {
1515 global $usces;
1516
1517 $acting = ( isset( $_GET['acting'] ) ) ? wp_unslash( $_GET['acting'] ) : '';
1518 $acting_flg = 'acting_' . $acting;
1519 if ( in_array( $acting_flg, $this->pay_method ) ) {
1520 if ( isset( $_REQUEST['order_id'] ) ) {
1521 $trans_id = wp_unslash( $_REQUEST['order_id'] );
1522 }
1523 }
1524 return $trans_id;
1525 }
1526
1527 /**
1528 * 受注データ登録
1529 * usces_action_reg_orderdata
1530 *
1531 * @param string $args {
1532 * The array of Order related data.
1533 * @type array $cart Cart data.
1534 * @type array $entry Entry data.
1535 * @type int $order_id Order ID.
1536 * @type int $member_id Member ID.
1537 * @type array $payments Payment data.
1538 * @type int $charging_type Charging type.
1539 * @type array $results Results data.
1540 * }
1541 */
1542 public function register_orderdata( $args ) {
1543 global $usces;
1544 extract( $args );
1545
1546 $acting_flg = $payments['settlement'];
1547 if ( ! in_array( $acting_flg, $this->pay_method ) ) {
1548 return;
1549 }
1550 if ( ! $entry['order']['total_full_price'] ) {
1551 return;
1552 }
1553
1554 if ( isset( $results['res_tracking_id'] ) ) {
1555 $usces->set_order_meta_value( 'res_tracking_id', $results['res_tracking_id'], $order_id );
1556 $usces->set_order_meta_value( 'wc_trans_id', $results['res_tracking_id'], $order_id );
1557 if ( isset( $results['order_id'] ) ) {
1558 $usces->set_order_meta_value( 'trans_id', $results['order_id'], $order_id );
1559 } elseif ( isset( $results['trans_id'] ) ) {
1560 $usces->set_order_meta_value( 'trans_id', $results['trans_id'], $order_id );
1561 }
1562 if ( ! isset( $results['acting'] ) ) {
1563 $results['acting'] = substr( $acting_flg, 7 );
1564 }
1565 if ( isset( $results['acting_return'] ) ) {
1566 unset( $results['acting_return'] );
1567 unset( $results['page_id'] );
1568 unset( $results['0'] );
1569 unset( $results['reg_order'] );
1570 }
1571 $usces->set_order_meta_value( $acting_flg, usces_serialize( $results ), $order_id );
1572 }
1573 }
1574
1575 /**
1576 * 会員データ削除
1577 * usces_action_pre_delete_memberdata
1578 *
1579 * @param string $member_id Member ID.
1580 */
1581 public function delete_member( $member_id ) {
1582 $this->api_customer_delete( $member_id );
1583 }
1584
1585 /**
1586 * 決済エラーメッセージ
1587 * usces_filter_get_error_settlement
1588 *
1589 * @param string $html Credit card number error.
1590 * @return string Credit card number re-entry message.
1591 */
1592 public function error_page_message( $html ) {
1593 if ( isset( $_REQUEST['acting'] ) && $this->acting_card === $_REQUEST['acting'] ) {
1594 if ( isset( $_GET['res_err_code'] ) && '101' === substr( $_GET['res_err_code'], 0, 3 ) ) {
1595 $html .= '<div class="support_box">
1596 クレジットカード�
1597 報に誤りがあります。<br />カード番号を再�
1598 �力する場合は、こちらをクリックしてください。<br /><br />
1599 <p class="return_settlement"><a href="' . add_query_arg( array( 'backDelivery' => $this->acting_card, 're-enter' => 1 ), USCES_CUSTOMER_URL ) . '">カード番号の再�
1600 �力</a></p>
1601 </div>';
1602 }
1603 }
1604 return $html;
1605 }
1606
1607 /**
1608 * 購�
1609 �完了メッセージ
1610 * usces_filter_completion_settlement_message
1611 *
1612 * @param string $html Purchase complete message.
1613 * @param array $usces_entries Entry data.
1614 * @return string
1615 */
1616 public function completion_settlement_message( $html, $usces_entries ) {
1617 if ( isset( $_REQUEST['acting'] ) && ( $this->acting_conv === $_REQUEST['acting'] || $this->acting_payeasy === $_REQUEST['acting'] ) ) {
1618 $title = ( $this->acting_conv === $_REQUEST['acting'] ) ? 'コンビニ決済' : 'ペイジー決済';
1619 $html .= '<div id="status_table"><h5>' . $this->acting_formal_name . ' ' . $title . '</h5>';
1620 $html .= '<p>' . sprintf( __( 'Information on payment will be mailed to %s.', 'usces' ), esc_html( $usces_entries['customer']['mailaddress1'] ) ) . '</p>';
1621 $html .= '</div>';
1622 }
1623 return $html;
1624 }
1625
1626 /**
1627 * フロントスクリプト
1628 * wp_enqueue_scripts
1629 */
1630 public function enqueue_scripts() {
1631 global $usces;
1632
1633 /* 発送・支払方法ページ */
1634 if ( ! is_admin() && 'delivery' === $usces->page && $this->is_validity_acting( 'card' ) ) :
1635 $acting_opts = $this->get_acting_settings();
1636 if ( isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) :
1637 $connection = $this->get_connection();
1638 ?>
1639 <script type="text/javascript" src="<?php echo esc_url( $connection['token_url'] ); ?>"></script>
1640 <?php
1641 endif;
1642 endif;
1643 }
1644
1645 /**
1646 * フロントスクリプト
1647 * wp_print_footer_scripts
1648 */
1649 public function footer_scripts() {
1650 global $usces;
1651
1652 /* 発送・支払方法ページ */
1653 if ( $this->is_validity_acting( 'card' ) && $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) && 'delivery' === $usces->page ) {
1654 $acting_opts = $this->get_acting_settings();
1655 if ( isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) {
1656 wp_register_style( 'sbps-token-style', USCES_FRONT_PLUGIN_URL . '/css/sbps_token.css' );
1657 wp_enqueue_style( 'sbps-token-style' );
1658 wp_register_script( 'usces_cart_sbps', USCES_FRONT_PLUGIN_URL . '/js/cart_sbps.js', array( 'jquery' ), USCES_VERSION, true );
1659 $sbps_params = array();
1660 $sbps_params['sbps_merchantId'] = $acting_opts['merchant_id'];
1661 $sbps_params['sbps_serviceId'] = $acting_opts['service_id'];
1662 $sbps_params['message'] = array(
1663 'error_token' => __( 'Credit card information is not appropriate.', 'usces' ),
1664 'error_card_number' => __( 'The card number is not a valid credit card number.', 'usces' ),
1665 'error_card_expym' => __( 'The card\'s expiration date is invalid.', 'usces' ),
1666 'error_card_seccd' => __( 'The card\'s security code is invalid.', 'usces' ),
1667 );
1668 wp_localize_script( 'usces_cart_sbps', 'sbps_params', $sbps_params );
1669 wp_enqueue_script( 'usces_cart_sbps' );
1670 }
1671 }
1672 }
1673
1674 /**
1675 * カード�
1676 報�
1677 �力チェック
1678 * usces_filter_delivery_check
1679 *
1680 * @param string $mes Validation check message.
1681 * @return string
1682 */
1683 public function delivery_check( $mes ) {
1684 global $usces;
1685
1686 if ( ! isset( $_POST['offer']['payment_name'] ) ) {
1687 return $mes;
1688 }
1689
1690 if ( ! empty( $mes ) ) {
1691 return $mes;
1692 }
1693
1694 $payment = $usces->getPayments( $_POST['offer']['payment_name'] );
1695 if ( $this->acting_flg_card === $payment['settlement'] ) {
1696 $acting_opts = $this->get_acting_settings();
1697 if ( isset( $acting_opts['card_activate'] ) && 'token' === $acting_opts['card_activate'] ) {
1698 if ( isset( $_POST['cust_quick'] ) && 'quick' === $_POST['cust_quick'] ) {
1699 } else {
1700 if ( ( isset( $_POST['token'] ) && empty( $_POST['token'] ) ) &&
1701 ( isset( $_POST['tokenKey'] ) && empty( $_POST['tokenKey'] ) ) ) {
1702 $mes .= __( 'Please enter the card information correctly.', 'usces' ) . '<br />';
1703 } else {
1704 if ( ! wel_check_credit_security() ) {
1705 $mes .= __( 'Update has been locked. Please contact the store administrator.', 'usces' ) . '<br />';
1706 }
1707 }
1708 }
1709 }
1710 }
1711 return $mes;
1712 }
1713
1714 /**
1715 * 支払方法ページ用�
1716 �力フォーム
1717 * usces_filter_delivery_secure_form_loop
1718 *
1719 * @param string $nouse Empty.
1720 * @param array $payment Payment data.
1721 * @return string
1722 */
1723 public function delivery_secure_form_loop( $nouse, $payment ) {
1724 global $usces;
1725
1726 $html = '';
1727 if ( $this->acting_flg_card === $payment['settlement'] ) {
1728 $acting_opts = $this->get_acting_settings();
1729 if ( ( ! isset( $acting_opts['activate'] ) || 'on' !== $acting_opts['activate'] ) ||
1730 ( ! isset( $acting_opts['card_activate'] ) || 'token' !== $acting_opts['card_activate'] ) ||
1731 'activate' !== $payment['use'] ) {
1732 return $html;
1733 }
1734
1735 $re_enter = ( isset( $_REQUEST['re_enter'] ) && false !== strpos( $_REQUEST['re_enter'], $this->paymod_id . '_card' ) ) ? true : false;
1736
1737 $cust_code = '';
1738 if ( usces_is_login() ) {
1739 $member = $usces->get_member();
1740 $cust_code = $member['ID'];
1741 }
1742
1743 $cust_ref = array();
1744 if ( 'on' === $acting_opts['cust_manage'] || 'choice' === $acting_opts['cust_manage'] ) {
1745 if ( ! empty( $cust_code ) ) {
1746 $cust_ref = $this->api_customer_reference( $cust_code );
1747 }
1748 }
1749
1750 $html .= '<table class="customer_form" id="' . $this->paymod_id . '_form">';
1751 $html .= '<tr><th scope="row">' . __( 'Credit card information', 'usces' ) . '</th><td>';
1752
1753 if ( 'off' !== $acting_opts['cust_manage'] && ! empty( $cust_ref['cc_number'] ) ) {
1754 $cardlast4 = substr( $cust_ref['cc_number'], -4 );
1755 $html .= '<p><label><input type="radio" name="cust_quick" class="cust_quick" id="cust_quick_use" value="quick"><span>登録済みのクレジットカードを使う</span></label></p>';
1756 $html .= '<div class="sbps_registerd_card_area">';
1757 $html .= '<div>登録済みのカード番号下4桁<span class="cc_cardlast4">' . $cardlast4 . '</span></div>';
1758 $html .= '</div>';
1759 $html .= '<p><label><input type="radio" name="cust_quick" class="cust_quick" id="cust_quick_new" value="new"><span>新しいクレジットカードを使う</span></label></p>';
1760 }
1761
1762 $html .= '<div class="sbps_new_card_area">';
1763 $html .= '<dl>';
1764 $html .= '<dt>' . __( 'card number', 'usces' ) . '</dt>
1765 <dd><input type="tel" class="cc_number" id="cc_number" maxlength="16" value=""></dd>';
1766
1767 if ( 'off' !== $acting_opts['cust_manage'] ) {
1768 if ( usces_have_regular_order() || usces_have_continue_charge() ) {
1769 $html .= '<input type="hidden" name="cust_manage" value="save" />';
1770 } elseif ( 'on' === $acting_opts['cust_manage'] ) {
1771 $html .= '<input type="hidden" name="cust_manage" value="save" />';
1772 } elseif ( 'choice' === $acting_opts['cust_manage'] ) {
1773 if ( ! empty( $cust_ref['cc_number'] ) ) {
1774 $html .= '<dd><label><input type="checkbox" name="cust_manage" id="cust_manage" value="change"><span id="cust_manage_label">登録済のカードを変更して購�
1775 �する</span></label></dd>';
1776 } else {
1777 $html .= '<dd><label><input type="checkbox" name="cust_manage" id="cust_manage" value="save"><span id="cust_manage_label">クレジットカードを登録して購�
1778 �する</span></label></dd>';
1779 }
1780 }
1781 }
1782 $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>' );
1783 $html .= $cardno_attention;
1784
1785 $html .= '<dt>' . __( 'Card expiration', 'usces' ) . '</dt>
1786 <dd><select class="cc_expmm" id="cc_expmm">
1787 <option value="">--</option>';
1788 for ( $i = 1; $i <= 12; $i++ ) {
1789 $html .= '
1790 <option value="' . sprintf( '%02d', $i ) . '">' . sprintf( '%02d', $i ) . '</option>';
1791 }
1792 $html .= '
1793 </select>' . __( 'month', 'usces' ) . '&nbsp;
1794 <select class="cc_expyy" id="cc_expyy">
1795 <option value="">----</option>';
1796 for ( $i = 0; $i <= 15; $i++ ) {
1797 $year = wp_date( 'Y' ) + $i;
1798 $html .= '
1799 <option value="' . $year . '">' . $year . '</option>';
1800 }
1801 $html .= '
1802 </select>' . __( 'year', 'usces' ) . '</dd>
1803 <dt>' . __( 'security code', 'usces' ) . '</dt>
1804 <dd><input type="tel" class="cc_seccd" id="cc_seccd" maxlength="4" value=""></dd>';
1805 $seccd_attention = apply_filters( 'usces_filter_seccd_attention', '' );
1806 $html .= $seccd_attention;
1807 $html .= '
1808 </dl>
1809 </div>';
1810 $html .= '
1811 <input type="hidden" name="acting" value="' . $this->paymod_id . '" />
1812 <input type="hidden" name="confirm" value="confirm" />
1813 <input type="hidden" name="token" id="token" value="" />
1814 <input type="hidden" name="tokenKey" id="tokenKey" value="" />';
1815 $html .= '</td></tr>';
1816 $html .= '</table>';
1817 }
1818 return $html;
1819 }
1820
1821 /**
1822 * 会員データ編集画面 カード�
1823 報登録�
1824
1825 * usces_action_admin_member_info
1826 *
1827 * @param array $member Member data.
1828 * @param array $member_metas Member meta data.
1829 * @param array $usces_member_history Member's history order data.
1830 */
1831 public function admin_member_info( $member, $member_metas, $usces_member_history ) {
1832 if ( 0 < count( $usces_member_history ) ) :
1833 $acting_opts = $this->get_acting_settings();
1834 if ( isset( $acting_opts['card_activate'] ) ) :
1835 $cust_ref = $this->api_customer_reference( $member['ID'] );
1836 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) :
1837 $cardlast4 = substr( $cust_ref['cc_number'], -4 );
1838 $expyy = substr( $cust_ref['cc_expiration'], 0, 4 );
1839 $expmm = substr( $cust_ref['cc_expiration'], 4, 2 );
1840 ?>
1841 <tr>
1842 <td class="label"><?php esc_html_e( 'Lower 4 digits', 'usces' ); ?></td>
1843 <td><div class="rod_left shortm"><?php echo esc_html( $cardlast4 ); ?></div></td>
1844 </tr>
1845 <tr>
1846 <td class="label"><?php esc_html_e( 'Expiration date', 'usces' ); ?></td>
1847 <td><div class="rod_left shortm"><?php echo esc_html( $expyy . '/' . $expmm ); ?></div></td>
1848 </tr>
1849 <tr>
1850 <td class="label">カード�
1851 </td>
1852 <td><div class="rod_left shortm"><?php esc_html_e( 'Registered', 'usces' ); ?></div></td>
1853 </tr>
1854 <?php
1855 if ( ! usces_have_member_continue_order( $member['ID'] ) && ! usces_have_member_regular_order( $member['ID'] ) ) :
1856 ?>
1857 <tr>
1858 <td class="label"><input type="checkbox" name="sbps_quick" id="sbps-quick-release" value="release"></td>
1859 <td><label for="sbps-quick-release">カード�
1860 報の登録を解除する</label></td>
1861 </tr>
1862 <?php
1863 endif;
1864 endif;
1865 endif;
1866 endif;
1867 }
1868
1869 /**
1870 * 会員データ編集画面 カード�
1871 報登録解除
1872 * usces_action_post_update_memberdata
1873 *
1874 * @param string $member_id Member ID.
1875 * @param boolean $res Deletable.
1876 */
1877 public function admin_update_memberdata( $member_id, $res ) {
1878 if ( ! $this->is_activate_card() || false === $res ) {
1879 return;
1880 }
1881 if ( isset( $_POST['sbps_quick'] ) && 'release' === $_POST['sbps_quick'] ) {
1882 $this->api_customer_delete( $member_id );
1883 }
1884 }
1885
1886 /**
1887 * Get order_id by meta_data
1888 *
1889 * @param string $res_tracking_id Tracking ID.
1890 * @return int
1891 */
1892 protected function get_order_id( $res_tracking_id ) {
1893 global $wpdb;
1894
1895 $order_meta_table_name = $wpdb->prefix . 'usces_order_meta';
1896 $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 );
1897 $order_id = $wpdb->get_var( $query );
1898 return $order_id;
1899 }
1900
1901 /**
1902 * Get order_status by order data
1903 *
1904 * @param int $order_id Order number.
1905 * @return string
1906 */
1907 protected function get_order_status( $order_id ) {
1908 global $wpdb;
1909
1910 $order_table_name = $wpdb->prefix . 'usces_order';
1911 $query = $wpdb->prepare( "SELECT `order_status` FROM $order_table_name WHERE `ID` = %d", $order_id );
1912 $order_status = $wpdb->get_var( $query );
1913 return $order_status;
1914 }
1915
1916 /**
1917 * Get customers card data
1918 *
1919 * @param string $cust_code Member ID.
1920 * @return array
1921 */
1922 protected function api_customer_reference( $cust_code ) {
1923 global $wpdb;
1924
1925 $cust_ref = array();
1926 $acting_opts = $this->get_acting_settings();
1927 if ( empty( $acting_opts['3des_key'] ) || empty( $acting_opts['3desinit_key'] ) ) {
1928 return $cust_ref;
1929 }
1930 $connection = $this->get_connection();
1931
1932 $sps_cust_info_return_flg = '1';
1933 $response_info_type = '2';
1934 $cardbrand_return_flg = '0';
1935 $encrypted_flg = '1';
1936 $request_date = wp_date( 'YmdHis' );
1937 $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'];
1938 $sps_hashcode = sha1( $sps_hashcode );
1939
1940 /* クレジットカード�
1941 報参�
1942 �要求 */
1943 $request_cust_ref = '<?xml version="1.0" encoding="Shift_JIS"?>
1944 <sps-api-request id="MG02-00104-101">
1945 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
1946 <service_id>' . $acting_opts['service_id'] . '</service_id>
1947 <cust_code>' . $cust_code . '</cust_code>
1948 <sps_cust_info_return_flg>' . $sps_cust_info_return_flg . '</sps_cust_info_return_flg>
1949 <response_info_type>' . $response_info_type . '</response_info_type>
1950 <pay_option_manage>
1951 <cardbrand_return_flg>' . $cardbrand_return_flg . '</cardbrand_return_flg>
1952 </pay_option_manage>
1953 <encrypted_flg>' . $encrypted_flg . '</encrypted_flg>
1954 <request_date>' . $request_date . '</request_date>
1955 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
1956 </sps-api-request>';
1957 $xml_cust_ref = $this->get_xml_response( $connection['api_url'], $request_cust_ref );
1958 $response_cust_ref = $this->xml2assoc( $xml_cust_ref, $this->acting_card );
1959 if ( isset( $response_cust_ref['res_result'] ) ) {
1960 $cust_ref['result'] = $response_cust_ref['res_result'];
1961 if ( 'OK' === $response_cust_ref['res_result'] ) {
1962 if ( isset( $response_cust_ref['res_pay_method_info']['cc_number'] ) && ! empty( $acting_opts['3des_key'] ) && ! empty( $acting_opts['3desinit_key'] ) ) {
1963 $cc_number = base64_decode( $response_cust_ref['res_pay_method_info']['cc_number'] );
1964 $cust_ref['cc_number'] = openssl_decrypt( $cc_number, 'des-ede3-cbc', $acting_opts['3des_key'], OPENSSL_NO_PADDING, $acting_opts['3desinit_key'] );
1965 }
1966 if ( isset( $response_cust_ref['res_pay_method_info']['cc_expiration'] ) && ! empty( $acting_opts['3des_key'] ) && ! empty( $acting_opts['3desinit_key'] ) ) {
1967 $cc_expiration = base64_decode( $response_cust_ref['res_pay_method_info']['cc_expiration'] );
1968 $cust_ref['cc_expiration'] = openssl_decrypt( $cc_expiration, 'des-ede3-cbc', $acting_opts['3des_key'], OPENSSL_NO_PADDING, $acting_opts['3desinit_key'] );
1969 }
1970 if ( isset( $response_cust_ref['res_sps_info']['cc_number'] ) ) {
1971 $cust_ref['sps_cust_no'] = $response_cust_ref['res_sps_info']['res_sps_cust_no'];
1972 }
1973 } else {
1974 if ( isset( $response_cust_ref['res_err_code'] ) ) {
1975 $cust_ref['err_code'] = $response_cust_ref['res_err_code'];
1976 }
1977 }
1978 }
1979 return $cust_ref;
1980 }
1981
1982 /**
1983 * Delete customers card data
1984 *
1985 * @param string $cust_code Member ID.
1986 * @return boolean
1987 */
1988 protected function api_customer_delete( $cust_code ) {
1989 $res = false;
1990 $cust_ref = $this->api_customer_reference( $cust_code );
1991 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) {
1992 $acting_opts = $this->get_acting_settings();
1993 $connection = $this->get_connection();
1994
1995 $sps_cust_info_return_flg = '0';
1996 $request_date = wp_date( 'YmdHis' );
1997 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $cust_code . $sps_cust_info_return_flg . $request_date . $acting_opts['hash_key'];
1998 $sps_hashcode = sha1( $sps_hashcode );
1999
2000 /* クレジットカード�
2001 報削除要求 */
2002 $request_cust_del = '<?xml version="1.0" encoding="Shift_JIS"?>
2003 <sps-api-request id="MG02-00103-101">
2004 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
2005 <service_id>' . $acting_opts['service_id'] . '</service_id>
2006 <cust_code>' . $cust_code . '</cust_code>
2007 <sps_cust_info_return_flg>' . $sps_cust_info_return_flg . '</sps_cust_info_return_flg>
2008 <request_date>' . $request_date . '</request_date>
2009 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
2010 </sps-api-request>';
2011 $xml_cust_del = $this->get_xml_response( $connection['api_url'], $request_cust_del );
2012 $response_cust_del = $this->xml2assoc( $xml_cust_del, $this->acting_card );
2013 if ( isset( $response_cust_del['res_result'] ) && 'OK' === $response_cust_del['res_result'] ) {
2014 $res = true;
2015 }
2016 }
2017 return $res;
2018 }
2019 }
2020