PluginProbe
Welcart e-Commerce / 2.12.3
Welcart e-Commerce v2.12.3
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 1.4.13 All 291 releases
usc-e-shop / classes / paymentTelecom.class.php

paymentTelecom.class.php in Welcart e-Commerce 2.12.3, at classes/paymentTelecom.class.php

489 lines 19.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * テレコムクレジット
4 *
5 * @class TELECOM_SETTLEMENT
6 * @author Collne Inc.
7 * @version 1.0.0
8 * @since 1.9.20
9 */
10 class TELECOM_SETTLEMENT {
11 /**
12 * Instance of this class.
13 *
14 * @var object
15 */
16 protected static $instance = null;
17
18 protected $paymod_id; // 決済代行会社ID.
19 protected $pay_method; // 決済種別.
20 protected $acting_name; // 決済代行会社略称.
21 protected $acting_formal_name; // 決済代行会社正式名称.
22 protected $acting_company_url; // 決済代行会社URL.
23
24 /**
25 * エラーメッセージ
26 *
27 * @var string
28 */
29 protected $error_mes;
30
31 /**
32 * Construct.
33 */
34 public function __construct() {
35
36 $this->paymod_id = 'telecom';
37 $this->pay_method = array(
38 'acting_telecom_card',
39 'acting_telecom_edy',
40 );
41 $this->acting_name = 'テレコムクレジット';
42 $this->acting_formal_name = 'テレコムクレジット';
43 $this->acting_company_url = 'https://www.telecomcredit.co.jp/';
44 $this->initialize_data();
45
46 if ( is_admin() ) {
47 add_action( 'usces_action_admin_settlement_update', array( $this, 'settlement_update' ) );
48 add_action( 'usces_action_settlement_tab_title', array( $this, 'settlement_tab_title' ) );
49 add_action( 'usces_action_settlement_tab_body', array( $this, 'settlement_tab_body' ) );
50 }
51
52 if ( $this->is_activate_card() ) {
53 add_action( 'usces_action_reg_orderdata', array( $this, 'register_orderdata' ) );
54 }
55
56 if ( $this->is_validity_acting( 'card' ) ) {
57 if ( is_admin() ) {
58 add_action( 'usces_action_admin_member_info', array( $this, 'member_settlement_info' ), 10, 3 );
59 add_action( 'usces_action_post_update_memberdata', array( $this, 'member_edit_post' ), 10, 2 );
60 }
61 }
62 }
63
64 /**
65 * Return an instance of this class.
66 */
67 public static function get_instance() {
68 if ( is_null( self::$instance ) ) {
69 self::$instance = new self();
70 }
71 return self::$instance;
72 }
73
74 /**
75 * Initialize
76 */
77 public function initialize_data() {
78
79 $options = get_option( 'usces', array() );
80 if ( ! isset( $options['acting_settings'] ) || ! isset( $options['acting_settings']['telecom'] ) ) {
81 $options['acting_settings']['telecom']['clientip'] = '';
82 $options['acting_settings']['telecom']['stype'] = '';
83 $options['acting_settings']['telecom']['card_activate'] = 'off';
84 $options['acting_settings']['telecom']['oneclick'] = '';
85 $options['acting_settings']['telecom']['edy_activate'] = 'off';
86 update_option( 'usces', $options );
87 }
88 }
89
90 /**
91 * 決済有効判定
92 * 引数が指定されたとき、支払方法で使用している場合に「有効」とする
93 *
94 * @param string $type Module type.
95 * @return boolean
96 */
97 public function is_validity_acting( $type = '' ) {
98
99 $acting_opts = $this->get_acting_settings();
100 if ( empty( $acting_opts ) ) {
101 return false;
102 }
103
104 $payment_method = usces_get_system_option( 'usces_payment_method', 'sort' );
105 $method = false;
106
107 switch ( $type ) {
108 case 'card':
109 foreach ( $payment_method as $payment ) {
110 if ( 'acting_telecom_card' == $payment['settlement'] && 'activate' == $payment['use'] ) {
111 $method = true;
112 break;
113 }
114 }
115 if ( $method && $this->is_activate_card() ) {
116 return true;
117 } else {
118 return false;
119 }
120 break;
121
122 case 'edy':
123 foreach ( $payment_method as $payment ) {
124 if ( 'acting_telecom_edy' == $payment['settlement'] && 'activate' == $payment['use'] ) {
125 $method = true;
126 break;
127 }
128 }
129 if ( $method && $this->is_activate_card() ) {
130 return true;
131 } else {
132 return false;
133 }
134 break;
135
136 default:
137 if ( 'on' == $acting_opts['activate'] ) {
138 return true;
139 } else {
140 return false;
141 }
142 }
143 }
144
145 /**
146 * クレジットカード決済有効判定
147 *
148 * @return boolean $res
149 */
150 public function is_activate_card() {
151
152 $acting_opts = $this->get_acting_settings();
153 if ( ( isset( $acting_opts['activate'] ) && 'on' == $acting_opts['activate'] ) &&
154 ( isset( $acting_opts['card_activate'] ) && ( 'on' == $acting_opts['card_activate'] ) ) ) {
155 $res = true;
156 } else {
157 $res = false;
158 }
159 return $res;
160 }
161
162 /**
163 * Edy 決済有効判定
164 *
165 * @return boolean $res
166 */
167 public function is_activate_edy() {
168
169 $acting_opts = $this->get_acting_settings();
170 if ( ( isset( $acting_opts['activate'] ) && 'on' == $acting_opts['activate'] ) &&
171 ( isset( $acting_opts['edy_activate'] ) && ( 'on' == $acting_opts['edy_activate'] ) ) ) {
172 $res = true;
173 } else {
174 $res = false;
175 }
176 return $res;
177 }
178
179 /**
180 * 決済オプション登録・更新
181 * usces_action_admin_settlement_update
182 */
183 public function settlement_update() {
184 global $usces;
185
186 if ( $this->paymod_id != $_POST['acting'] ) {
187 return;
188 }
189
190 $this->error_mes = '';
191 $options = get_option( 'usces', array() );
192 $payment_method = usces_get_system_option( 'usces_payment_method', 'settlement' );
193
194 unset( $options['acting_settings']['telecom'] );
195 $options['acting_settings']['telecom']['clientip'] = ( isset( $_POST['clientip'] ) ) ? $_POST['clientip'] : '';
196 $options['acting_settings']['telecom']['stype'] = ( isset( $_POST['stype'] ) ) ? $_POST['stype'] : '';
197 $options['acting_settings']['telecom']['card_activate'] = ( isset( $_POST['card_activate'] ) ) ? $_POST['card_activate'] : 'off';
198 $options['acting_settings']['telecom']['oneclick'] = ( isset( $_POST['oneclick'] ) ) ? $_POST['oneclick'] : '';
199 // $options['acting_settings']['telecom']['edy_activate'] = ( isset( $_POST['edy_activate'] ) ) ? $_POST['edy_activate'] : 'off';
200 $options['acting_settings']['telecom']['edy_activate'] = 'off';
201
202 if ( WCUtils::is_blank( $_POST['clientip'] ) ) {
203 $this->error_mes .= '※クライアントIPを�
204 �力してください<br />';
205 }
206 if ( WCUtils::is_blank( $_POST['stype'] ) ) {
207 $this->error_mes .= '※決済タイプを�
208 �力してください<br />';
209 }
210
211 if ( '' == $this->error_mes ) {
212 $usces->action_status = 'success';
213 $usces->action_message = __( 'Options are updated.', 'usces' );
214 if ( 'on' == $options['acting_settings']['telecom']['card_activate'] || 'on' == $options['acting_settings']['telecom']['edy_activate'] ) {
215 $options['acting_settings']['telecom']['activate'] = 'on';
216 $toactive = array();
217 if ( 'on' == $options['acting_settings']['telecom']['card_activate'] ) {
218 if ( 'EP' == $options['acting_settings']['telecom']['stype'] ) {
219 $options['acting_settings']['telecom']['send_url'] = 'https://settle.saa-s.com/inetcredit/secure/order.pl';
220 if ( 'on' == $options['acting_settings']['telecom']['oneclick'] ) {
221 $options['acting_settings']['telecom']['oneclick_send_url'] = 'https://settle.saa-s.com/inetcredit/secure/one-click-order.pl';
222 }
223 } else {
224 if ( 'E' == $options['acting_settings']['telecom']['stype'][0] ) {
225 $options['acting_settings']['telecom']['send_url'] = 'https://www.credit-cgiserver.com/inetcredit/secure/order.pl';
226 } else {
227 $options['acting_settings']['telecom']['send_url'] = 'https://secure.telecomcredit.co.jp/inetcredit/secure/order.pl';
228 }
229 if ( 'on' == $options['acting_settings']['telecom']['oneclick'] ) {
230 $options['acting_settings']['telecom']['oneclick_send_url'] = 'https://secure.telecomcredit.co.jp/inetcredit/secure/one-click-order.pl';
231 }
232 }
233 $usces->payment_structure['acting_telecom_card'] = 'カード決済(' . $this->acting_name . '';
234 foreach ( $payment_method as $settlement => $payment ) {
235 if ( 'acting_telecom_card' == $settlement && 'deactivate' == $payment['use'] ) {
236 $toactive[] = $payment['name'];
237 }
238 }
239 } else {
240 unset( $usces->payment_structure['acting_telecom_card'] );
241 }
242 if ( 'on' == $options['acting_settings']['telecom']['edy_activate'] ) {
243 $options['acting_settings']['telecom']['send_url_edy'] = 'https://secure.telecomcredit.co.jp/payment/edy/order.pl';
244 $usces->payment_structure['acting_telecom_edy'] = 'Edy決済(' . $this->acting_name . '';
245 foreach ( $payment_method as $settlement => $payment ) {
246 if ( 'acting_telecom_edy' == $settlement && 'deactivate' == $payment['use'] ) {
247 $toactive[] = $payment['name'];
248 }
249 }
250 } else {
251 unset( $usces->payment_structure['acting_telecom_edy'] );
252 }
253 usces_admin_orderlist_show_wc_trans_id();
254 if ( 0 < count( $toactive ) ) {
255 $usces->action_message .= __( "Please update the payment method to \"Activate\". <a href=\"admin.php?page=usces_initial#payment_method_setting\">General Setting > Payment Methods</a>", 'usces' );
256 }
257 } else {
258 $options['acting_settings']['telecom']['activate'] = 'off';
259 unset( $usces->payment_structure['acting_telecom_card'] );
260 unset( $usces->payment_structure['acting_telecom_edy'] );
261 }
262 if ( 'on' != $options['acting_settings']['telecom']['oneclick'] || 'off' == $options['acting_settings']['telecom']['activate'] ) {
263 usces_clear_quickcharge( 'telecom_oneclick' );
264 }
265 $deactivate = array();
266 foreach ( $payment_method as $settlement => $payment ) {
267 if ( ! array_key_exists( $settlement, $usces->payment_structure ) ) {
268 if ( 'deactivate' != $payment['use'] ) {
269 $payment['use'] = 'deactivate';
270 $deactivate[] = $payment['name'];
271 usces_update_system_option( 'usces_payment_method', $payment['id'], $payment );
272 }
273 }
274 }
275 if ( 0 < count( $deactivate ) ) {
276 $deactivate_message = sprintf( __( "\"Deactivate\" %s of payment method.", 'usces' ), implode( ',', $deactivate ) );
277 $usces->action_message .= $deactivate_message;
278 }
279 } else {
280 $usces->action_status = 'error';
281 $usces->action_message = __( 'Data have deficiency.', 'usces' );
282 $options['acting_settings']['telecom']['activate'] = 'off';
283 unset( $usces->payment_structure['acting_telecom_card'] );
284 unset( $usces->payment_structure['acting_telecom_edy'] );
285 $deactivate = array();
286 foreach ( $payment_method as $settlement => $payment ) {
287 if ( in_array( $settlement, $this->pay_method ) ) {
288 if ( 'deactivate' != $payment['use'] ) {
289 $payment['use'] = 'deactivate';
290 $deactivate[] = $payment['name'];
291 usces_update_system_option( 'usces_payment_method', $payment['id'], $payment );
292 }
293 }
294 }
295 if ( 0 < count( $deactivate ) ) {
296 $deactivate_message = sprintf( __( "\"Deactivate\" %s of payment method.", 'usces' ), implode( ',', $deactivate ) );
297 $usces->action_message .= $deactivate_message . __( "Please complete the setup and update the payment method to \"Activate\".", 'usces' );
298 }
299 }
300 ksort( $usces->payment_structure );
301 update_option( 'usces', $options );
302 update_option( 'usces_payment_structure', $usces->payment_structure );
303 }
304
305 /**
306 * クレジット決済設定画面タブ
307 * usces_action_settlement_tab_title
308 */
309 public function settlement_tab_title() {
310
311 $settlement_selected = get_option( 'usces_settlement_selected' );
312 if ( in_array( $this->paymod_id, (array) $settlement_selected ) ) {
313 echo '<li><a href="#uscestabs_' . $this->paymod_id . '">' . $this->acting_name . '</a></li>';
314 }
315 }
316
317 /**
318 * クレジット決済設定画面フォーム
319 * usces_action_settlement_tab_body
320 */
321 public function settlement_tab_body() {
322 global $usces;
323
324 $acting_opts = $this->get_acting_settings();
325 $settlement_selected = get_option( 'usces_settlement_selected' );
326 if ( in_array( $this->paymod_id, (array) $settlement_selected ) ) :
327 ?>
328 <div id="uscestabs_telecom">
329 <div class="settlement_service"><span class="service_title"><?php echo esc_html( $this->acting_formal_name ); ?></span></div>
330 <?php if ( isset( $_POST['acting'] ) && 'telecom' == $_POST['acting'] ) : ?>
331 <?php if ( '' != $this->error_mes ) : ?>
332 <div class="error_message"><?php wel_esc_script_e( $this->error_mes ); ?></div>
333 <?php elseif ( isset( $acting_opts['activate'] ) && 'on' == $acting_opts['activate'] ) : ?>
334 <div class="message">十分にテストを行ってから運用してください。</div>
335 <?php endif; ?>
336 <?php endif; ?>
337 <form action="" method="post" name="telecom_form" id="telecom_form">
338 <table class="settle_table">
339 <tr>
340 <th><a class="explanation-label" id="label_ex_clientip_telecom">クライアントIP</a></th>
341 <td><input name="clientip" type="text" id="clientip_telecom" value="<?php echo esc_html( isset( $acting_opts['clientip'] ) ? $acting_opts['clientip'] : '' ); ?>" class="regular-text" maxlength="5" /></td>
342 </tr>
343 <tr id="ex_clientip_telecom" class="explanation"><td colspan="2">契約時に<?php echo esc_html( $this->acting_name ); ?>から発行されるクライアントIP(半角数字)</td></tr>
344 <tr>
345 <th><a class="explanation-label" id="label_ex_stype_telecom">決済タイプ</a></th>
346 <td><input name="stype" type="text" id="stype_telecom" value="<?php echo esc_html( isset( $acting_opts['stype'] ) ? $acting_opts['stype'] : '' ); ?>" class="regular-text" /></td>
347 </tr>
348 <tr id="ex_stype_telecom" class="explanation"><td colspan="2">設定依頼書に記載されている決済タイプ</td></tr>
349 </table>
350 <table class="settle_table">
351 <tr>
352 <th>クレジットカード決済</th>
353 <td><label><input name="card_activate" type="radio" id="card_activate_telecom_1" value="on"<?php checked( isset( $acting_opts['card_activate'] ) && 'on' == $acting_opts['card_activate'], true ); ?> /><span>利用する</span></label><br />
354 <label><input name="card_activate" type="radio" id="card_activate_telecom_2" value="off"<?php checked( isset( $acting_opts['card_activate'] ) && 'off' == $acting_opts['card_activate'], true ); ?> /><span>利用しない</span></label>
355 </td>
356 </tr>
357 <tr>
358 <th><a class="explanation-label" id="label_ex_oneclick_telecom">スピード決済</a></th>
359 <td><label><input name="oneclick" type="radio" id="oneclick_telecom_1" value="on"<?php checked( isset( $acting_opts['oneclick'] ) && 'on' == $acting_opts['oneclick'], true ); ?> /><span>利用する</span></label><br />
360 <label><input name="oneclick" type="radio" id="oneclick_telecom_2" value="off"<?php checked( isset( $acting_opts['oneclick'] ) && 'off' == $acting_opts['oneclick'], true ); ?> /><span>利用しない</span></label>
361 </td>
362 </tr>
363 <tr id="ex_oneclick_telecom" class="explanation"><td colspan="2">2回目以降の利用はカード番号を�
364 �力しなくても決済可能となります。</td></tr>
365 </table>
366 <!--<table class="settle_table">
367 <tr>
368 <th>Edy決済</th>
369 <td><label><input name="edy_activate" type="radio" id="edy_activate_telecom_1" value="on"<?php checked( isset( $acting_opts['edy_activate'] ) && 'on' == $acting_opts['edy_activate'], true ); ?> /><span>利用する</span></label><br />
370 <label><input name="edy_activate" type="radio" id="edy_activate_telecom_2" value="off"<?php checked( isset( $acting_opts['edy_activate'] ) && 'off' == $acting_opts['edy_activate'], true ); ?> /><span>利用しない</span></label>
371 </td>
372 </tr>
373 </table>-->
374 <input name="acting" type="hidden" value="telecom" />
375 <input name="usces_option_update" type="submit" class="button button-primary" value="<?php echo esc_html( $this->acting_name ); ?>の設定を更新する" />
376 <?php wp_nonce_field( 'admin_settlement', 'wc_nonce' ); ?>
377 </form>
378 <div class="settle_exp">
379 <p><strong><?php echo esc_html( $this->acting_formal_name ); ?></strong></p>
380 <a href="<?php echo esc_url( $this->acting_company_url ); ?>" target="_blank"><?php echo esc_html( $this->acting_name ); ?>の詳細はこちら </a>
381 <p> </p>
382 <p>この決済は「外部リンク型」の決済システムです。</p>
383 <p>「外部リンク型」とは、決済会社のページへ遷移してカード�
384 報を�
385 �力する決済システムです。</p>
386 </div>
387 </div><!--uscestabs_telecom-->
388 <?php
389 endif;
390 }
391
392 /**
393 * 受注データ登録
394 * Call from usces_reg_orderdata() and usces_new_orderdata().
395 * usces_action_reg_orderdata
396 *
397 * @param array $args ( $cart, $entry, $order_id, $member_id, $payments, $charging_type, $results ).
398 */
399 public function register_orderdata( $args ) {
400 global $usces;
401 extract( $args );
402
403 $acting_flg = $payments['settlement'];
404 if ( ! in_array( $acting_flg, $this->pay_method ) ) {
405 return;
406 }
407
408 if ( ! $entry['order']['total_full_price'] ) {
409 return;
410 }
411
412 if ( isset( $_REQUEST['acting'] ) && 'telecom_card' == $_REQUEST['acting'] && isset( $_REQUEST['acting_return'] ) && isset( $_REQUEST['option'] ) ) {
413 if ( empty( $data ) ) {
414 $data = array();
415 }
416 $data['option'] = esc_sql( $_REQUEST['option'] );
417 $usces->set_order_meta_value( 'acting_telecom_card', serialize( $data ), $order_id );
418 $usces->set_order_meta_value( 'wc_trans_id', $_REQUEST['option'], $order_id );
419 $usces->set_order_meta_value( 'trans_id', $_REQUEST['option'], $order_id );
420 $acting_opts = $usces->options['acting_settings']['telecom'];
421 if ( 'on' == $acting_opts['oneclick'] ) {
422 $usces->set_member_meta_value( 'telecom_oneclick', $member_id );
423 }
424 }
425 }
426
427 /**
428 * 会員データ編集画面 スピード決済登録�
429
430 * usces_action_admin_member_info
431 *
432 * @param array $member_data Member data.
433 * @param array $member_meta_data Member meta data.
434 * @param array $member_history Member history data.
435 */
436 public function member_settlement_info( $member_data, $member_meta_data, $member_history ) {
437
438 if ( 0 < count( $member_meta_data ) ) :
439 $cardinfo = array();
440 foreach ( $member_meta_data as $value ) {
441 if ( in_array( $value['meta_key'], array( 'telecom_oneclick' ) ) ) {
442 $cardinfo[ $value['meta_key'] ] = $value['meta_value'];
443 }
444 }
445 if ( 0 < count( $cardinfo ) ) :
446 if ( array_key_exists( 'telecom_oneclick', $cardinfo ) ) :
447 ?>
448 <tr>
449 <td class="label">スピード決済</td>
450 <td><div class="rod_left shortm">登録あり</div></td>
451 </tr>
452 <tr>
453 <td class="label"><input type="checkbox" name="telecom_oneclick" id="telecom_oneclick" value="delete"></td>
454 <td><label for="telecom_oneclick">スピード決済を解除する</label></td>
455 </tr>
456 <?php
457 endif;
458 endif;
459 endif;
460 }
461
462 /**
463 * 会員データ編集画面 スピード決済登録解除
464 * usces_action_post_update_memberdata
465 *
466 * @param int $member_id Member ID.
467 * @param array $res Results.
468 */
469 public function member_edit_post( $member_id, $res ) {
470 global $usces;
471
472 if ( isset( $_POST['telecom_oneclick'] ) && 'delete' == $_POST['telecom_oneclick'] ) {
473 $usces->del_member_meta( 'telecom_oneclick', $member_id );
474 }
475 }
476
477 /**
478 * 決済オプション取得
479 *
480 * @return array $acting_settings
481 */
482 protected function get_acting_settings() {
483 global $usces;
484
485 $acting_settings = ( isset( $usces->options['acting_settings'][ $this->paymod_id ] ) ) ? $usces->options['acting_settings'][ $this->paymod_id ] : array();
486 return $acting_settings;
487 }
488 }
489