| 1 |
<?php |
| 2 |
/** |
| 3 |
* アナザーレーン |
| 4 |
* |
| 5 |
* @class ANOTHERLANE_SETTLEMENT |
| 6 |
* @author Collne Inc. |
| 7 |
* @version 1.0.0 |
| 8 |
* @since 1.9.20 |
| 9 |
*/ |
| 10 |
class ANOTHERLANE_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 = 'anotherlane'; |
| 37 |
$this->pay_method = array( |
| 38 |
'acting_anotherlane_card', |
| 39 |
); |
| 40 |
$this->acting_name = 'アナザーレーン'; |
| 41 |
$this->acting_formal_name = 'アナザーレーン'; |
| 42 |
$this->acting_company_url = 'https://www.alij.ne.jp/'; |
| 43 |
|
| 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 |
|
| 57 |
/** |
| 58 |
* Return an instance of this class. |
| 59 |
*/ |
| 60 |
public static function get_instance() { |
| 61 |
if ( is_null( self::$instance ) ) { |
| 62 |
self::$instance = new self(); |
| 63 |
} |
| 64 |
return self::$instance; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Initialize |
| 69 |
*/ |
| 70 |
public function initialize_data() { |
| 71 |
|
| 72 |
$options = get_option( 'usces', array() ); |
| 73 |
if ( ! isset( $options['acting_settings'] ) || ! isset( $options['acting_settings']['anotherlane'] ) ) { |
| 74 |
$options['acting_settings']['anotherlane']['siteid'] = ''; |
| 75 |
$options['acting_settings']['anotherlane']['sitepass'] = ''; |
| 76 |
$options['acting_settings']['anotherlane']['ope'] = ''; |
| 77 |
$options['acting_settings']['anotherlane']['quickcharge'] = ''; |
| 78 |
$options['acting_settings']['anotherlane']['card_activate'] = 'off'; |
| 79 |
update_option( 'usces', $options ); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* 決済有効判定 |
| 85 |
* 引数が指定されたとき、支払方法で使用している場合に「有効」とする |
| 86 |
* |
| 87 |
* @param string $type Module type. |
| 88 |
* @return boolean |
| 89 |
*/ |
| 90 |
public function is_validity_acting( $type = '' ) { |
| 91 |
|
| 92 |
$acting_opts = $this->get_acting_settings(); |
| 93 |
if ( empty( $acting_opts ) ) { |
| 94 |
return false; |
| 95 |
} |
| 96 |
|
| 97 |
$payment_method = usces_get_system_option( 'usces_payment_method', 'sort' ); |
| 98 |
$method = false; |
| 99 |
|
| 100 |
switch ( $type ) { |
| 101 |
case 'card': |
| 102 |
foreach ( $payment_method as $payment ) { |
| 103 |
if ( 'acting_anotherlane_card' == $payment['settlement'] && 'activate' == $payment['use'] ) { |
| 104 |
$method = true; |
| 105 |
break; |
| 106 |
} |
| 107 |
} |
| 108 |
if ( $method && $this->is_activate_card() ) { |
| 109 |
return true; |
| 110 |
} else { |
| 111 |
return false; |
| 112 |
} |
| 113 |
break; |
| 114 |
|
| 115 |
default: |
| 116 |
if ( 'on' == $acting_opts['activate'] ) { |
| 117 |
return true; |
| 118 |
} else { |
| 119 |
return false; |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* クレジットカード決済有効判定 |
| 126 |
* |
| 127 |
* @return boolean $res |
| 128 |
*/ |
| 129 |
public function is_activate_card() { |
| 130 |
|
| 131 |
$acting_opts = $this->get_acting_settings(); |
| 132 |
if ( ( isset( $acting_opts['activate'] ) && 'on' == $acting_opts['activate'] ) && |
| 133 |
( isset( $acting_opts['card_activate'] ) && ( 'on' == $acting_opts['card_activate'] ) ) ) { |
| 134 |
$res = true; |
| 135 |
} else { |
| 136 |
$res = false; |
| 137 |
} |
| 138 |
return $res; |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* 決済オプション登録・更新 |
| 143 |
* usces_action_admin_settlement_update |
| 144 |
*/ |
| 145 |
public function settlement_update() { |
| 146 |
global $usces; |
| 147 |
|
| 148 |
if ( $this->paymod_id != $_POST['acting'] ) { |
| 149 |
return; |
| 150 |
} |
| 151 |
|
| 152 |
$this->error_mes = ''; |
| 153 |
$options = get_option( 'usces', array() ); |
| 154 |
$payment_method = usces_get_system_option( 'usces_payment_method', 'settlement' ); |
| 155 |
|
| 156 |
unset( $options['acting_settings']['anotherlane'] ); |
| 157 |
$options['acting_settings']['anotherlane']['siteid'] = ( isset( $_POST['siteid'] ) ) ? trim( $_POST['siteid'] ) : ''; |
| 158 |
$options['acting_settings']['anotherlane']['sitepass'] = ( isset( $_POST['sitepass'] ) ) ? trim( $_POST['sitepass'] ) : ''; |
| 159 |
$options['acting_settings']['anotherlane']['ope'] = ( isset( $_POST['ope'] ) ) ? $_POST['ope'] : ''; |
| 160 |
$options['acting_settings']['anotherlane']['quickcharge'] = ( isset( $_POST['quickcharge'] ) ) ? $_POST['quickcharge'] : ''; |
| 161 |
$options['acting_settings']['anotherlane']['card_activate'] = ( isset( $_POST['card_activate'] ) ) ? $_POST['card_activate'] : 'off'; |
| 162 |
|
| 163 |
if ( 'on' == $options['acting_settings']['anotherlane']['card_activate'] ) { |
| 164 |
if ( WCUtils::is_blank( $_POST['siteid'] ) ) { |
| 165 |
$this->error_mes .= '※サイトIDを� |
| 166 |
�力してください<br />'; |
| 167 |
} |
| 168 |
if ( WCUtils::is_blank( $_POST['sitepass'] ) ) { |
| 169 |
$this->error_mes .= '※サイトパスワードを� |
| 170 |
�力してください<br />'; |
| 171 |
} |
| 172 |
if ( WCUtils::is_blank( $options['acting_settings']['anotherlane']['ope'] ) ) { |
| 173 |
$this->error_mes .= '※稼働環境を選択してください<br />'; |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
if ( '' == $this->error_mes ) { |
| 178 |
$usces->action_status = 'success'; |
| 179 |
$usces->action_message = __( 'Options are updated.', 'usces' ); |
| 180 |
if ( 'on' == $options['acting_settings']['anotherlane']['card_activate'] ) { |
| 181 |
$options['acting_settings']['anotherlane']['activate'] = 'on'; |
| 182 |
if ( 'public' == $options['acting_settings']['anotherlane']['ope'] ) { |
| 183 |
$options['acting_settings']['anotherlane']['send_url'] = 'https://payment.alij.ne.jp/service/credit'; |
| 184 |
} else { |
| 185 |
$options['acting_settings']['anotherlane']['send_url'] = 'https://test-payment.alij.ne.jp/service/credit'; |
| 186 |
} |
| 187 |
$usces->payment_structure['acting_anotherlane_card'] = 'カード決済(' . $this->acting_name . ')'; |
| 188 |
usces_admin_orderlist_show_wc_trans_id(); |
| 189 |
$toactive = array(); |
| 190 |
foreach ( $payment_method as $settlement => $payment ) { |
| 191 |
if ( 'acting_anotherlane_card' == $settlement && 'deactivate' == $payment['use'] ) { |
| 192 |
$toactive[] = $payment['name']; |
| 193 |
} |
| 194 |
} |
| 195 |
if ( 0 < count( $toactive ) ) { |
| 196 |
$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' ); |
| 197 |
} |
| 198 |
} else { |
| 199 |
$options['acting_settings']['anotherlane']['activate'] = 'off'; |
| 200 |
unset( $usces->payment_structure['acting_anotherlane_card'] ); |
| 201 |
$deactivate = array(); |
| 202 |
foreach ( $payment_method as $settlement => $payment ) { |
| 203 |
if ( ! array_key_exists( $settlement, $usces->payment_structure ) ) { |
| 204 |
if ( 'deactivate' != $payment['use'] ) { |
| 205 |
$payment['use'] = 'deactivate'; |
| 206 |
$deactivate[] = $payment['name']; |
| 207 |
usces_update_system_option( 'usces_payment_method', $payment['id'], $payment ); |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
if ( 0 < count( $deactivate ) ) { |
| 212 |
$deactivate_message = sprintf( __( "\"Deactivate\" %s of payment method.", 'usces' ), implode( ',', $deactivate ) ); |
| 213 |
$usces->action_message .= $deactivate_message; |
| 214 |
} |
| 215 |
} |
| 216 |
} else { |
| 217 |
$usces->action_status = 'error'; |
| 218 |
$usces->action_message = __( 'Data have deficiency.', 'usces' ); |
| 219 |
$options['acting_settings']['anotherlane']['activate'] = 'off'; |
| 220 |
unset( $usces->payment_structure['acting_anotherlane_card'] ); |
| 221 |
$deactivate = array(); |
| 222 |
foreach ( $payment_method as $settlement => $payment ) { |
| 223 |
if ( in_array( $settlement, $this->pay_method ) ) { |
| 224 |
if ( 'deactivate' != $payment['use'] ) { |
| 225 |
$payment['use'] = 'deactivate'; |
| 226 |
$deactivate[] = $payment['name']; |
| 227 |
usces_update_system_option( 'usces_payment_method', $payment['id'], $payment ); |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
if ( 0 < count( $deactivate ) ) { |
| 232 |
$deactivate_message = sprintf( __( "\"Deactivate\" %s of payment method.", 'usces' ), implode( ',', $deactivate ) ); |
| 233 |
$usces->action_message .= $deactivate_message . __( "Please complete the setup and update the payment method to \"Activate\".", 'usces' ); |
| 234 |
} |
| 235 |
} |
| 236 |
ksort( $usces->payment_structure ); |
| 237 |
update_option( 'usces', $options ); |
| 238 |
update_option( 'usces_payment_structure', $usces->payment_structure ); |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* クレジット決済設定画面タブ |
| 243 |
* usces_action_settlement_tab_title |
| 244 |
*/ |
| 245 |
public function settlement_tab_title() { |
| 246 |
|
| 247 |
$settlement_selected = get_option( 'usces_settlement_selected' ); |
| 248 |
if ( in_array( $this->paymod_id, (array) $settlement_selected ) ) { |
| 249 |
echo '<li><a href="#uscestabs_' . $this->paymod_id . '">' . $this->acting_name . '</a></li>'; |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
/** |
| 254 |
* クレジット決済設定画面フォーム |
| 255 |
* usces_action_settlement_tab_body |
| 256 |
*/ |
| 257 |
public function settlement_tab_body() { |
| 258 |
global $usces; |
| 259 |
|
| 260 |
$acting_opts = $this->get_acting_settings(); |
| 261 |
$settlement_selected = get_option( 'usces_settlement_selected' ); |
| 262 |
if ( in_array( $this->paymod_id, (array) $settlement_selected ) ) : |
| 263 |
?> |
| 264 |
<div id="uscestabs_anotherlane"> |
| 265 |
<div class="settlement_service"><span class="service_title"><?php echo esc_html( $this->acting_formal_name ); ?></span></div> |
| 266 |
<?php if ( isset( $_POST['acting'] ) && 'anotherlane' == $_POST['acting'] ) : ?> |
| 267 |
<?php if ( '' != $this->error_mes ) : ?> |
| 268 |
<div class="error_message"><?php wel_esc_script_e( $this->error_mes ); ?></div> |
| 269 |
<?php elseif ( isset( $acting_opts['activate'] ) && 'on' == $acting_opts['activate'] ) : ?> |
| 270 |
<div class="message">十分にテストを行ってから運用してください。</div> |
| 271 |
<?php endif; ?> |
| 272 |
<?php endif; ?> |
| 273 |
<form action="" method="post" name="anotherlane_form" id="anotherlane_form"> |
| 274 |
<table class="settle_table"> |
| 275 |
<tr> |
| 276 |
<th><a class="explanation-label" id="label_ex_siteid_anotherlane">サイトID</a></th> |
| 277 |
<td><input name="siteid" type="text" id="siteid_anotherlane" value="<?php echo esc_html( isset( $acting_opts['siteid'] ) ? $acting_opts['siteid'] : '' ); ?>" class="regular-text" maxlength="8" /></td> |
| 278 |
</tr> |
| 279 |
<tr id="ex_siteid_anotherlane" class="explanation"><td colspan="2">契約時に<?php echo esc_html( $this->acting_name ); ?>から発行されるID(半角数字)</td></tr> |
| 280 |
<tr> |
| 281 |
<th><a class="explanation-label" id="label_ex_sitepass_anotherlane">サイトパスワード</a></th> |
| 282 |
<td><input name="sitepass" type="text" id="sitepass_anotherlane" value="<?php echo esc_html( isset( $acting_opts['sitepass'] ) ? $acting_opts['sitepass'] : '' ); ?>" class="regular-text" maxlength="8" /></td> |
| 283 |
</tr> |
| 284 |
<tr id="ex_sitepass_anotherlane" class="explanation"><td colspan="2">契約時に<?php echo esc_html( $this->acting_name ); ?>から発行されるパスワード(半角英数字)</td></tr> |
| 285 |
<tr> |
| 286 |
<th><a class="explanation-label" id="label_ex_ope_anotherlane">稼働環境</a></th> |
| 287 |
<td><label><input name="ope" type="radio" id="ope_anotherlane_1" value="test"<?php checked( isset( $acting_opts['ope'] ) && 'test' == $acting_opts['ope'], true ); ?> /><span>テスト環境</span></label><br /> |
| 288 |
<label><input name="ope" type="radio" id="ope_anotherlane_2" value="public"<?php checked( isset( $acting_opts['ope'] ) && 'public' == $acting_opts['ope'], true ); ?> /><span>本番環境</span></label> |
| 289 |
</td> |
| 290 |
</tr> |
| 291 |
<tr id="ex_ope_anotherlane" class="explanation"><td colspan="2">動作環境を切り替えます。</td></tr> |
| 292 |
<tr> |
| 293 |
<th><a class="explanation-label" id="label_ex_quickcharge_anotherlane">クイックチャージ</a></th> |
| 294 |
<td><label><input name="quickcharge" type="radio" id="quickcharge_anotherlane_1" value="on"<?php checked( isset( $acting_opts['quickcharge'] ) && 'on' == $acting_opts['quickcharge'], true ); ?> /><span>利用する</span></label><br /> |
| 295 |
<label><input name="quickcharge" type="radio" id="quickcharge_anotherlane_2" value="off"<?php checked( isset( $acting_opts['quickcharge'] ) && 'off' == $acting_opts['quickcharge'], true ); ?> /><span>利用しない</span></label> |
| 296 |
</td> |
| 297 |
</tr> |
| 298 |
<tr id="ex_quickcharge_anotherlane" class="explanation"><td colspan="2">ログインして一度購� |
| 299 |
�したメンバーは、次の購� |
| 300 |
�時にはカード番号を� |
| 301 |
�力する� |
| 302 |
要がなくなります。</td></tr> |
| 303 |
</table> |
| 304 |
<table class="settle_table"> |
| 305 |
<tr> |
| 306 |
<th>クレジットカード決済</th> |
| 307 |
<td><label><input name="card_activate" type="radio" id="card_activate_anotherlane_1" value="on"<?php checked( isset( $acting_opts['card_activate'] ) && 'on' == $acting_opts['card_activate'], true ); ?> /><span>利用する</span></label><br /> |
| 308 |
<label><input name="card_activate" type="radio" id="card_activate_anotherlane_2" value="off"<?php checked( isset( $acting_opts['card_activate'] ) && 'off' == $acting_opts['card_activate'], true ); ?> /><span>利用しない</span></label> |
| 309 |
</td> |
| 310 |
</tr> |
| 311 |
</table> |
| 312 |
<input name="acting" type="hidden" value="anotherlane" /> |
| 313 |
<input name="usces_option_update" type="submit" class="button button-primary" value="<?php echo esc_attr( $this->acting_name ); ?>の設定を更新する" /> |
| 314 |
<?php wp_nonce_field( 'admin_settlement', 'wc_nonce' ); ?> |
| 315 |
</form> |
| 316 |
<div class="settle_exp"> |
| 317 |
<p><strong><?php echo esc_attr( $this->acting_formal_name ); ?></strong></p> |
| 318 |
<a href="<?php echo esc_url( $this->acting_company_url ); ?>" target="_blank"><?php echo esc_html( $this->acting_name ); ?>の詳細はこちら 》</a> |
| 319 |
<p> </p> |
| 320 |
<p>この決済は「外部リンク型」の決済システムです。</p> |
| 321 |
<p>「外部リンク型」とは、決済会社のページへ遷移してカード� |
| 322 |
報を� |
| 323 |
�力する決済システムです。</p> |
| 324 |
</div> |
| 325 |
</div><!--uscestabs_anotherlane--> |
| 326 |
<?php |
| 327 |
endif; |
| 328 |
} |
| 329 |
|
| 330 |
/** |
| 331 |
* 受注データ登録 |
| 332 |
* Call from usces_reg_orderdata() and usces_new_orderdata(). |
| 333 |
* usces_action_reg_orderdata |
| 334 |
* |
| 335 |
* @param array $args ( $cart, $entry, $order_id, $member_id, $payments, $charging_type, $results ). |
| 336 |
*/ |
| 337 |
public function register_orderdata( $args ) { |
| 338 |
global $usces; |
| 339 |
extract( $args ); |
| 340 |
|
| 341 |
$acting_flg = $payments['settlement']; |
| 342 |
if ( ! in_array( $acting_flg, $this->pay_method ) ) { |
| 343 |
return; |
| 344 |
} |
| 345 |
|
| 346 |
if ( ! $entry['order']['total_full_price'] ) { |
| 347 |
return; |
| 348 |
} |
| 349 |
|
| 350 |
if ( isset( $_REQUEST['SiteId'] ) && $usces->options['acting_settings']['anotherlane']['siteid'] == $_REQUEST['SiteId'] && isset( $_REQUEST['TransactionId'] ) ) { |
| 351 |
$usces->set_order_meta_value( 'TransactionId', $_REQUEST['TransactionId'], $order_id ); |
| 352 |
$usces->set_order_meta_value( 'wc_trans_id', $_REQUEST['TransactionId'], $order_id ); |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
/** |
| 357 |
* 決済オプション取得 |
| 358 |
* |
| 359 |
* @return array $acting_settings |
| 360 |
*/ |
| 361 |
protected function get_acting_settings() { |
| 362 |
global $usces; |
| 363 |
|
| 364 |
$acting_settings = ( isset( $usces->options['acting_settings'][ $this->paymod_id ] ) ) ? $usces->options['acting_settings'][ $this->paymod_id ] : array(); |
| 365 |
return $acting_settings; |
| 366 |
} |
| 367 |
} |
| 368 |
|