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

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