| 1 |
<?php |
| 2 |
/** |
| 3 |
* ペイディ決済モジュール |
| 4 |
* |
| 5 |
* @package Welcart |
| 6 |
* @author Collne Inc. |
| 7 |
* @version 1.0.0 |
| 8 |
* @since 2.6.11 |
| 9 |
*/ |
| 10 |
class PAIDY_SETTLEMENT { |
| 11 |
/** |
| 12 |
* Instance of this class. |
| 13 |
* |
| 14 |
* @var object |
| 15 |
*/ |
| 16 |
protected static $instance = null; |
| 17 |
|
| 18 |
/** |
| 19 |
* 決済代行会社ID |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
protected $paymod_id; |
| 24 |
|
| 25 |
/** |
| 26 |
* 決済種別 |
| 27 |
* |
| 28 |
* @var string |
| 29 |
*/ |
| 30 |
protected $pay_method; |
| 31 |
|
| 32 |
/** |
| 33 |
* 決済代行会社略称 |
| 34 |
* |
| 35 |
* @var string |
| 36 |
*/ |
| 37 |
protected $acting_name; |
| 38 |
|
| 39 |
/** |
| 40 |
* 決済代行会社正式名称 |
| 41 |
* |
| 42 |
* @var string |
| 43 |
*/ |
| 44 |
protected $acting_formal_name; |
| 45 |
|
| 46 |
/** |
| 47 |
* 決済代行会社URL |
| 48 |
* |
| 49 |
* @var string |
| 50 |
*/ |
| 51 |
protected $acting_company_url; |
| 52 |
|
| 53 |
/** |
| 54 |
* 併用不可決済モジュール |
| 55 |
* |
| 56 |
* @var array |
| 57 |
*/ |
| 58 |
protected $unavailable_method; |
| 59 |
|
| 60 |
/** |
| 61 |
* エラーメッセージ |
| 62 |
* |
| 63 |
* @var string |
| 64 |
*/ |
| 65 |
protected $error_mes; |
| 66 |
|
| 67 |
/** |
| 68 |
* Construct. |
| 69 |
*/ |
| 70 |
public function __construct() { |
| 71 |
$this->paymod_id = 'paidy'; |
| 72 |
$this->pay_method = array( |
| 73 |
'acting_paidy', |
| 74 |
); |
| 75 |
$this->acting_name = 'ペイディ'; |
| 76 |
$this->acting_formal_name = 'あと払い(ペイディ)'; |
| 77 |
$this->acting_company_url = 'https://paidy.com/'; |
| 78 |
|
| 79 |
$this->initialize_data(); |
| 80 |
|
| 81 |
if ( is_admin() ) { |
| 82 |
add_action( 'admin_print_footer_scripts', array( $this, 'admin_scripts' ) ); |
| 83 |
add_action( 'usces_action_admin_settlement_update', array( $this, 'settlement_update' ) ); |
| 84 |
add_action( 'usces_action_settlement_tab_title', array( $this, 'settlement_tab_title' ) ); |
| 85 |
add_action( 'usces_action_settlement_tab_body', array( $this, 'settlement_tab_body' ) ); |
| 86 |
add_action( 'usces_filter_add_payment_method', array( $this, 'add_payment_method' ) ); |
| 87 |
add_action( 'usces_filter_up_payment_method', array( $this, 'up_payment_method' ) ); |
| 88 |
} |
| 89 |
|
| 90 |
if ( $this->is_validity_acting() ) { |
| 91 |
add_action( 'init', array( $this, 'acting_transaction' ) ); |
| 92 |
add_filter( 'usces_filter_is_complete_settlement', array( $this, 'is_complete_settlement' ), 10, 3 ); |
| 93 |
if ( is_admin() ) { |
| 94 |
add_action( 'usces_action_admin_ajax', array( $this, 'admin_ajax' ) ); |
| 95 |
add_filter( 'usces_filter_orderlist_detail_value', array( $this, 'orderlist_settlement_status' ), 10, 4 ); |
| 96 |
add_action( 'usces_action_order_edit_form_status_block_middle', array( $this, 'settlement_status' ), 10, 3 ); |
| 97 |
add_action( 'usces_action_order_edit_form_settle_info', array( $this, 'settlement_information' ), 10, 2 ); |
| 98 |
add_action( 'usces_action_endof_order_edit_form', array( $this, 'settlement_dialog' ), 10, 2 ); |
| 99 |
add_filter( 'usces_filter_settle_info_field_meta_keys', array( $this, 'settlement_info_field_meta_keys' ) ); |
| 100 |
add_filter( 'usces_filter_settle_info_field_keys', array( $this, 'settlement_info_field_keys' ), 10, 2 ); |
| 101 |
add_filter( 'usces_filter_settle_info_field_value', array( $this, 'settlement_info_field_value' ), 10, 3 ); |
| 102 |
add_filter( 'usces_filter_get_link_key', array( $this, 'get_link_key' ), 10, 2 ); |
| 103 |
add_action( 'usces_action_revival_order_data', array( $this, 'revival_orderdata' ), 10, 3 ); |
| 104 |
} else { |
| 105 |
add_action( 'wp_print_footer_scripts', array( $this, 'footer_scripts' ), 9 ); |
| 106 |
add_filter( 'usces_filter_confirm_inform', array( $this, 'confirm_inform' ), 10, 5 ); |
| 107 |
add_action( 'usces_action_acting_processing', array( $this, 'acting_processing' ), 10, 2 ); |
| 108 |
add_filter( 'usces_filter_check_acting_return_results', array( $this, 'acting_return' ) ); |
| 109 |
add_filter( 'usces_filter_check_acting_return_duplicate', array( $this, 'check_acting_return_duplicate' ), 10, 2 ); |
| 110 |
add_action( 'usces_action_reg_orderdata', array( $this, 'register_orderdata' ) ); |
| 111 |
add_filter( 'usces_filter_get_error_settlement', array( $this, 'error_page_message' ) ); |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Return an instance of this class. |
| 118 |
*/ |
| 119 |
public static function get_instance() { |
| 120 |
if ( is_null( self::$instance ) ) { |
| 121 |
self::$instance = new self(); |
| 122 |
} |
| 123 |
return self::$instance; |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Initialize. |
| 128 |
*/ |
| 129 |
public function initialize_data() { |
| 130 |
$options = get_option( 'usces', array() ); |
| 131 |
$options['acting_settings']['paidy']['activate'] = ( isset( $options['acting_settings']['paidy']['activate'] ) ) ? $options['acting_settings']['paidy']['activate'] : 'off'; |
| 132 |
$options['acting_settings']['paidy']['paidy_activate'] = ( isset( $options['acting_settings']['paidy']['paidy_activate'] ) ) ? $options['acting_settings']['paidy']['paidy_activate'] : 'off'; |
| 133 |
if ( false !== strpos( $options['acting_settings']['paidy']['public_key'], '_test_' ) ) { |
| 134 |
$options['acting_settings']['paidy']['environment'] = 'test'; |
| 135 |
$options['acting_settings']['paidy']['public_key'] = ( ! empty( $options['acting_settings']['paidy']['public_key'] ) ) ? $options['acting_settings']['paidy']['public_key'] : ''; |
| 136 |
$options['acting_settings']['paidy']['secret_key'] = ( ! empty( $options['acting_settings']['paidy']['secret_key'] ) ) ? $options['acting_settings']['paidy']['secret_key'] : ''; |
| 137 |
$options['acting_settings']['paidy']['public_key_test'] = ( ! empty( $options['acting_settings']['paidy']['public_key'] ) ) ? $options['acting_settings']['paidy']['public_key'] : ''; |
| 138 |
$options['acting_settings']['paidy']['secret_key_test'] = ( ! empty( $options['acting_settings']['paidy']['secret_key'] ) ) ? $options['acting_settings']['paidy']['secret_key'] : ''; |
| 139 |
} else { |
| 140 |
$options['acting_settings']['paidy']['environment'] = ( isset( $options['acting_settings']['paidy']['environment'] ) ) ? $options['acting_settings']['paidy']['environment'] : 'live'; |
| 141 |
$options['acting_settings']['paidy']['public_key'] = ( isset( $options['acting_settings']['paidy']['public_key'] ) ) ? $options['acting_settings']['paidy']['public_key'] : ''; |
| 142 |
$options['acting_settings']['paidy']['secret_key'] = ( isset( $options['acting_settings']['paidy']['secret_key'] ) ) ? $options['acting_settings']['paidy']['secret_key'] : ''; |
| 143 |
$options['acting_settings']['paidy']['public_key_test'] = ( isset( $options['acting_settings']['paidy']['public_key_test'] ) ) ? $options['acting_settings']['paidy']['public_key_test'] : ''; |
| 144 |
$options['acting_settings']['paidy']['secret_key_test'] = ( isset( $options['acting_settings']['paidy']['secret_key_test'] ) ) ? $options['acting_settings']['paidy']['secret_key_test'] : ''; |
| 145 |
} |
| 146 |
update_option( 'usces', $options ); |
| 147 |
|
| 148 |
$available_settlement = get_option( 'usces_available_settlement', array() ); |
| 149 |
if ( ! in_array( $this->paymod_id, $available_settlement, true ) ) { |
| 150 |
$available_settlement[ $this->paymod_id ] = $this->acting_name; |
| 151 |
update_option( 'usces_available_settlement', $available_settlement ); |
| 152 |
} |
| 153 |
|
| 154 |
$this->unavailable_method = array( 'acting_paygent_paidy' ); |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* 決済有効判定 |
| 159 |
* 支払方法で使用している場合に true |
| 160 |
* |
| 161 |
* @param string $type Module type. |
| 162 |
* @return boolean |
| 163 |
*/ |
| 164 |
public function is_validity_acting( $type = '' ) { |
| 165 |
$options = get_option( 'usces', array() ); |
| 166 |
if ( empty( $options['acting_settings']['paidy'] ) ) { |
| 167 |
return false; |
| 168 |
} |
| 169 |
|
| 170 |
$payment_method = usces_get_system_option( 'usces_payment_method', 'sort' ); |
| 171 |
$method = false; |
| 172 |
|
| 173 |
switch ( $type ) { |
| 174 |
case 'paidy': |
| 175 |
foreach ( $payment_method as $payment ) { |
| 176 |
if ( 'acting_paidy' === $payment['settlement'] && 'activate' === $payment['use'] ) { |
| 177 |
$method = true; |
| 178 |
break; |
| 179 |
} |
| 180 |
} |
| 181 |
if ( $method && $this->is_activate_paidy() ) { |
| 182 |
return true; |
| 183 |
} else { |
| 184 |
return false; |
| 185 |
} |
| 186 |
break; |
| 187 |
default: |
| 188 |
if ( isset( $options['acting_settings']['paidy']['activate'] ) && 'on' === $options['acting_settings']['paidy']['activate'] ) { |
| 189 |
return true; |
| 190 |
} else { |
| 191 |
return false; |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* ペイディ決済有効判定 |
| 198 |
* |
| 199 |
* @return boolean |
| 200 |
*/ |
| 201 |
public function is_activate_paidy() { |
| 202 |
$options = get_option( 'usces', array() ); |
| 203 |
if ( ( isset( $options['acting_settings']['paidy']['activate'] ) && 'on' === $options['acting_settings']['paidy']['activate'] ) && |
| 204 |
( isset( $options['acting_settings']['paidy']['paidy_activate'] ) && 'on' === $options['acting_settings']['paidy']['paidy_activate'] ) ) { |
| 205 |
$res = true; |
| 206 |
} else { |
| 207 |
$res = false; |
| 208 |
} |
| 209 |
return $res; |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* 管理画面スクリプト |
| 214 |
* admin_print_footer_scripts |
| 215 |
*/ |
| 216 |
public function admin_scripts() { |
| 217 |
$admin_page = filter_input( INPUT_GET, 'page' ); |
| 218 |
switch ( $admin_page ) : |
| 219 |
/* クレジット決済設定画面 */ |
| 220 |
case 'usces_settlement': |
| 221 |
$settlement_selected = get_option( 'usces_settlement_selected', array() ); |
| 222 |
if ( in_array( $this->paymod_id, (array) $settlement_selected, true ) ) : |
| 223 |
$options = get_option( 'usces', array() ); |
| 224 |
$paidy_activate = ( isset( $options['acting_settings']['paidy']['paidy_activate'] ) ) ? $options['acting_settings']['paidy']['paidy_activate'] : 'off'; |
| 225 |
?> |
| 226 |
<script type="text/javascript"> |
| 227 |
jQuery(document).ready( function($) { |
| 228 |
var paidy_activate = "<?php echo esc_js( $paidy_activate ); ?>"; |
| 229 |
if( "on" == paidy_activate ) { |
| 230 |
$(".paidy_form").css("display",""); |
| 231 |
} else { |
| 232 |
$(".paidy_form").css("display","none"); |
| 233 |
} |
| 234 |
$(document).on( "change", ".paidy_activate", function() { |
| 235 |
if( "on" == $(this).val() ) { |
| 236 |
$(".paidy_form").css("display",""); |
| 237 |
} else { |
| 238 |
$(".paidy_form").css("display","none"); |
| 239 |
} |
| 240 |
}); |
| 241 |
}); |
| 242 |
</script> |
| 243 |
<?php |
| 244 |
endif; |
| 245 |
break; |
| 246 |
|
| 247 |
/* 受注編集画面 */ |
| 248 |
case 'usces_orderlist': |
| 249 |
$order_id = ''; |
| 250 |
$acting_flg = ''; |
| 251 |
$order_action = filter_input( INPUT_GET, 'order_action' ); |
| 252 |
if ( 'usces_orderlist' === $admin_page && ( 'edit' === $order_action || 'editpost' === $order_action || 'newpost' === $order_action ) ) { |
| 253 |
$order_id = ( isset( $_REQUEST['order_id'] ) ) ? wp_unslash( $_REQUEST['order_id'] ) : ''; |
| 254 |
if ( ! empty( $order_id ) ) { |
| 255 |
$acting_flg = $this->get_order_acting_flg( $order_id ); |
| 256 |
} |
| 257 |
} |
| 258 |
if ( in_array( $acting_flg, $this->pay_method, true ) ) : |
| 259 |
?> |
| 260 |
<script type="text/javascript"> |
| 261 |
jQuery(document).ready( function($) { |
| 262 |
adminOrderEdit = { |
| 263 |
retrieveSettlementPaidy : function() { |
| 264 |
$("#settlement-response").html(""); |
| 265 |
$("#settlement-response-loading").html('<img src="'+uscesL10n.USCES_PLUGIN_URL+'/images/loading.gif" />'); |
| 266 |
$.ajax({ |
| 267 |
url: ajaxurl, |
| 268 |
type: "POST", |
| 269 |
cache: false, |
| 270 |
dataType: "json", |
| 271 |
data: { |
| 272 |
action: "usces_admin_ajax", |
| 273 |
mode: "retrieve_paidy", |
| 274 |
order_id: $("#order_id").val(), |
| 275 |
trans_id: $("#trans_id").val(), |
| 276 |
wc_nonce: $("#wc_nonce").val() |
| 277 |
} |
| 278 |
}).done( function(retVal,dataType) { |
| 279 |
if( retVal.result ) { |
| 280 |
$("#settlement-response").html(retVal.result); |
| 281 |
} |
| 282 |
$("#settlement-response-loading").html(""); |
| 283 |
}).fail( function(jqXHR,textStatus,errorThrown) { |
| 284 |
console.log(textStatus); |
| 285 |
console.log(jqXHR.status); |
| 286 |
console.log(errorThrown.message); |
| 287 |
$("#settlement-response-loading").html(""); |
| 288 |
}); |
| 289 |
return false; |
| 290 |
}, |
| 291 |
closeSettlementPaidy : function() { |
| 292 |
$("#settlement-response").html(""); |
| 293 |
$("#settlement-response-loading").html('<img src="'+uscesL10n.USCES_PLUGIN_URL+'/images/loading.gif" />'); |
| 294 |
$.ajax({ |
| 295 |
url: ajaxurl, |
| 296 |
type: "POST", |
| 297 |
cache: false, |
| 298 |
dataType: "json", |
| 299 |
data: { |
| 300 |
action: "usces_admin_ajax", |
| 301 |
mode: "close_paidy", |
| 302 |
order_id: $("#order_id").val(), |
| 303 |
trans_id: $("#trans_id").val(), |
| 304 |
wc_nonce: $("#wc_nonce").val() |
| 305 |
} |
| 306 |
}).done( function(retVal,dataType) { |
| 307 |
if( retVal.acting_status ) { |
| 308 |
$("#settlement-status").html(retVal.acting_status); |
| 309 |
} |
| 310 |
if( retVal.result ) { |
| 311 |
$("#settlement-response").html(retVal.result); |
| 312 |
} |
| 313 |
$("#settlement-response-loading").html(""); |
| 314 |
}).fail( function(jqXHR,textStatus,errorThrown) { |
| 315 |
console.log(textStatus); |
| 316 |
console.log(jqXHR.status); |
| 317 |
console.log(errorThrown.message); |
| 318 |
$("#settlement-response-loading").html(""); |
| 319 |
}); |
| 320 |
return false; |
| 321 |
}, |
| 322 |
captureSettlementPaidy : function() { |
| 323 |
$("#settlement-response").html(""); |
| 324 |
$("#settlement-response-loading").html('<img src="'+uscesL10n.USCES_PLUGIN_URL+'/images/loading.gif" />'); |
| 325 |
$.ajax({ |
| 326 |
url: ajaxurl, |
| 327 |
type: "POST", |
| 328 |
cache: false, |
| 329 |
dataType: "json", |
| 330 |
data: { |
| 331 |
action: "usces_admin_ajax", |
| 332 |
mode: "capture_paidy", |
| 333 |
order_id: $("#order_id").val(), |
| 334 |
trans_id: $("#trans_id").val(), |
| 335 |
wc_nonce: $("#wc_nonce").val() |
| 336 |
} |
| 337 |
}).done( function(retVal,dataType) { |
| 338 |
if( retVal.acting_status ) { |
| 339 |
$("#settlement-status").html(retVal.acting_status); |
| 340 |
} |
| 341 |
if( retVal.result ) { |
| 342 |
$("#settlement-response").html(retVal.result); |
| 343 |
} |
| 344 |
$("#settlement-response-loading").html(""); |
| 345 |
}).fail( function(jqXHR,textStatus,errorThrown) { |
| 346 |
console.log(textStatus); |
| 347 |
console.log(jqXHR.status); |
| 348 |
console.log(errorThrown.message); |
| 349 |
$("#settlement-response-loading").html(""); |
| 350 |
}); |
| 351 |
return false; |
| 352 |
}, |
| 353 |
refundSettlementPaidy : function(amount) { |
| 354 |
$("#settlement-response").html(""); |
| 355 |
$("#settlement-response-loading").html('<img src="'+uscesL10n.USCES_PLUGIN_URL+'/images/loading.gif" />'); |
| 356 |
$.ajax({ |
| 357 |
url: ajaxurl, |
| 358 |
type: "POST", |
| 359 |
cache: false, |
| 360 |
dataType: "json", |
| 361 |
data: { |
| 362 |
action: "usces_admin_ajax", |
| 363 |
mode: "refund_paidy", |
| 364 |
order_id: $("#order_id").val(), |
| 365 |
trans_id: $("#trans_id").val(), |
| 366 |
amount: amount, |
| 367 |
wc_nonce: $("#wc_nonce").val() |
| 368 |
} |
| 369 |
}).done( function(retVal,dataType) { |
| 370 |
if( retVal.acting_status ) { |
| 371 |
$("#settlement-status").html(retVal.acting_status); |
| 372 |
} |
| 373 |
if( retVal.result ) { |
| 374 |
$("#settlement-response").html(retVal.result); |
| 375 |
} |
| 376 |
$("#settlement-response-loading").html(""); |
| 377 |
}).fail( function(jqXHR,textStatus,errorThrown) { |
| 378 |
console.log(textStatus); |
| 379 |
console.log(jqXHR.status); |
| 380 |
console.log(errorThrown.message); |
| 381 |
$("#settlement-response-loading").html(""); |
| 382 |
}); |
| 383 |
return false; |
| 384 |
} |
| 385 |
}; |
| 386 |
|
| 387 |
$("#settlement_dialog").dialog({ |
| 388 |
dialogClass: "admin-paidy-dialog", |
| 389 |
bgiframe: true, |
| 390 |
autoOpen: false, |
| 391 |
height: "auto", |
| 392 |
width: 800, |
| 393 |
resizable: true, |
| 394 |
modal: true, |
| 395 |
buttons: { |
| 396 |
"<?php esc_html_e( 'Close' ); ?>": function() { |
| 397 |
$(this).dialog("close"); |
| 398 |
} |
| 399 |
}, |
| 400 |
open: function() { |
| 401 |
adminOrderEdit.retrieveSettlementPaidy(); |
| 402 |
}, |
| 403 |
close: function() { |
| 404 |
} |
| 405 |
}); |
| 406 |
|
| 407 |
$(document).on( "click", ".settlement-information", function() { |
| 408 |
var trans_id = $(this).attr("data-trans_id"); |
| 409 |
var order_num = $(this).attr("data-num"); |
| 410 |
$("#trans_id").val(trans_id); |
| 411 |
$("#order_num").val(order_num); |
| 412 |
$("#settlement_dialog").dialog("option","title","<?php echo esc_js( $this->acting_name ); ?>"); |
| 413 |
$("#settlement_dialog").dialog("open"); |
| 414 |
}); |
| 415 |
|
| 416 |
$(document).on( "click", "#paidy-capture-settlement", function() { |
| 417 |
if( ! confirm("キャプチャー(売上確定)します。よろしいですか?") ) { |
| 418 |
return; |
| 419 |
} |
| 420 |
adminOrderEdit.captureSettlementPaidy(); |
| 421 |
}); |
| 422 |
|
| 423 |
$(document).on( "click", "#paidy-close-settlement", function() { |
| 424 |
if( ! confirm("クローズします。よろしいですか?") ) { |
| 425 |
return; |
| 426 |
} |
| 427 |
adminOrderEdit.closeSettlementPaidy(); |
| 428 |
}); |
| 429 |
|
| 430 |
$(document).on( "click", "#paidy-refund-settlement", function() { |
| 431 |
var amount_original = parseInt($("#amount_original").val())||0; |
| 432 |
var amount_change = parseInt($("#amount_change").val())||0; |
| 433 |
if( amount_change == amount_original ) { |
| 434 |
return; |
| 435 |
} |
| 436 |
if( amount_change > amount_original ) { |
| 437 |
alert("決済金額を� |
| 438 |
える金額はリファンド(返金)できません。"); |
| 439 |
return; |
| 440 |
} |
| 441 |
if( 0 == amount_change ) { |
| 442 |
if( ! confirm("� |
| 443 |
�額リファンド(返金)します。よろしいですか?") ) { |
| 444 |
return; |
| 445 |
} |
| 446 |
adminOrderEdit.refundSettlementPaidy(amount_original); |
| 447 |
} else { |
| 448 |
var amount = amount_original - amount_change; |
| 449 |
if( ! confirm(amount+"円をリファンド(返金)します。よろしいですか?") ) { |
| 450 |
return; |
| 451 |
} |
| 452 |
adminOrderEdit.refundSettlementPaidy(amount); |
| 453 |
} |
| 454 |
}); |
| 455 |
|
| 456 |
$(document).on( "keydown", ".settlement-amount", function(e) { |
| 457 |
var halfVal = $(this).val().replace(/[!-~]/g, |
| 458 |
function(tmpStr) { |
| 459 |
return String.fromCharCode(tmpStr.charCodeAt(0) - 0xFEE0); |
| 460 |
} |
| 461 |
); |
| 462 |
$(this).val(halfVal.replace(/[^0-9]/g,'')); |
| 463 |
}); |
| 464 |
$(document).on( "keyup", ".settlement-amount", function() { |
| 465 |
this.value = this.value.replace(/[^0-9]+/i,''); |
| 466 |
this.value = Number(this.value)||0; |
| 467 |
}); |
| 468 |
$(document).on( "blur", ".settlement-amount", function() { |
| 469 |
this.value = this.value.replace(/[^0-9]+/i,''); |
| 470 |
}); |
| 471 |
}); |
| 472 |
</script> |
| 473 |
<?php |
| 474 |
endif; |
| 475 |
break; |
| 476 |
endswitch; |
| 477 |
} |
| 478 |
|
| 479 |
/** |
| 480 |
* 決済オプション登録・更新 |
| 481 |
* usces_action_admin_settlement_update |
| 482 |
*/ |
| 483 |
public function settlement_update() { |
| 484 |
global $usces; |
| 485 |
|
| 486 |
if ( filter_input( INPUT_POST, 'acting' ) !== $this->paymod_id ) { |
| 487 |
return; |
| 488 |
} |
| 489 |
|
| 490 |
$this->error_mes = ''; |
| 491 |
$payment_method = usces_get_system_option( 'usces_payment_method', 'settlement' ); |
| 492 |
$options = get_option( 'usces', array() ); |
| 493 |
$post_data = wp_unslash( $_POST ); |
| 494 |
|
| 495 |
unset( $options['acting_settings']['paidy'] ); |
| 496 |
$options['acting_settings']['paidy']['paidy_activate'] = ( isset( $post_data['paidy_activate'] ) ) ? $post_data['paidy_activate'] : 'off'; |
| 497 |
$options['acting_settings']['paidy']['environment'] = ( isset( $post_data['environment'] ) ) ? $post_data['environment'] : 'live'; |
| 498 |
$options['acting_settings']['paidy']['public_key'] = ( isset( $post_data['public_key'] ) ) ? $post_data['public_key'] : ''; |
| 499 |
$options['acting_settings']['paidy']['secret_key'] = ( isset( $post_data['secret_key'] ) ) ? $post_data['secret_key'] : ''; |
| 500 |
$options['acting_settings']['paidy']['public_key_test'] = ( isset( $post_data['public_key_test'] ) ) ? $post_data['public_key_test'] : ''; |
| 501 |
$options['acting_settings']['paidy']['secret_key_test'] = ( isset( $post_data['secret_key_test'] ) ) ? $post_data['secret_key_test'] : ''; |
| 502 |
|
| 503 |
if ( 'on' === $options['acting_settings']['paidy']['paidy_activate'] ) { |
| 504 |
if ( 'live' === $options['acting_settings']['paidy']['environment'] ) { |
| 505 |
if ( WCUtils::is_blank( $options['acting_settings']['paidy']['public_key'] ) ) { |
| 506 |
$this->error_mes .= '※本番用パブリックキーを� |
| 507 |
�力してください<br />'; |
| 508 |
} |
| 509 |
if ( WCUtils::is_blank( $options['acting_settings']['paidy']['secret_key'] ) ) { |
| 510 |
$this->error_mes .= '※本番用シークレットキーを� |
| 511 |
�力してください<br />'; |
| 512 |
} |
| 513 |
} else { |
| 514 |
if ( WCUtils::is_blank( $options['acting_settings']['paidy']['public_key_test'] ) ) { |
| 515 |
$this->error_mes .= '※テスト用パブリックキーを� |
| 516 |
�力してください<br />'; |
| 517 |
} |
| 518 |
if ( WCUtils::is_blank( $options['acting_settings']['paidy']['secret_key_test'] ) ) { |
| 519 |
$this->error_mes .= '※テスト用シークレットキーを� |
| 520 |
�力してください<br />'; |
| 521 |
} |
| 522 |
} |
| 523 |
} |
| 524 |
|
| 525 |
if ( '' === $this->error_mes ) { |
| 526 |
$usces->action_status = 'success'; |
| 527 |
$usces->action_message = __( 'Options are updated.', 'usces' ); |
| 528 |
$toactive = array(); |
| 529 |
if ( 'on' === $options['acting_settings']['paidy']['paidy_activate'] ) { |
| 530 |
$usces->payment_structure['acting_paidy'] = 'Paidy'; |
| 531 |
foreach ( $payment_method as $settlement => $payment ) { |
| 532 |
if ( 'acting_paidy' === $settlement && 'activate' !== $payment['use'] ) { |
| 533 |
$toactive[] = $payment['name']; |
| 534 |
} |
| 535 |
} |
| 536 |
} else { |
| 537 |
unset( $usces->payment_structure['acting_paidy'] ); |
| 538 |
} |
| 539 |
if ( 'on' === $options['acting_settings']['paidy']['paidy_activate'] ) { |
| 540 |
$options['acting_settings']['paidy']['activate'] = 'on'; |
| 541 |
usces_admin_orderlist_show_wc_trans_id(); |
| 542 |
if ( 0 < count( $toactive ) ) { |
| 543 |
$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' ); |
| 544 |
} |
| 545 |
} else { |
| 546 |
$options['acting_settings']['paidy']['activate'] = 'off'; |
| 547 |
unset( $usces->payment_structure['acting_paidy'] ); |
| 548 |
} |
| 549 |
$deactivate = array(); |
| 550 |
foreach ( $payment_method as $settlement => $payment ) { |
| 551 |
if ( ! array_key_exists( $settlement, $usces->payment_structure ) ) { |
| 552 |
if ( 'deactivate' !== $payment['use'] ) { |
| 553 |
$payment['use'] = 'deactivate'; |
| 554 |
$deactivate[] = $payment['name']; |
| 555 |
usces_update_system_option( 'usces_payment_method', $payment['id'], $payment ); |
| 556 |
} |
| 557 |
} |
| 558 |
} |
| 559 |
if ( 0 < count( $deactivate ) ) { |
| 560 |
$deactivate_message = sprintf( __( '"Deactivate" %s of payment method.', 'usces' ), implode( ',', $deactivate ) ); |
| 561 |
$usces->action_message .= $deactivate_message; |
| 562 |
} |
| 563 |
} else { |
| 564 |
$usces->action_status = 'error'; |
| 565 |
$usces->action_message = __( 'Data have deficiency.', 'usces' ); |
| 566 |
$options['acting_settings']['paidy']['activate'] = 'off'; |
| 567 |
unset( $usces->payment_structure['acting_paidy'] ); |
| 568 |
$deactivate = array(); |
| 569 |
foreach ( $payment_method as $settlement => $payment ) { |
| 570 |
if ( in_array( $settlement, $this->pay_method, true ) ) { |
| 571 |
if ( 'deactivate' !== $payment['use'] ) { |
| 572 |
$payment['use'] = 'deactivate'; |
| 573 |
$deactivate[] = $payment['name']; |
| 574 |
usces_update_system_option( 'usces_payment_method', $payment['id'], $payment ); |
| 575 |
} |
| 576 |
} |
| 577 |
} |
| 578 |
if ( 0 < count( $deactivate ) ) { |
| 579 |
$deactivate_message = sprintf( __( '"Deactivate" %s of payment method.', 'usces' ), implode( ',', $deactivate ) ); |
| 580 |
$usces->action_message .= $deactivate_message . __( 'Please complete the setup and update the payment method to "Activate".', 'usces' ); |
| 581 |
} |
| 582 |
} |
| 583 |
|
| 584 |
ksort( $usces->payment_structure ); |
| 585 |
update_option( 'usces', $options ); |
| 586 |
update_option( 'usces_payment_structure', $usces->payment_structure ); |
| 587 |
} |
| 588 |
|
| 589 |
/** |
| 590 |
* クレジット決済設定画面タブ |
| 591 |
* usces_action_settlement_tab_title |
| 592 |
*/ |
| 593 |
public function settlement_tab_title() { |
| 594 |
$settlement_selected = get_option( 'usces_settlement_selected', array() ); |
| 595 |
if ( in_array( $this->paymod_id, $settlement_selected, true ) ) { |
| 596 |
echo '<li><a href="#uscestabs_' . esc_html( $this->paymod_id ) . '">' . esc_html( $this->acting_name ) . '</a></li>'; |
| 597 |
} |
| 598 |
} |
| 599 |
|
| 600 |
/** |
| 601 |
* クレジット決済設定画面フォーム |
| 602 |
* usces_action_settlement_tab_body |
| 603 |
*/ |
| 604 |
public function settlement_tab_body() { |
| 605 |
$settlement_selected = get_option( 'usces_settlement_selected', array() ); |
| 606 |
if ( in_array( $this->paymod_id, $settlement_selected, true ) ) : |
| 607 |
$options = get_option( 'usces', array() ); |
| 608 |
$activate = ( isset( $options['acting_settings']['paidy']['activate'] ) && 'on' === $options['acting_settings']['paidy']['activate'] ) ? true : false; |
| 609 |
$paidy_activate = ( isset( $options['acting_settings']['paidy']['paidy_activate'] ) && ( 'on' === $options['acting_settings']['paidy']['paidy_activate'] ) ) ? 'on' : 'off'; |
| 610 |
$environment = ( isset( $options['acting_settings']['paidy']['environment'] ) ) ? $options['acting_settings']['paidy']['environment'] : 'live'; |
| 611 |
?> |
| 612 |
<div id="uscestabs_paidy"> |
| 613 |
<div class="settlement_service"><span class="service_title"><?php echo esc_html( $this->acting_name ); ?></span></div> |
| 614 |
<?php |
| 615 |
if ( filter_input( INPUT_POST, 'acting' ) === $this->paymod_id ) : |
| 616 |
if ( '' !== $this->error_mes ) : |
| 617 |
?> |
| 618 |
<div class="error_message"><?php wel_esc_script_e( $this->error_mes ); ?></div> |
| 619 |
<?php |
| 620 |
elseif ( $activate ) : |
| 621 |
?> |
| 622 |
<div class="message">十分にテストを行ってから運用してください。</div> |
| 623 |
<?php |
| 624 |
endif; |
| 625 |
endif; |
| 626 |
?> |
| 627 |
<form action="" method="post" name="paidy_form" id="paidy_form"> |
| 628 |
<table class="settle_table"> |
| 629 |
<tr> |
| 630 |
<th><?php echo esc_html( $this->acting_name ); ?></th> |
| 631 |
<td><label><input name="paidy_activate" type="radio" class="paidy_activate" id="paidy_activate_on" value="on"<?php checked( $paidy_activate, 'on' ); ?> /><span>利用する</span></label><br /> |
| 632 |
<label><input name="paidy_activate" type="radio" class="paidy_activate" id="paidy_activate_off" value="off"<?php checked( $paidy_activate, 'off' ); ?> /><span>利用しない</span></label> |
| 633 |
</td> |
| 634 |
</tr> |
| 635 |
<tr class="paidy_form"> |
| 636 |
<th>動作環境</th> |
| 637 |
<td><label><input name="environment" type="radio" class="paidy_environment" id="paidy_environment_live" value="live"<?php checked( $environment, 'live' ); ?> /><span>本番環境</span></label><br /> |
| 638 |
<label><input name="environment" type="radio" class="paidy_environment" id="paidy_environment_test" value="test"<?php checked( $environment, 'test' ); ?> /><span>テスト環境</span></label> |
| 639 |
</td> |
| 640 |
</tr> |
| 641 |
<tr class="paidy_form"> |
| 642 |
<th><a class="explanation-label" id="label_ex_public_key_paidy">本番用パブリックキー</a></th> |
| 643 |
<td><input name="public_key" type="text" id="public_key_paidy" value="<?php echo esc_attr( $options['acting_settings']['paidy']['public_key'] ); ?>" class="regular-text" /></td> |
| 644 |
</tr> |
| 645 |
<tr id="ex_public_key_paidy" class="explanation paidy_form"><td colspan="2">ペイディ加盟店管理画面の設定より本番用の「パブリックキー」を取得してください。(半角英数字)</td></tr> |
| 646 |
<tr class="paidy_form"> |
| 647 |
<th><a class="explanation-label" id="label_ex_secret_key_paidy">本番用シークレットキー</a></th> |
| 648 |
<td><input name="secret_key" type="text" id="secret_key_paidy" value="<?php echo esc_attr( $options['acting_settings']['paidy']['secret_key'] ); ?>" class="regular-text" /></td> |
| 649 |
</tr> |
| 650 |
<tr id="ex_secret_key_paidy" class="explanation paidy_form"><td colspan="2">ペイディ加盟店管理画面の設定より本番用の「シークレットキー」を取得してください。(半角英数字)</td></tr> |
| 651 |
<tr class="paidy_form"> |
| 652 |
<th><a class="explanation-label" id="label_ex_public_key_test_paidy">テスト用パブリックキー</a></th> |
| 653 |
<td><input name="public_key_test" type="text" id="public_key_test_paidy" value="<?php echo esc_attr( $options['acting_settings']['paidy']['public_key_test'] ); ?>" class="regular-text" /></td> |
| 654 |
</tr> |
| 655 |
<tr id="ex_public_key_test_paidy" class="explanation paidy_form"><td colspan="2">ペイディ加盟店管理画面の設定よりテスト用の「パブリックキー」を取得してください。(半角英数字)</td></tr> |
| 656 |
<tr class="paidy_form"> |
| 657 |
<th><a class="explanation-label" id="label_ex_secret_key_test_paidy">テスト用シークレットキー</a></th> |
| 658 |
<td><input name="secret_key_test" type="text" id="secret_key_test_paidy" value="<?php echo esc_attr( $options['acting_settings']['paidy']['secret_key_test'] ); ?>" class="regular-text" /></td> |
| 659 |
</tr> |
| 660 |
<tr id="ex_secret_key_test_paidy" class="explanation paidy_form"><td colspan="2">ペイディ加盟店管理画面の設定よりテスト用の「シークレットキー」を取得してください。(半角英数字)</td></tr> |
| 661 |
</table> |
| 662 |
<input name="acting" type="hidden" value="paidy" /> |
| 663 |
<input name="usces_option_update" type="submit" class="button button-primary" value="<?php echo esc_attr( $this->acting_name ); ?>の設定を更新する" /> |
| 664 |
<?php wp_nonce_field( 'admin_settlement', 'wc_nonce' ); ?> |
| 665 |
</form> |
| 666 |
<div class="settle_exp"> |
| 667 |
<p><strong>ペイディとは</strong></p> |
| 668 |
<p>クレジットカードが不要なため、クレジットカードを持っていない若年層や、セキュリティが不安でクレジットカードをなるべく使いたくないユーザーも、安心してお買い物を楽しむことができる決済です。</p> |
| 669 |
<p><a href="https://paidy.com/landing/" target="_blank">ペイディの詳細はこちら 》</a></p> |
| 670 |
<p>【ご利用までの流れ】<br> |
| 671 |
お申し込み前に「特定商取引法に基づく表示」と「プライバシーポリシー(個人� |
| 672 |
報の第三� |
| 673 |
提供含む)」ページのご準備をお願いいたします。<br> |
| 674 |
<ol> |
| 675 |
<li>加盟店申請:ダッシュボードのペイディ決済らくらく設定、または<a href="https://paidy.com/merchant/application/" target="_blank">ペイディWebサイト</a>からお申し込みください。</li> |
| 676 |
<li>加盟店審査:お申し込みから最大10営業日で、審査結果メールがPaidy合同会社より届きます。添付されている条件通知書で、「契約日」と「経済条件」をご確認ください。</li> |
| 677 |
<li>利用開始 : |
| 678 |
<ol> |
| 679 |
<li type="a">ペイディ決済らくらく設定から申し込んだ場合、ダッシュボードに表示されるボタンによりご利用開始が可能です。</li> |
| 680 |
<li type="a">ペイディWebサイトから申し込んだ場合、WelcartでAPIキーの設定が完了したら、ご利用開始となります。</li> |
| 681 |
</ol> |
| 682 |
</li> |
| 683 |
</ol> |
| 684 |
</p> |
| 685 |
<p>APIキーの確認方法は、<a href="https://download.paidy.com/merchant/paidy_intro_guide.pdf" target="_blank">ペイディ導� |
| 686 |
�ガイド</a>の Paidy APIキー をご確認ください。</p> |
| 687 |
<p>【資料】<br> |
| 688 |
操作方法などについては下記をご覧ください。<br> |
| 689 |
<a href="https://download.paidy.com/merchant/paidy_intro_guide.pdf" target="_blank">ペイディ導� |
| 690 |
�ガイド</a><br> |
| 691 |
<a href="https://download.paidy.com/merchant/PaidyMerchantWebUserGuide.pdf" target="_blank">ペイディ加盟店管理画面マニュアル</a><br> |
| 692 |
<a href="https://merchant-support.paidy.com/hc/ja" target="_blank">加盟店FAQ</a></p> |
| 693 |
</div> |
| 694 |
</div><!--uscestabs_paidy--> |
| 695 |
<?php |
| 696 |
endif; |
| 697 |
} |
| 698 |
|
| 699 |
/** |
| 700 |
* 支払方法追加 |
| 701 |
* usces_filter_add_payment_method |
| 702 |
* |
| 703 |
* @param array $newvalue Payment method data. |
| 704 |
* @return array |
| 705 |
*/ |
| 706 |
public function add_payment_method( $newvalue ) { |
| 707 |
if ( USCES_JP && 'acting_paidy' === $newvalue['settlement'] ) { |
| 708 |
$payment_method = get_option( 'usces_payment_method', array() ); |
| 709 |
$unique = true; |
| 710 |
foreach ( (array) $payment_method as $pm ) { |
| 711 |
if ( $pm['name'] === $this->acting_formal_name ) { |
| 712 |
$unique = false; |
| 713 |
} elseif ( $pm['name'] === $newvalue['name'] ) { |
| 714 |
$unique = false; |
| 715 |
} |
| 716 |
} |
| 717 |
if ( $unique ) { |
| 718 |
$newvalue['name'] = $this->acting_formal_name; |
| 719 |
} |
| 720 |
$newvalue['explanation'] = '<ul> |
| 721 |
<li>クレジットカード、事前登録不要。</li> |
| 722 |
<li>メールアドレスと携帯番号だけで、今すぐお買い物。</li> |
| 723 |
<li>1か月に何度お買い物しても、お支払いは翌月まとめて1回でOK。</li> |
| 724 |
<li>お支払いは翌月10日までに、コンビニ払い・銀行振込・口座振替で。</li> |
| 725 |
</ul>'; |
| 726 |
} |
| 727 |
return $newvalue; |
| 728 |
} |
| 729 |
|
| 730 |
/** |
| 731 |
* 支払方法変更 |
| 732 |
* usces_filter_up_payment_method |
| 733 |
* |
| 734 |
* @param array $value Payment method data. |
| 735 |
* @return array |
| 736 |
*/ |
| 737 |
public function up_payment_method( $value ) { |
| 738 |
if ( USCES_JP && 'acting_paidy' === $value['settlement'] ) { |
| 739 |
$value['name'] = $this->acting_formal_name; |
| 740 |
} |
| 741 |
return $value; |
| 742 |
} |
| 743 |
|
| 744 |
/** |
| 745 |
* 結果通知処理 |
| 746 |
* usces_after_cart_instant |
| 747 |
*/ |
| 748 |
public function acting_transaction() { |
| 749 |
global $usces; |
| 750 |
|
| 751 |
$post_json = file_get_contents( 'php://input' ); |
| 752 |
$post_data = json_decode( $post_json, true ); |
| 753 |
if ( isset( $post_data['payment_id'] ) && isset( $post_data['status'] ) && isset( $post_data['order_ref'] ) ) { |
| 754 |
if ( 'authorize_success' === $post_data['status'] ) { |
| 755 |
$order_id = usces_get_order_id_by_trans_id( $post_data['order_ref'] ); |
| 756 |
if ( empty( $order_id ) ) { |
| 757 |
// $response_data = $this->api_close( $post_data['payment_id'] ); |
| 758 |
$response_data = $this->api_retrieve( $post_data['payment_id'] ); |
| 759 |
if ( isset( $response_data['status'] ) && 'authorized' === $response_data['status'] ) { |
| 760 |
if ( ! isset( $response_data['acting'] ) ) { |
| 761 |
$response_data['acting'] = 'paidy'; |
| 762 |
} |
| 763 |
$res = $usces->order_processing( $response_data ); |
| 764 |
} |
| 765 |
} |
| 766 |
} |
| 767 |
header( 'HTTP/1.0 200 OK' ); |
| 768 |
die(); |
| 769 |
} |
| 770 |
} |
| 771 |
|
| 772 |
/** |
| 773 |
* ポイント即時付与 |
| 774 |
* usces_filter_is_complete_settlement |
| 775 |
* |
| 776 |
* @param boolean $complete Complete the payment. |
| 777 |
* @param string $payment_name Payment name. |
| 778 |
* @param string $status Payment status. |
| 779 |
* @return boolean |
| 780 |
*/ |
| 781 |
public function is_complete_settlement( $complete, $payment_name, $status ) { |
| 782 |
$payment = usces_get_payments_by_name( $payment_name ); |
| 783 |
if ( isset( $payment['settlement'] ) && 'acting_paidy' === $payment['settlement'] ) { |
| 784 |
$complete = true; |
| 785 |
} |
| 786 |
return $complete; |
| 787 |
} |
| 788 |
|
| 789 |
/** |
| 790 |
* 管理画面決済処理 |
| 791 |
* usces_action_admin_ajax |
| 792 |
*/ |
| 793 |
public function admin_ajax() { |
| 794 |
global $usces; |
| 795 |
|
| 796 |
$mode = filter_input( INPUT_POST, 'mode' ); |
| 797 |
$data = array(); |
| 798 |
|
| 799 |
switch ( $mode ) { |
| 800 |
/* 参� |
| 801 |
� */ |
| 802 |
case 'retrieve_paidy': |
| 803 |
check_admin_referer( 'order_edit', 'wc_nonce' ); |
| 804 |
$order_id = filter_input( INPUT_POST, 'order_id' ); |
| 805 |
$trans_id = filter_input( INPUT_POST, 'trans_id' ); |
| 806 |
if ( empty( $order_id ) || empty( $trans_id ) ) { |
| 807 |
$data['status'] = 'retrieve_error'; |
| 808 |
wp_send_json( $data ); |
| 809 |
break; |
| 810 |
} |
| 811 |
|
| 812 |
$result = ''; |
| 813 |
|
| 814 |
$latest_log = $this->get_acting_latest_log( $order_id, $trans_id ); |
| 815 |
$payment_id = ( isset( $latest_log['payment_id'] ) ) ? $latest_log['payment_id'] : ''; |
| 816 |
$response_data = $this->api_retrieve( $payment_id, true ); |
| 817 |
if ( isset( $response_data['status'] ) ) { |
| 818 |
$status = $response_data['status']; |
| 819 |
$amount = ( isset( $response_data['final_amount'] ) ) ? $response_data['final_amount'] : $response_data['amount']; |
| 820 |
if ( ! empty( $response_data['capture_id'] ) && 0 < $amount ) { |
| 821 |
$status = 'capture'; |
| 822 |
} |
| 823 |
$class = ' paidy-' . $status; |
| 824 |
$status_name = $this->get_status_name( $status ); |
| 825 |
$result .= '<div class="paidy-settlement-admin' . $class . '">' . $status_name . '</div>'; |
| 826 |
switch ( $status ) { |
| 827 |
case 'authorized': |
| 828 |
$result .= '<table class="settlement-admin-table">'; |
| 829 |
$result .= '<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>'; |
| 830 |
$result .= '<td><input type="tel" class="settlement-amount" value="' . intval( $amount ) . '" disabled="disabled" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>'; |
| 831 |
$result .= '</tr></table>'; |
| 832 |
$result .= '<div class="settlement-admin-button">'; |
| 833 |
$result .= '<input id="paidy-capture-settlement" type="button" class="button" value="キャプチャー(売上確定)" />'; |
| 834 |
$result .= '<input id="paidy-close-settlement" type="button" class="button" value="クローズ" />'; |
| 835 |
$result .= '</div>'; |
| 836 |
break; |
| 837 |
case 'capture': |
| 838 |
$result .= '<table class="settlement-admin-table">'; |
| 839 |
$result .= '<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>'; |
| 840 |
$result .= '<td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $amount ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $amount ) . '" /></td>'; |
| 841 |
$result .= '</tr></table>'; |
| 842 |
$result .= '<div class="settlement-admin-button">'; |
| 843 |
$result .= '<input id="paidy-refund-settlement" type="button" class="button" value="リファンド(返金)" />'; |
| 844 |
$result .= '</div>'; |
| 845 |
break; |
| 846 |
case 'closed': |
| 847 |
$result .= '<table class="settlement-admin-table">'; |
| 848 |
$result .= '<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>'; |
| 849 |
$result .= '<td><input type="tel" class="settlement-amount" value="0" disabled="disabled" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>'; |
| 850 |
$result .= '</tr></table>'; |
| 851 |
break; |
| 852 |
} |
| 853 |
} |
| 854 |
$result .= $this->settlement_history( $order_id, $trans_id ); |
| 855 |
$data['result'] = $result; |
| 856 |
wp_send_json( $data ); |
| 857 |
break; |
| 858 |
|
| 859 |
/* クローズ */ |
| 860 |
case 'close_paidy': |
| 861 |
check_admin_referer( 'order_edit', 'wc_nonce' ); |
| 862 |
$order_id = filter_input( INPUT_POST, 'order_id' ); |
| 863 |
$trans_id = filter_input( INPUT_POST, 'trans_id' ); |
| 864 |
if ( empty( $order_id ) || empty( $trans_id ) ) { |
| 865 |
$data['status'] = 'retrieve_error'; |
| 866 |
wp_send_json( $data ); |
| 867 |
break; |
| 868 |
} |
| 869 |
|
| 870 |
$result = ''; |
| 871 |
$status = 'closed'; |
| 872 |
$acting_status = ''; |
| 873 |
|
| 874 |
$latest_log = $this->get_acting_latest_log( $order_id, $trans_id ); |
| 875 |
$payment_id = ( isset( $latest_log['payment_id'] ) ) ? $latest_log['payment_id'] : ''; |
| 876 |
$response_data = $this->api_close( $payment_id ); |
| 877 |
if ( isset( $response_data['status'] ) && ! isset( $response_data['code'] ) ) { |
| 878 |
$this->save_acting_log( $response_data, 'paidy', $status, 'OK', $order_id, $trans_id ); |
| 879 |
$class = ' paidy-' . $status; |
| 880 |
$status_name = $this->get_status_name( $status ); |
| 881 |
$result .= '<div class="paidy-settlement-admin' . $class . '">' . $status_name . '</div>'; |
| 882 |
$acting_status = '<span class="acting-status' . $class . '">' . $status_name . '</span>'; |
| 883 |
$result .= '<table class="settlement-admin-table">'; |
| 884 |
$result .= '<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>'; |
| 885 |
$result .= '<td><input type="tel" class="settlement-amount" value="0" disabled="disabled" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>'; |
| 886 |
$result .= '</tr></table>'; |
| 887 |
} else { |
| 888 |
$status = 'closed_error'; |
| 889 |
$this->save_acting_log( $response_data, 'paidy', $status, 'NG', $order_id, $trans_id ); |
| 890 |
$status_name = $this->get_status_name( $status ); |
| 891 |
$result .= '<div class="paidy-settlement-admin paidy-error">' . $status_name . '</div>'; |
| 892 |
$amount = (int) $latest_log['amount']; |
| 893 |
switch ( $latest_log['status'] ) { |
| 894 |
case 'authorized': |
| 895 |
$result .= '<table class="settlement-admin-table">'; |
| 896 |
$result .= '<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>'; |
| 897 |
$result .= '<td><input type="tel" class="settlement-amount" value="' . intval( $amount ) . '" disabled="disabled" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>'; |
| 898 |
$result .= '</tr></table>'; |
| 899 |
$result .= '<div class="settlement-admin-button">'; |
| 900 |
$result .= '<input id="paidy-capture-settlement" type="button" class="button" value="キャプチャー(売上確定)" />'; |
| 901 |
$result .= '<input id="paidy-close-settlement" type="button" class="button" value="クローズ" />'; |
| 902 |
$result .= '</div>'; |
| 903 |
break; |
| 904 |
case 'capture': |
| 905 |
$result .= '<table class="settlement-admin-table">'; |
| 906 |
$result .= '<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>'; |
| 907 |
$result .= '<td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $amount ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $amount ) . '" /></td>'; |
| 908 |
$result .= '</tr></table>'; |
| 909 |
$result .= '<div class="settlement-admin-button">'; |
| 910 |
$result .= '<input id="paidy-refund-settlement" type="button" class="button" value="リファンド(返金)" />'; |
| 911 |
$result .= '</div>'; |
| 912 |
break; |
| 913 |
} |
| 914 |
} |
| 915 |
$result .= $this->settlement_history( $order_id, $trans_id ); |
| 916 |
$data['result'] = $result; |
| 917 |
$data['acting_status'] = $acting_status; |
| 918 |
wp_send_json( $data ); |
| 919 |
break; |
| 920 |
|
| 921 |
/* キャプチャー(売上確定) */ |
| 922 |
case 'capture_paidy': |
| 923 |
check_admin_referer( 'order_edit', 'wc_nonce' ); |
| 924 |
$order_id = filter_input( INPUT_POST, 'order_id' ); |
| 925 |
$trans_id = filter_input( INPUT_POST, 'trans_id' ); |
| 926 |
if ( empty( $order_id ) || empty( $trans_id ) ) { |
| 927 |
$data['status'] = 'retrieve_error'; |
| 928 |
wp_send_json( $data ); |
| 929 |
break; |
| 930 |
} |
| 931 |
|
| 932 |
$result = ''; |
| 933 |
$status = 'capture'; |
| 934 |
$acting_status = ''; |
| 935 |
|
| 936 |
$latest_log = $this->get_acting_latest_log( $order_id, $trans_id ); |
| 937 |
$payment_id = ( isset( $latest_log['payment_id'] ) ) ? $latest_log['payment_id'] : ''; |
| 938 |
$response_data = $this->api_capture( $payment_id ); |
| 939 |
if ( isset( $response_data['status'] ) && ! isset( $response_data['code'] ) ) { |
| 940 |
$this->save_acting_log( $response_data, 'paidy', $status, 'OK', $order_id, $trans_id ); |
| 941 |
$class = ' paidy-' . $status; |
| 942 |
$status_name = $this->get_status_name( $status ); |
| 943 |
$result .= '<div class="paidy-settlement-admin' . $class . '">' . $status_name . '</div>'; |
| 944 |
$acting_status = '<span class="acting-status' . $class . '">' . $status_name . '</span>'; |
| 945 |
$amount = (int) $latest_log['amount']; |
| 946 |
$result .= '<table class="settlement-admin-table">'; |
| 947 |
$result .= '<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>'; |
| 948 |
$result .= '<td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $amount ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $amount ) . '" /></td>'; |
| 949 |
$result .= '</tr></table>'; |
| 950 |
$result .= '<div class="settlement-admin-button">'; |
| 951 |
$result .= '<input id="paidy-refund-settlement" type="button" class="button" value="リファンド(返金)" />'; |
| 952 |
$result .= '</div>'; |
| 953 |
} else { |
| 954 |
$status = 'capture_error'; |
| 955 |
$this->save_acting_log( $response_data, 'paidy', $status, 'NG', $order_id, $trans_id ); |
| 956 |
$status_name = $this->get_status_name( $status ); |
| 957 |
$amount = (int) $latest_log['amount']; |
| 958 |
$result .= '<div class="paidy-settlement-admin paidy-error">' . $status_name . '</div>'; |
| 959 |
$result .= '<table class="settlement-admin-table">'; |
| 960 |
$result .= '<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>'; |
| 961 |
$result .= '<td><input type="tel" class="settlement-amount" value="' . intval( $amount ) . '" disabled="disabled" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>'; |
| 962 |
$result .= '</tr></table>'; |
| 963 |
$result .= '<div class="settlement-admin-button">'; |
| 964 |
$result .= '<input id="paidy-capture-settlement" type="button" class="button" value="キャプチャー(売上確定)" />'; |
| 965 |
$result .= '<input id="paidy-close-settlement" type="button" class="button" value="クローズ" />'; |
| 966 |
$result .= '</div>'; |
| 967 |
} |
| 968 |
$result .= $this->settlement_history( $order_id, $trans_id ); |
| 969 |
$data['result'] = $result; |
| 970 |
$data['acting_status'] = $acting_status; |
| 971 |
wp_send_json( $data ); |
| 972 |
break; |
| 973 |
|
| 974 |
/* リファンド(返金) */ |
| 975 |
case 'refund_paidy': |
| 976 |
check_admin_referer( 'order_edit', 'wc_nonce' ); |
| 977 |
$order_id = filter_input( INPUT_POST, 'order_id' ); |
| 978 |
$trans_id = filter_input( INPUT_POST, 'trans_id' ); |
| 979 |
$amount = filter_input( INPUT_POST, 'amount' ); |
| 980 |
if ( empty( $order_id ) || empty( $trans_id ) ) { |
| 981 |
$data['status'] = 'retrieve_error'; |
| 982 |
wp_send_json( $data ); |
| 983 |
break; |
| 984 |
} |
| 985 |
|
| 986 |
$result = ''; |
| 987 |
$status = 'refund'; |
| 988 |
$acting_status = ''; |
| 989 |
|
| 990 |
$latest_log = $this->get_acting_latest_log( $order_id, $trans_id ); |
| 991 |
$payment_id = ( isset( $latest_log['payment_id'] ) ) ? $latest_log['payment_id'] : ''; |
| 992 |
$retrieve_data = $this->api_retrieve( $payment_id, true ); |
| 993 |
if ( isset( $retrieve_data['status'] ) && 'closed' === $retrieve_data['status'] && ! empty( $retrieve_data['capture_id'] ) && ! empty( $retrieve_data['final_amount'] ) ) { |
| 994 |
$response_data = $this->api_refund( $payment_id, $retrieve_data['capture_id'], $amount ); |
| 995 |
if ( isset( $response_data['status'] ) && ! isset( $response_data['code'] ) ) { |
| 996 |
$this->save_acting_log( $response_data, 'paidy', $status, 'OK', $order_id, $trans_id, $amount ); |
| 997 |
$final_amount = (int) $retrieve_data['final_amount'] - $amount; |
| 998 |
if ( 0 === $final_amount ) { |
| 999 |
$status = 'closed'; |
| 1000 |
$this->save_acting_log( $response_data, 'paidy', $status, 'OK', $order_id, $trans_id ); |
| 1001 |
} else { |
| 1002 |
$status = 'capture'; |
| 1003 |
} |
| 1004 |
$class = ' paidy-' . $status; |
| 1005 |
$status_name = $this->get_status_name( $status ); |
| 1006 |
$result .= '<div class="paidy-settlement-admin' . $class . '">' . $status_name . '</div>'; |
| 1007 |
$acting_status = '<span class="acting-status' . $class . '">' . $status_name . '</span>'; |
| 1008 |
} else { |
| 1009 |
$status = 'refund_error'; |
| 1010 |
$this->save_acting_log( $response_data, 'paidy', $status, 'NG', $order_id, $trans_id ); |
| 1011 |
$status_name = $this->get_status_name( $status ); |
| 1012 |
$result .= '<div class="paidy-settlement-admin paidy-error">' . $status_name . '</div>'; |
| 1013 |
$final_amount = (int) $latest_log['amount']; |
| 1014 |
} |
| 1015 |
switch ( $status ) { |
| 1016 |
case 'closed': |
| 1017 |
$result .= '<table class="settlement-admin-table">'; |
| 1018 |
$result .= '<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>'; |
| 1019 |
$result .= '<td><input type="tel" class="settlement-amount" value="0" disabled="disabled" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>'; |
| 1020 |
$result .= '</tr></table>'; |
| 1021 |
break; |
| 1022 |
default: |
| 1023 |
$result .= '<table class="settlement-admin-table">'; |
| 1024 |
$result .= '<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>'; |
| 1025 |
$result .= '<td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $final_amount ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $final_amount ) . '" /></td>'; |
| 1026 |
$result .= '</tr></table>'; |
| 1027 |
$result .= '<div class="settlement-admin-button">'; |
| 1028 |
$result .= '<input id="paidy-refund-settlement" type="button" class="button" value="リファンド(返金)" />'; |
| 1029 |
$result .= '</div>'; |
| 1030 |
} |
| 1031 |
} |
| 1032 |
$result .= $this->settlement_history( $order_id, $trans_id ); |
| 1033 |
$data['result'] = $result; |
| 1034 |
$data['acting_status'] = $acting_status; |
| 1035 |
wp_send_json( $data ); |
| 1036 |
break; |
| 1037 |
} |
| 1038 |
} |
| 1039 |
|
| 1040 |
/** |
| 1041 |
* 決済履歴 |
| 1042 |
* |
| 1043 |
* @param int $order_id Order number. |
| 1044 |
* @param string $trans_id Transaction ID. |
| 1045 |
* @return string |
| 1046 |
*/ |
| 1047 |
private function settlement_history( $order_id, $trans_id ) { |
| 1048 |
$history = ''; |
| 1049 |
$log_data = $this->get_acting_log( $order_id, $trans_id, 'ALL' ); |
| 1050 |
if ( $log_data ) { |
| 1051 |
$num = count( $log_data ); |
| 1052 |
$history = '<table class="settlement-history">'; |
| 1053 |
$history .= '<thead class="settlement-history-head">'; |
| 1054 |
$history .= '<tr><th></th><th>' . __( 'Processing date', 'usces' ) . '</th><th>決済ID</th><th>' . __( 'Status', 'usces' ) . '</th><th>' . __( 'Amount', 'usces' ) . '</th><th>' . __( 'Result', 'usces' ) . '</th></tr>'; |
| 1055 |
$history .= '</thead>'; |
| 1056 |
$history .= '<tbody class="settlement-history-body">'; |
| 1057 |
foreach ( (array) $log_data as $data ) { |
| 1058 |
$log = usces_unserialize( $data['log'] ); |
| 1059 |
$payment_id = ( isset( $log['id'] ) ) ? $log['id'] : ''; |
| 1060 |
$status_name = ( isset( $data['status'] ) ) ? $this->get_status_name( $data['status'] ) : ''; |
| 1061 |
$err_code = ''; |
| 1062 |
$class = ''; |
| 1063 |
if ( 'OK' === $data['result'] && 0 < $data['amount'] ) { |
| 1064 |
$amount = usces_crform( $data['amount'], false, true, 'return', true ); |
| 1065 |
} else { |
| 1066 |
$amount = ''; |
| 1067 |
} |
| 1068 |
if ( 'OK' !== $data['result'] ) { |
| 1069 |
$err_code = ( isset( $log['code'] ) ) ? $log['code'] : ''; |
| 1070 |
$class = ' error'; |
| 1071 |
} |
| 1072 |
$history .= '<tr>'; |
| 1073 |
$history .= '<td class="num">' . $num . '</td>'; |
| 1074 |
$history .= '<td class="datetime">' . $data['datetime'] . '</td>'; |
| 1075 |
$history .= '<td class="transactionid">' . $payment_id . '</td>'; |
| 1076 |
$history .= '<td class="status">' . $status_name . '</td>'; |
| 1077 |
$history .= '<td class="amount">' . $amount . '</td>'; |
| 1078 |
$history .= '<td class="result' . $class . '">' . $err_code . '</td>'; |
| 1079 |
$history .= '</tr>'; |
| 1080 |
$num--; |
| 1081 |
} |
| 1082 |
$history .= '</tbody>'; |
| 1083 |
$history .= '</table>'; |
| 1084 |
} |
| 1085 |
return $history; |
| 1086 |
} |
| 1087 |
|
| 1088 |
/** |
| 1089 |
* 決済状況 |
| 1090 |
* usces_filter_orderlist_detail_value |
| 1091 |
* |
| 1092 |
* @param string $detail HTML. |
| 1093 |
* @param string $value Settlement info key. |
| 1094 |
* @param string $key Settlement info value. |
| 1095 |
* @param int $order_id Order number. |
| 1096 |
* @return array |
| 1097 |
*/ |
| 1098 |
public function orderlist_settlement_status( $detail, $value, $key, $order_id ) { |
| 1099 |
if ( 'wc_trans_id' !== $key || empty( $value ) ) { |
| 1100 |
return $detail; |
| 1101 |
} |
| 1102 |
|
| 1103 |
$acting_flg = $this->get_order_acting_flg( $order_id ); |
| 1104 |
if ( 'acting_paidy' === $acting_flg ) { |
| 1105 |
$trans_id = $this->get_trans_id( $order_id ); |
| 1106 |
$payment_status = $this->get_payment_status( $order_id, $trans_id ); |
| 1107 |
if ( ! empty( $payment_status ) ) { |
| 1108 |
$class = ' paidy-' . $this->get_status( $payment_status ); |
| 1109 |
$status_name = $this->get_status_name( $payment_status ); |
| 1110 |
if ( ! empty( $status_name ) ) { |
| 1111 |
$detail = '<td>' . esc_html( $value ) . '<span class="acting-status' . esc_html( $class ) . '">' . esc_html( $status_name ) . '</span></td>'; |
| 1112 |
} |
| 1113 |
} |
| 1114 |
} |
| 1115 |
return $detail; |
| 1116 |
} |
| 1117 |
|
| 1118 |
/** |
| 1119 |
* 受注編集画面【ステータス】 |
| 1120 |
* usces_action_order_edit_form_status_block_middle |
| 1121 |
* |
| 1122 |
* @param array $data Order data. |
| 1123 |
* @param array $cscs_meta Custom field data. |
| 1124 |
* @param array $action_args Compact array( 'order_action', 'order_id', 'cart' ). |
| 1125 |
*/ |
| 1126 |
public function settlement_status( $data, $cscs_meta, $action_args ) { |
| 1127 |
extract( $action_args ); |
| 1128 |
|
| 1129 |
if ( 'new' !== $order_action && ! empty( $order_id ) ) { |
| 1130 |
$payment = usces_get_payments_by_name( $data['order_payment_name'] ); |
| 1131 |
$acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : ''; |
| 1132 |
if ( 'acting_paidy' === $acting_flg ) { |
| 1133 |
$trans_id = $this->get_trans_id( $order_id ); |
| 1134 |
$payment_status = $this->get_payment_status( $order_id, $trans_id ); |
| 1135 |
if ( ! empty( $payment_status ) ) { |
| 1136 |
$class = ' paidy-' . $this->get_status( $payment_status ); |
| 1137 |
$status_name = $this->get_status_name( $payment_status ); |
| 1138 |
if ( ! empty( $status_name ) ) { |
| 1139 |
echo ' |
| 1140 |
<tr> |
| 1141 |
<td class="label status">' . esc_html__( 'Settlement status', 'usces' ) . '</td> |
| 1142 |
<td class="col1 status"><span id="settlement-status"><span class="acting-status' . esc_attr( $class ) . '">' . esc_html( $status_name ) . '</span></span></td> |
| 1143 |
</tr>'; |
| 1144 |
} |
| 1145 |
} |
| 1146 |
} |
| 1147 |
} |
| 1148 |
} |
| 1149 |
|
| 1150 |
/** |
| 1151 |
* 受注編集画面【支払� |
| 1152 |
報】 |
| 1153 |
* usces_action_order_edit_form_settle_info |
| 1154 |
* |
| 1155 |
* @param array $data Order data. |
| 1156 |
* @param array $action_args Compact array( 'order_action', 'order_id', 'cart' ). |
| 1157 |
*/ |
| 1158 |
public function settlement_information( $data, $action_args ) { |
| 1159 |
global $usces; |
| 1160 |
extract( $action_args ); |
| 1161 |
|
| 1162 |
if ( 'new' !== $order_action && ! empty( $order_id ) ) { |
| 1163 |
$payment = usces_get_payments_by_name( $data['order_payment_name'] ); |
| 1164 |
if ( isset( $payment['settlement'] ) && 'acting_paidy' === $payment['settlement'] ) { |
| 1165 |
$trans_id = $this->get_trans_id( $order_id ); |
| 1166 |
$acting_data = usces_unserialize( $usces->get_order_meta_value( $payment['settlement'], $order_id ) ); |
| 1167 |
if ( ! empty( $trans_id ) && isset( $acting_data['id'] ) ) { |
| 1168 |
echo '<input type="button" class="button settlement-information" id="settlement-information-' . esc_html( $trans_id ) . '" data-trans_id="' . esc_attr( $trans_id ) . '" data-num="1" value="' . esc_attr__( 'Settlement info', 'usces' ) . '">'; |
| 1169 |
} |
| 1170 |
} |
| 1171 |
} |
| 1172 |
} |
| 1173 |
|
| 1174 |
/** |
| 1175 |
* 決済� |
| 1176 |
報ダイアログ |
| 1177 |
* usces_action_endof_order_edit_form |
| 1178 |
* |
| 1179 |
* @param array $data Order data. |
| 1180 |
* @param array $action_args Compact array( 'order_action', 'order_id', 'cart' ). |
| 1181 |
*/ |
| 1182 |
public function settlement_dialog( $data, $action_args ) { |
| 1183 |
extract( $action_args ); |
| 1184 |
|
| 1185 |
if ( 'new' !== $order_action && ! empty( $order_id ) ) : |
| 1186 |
$payment = usces_get_payments_by_name( $data['order_payment_name'] ); |
| 1187 |
if ( isset( $payment['settlement'] ) && 'acting_paidy' === $payment['settlement'] ) : |
| 1188 |
?> |
| 1189 |
<div id="settlement_dialog" title=""> |
| 1190 |
<div id="settlement-response-loading"></div> |
| 1191 |
<fieldset> |
| 1192 |
<div id="settlement-response"></div> |
| 1193 |
<input type="hidden" id="order_num"> |
| 1194 |
<input type="hidden" id="trans_id"> |
| 1195 |
<input type="hidden" id="acting" value="acting_paidy"> |
| 1196 |
<input type="hidden" id="error"> |
| 1197 |
</fieldset> |
| 1198 |
</div> |
| 1199 |
<?php |
| 1200 |
endif; |
| 1201 |
endif; |
| 1202 |
} |
| 1203 |
|
| 1204 |
/** |
| 1205 |
* 受注データから取得する決済� |
| 1206 |
報のキー |
| 1207 |
* usces_filter_settle_info_field_meta_keys |
| 1208 |
* |
| 1209 |
* @param array $keys Settlement information key. |
| 1210 |
* @return array |
| 1211 |
*/ |
| 1212 |
public function settlement_info_field_meta_keys( $keys ) { |
| 1213 |
$keys = array_merge( $keys, array( 'acting', 'trans_id', 'trading_id' ) ); |
| 1214 |
return $keys; |
| 1215 |
} |
| 1216 |
|
| 1217 |
/** |
| 1218 |
* 受注編集画面に表示する決済� |
| 1219 |
報のキー |
| 1220 |
* usces_filter_settle_info_field_keys |
| 1221 |
* |
| 1222 |
* @param array $keys Settlement information keys. |
| 1223 |
* @param array $fields Settlement information fields. |
| 1224 |
* @return array |
| 1225 |
*/ |
| 1226 |
public function settlement_info_field_keys( $keys, $fields ) { |
| 1227 |
if ( isset( $fields['acting'] ) && 'paidy' === $fields['acting'] ) { |
| 1228 |
$keys = array( 'acting', 'trans_id', 'trading_id' ); |
| 1229 |
} |
| 1230 |
return $keys; |
| 1231 |
} |
| 1232 |
|
| 1233 |
/** |
| 1234 |
* 受注編集画面に表示する決済� |
| 1235 |
報の値整形 |
| 1236 |
* usces_filter_settle_info_field_value |
| 1237 |
* |
| 1238 |
* @param string $value Value. |
| 1239 |
* @param string $key Key. |
| 1240 |
* @param string $acting Acting type. |
| 1241 |
* @return string |
| 1242 |
*/ |
| 1243 |
public function settlement_info_field_value( $value, $key, $acting ) { |
| 1244 |
if ( 'acting' === $key && 'paidy' === $value ) { |
| 1245 |
$value = $this->acting_name; |
| 1246 |
} |
| 1247 |
return $value; |
| 1248 |
} |
| 1249 |
|
| 1250 |
/** |
| 1251 |
* 決済リンクキー |
| 1252 |
* usces_filter_get_link_key |
| 1253 |
* |
| 1254 |
* @param string $linkkey Settlement link key. |
| 1255 |
* @param array $results Response data. |
| 1256 |
* @return string |
| 1257 |
*/ |
| 1258 |
public function get_link_key( $linkkey, $results ) { |
| 1259 |
if ( isset( $results['trans_id'] ) ) { |
| 1260 |
$linkkey = $results['trans_id']; |
| 1261 |
} elseif ( isset( $results['trading_id'] ) ) { |
| 1262 |
$linkkey = $results['trading_id']; |
| 1263 |
} |
| 1264 |
return $linkkey; |
| 1265 |
} |
| 1266 |
|
| 1267 |
/** |
| 1268 |
* 受注データ復旧処理 |
| 1269 |
* usces_action_revival_order_data |
| 1270 |
* |
| 1271 |
* @param int $order_id Order number. |
| 1272 |
* @param string $log_key Link key. |
| 1273 |
* @param string $acting_flg Payment type. |
| 1274 |
*/ |
| 1275 |
public function revival_orderdata( $order_id, $log_key, $acting_flg ) { |
| 1276 |
global $usces; |
| 1277 |
|
| 1278 |
if ( 'acting_paidy' === $acting_flg ) { |
| 1279 |
$usces->set_order_meta_value( 'trans_id', $log_key, $order_id ); |
| 1280 |
$usces->set_order_meta_value( 'wc_trans_id', $log_key, $order_id ); |
| 1281 |
$data = array( |
| 1282 |
'trans_id' => $log_key, |
| 1283 |
); |
| 1284 |
$usces->set_order_meta_value( $acting_flg, usces_serialize( $data ), $order_id ); |
| 1285 |
} |
| 1286 |
} |
| 1287 |
|
| 1288 |
/** |
| 1289 |
* � |
| 1290 |
容確認ページ [注文する] ボタン |
| 1291 |
* usces_filter_confirm_inform |
| 1292 |
* |
| 1293 |
* @param string $form Purchase post form. |
| 1294 |
* @param array $payments Payment data. |
| 1295 |
* @param string $acting_flg Payment type. |
| 1296 |
* @param string $rand Welcart transaction key. |
| 1297 |
* @param string $purchase_disabled Disable purchase button. |
| 1298 |
* @return string |
| 1299 |
*/ |
| 1300 |
public function confirm_inform( $form, $payments, $acting_flg, $rand, $purchase_disabled ) { |
| 1301 |
global $usces; |
| 1302 |
|
| 1303 |
if ( 'acting_paidy' !== $acting_flg ) { |
| 1304 |
return $form; |
| 1305 |
} |
| 1306 |
|
| 1307 |
$entry = $usces->cart->get_entry(); |
| 1308 |
$cart = $usces->cart->get_cart(); |
| 1309 |
if ( ! $entry || ! $cart ) { |
| 1310 |
return $form; |
| 1311 |
} |
| 1312 |
if ( ! $entry['order']['total_full_price'] ) { |
| 1313 |
return $form; |
| 1314 |
} |
| 1315 |
|
| 1316 |
usces_save_order_acting_data( $rand ); |
| 1317 |
$form = '<form name="purchase_form" action="' . USCES_CART_URL . '" method="post" onKeyDown="if(event.keyCode == 13){return false;}"> |
| 1318 |
<input type="hidden" name="purchase" value="' . $acting_flg . '"> |
| 1319 |
<input type="hidden" name="trans_id" value="' . $rand . '"> |
| 1320 |
<input type="hidden" name="paidy_id"> |
| 1321 |
<input type="hidden" name="paidy_created_at"> |
| 1322 |
<input type="hidden" name="paidy_status"> |
| 1323 |
<input type="hidden" name="_nonce" value="' . wp_create_nonce( $acting_flg ) . '"> |
| 1324 |
<div class="send paidy-send"><input type="button" id="paidy-checkout-button" onclick="paidyPay()" value="ペイディでお支払い" /></div> |
| 1325 |
</form> |
| 1326 |
<form action="' . USCES_CART_URL . '" method="post" onKeyDown="if(event.keyCode == 13){return false;}"> |
| 1327 |
<div class="send"> |
| 1328 |
' . apply_filters( 'usces_filter_confirm_before_backbutton', '', $payments, $acting_flg, $rand ) . ' |
| 1329 |
<input name="backDelivery" type="submit" id="back_button" class="back_to_delivery_button" value="' . __( 'Back', 'usces' ) . '"' . apply_filters( 'usces_filter_confirm_prebutton', '' ) . ' /> |
| 1330 |
</div>'; |
| 1331 |
return $form; |
| 1332 |
} |
| 1333 |
|
| 1334 |
/** |
| 1335 |
* 決済処理 |
| 1336 |
* usces_action_acting_processing |
| 1337 |
* |
| 1338 |
* @param string $acting_flg Payment type. |
| 1339 |
* @param array $post_query Post data. |
| 1340 |
*/ |
| 1341 |
public function acting_processing( $acting_flg, $post_query ) { |
| 1342 |
global $usces; |
| 1343 |
|
| 1344 |
if ( 'acting_paidy' !== $acting_flg ) { |
| 1345 |
return; |
| 1346 |
} |
| 1347 |
|
| 1348 |
$entry = $usces->cart->get_entry(); |
| 1349 |
$cart = $usces->cart->get_cart(); |
| 1350 |
if ( ! $entry || ! $cart ) { |
| 1351 |
wp_redirect( USCES_CART_URL ); |
| 1352 |
exit(); |
| 1353 |
} |
| 1354 |
|
| 1355 |
parse_str( $post_query, $post_data ); |
| 1356 |
if ( isset( $post_data['_nonce'] ) && ! wp_verify_nonce( $post_data['_nonce'], $acting_flg ) ) { |
| 1357 |
wp_redirect( USCES_CART_URL ); |
| 1358 |
exit(); |
| 1359 |
} |
| 1360 |
|
| 1361 |
if ( isset( $post_data['paidy_id'] ) && isset( $post_data['paidy_created_at'] ) && isset( $post_data['paidy_status'] ) && 'authorized' === $post_data['paidy_status'] ) { |
| 1362 |
$acting = substr( $acting_flg, 7 ); |
| 1363 |
$trans_id = ( isset( $post_data['trans_id'] ) ) ? $post_data['trans_id'] : ''; |
| 1364 |
$response_data = $this->api_retrieve( $post_data['paidy_id'] ); |
| 1365 |
if ( isset( $response_data['status'] ) && 'authorized' === $response_data['status'] ) { |
| 1366 |
$res = $usces->order_processing( $response_data ); |
| 1367 |
if ( 'ordercompletion' === $res ) { |
| 1368 |
wp_redirect( |
| 1369 |
add_query_arg( |
| 1370 |
array( |
| 1371 |
'acting' => $acting, |
| 1372 |
'acting_return' => 1, |
| 1373 |
'result' => 1, |
| 1374 |
'_nonce' => $post_data['_nonce'], |
| 1375 |
), |
| 1376 |
USCES_CART_URL |
| 1377 |
) |
| 1378 |
); |
| 1379 |
} else { |
| 1380 |
$log = array( |
| 1381 |
'acting' => $acting, |
| 1382 |
'key' => $trans_id, |
| 1383 |
'result' => 'ORDER DATA REGISTERED ERROR', |
| 1384 |
'data' => $response_data, |
| 1385 |
); |
| 1386 |
usces_save_order_acting_error( $log ); |
| 1387 |
wp_redirect( |
| 1388 |
add_query_arg( |
| 1389 |
array( |
| 1390 |
'acting' => $acting, |
| 1391 |
'acting_return' => 0, |
| 1392 |
'result' => 0, |
| 1393 |
), |
| 1394 |
USCES_CART_URL |
| 1395 |
) |
| 1396 |
); |
| 1397 |
} |
| 1398 |
} else { |
| 1399 |
$log = array( |
| 1400 |
'acting' => $acting, |
| 1401 |
'key' => $trans_id, |
| 1402 |
'result' => 'PAIDY AUTHORIZE ERROR', |
| 1403 |
'data' => $response_data, |
| 1404 |
); |
| 1405 |
usces_save_order_acting_error( $log ); |
| 1406 |
wp_redirect( |
| 1407 |
add_query_arg( |
| 1408 |
array( |
| 1409 |
'acting' => $acting, |
| 1410 |
'acting_return' => 0, |
| 1411 |
'result' => 0, |
| 1412 |
), |
| 1413 |
USCES_CART_URL |
| 1414 |
) |
| 1415 |
); |
| 1416 |
} |
| 1417 |
exit(); |
| 1418 |
} elseif ( isset( $post_data['paidy_id'] ) && isset( $post_data['paidy_created_at'] ) && isset( $post_data['paidy_status'] ) && 'rejected' === $post_data['paidy_status'] ) { |
| 1419 |
$acting = substr( $acting_flg, 7 ); |
| 1420 |
$trans_id = ( isset( $post_data['trans_id'] ) ) ? $post_data['trans_id'] : ''; |
| 1421 |
$log = array( |
| 1422 |
'acting' => $acting, |
| 1423 |
'key' => $trans_id, |
| 1424 |
'result' => 'PAIDY REJECTED', |
| 1425 |
'data' => $post_data, |
| 1426 |
); |
| 1427 |
usces_save_order_acting_error( $log ); |
| 1428 |
wp_redirect( |
| 1429 |
add_query_arg( |
| 1430 |
array( |
| 1431 |
'acting' => $acting, |
| 1432 |
'acting_return' => 0, |
| 1433 |
'result' => 0, |
| 1434 |
), |
| 1435 |
USCES_CART_URL |
| 1436 |
) |
| 1437 |
); |
| 1438 |
exit(); |
| 1439 |
} |
| 1440 |
} |
| 1441 |
|
| 1442 |
/** |
| 1443 |
* 決済完了ページ制御 |
| 1444 |
* usces_filter_check_acting_return_results |
| 1445 |
* |
| 1446 |
* @param array $results Result data. |
| 1447 |
* @return array |
| 1448 |
*/ |
| 1449 |
public function acting_return( $results ) { |
| 1450 |
$acting = filter_input( INPUT_GET, 'acting' ); |
| 1451 |
if ( 'paidy' === $acting ) { |
| 1452 |
$results = wp_unslash( $_GET ); |
| 1453 |
$results[0] = filter_input( INPUT_GET, 'acting_return' ); |
| 1454 |
$results['reg_order'] = false; |
| 1455 |
} |
| 1456 |
return $results; |
| 1457 |
} |
| 1458 |
|
| 1459 |
/** |
| 1460 |
* 重複オーダー禁止処理 |
| 1461 |
* usces_filter_check_acting_return_duplicate |
| 1462 |
* |
| 1463 |
* @param string $trans_id Transaction ID. |
| 1464 |
* @param array $results Result data. |
| 1465 |
* @return string |
| 1466 |
*/ |
| 1467 |
public function check_acting_return_duplicate( $trans_id, $results ) { |
| 1468 |
if ( isset( $_POST['paidy_id'] ) || ( isset( $results['acting'] ) && 'paidy' === $results['acting'] ) ) { |
| 1469 |
if ( isset( $_POST['trans_id'] ) ) { |
| 1470 |
$trans_id = filter_input( INPUT_POST, 'trans_id' ); |
| 1471 |
} elseif ( isset( $results['order']['order_ref'] ) ) { |
| 1472 |
$trans_id = $results['order']['order_ref']; |
| 1473 |
} |
| 1474 |
} |
| 1475 |
return $trans_id; |
| 1476 |
} |
| 1477 |
|
| 1478 |
/** |
| 1479 |
* 受注データ登録 |
| 1480 |
* Called by usces_reg_orderdata() and usces_new_orderdata(). |
| 1481 |
* usces_action_reg_orderdata |
| 1482 |
* |
| 1483 |
* @param array $args Compact array( $cart, $entry, $order_id, $member_id, $payments, $charging_type, $results ). |
| 1484 |
*/ |
| 1485 |
public function register_orderdata( $args ) { |
| 1486 |
global $usces; |
| 1487 |
extract( $args ); |
| 1488 |
|
| 1489 |
$acting_flg = ( isset( $payments['settlement'] ) ) ? $payments['settlement'] : ''; |
| 1490 |
if ( 'acting_paidy' !== $acting_flg ) { |
| 1491 |
return; |
| 1492 |
} |
| 1493 |
if ( ! $entry['order']['total_full_price'] ) { |
| 1494 |
return; |
| 1495 |
} |
| 1496 |
|
| 1497 |
$trans_id = ''; |
| 1498 |
if ( isset( $results['order']['order_ref'] ) ) { |
| 1499 |
$trans_id = $results['order']['order_ref']; |
| 1500 |
} elseif ( isset( $results['order_ref'] ) ) { |
| 1501 |
$trans_id = $results['order_ref']; |
| 1502 |
} |
| 1503 |
if ( ! empty( $trans_id ) ) { |
| 1504 |
if ( ! isset( $results['acting'] ) ) { |
| 1505 |
$results['acting'] = 'paidy'; |
| 1506 |
} |
| 1507 |
$usces->set_order_meta_value( $acting_flg, usces_serialize( $results ), $order_id ); |
| 1508 |
$usces->set_order_meta_value( 'trans_id', $trans_id, $order_id ); |
| 1509 |
$usces->set_order_meta_value( 'wc_trans_id', $trans_id, $order_id ); |
| 1510 |
$this->save_acting_log( $results, 'paidy', $results['status'], 'OK', $order_id, $trans_id ); |
| 1511 |
} |
| 1512 |
} |
| 1513 |
|
| 1514 |
/** |
| 1515 |
* 決済エラーメッセージ |
| 1516 |
* usces_filter_get_error_settlement |
| 1517 |
* |
| 1518 |
* @param string $form Payment error message. |
| 1519 |
* @return string |
| 1520 |
*/ |
| 1521 |
public function error_page_message( $form ) { |
| 1522 |
$acting = ( isset( $_REQUEST['acting'] ) ) ? wp_unslash( $_REQUEST['acting'] ) : ''; |
| 1523 |
if ( 'paidy' === $acting ) { |
| 1524 |
$form .= '<br /> |
| 1525 |
<a href="' . USCES_CUSTOMER_URL . '">他の支払方法を選ぶ 》</a><br />'; |
| 1526 |
} |
| 1527 |
return $form; |
| 1528 |
} |
| 1529 |
|
| 1530 |
/** |
| 1531 |
* Front scripts. |
| 1532 |
* wp_print_footer_scripts |
| 1533 |
*/ |
| 1534 |
public function footer_scripts() { |
| 1535 |
global $usces; |
| 1536 |
|
| 1537 |
if ( $this->is_validity_acting( 'paidy' ) ) : |
| 1538 |
/* � |
| 1539 |
容確認ページ */ |
| 1540 |
if ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) && 'confirm' === $usces->page ) : |
| 1541 |
$entry = $usces->cart->get_entry(); |
| 1542 |
$cart = $usces->cart->get_cart(); |
| 1543 |
if ( empty( $entry['order']['total_full_price'] ) ) { |
| 1544 |
return; |
| 1545 |
} |
| 1546 |
$payment = usces_get_payments_by_name( $entry['order']['payment_name'] ); |
| 1547 |
if ( empty( $payment['settlement'] ) || 'acting_paidy' !== $payment['settlement'] ) { |
| 1548 |
return; |
| 1549 |
} |
| 1550 |
|
| 1551 |
$continue = ( defined( 'WCEX_DLSELLER' ) ) ? usces_have_continue_charge( $cart ) : false; |
| 1552 |
$regular = ( defined( 'WCEX_AUTO_DELIVERY' ) ) ? usces_have_regular_order() : false; |
| 1553 |
if ( $continue || $regular ) { |
| 1554 |
return; |
| 1555 |
} |
| 1556 |
|
| 1557 |
$acting_opts = $this->get_acting_settings(); |
| 1558 |
if ( usces_is_login() ) { |
| 1559 |
$member = $usces->get_member(); |
| 1560 |
$age = ceil( ( strtotime( date_i18n( 'Y-m-d H:i:s' ) ) - strtotime( $member['registered'] ) ) / ( 60 * 60 * 24 ) ); |
| 1561 |
$member_data = $this->get_buyer_data( $member['ID'] ); |
| 1562 |
$buyer_data = '"user_id": "' . $member['ID'] . '",' . "\n"; |
| 1563 |
$buyer_data .= "\t\t\t" . '"age": ' . $age . ',' . "\n"; |
| 1564 |
$buyer_data .= "\t\t\t" . '"ltv": ' . $member_data['ltv'] . ',' . "\n"; |
| 1565 |
$buyer_data .= "\t\t\t" . '"order_count": ' . $member_data['order_count'] . ',' . "\n"; |
| 1566 |
$buyer_data .= "\t\t\t" . '"last_order_amount": ' . $member_data['last_order_amount'] . ',' . "\n"; |
| 1567 |
$buyer_data .= "\t\t\t" . '"last_order_at": ' . $member_data['last_order_at'] . ',' . "\n"; |
| 1568 |
$number_of_points = '"number_of_points": "' . $member['point'] . '"' . "\n"; |
| 1569 |
} else { |
| 1570 |
$buyer_data = '"age": null,' . "\n"; |
| 1571 |
$buyer_data .= "\t\t\t" . '"ltv": null,' . "\n"; |
| 1572 |
$buyer_data .= "\t\t\t" . '"order_count": null,' . "\n"; |
| 1573 |
$buyer_data .= "\t\t\t" . '"last_order_amount": null,' . "\n"; |
| 1574 |
$buyer_data .= "\t\t\t" . '"last_order_at": null,' . "\n"; |
| 1575 |
$number_of_points = ''; |
| 1576 |
} |
| 1577 |
$amount = usces_crform( $entry['order']['total_full_price'], false, false, 'return', false ); |
| 1578 |
// if ( isset( $acting_opts['environment'] ) && 'live' === $acting_opts['environment'] ) { |
| 1579 |
$email = trim( $entry['customer']['mailaddress1'] ); |
| 1580 |
if ( ! empty( $entry['customer']['tel'] ) ) { |
| 1581 |
$phone = '"phone": "' . str_replace( '-', '', mb_convert_kana( $entry['customer']['tel'], 'a', 'UTF-8' ) ) . '"' . "\n"; |
| 1582 |
} else { |
| 1583 |
$phone = ''; |
| 1584 |
} |
| 1585 |
// } else { |
| 1586 |
// $email = 'successful.payment@paidy.com'; |
| 1587 |
// $phone = '"phone": "08000000001"' . "\n"; |
| 1588 |
// } |
| 1589 |
$name1 = $entry['customer']['name1'] . ' ' . $entry['customer']['name2']; |
| 1590 |
if ( ! empty( $entry['customer']['name3'] ) ) { |
| 1591 |
$name2 = '"name2": "' . $entry['customer']['name3'] . ' ' . $entry['customer']['name4'] . '",' . "\n"; |
| 1592 |
} else { |
| 1593 |
$name2 = ''; |
| 1594 |
} |
| 1595 |
$line1 = ''; |
| 1596 |
$line2 = ''; |
| 1597 |
$city = ''; |
| 1598 |
$state = ''; |
| 1599 |
$zip = ''; |
| 1600 |
$additional_shipping_addresses = ''; |
| 1601 |
$billing_address = ''; |
| 1602 |
if ( usces_is_login() && defined( 'WCEX_MSA' ) && isset( $entry['delivery']['delivery_flag'] ) && 2 === (int) $entry['delivery']['delivery_flag'] ) { |
| 1603 |
$msacart = $usces->msacart->get_cart(); |
| 1604 |
$count_msa = ( is_array( $msacart ) ) ? count( $msacart ) : 0; |
| 1605 |
if ( 0 < $count_msa ) { |
| 1606 |
krsort( $msacart ); |
| 1607 |
$idx_msa = 0; |
| 1608 |
foreach ( $msacart as $group_id => $group ) { |
| 1609 |
$delivery = $group['delivery']; |
| 1610 |
$destination_info = msa_get_destination( $usces->current_member['id'], $delivery['destination_id'] ); |
| 1611 |
if ( 7 === strlen( trim( $destination_info['msa_zip'] ) ) ) { |
| 1612 |
$msa_zip = substr( trim( $destination_info['msa_zip'] ), 0, 3 ) . '-' . substr( trim( $destination_info['msa_zip'] ), 3 ); |
| 1613 |
} else { |
| 1614 |
$msa_zip = trim( $destination_info['msa_zip'] ); |
| 1615 |
} |
| 1616 |
if ( 0 === $idx_msa ) { |
| 1617 |
$line1 = trim( $destination_info['msa_address3'] ); |
| 1618 |
$line2 = trim( $destination_info['msa_address2'] ); |
| 1619 |
$city = trim( $destination_info['msa_address1'] ); |
| 1620 |
$state = trim( $destination_info['msa_pref'] ); |
| 1621 |
$zip = $msa_zip; |
| 1622 |
} elseif ( 1 === $idx_msa ) { |
| 1623 |
$additional_shipping_addresses .= '"additional_shipping_addresses": [{' . "\n"; |
| 1624 |
$additional_shipping_addresses .= "\t\t\t\t" . '"line1": "' . trim( $destination_info['msa_address3'] ) . '",' . "\n"; |
| 1625 |
$additional_shipping_addresses .= "\t\t\t\t" . '"line2": "' . trim( $destination_info['msa_address2'] ) . '",' . "\n"; |
| 1626 |
$additional_shipping_addresses .= "\t\t\t\t" . '"city": "' . trim( $destination_info['msa_address1'] ) . '",' . "\n"; |
| 1627 |
$additional_shipping_addresses .= "\t\t\t\t" . '"state": "' . trim( $destination_info['msa_pref'] ) . '",' . "\n"; |
| 1628 |
$additional_shipping_addresses .= "\t\t\t\t" . '"zip": "' . $msa_zip . '"' . "\n"; |
| 1629 |
$additional_shipping_addresses .= "\t\t\t" . '}'; |
| 1630 |
} else { |
| 1631 |
$additional_shipping_addresses .= ',' . "\n\t\t\t" . '{' . "\n"; |
| 1632 |
$additional_shipping_addresses .= "\t\t\t\t" . '"line1": "' . trim( $destination_info['msa_address3'] ) . '",' . "\n"; |
| 1633 |
$additional_shipping_addresses .= "\t\t\t\t" . '"line2": "' . trim( $destination_info['msa_address2'] ) . '",' . "\n"; |
| 1634 |
$additional_shipping_addresses .= "\t\t\t\t" . '"city": "' . trim( $destination_info['msa_address1'] ) . '",' . "\n"; |
| 1635 |
$additional_shipping_addresses .= "\t\t\t\t" . '"state": "' . trim( $destination_info['msa_pref'] ) . '",' . "\n"; |
| 1636 |
$additional_shipping_addresses .= "\t\t\t\t" . '"zip": "' . $msa_zip . '"' . "\n"; |
| 1637 |
$additional_shipping_addresses .= "\t\t\t" . '}'; |
| 1638 |
} |
| 1639 |
$idx_msa++; |
| 1640 |
} |
| 1641 |
$additional_shipping_addresses .= '],' . "\n"; |
| 1642 |
} |
| 1643 |
} else { |
| 1644 |
$line1 = trim( $entry['delivery']['address3'] ); |
| 1645 |
$line2 = trim( $entry['delivery']['address2'] ); |
| 1646 |
$city = trim( $entry['delivery']['address1'] ); |
| 1647 |
$state = trim( $entry['delivery']['pref'] ); |
| 1648 |
if ( 7 === strlen( trim( $entry['delivery']['zipcode'] ) ) ) { |
| 1649 |
$zip = substr( trim( $entry['delivery']['zipcode'] ), 0, 3 ) . '-' . substr( trim( $entry['delivery']['zipcode'] ), 3 ); |
| 1650 |
} else { |
| 1651 |
$zip = trim( $entry['delivery']['zipcode'] ); |
| 1652 |
} |
| 1653 |
if ( isset( $entry['delivery']['delivery_flag'] ) && 1 === (int) $entry['delivery']['delivery_flag'] ) { |
| 1654 |
$customer_line1 = trim( $entry['customer']['address3'] ); |
| 1655 |
$customer_line2 = trim( $entry['customer']['address2'] ); |
| 1656 |
$customer_city = trim( $entry['customer']['address1'] ); |
| 1657 |
$customer_state = trim( $entry['customer']['pref'] ); |
| 1658 |
if ( 7 === strlen( trim( $entry['customer']['zipcode'] ) ) ) { |
| 1659 |
$customer_zip = substr( trim( $entry['customer']['zipcode'] ), 0, 3 ) . '-' . substr( trim( $entry['customer']['zipcode'] ), 3 ); |
| 1660 |
} else { |
| 1661 |
$customer_zip = trim( $entry['customer']['zipcode'] ); |
| 1662 |
} |
| 1663 |
if ( $line1 !== $customer_line1 || $line2 !== $customer_line2 || $city !== $customer_city || $state !== $customer_state || $zip !== $customer_zip ) { |
| 1664 |
$billing_address .= ',"delivery_locn_type": "not_primary_home",' . "\n"; |
| 1665 |
$billing_address .= "\t\t\t" . '"billing_address": {' . "\n"; |
| 1666 |
$billing_address .= "\t\t\t\t" . '"line1": "' . $customer_line1 . '",' . "\n"; |
| 1667 |
$billing_address .= "\t\t\t\t" . '"line2": "' . $customer_line2 . '",' . "\n"; |
| 1668 |
$billing_address .= "\t\t\t\t" . '"city": "' . $customer_city . '",' . "\n"; |
| 1669 |
$billing_address .= "\t\t\t\t" . '"state": "' . $customer_state . '",' . "\n"; |
| 1670 |
$billing_address .= "\t\t\t\t" . '"zip": "' . $customer_zip . '"' . "\n"; |
| 1671 |
$billing_address .= "\t\t\t" . '}' . "\n"; |
| 1672 |
} |
| 1673 |
} elseif ( ! isset( $entry['delivery']['delivery_flag'] ) || 0 === (int) $entry['delivery']['delivery_flag'] ) { |
| 1674 |
$billing_address .= ',"delivery_locn_type": "home",' . "\n"; |
| 1675 |
} |
| 1676 |
} |
| 1677 |
$items = ''; |
| 1678 |
foreach ( $cart as $cart_row ) { |
| 1679 |
$items .= "\n\t\t\t\t" . '{' . "\n"; |
| 1680 |
$items .= "\t\t\t\t\t" . '"id": ' . wp_json_encode( (string) $usces->getItemCode( $cart_row['post_id'] ) ) . ',' . "\n"; |
| 1681 |
$items .= "\t\t\t\t\t" . '"quantity": ' . $cart_row['quantity'] . ',' . "\n"; |
| 1682 |
$items .= "\t\t\t\t\t" . '"title": ' . wp_json_encode( (string) $usces->getItemName( $cart_row['post_id'] ) ) . ',' . "\n"; |
| 1683 |
$items .= "\t\t\t\t\t" . '"unit_price": ' . $cart_row['price'] . "\n"; |
| 1684 |
$items .= "\t\t\t\t" . '},'; |
| 1685 |
} |
| 1686 |
if ( isset( $entry['order']['discount'] ) && 0 !== $entry['order']['discount'] ) { |
| 1687 |
$items .= "\n\t\t\t\t" . '{' . "\n"; |
| 1688 |
$items .= "\t\t\t\t\t" . '"quantity": 1,' . "\n"; |
| 1689 |
$items .= "\t\t\t\t\t" . '"title": "' . apply_filters( 'usces_confirm_discount_label', __( 'Campaign discount', 'usces' ) ) . '",' . "\n"; |
| 1690 |
$items .= "\t\t\t\t\t" . '"unit_price": ' . $entry['order']['discount'] . "\n"; |
| 1691 |
$items .= "\t\t\t\t" . '},'; |
| 1692 |
} |
| 1693 |
if ( usces_is_member_system() && usces_is_member_system_point() && ! empty( $entry['order']['usedpoint'] ) ) { |
| 1694 |
$items .= "\n\t\t\t\t" . '{' . "\n"; |
| 1695 |
$items .= "\t\t\t\t\t" . '"quantity": 1,' . "\n"; |
| 1696 |
$items .= "\t\t\t\t\t" . '"title": "' . __( 'Used points', 'usces' ) . '",' . "\n"; |
| 1697 |
$items .= "\t\t\t\t\t" . '"unit_price": ' . ( $entry['order']['usedpoint'] * -1 ) . "\n"; |
| 1698 |
$items .= "\t\t\t\t" . '},'; |
| 1699 |
} |
| 1700 |
if ( ! empty( $entry['order']['cod_fee'] ) ) { |
| 1701 |
$items .= "\n\t\t\t\t" . '{' . "\n"; |
| 1702 |
$items .= "\t\t\t\t\t" . '"quantity": 1,' . "\n"; |
| 1703 |
$items .= "\t\t\t\t\t" . '"title": "' . apply_filters( 'usces_filter_paidy_fee_label', 'ペイディ手数料' ) . '",' . "\n"; |
| 1704 |
$items .= "\t\t\t\t\t" . '"unit_price": ' . $entry['order']['cod_fee'] . "\n"; |
| 1705 |
$items .= "\t\t\t\t" . '},'; |
| 1706 |
} |
| 1707 |
$items = rtrim( $items, ',' ) . "\n"; |
| 1708 |
if ( 0 !== $entry['order']['shipping_charge'] ) { |
| 1709 |
$shipping = $entry['order']['shipping_charge']; |
| 1710 |
} else { |
| 1711 |
$shipping = '0'; |
| 1712 |
} |
| 1713 |
if ( isset( $entry['order']['tax'] ) && 'exclude' === usces_get_tax_mode() ) { |
| 1714 |
$tax = $entry['order']['tax'] . "\n"; |
| 1715 |
} else { |
| 1716 |
$tax = '0' . "\n"; |
| 1717 |
} |
| 1718 |
?> |
| 1719 |
<script type="text/javascript" src="<?php echo esc_url( $acting_opts['apps_url'] ); ?>"></script> |
| 1720 |
<script type="text/javascript"> |
| 1721 |
var config = { |
| 1722 |
"api_key": "<?php echo esc_html( $acting_opts['public_key'] ); ?>", |
| 1723 |
"closed": function(callbackData) { |
| 1724 |
if( 'closed' == callbackData.status ) { |
| 1725 |
document.getElementById("paidy-checkout-button").style.pointerEvents = "auto"; |
| 1726 |
} else { |
| 1727 |
var purchase_form = document.forms.purchase_form; |
| 1728 |
purchase_form.paidy_id.value = callbackData.id; |
| 1729 |
purchase_form.paidy_created_at.value = callbackData.created_at; |
| 1730 |
purchase_form.paidy_status.value = callbackData.status; |
| 1731 |
purchase_form.submit(); |
| 1732 |
} |
| 1733 |
} |
| 1734 |
}; |
| 1735 |
var paidyHandler = Paidy.configure(config); |
| 1736 |
function paidyPay() { |
| 1737 |
document.getElementById("paidy-checkout-button").style.pointerEvents = "none"; |
| 1738 |
var rand = document.getElementsByName("trans_id")[0].value; |
| 1739 |
var payload = { |
| 1740 |
"amount": <?php echo esc_js( $amount ); ?>, |
| 1741 |
"currency": "JPY", |
| 1742 |
"store_name": "<?php echo esc_html( get_option( 'blogname' ) ); ?>", |
| 1743 |
"buyer": { |
| 1744 |
"email": "<?php echo esc_js( $email ); ?>", |
| 1745 |
"name1": "<?php echo esc_js( $name1 ); ?>", |
| 1746 |
<?php echo $name2; // no escape. ?> |
| 1747 |
<?php echo $phone; // no escape. ?> |
| 1748 |
}, |
| 1749 |
"buyer_data": { |
| 1750 |
<?php echo $buyer_data; // no escape. ?> |
| 1751 |
<?php echo $additional_shipping_addresses; // no escape. ?> |
| 1752 |
<?php echo $number_of_points; // no escape. ?> |
| 1753 |
<?php echo $billing_address; // no escape. ?> |
| 1754 |
}, |
| 1755 |
"order": { |
| 1756 |
"items": [ |
| 1757 |
<?php echo $items; // no escape. ?> |
| 1758 |
], |
| 1759 |
"order_ref": rand, |
| 1760 |
"shipping": <?php echo $shipping; // no escape. ?>, |
| 1761 |
"tax": <?php echo $tax; // no escape. ?> |
| 1762 |
}, |
| 1763 |
"shipping_address": { |
| 1764 |
"line1": "<?php echo esc_js( $line1 ); ?>", |
| 1765 |
"line2": "<?php echo esc_js( $line2 ); ?>", |
| 1766 |
"city": "<?php echo esc_js( $city ); ?>", |
| 1767 |
"state": "<?php echo esc_js( $state ); ?>", |
| 1768 |
"zip": "<?php echo esc_js( $zip ); ?>" |
| 1769 |
}, |
| 1770 |
"metadata": { |
| 1771 |
"Platform": "Welcart" |
| 1772 |
} |
| 1773 |
}; |
| 1774 |
paidyHandler.launch(payload); |
| 1775 |
}; |
| 1776 |
</script> |
| 1777 |
<?php |
| 1778 |
endif; |
| 1779 |
endif; |
| 1780 |
} |
| 1781 |
|
| 1782 |
/** |
| 1783 |
* Paidy Checkout Buyer data オブジェクト |
| 1784 |
* |
| 1785 |
* @param int $member_id Post ID. |
| 1786 |
* @return array |
| 1787 |
*/ |
| 1788 |
private function get_buyer_data( $member_id ) { |
| 1789 |
global $wpdb; |
| 1790 |
|
| 1791 |
$ltv = 0; |
| 1792 |
$order_count = 0; |
| 1793 |
$last_order_amount = 0; |
| 1794 |
$last_order_at = 0; |
| 1795 |
|
| 1796 |
$query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usces_order WHERE `mem_id` = %d ORDER BY `order_date` DESC", $member_id ); |
| 1797 |
$results = $wpdb->get_results( $query, ARRAY_A ); |
| 1798 |
if ( 0 < count( $results ) ) { |
| 1799 |
foreach ( $results as $order ) { |
| 1800 |
if ( false === strpos( $order['order_status'], 'cancel' ) && false === strpos( $order['order_status'], 'estimate' ) ) { |
| 1801 |
$payment = usces_get_payments_by_name( $order['order_payment_name'] ); |
| 1802 |
if ( isset( $payment['settlement'] ) && 'acting_paidy' !== $payment['settlement'] ) { |
| 1803 |
$total_price = $order['order_item_total_price'] - $order['order_usedpoint'] + $order['order_discount'] + $order['order_shipping_charge'] + $order['order_cod_fee'] + $order['order_tax']; |
| 1804 |
if ( 0 === $order_count ) { |
| 1805 |
$last_order_amount = $total_price; |
| 1806 |
$last_order_at = ceil( ( strtotime( date_i18n( 'Y-m-d H:i:s' ) ) - strtotime( $order['order_date'] ) ) / ( 60 * 60 * 24 ) ); |
| 1807 |
} |
| 1808 |
$ltv += $total_price; |
| 1809 |
$order_count++; |
| 1810 |
} |
| 1811 |
} |
| 1812 |
} |
| 1813 |
} |
| 1814 |
$member_data = array( |
| 1815 |
'ID' => $member_id, |
| 1816 |
'ltv' => $ltv, |
| 1817 |
'order_count' => $order_count, |
| 1818 |
'last_order_amount' => $last_order_amount, |
| 1819 |
'last_order_at' => $last_order_at, |
| 1820 |
); |
| 1821 |
|
| 1822 |
return $member_data; |
| 1823 |
} |
| 1824 |
|
| 1825 |
/** |
| 1826 |
* 決済オプション取得 |
| 1827 |
* |
| 1828 |
* @return array |
| 1829 |
*/ |
| 1830 |
protected function get_acting_settings() { |
| 1831 |
$options = get_option( 'usces', array() ); |
| 1832 |
$acting_settings = array(); |
| 1833 |
if ( isset( $options['acting_settings']['paidy'] ) ) { |
| 1834 |
$environment = ( ! empty( $options['acting_settings']['paidy']['environment'] ) ) ? $options['acting_settings']['paidy']['environment'] : 'live'; |
| 1835 |
$acting_settings['api_url'] = 'https://api.paidy.com/payments/'; |
| 1836 |
$acting_settings['apps_url'] = 'https://apps.paidy.com/'; |
| 1837 |
if ( 'live' === $environment ) { |
| 1838 |
$acting_settings['send_url'] = 'https://link.paidy.co.jp/v/u/request'; |
| 1839 |
$acting_settings['token_url'] = 'https://token.paidy.co.jp/js/PaygentToken.js'; |
| 1840 |
$acting_settings['public_key'] = ( ! empty( $options['acting_settings']['paidy']['public_key'] ) ) ? $options['acting_settings']['paidy']['public_key'] : ''; |
| 1841 |
$acting_settings['secret_key'] = ( ! empty( $options['acting_settings']['paidy']['secret_key'] ) ) ? $options['acting_settings']['paidy']['secret_key'] : ''; |
| 1842 |
} else { |
| 1843 |
$acting_settings['send_url'] = 'https://sandbox.paidy.co.jp/v/u/request'; |
| 1844 |
$acting_settings['token_url'] = 'https://sandbox.paidy.co.jp/js/PaygentToken.js'; |
| 1845 |
$acting_settings['public_key'] = ( ! empty( $options['acting_settings']['paidy']['public_key_test'] ) ) ? $options['acting_settings']['paidy']['public_key_test'] : ''; |
| 1846 |
$acting_settings['secret_key'] = ( ! empty( $options['acting_settings']['paidy']['secret_key_test'] ) ) ? $options['acting_settings']['paidy']['secret_key_test'] : ''; |
| 1847 |
} |
| 1848 |
} |
| 1849 |
return $acting_settings; |
| 1850 |
} |
| 1851 |
|
| 1852 |
/** |
| 1853 |
* 受注ID 取得 |
| 1854 |
* |
| 1855 |
* @param string $trans_id Transaction ID. |
| 1856 |
* @return int |
| 1857 |
*/ |
| 1858 |
protected function get_order_id( $trans_id ) { |
| 1859 |
global $wpdb; |
| 1860 |
|
| 1861 |
$query = $wpdb->prepare( "SELECT `order_id` FROM {$wpdb->prefix}usces_order_meta WHERE `meta_key` = %s AND `meta_value` = %s", 'trans_id', $trans_id ); |
| 1862 |
$order_id = $wpdb->get_var( $query ); |
| 1863 |
return $order_id; |
| 1864 |
} |
| 1865 |
|
| 1866 |
/** |
| 1867 |
* 取引ID 取得 |
| 1868 |
* |
| 1869 |
* @param int $order_id Order number. |
| 1870 |
* @return string |
| 1871 |
*/ |
| 1872 |
protected function get_trans_id( $order_id ) { |
| 1873 |
global $usces; |
| 1874 |
|
| 1875 |
$trans_id = $usces->get_order_meta_value( 'trans_id', $order_id ); |
| 1876 |
if ( empty( $trans_id ) ) { |
| 1877 |
$trans_id = $usces->get_order_meta_value( 'trading_id', $order_id ); |
| 1878 |
} |
| 1879 |
return $trans_id; |
| 1880 |
} |
| 1881 |
|
| 1882 |
/** |
| 1883 |
* 受注ステータス取得 |
| 1884 |
* |
| 1885 |
* @param int $order_id Order number. |
| 1886 |
* @return string |
| 1887 |
*/ |
| 1888 |
protected function get_order_status( $order_id ) { |
| 1889 |
global $wpdb; |
| 1890 |
|
| 1891 |
$query = $wpdb->prepare( "SELECT LOCATE( 'receipted', `order_status` ) FROM {$wpdb->prefix}usces_order WHERE `ID` = %d", $order_id ); |
| 1892 |
$order_status = $wpdb->get_var( $query ); |
| 1893 |
return $order_status; |
| 1894 |
} |
| 1895 |
|
| 1896 |
/** |
| 1897 |
* 受注データ支払方法取得 |
| 1898 |
* |
| 1899 |
* @param int $order_id Order number. |
| 1900 |
* @return string |
| 1901 |
*/ |
| 1902 |
protected function get_order_acting_flg( $order_id ) { |
| 1903 |
global $wpdb; |
| 1904 |
|
| 1905 |
$query = $wpdb->prepare( "SELECT `order_payment_name` FROM {$wpdb->prefix}usces_order WHERE `ID` = %d", $order_id ); |
| 1906 |
$order_payment_name = $wpdb->get_var( $query ); |
| 1907 |
$payment = usces_get_payments_by_name( $order_payment_name ); |
| 1908 |
$acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : ''; |
| 1909 |
return $acting_flg; |
| 1910 |
} |
| 1911 |
|
| 1912 |
/** |
| 1913 |
* 決済ログ取得 |
| 1914 |
* |
| 1915 |
* @param int $order_id Order number. |
| 1916 |
* @param string $trans_id Transaction ID. |
| 1917 |
* @param string $result Result. |
| 1918 |
* @return array |
| 1919 |
*/ |
| 1920 |
public function get_acting_log( $order_id = 0, $trans_id = 0, $result = 'OK' ) { |
| 1921 |
global $wpdb; |
| 1922 |
|
| 1923 |
if ( empty( $order_id ) ) { |
| 1924 |
if ( empty( $trans_id ) ) { |
| 1925 |
return array(); |
| 1926 |
} |
| 1927 |
if ( 'OK' === $result ) { |
| 1928 |
$query = $wpdb->prepare( |
| 1929 |
"SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `tracking_id` = %s AND `result` = %s ORDER BY `ID` DESC, `datetime` DESC", |
| 1930 |
$trans_id, |
| 1931 |
'OK' |
| 1932 |
); |
| 1933 |
} else { |
| 1934 |
$query = $wpdb->prepare( |
| 1935 |
"SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `tracking_id` = %s ORDER BY `ID` DESC, `datetime` DESC", |
| 1936 |
$trans_id |
| 1937 |
); |
| 1938 |
} |
| 1939 |
} else { |
| 1940 |
if ( empty( $trans_id ) ) { |
| 1941 |
if ( 'OK' === $result ) { |
| 1942 |
$query = $wpdb->prepare( |
| 1943 |
"SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `datetime` IN( SELECT MAX( `datetime` ) FROM {$wpdb->prefix}usces_acting_log WHERE `order_id` = %d GROUP BY `tracking_id` ) AND `order_id` = %d AND `result` = %s ORDER BY `ID` DESC, `datetime` DESC", |
| 1944 |
$order_id, |
| 1945 |
$order_id, |
| 1946 |
'OK' |
| 1947 |
); |
| 1948 |
} else { |
| 1949 |
$query = $wpdb->prepare( |
| 1950 |
"SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `datetime` IN( SELECT MAX( `datetime` ) FROM {$wpdb->prefix}usces_acting_log WHERE `order_id` = %d GROUP BY `tracking_id` ) AND `order_id` = %d ORDER BY `ID` DESC, `datetime` DESC", |
| 1951 |
$order_id, |
| 1952 |
$order_id |
| 1953 |
); |
| 1954 |
} |
| 1955 |
} else { |
| 1956 |
if ( 'OK' === $result ) { |
| 1957 |
$query = $wpdb->prepare( |
| 1958 |
"SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `order_id` = %d AND `tracking_id` = %s AND `result` = %s ORDER BY `ID` DESC, `datetime` DESC", |
| 1959 |
$order_id, |
| 1960 |
$trans_id, |
| 1961 |
'OK' |
| 1962 |
); |
| 1963 |
} else { |
| 1964 |
$query = $wpdb->prepare( |
| 1965 |
"SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `order_id` = %d AND `tracking_id` = %s ORDER BY `ID` DESC, `datetime` DESC", |
| 1966 |
$order_id, |
| 1967 |
$trans_id |
| 1968 |
); |
| 1969 |
} |
| 1970 |
} |
| 1971 |
} |
| 1972 |
$log_data = $wpdb->get_results( $query, ARRAY_A ); |
| 1973 |
return $log_data; |
| 1974 |
} |
| 1975 |
|
| 1976 |
/** |
| 1977 |
* 決済ログ出力 |
| 1978 |
* |
| 1979 |
* @param string $log Log data. |
| 1980 |
* @param string $acting Acting type. |
| 1981 |
* @param string $status Status. |
| 1982 |
* @param string $result Result. |
| 1983 |
* @param int $order_id Order number. |
| 1984 |
* @param string $trans_id Transaction ID. |
| 1985 |
* @param float $amount Amount. |
| 1986 |
* @return array |
| 1987 |
*/ |
| 1988 |
private function save_acting_log( $log, $acting, $status, $result, $order_id, $trans_id, $amount = 0 ) { |
| 1989 |
global $wpdb; |
| 1990 |
|
| 1991 |
if ( 'OK' === $result ) { |
| 1992 |
if ( empty( $amount ) && isset( $log['amount'] ) ) { |
| 1993 |
$amount = $log['amount']; |
| 1994 |
} |
| 1995 |
} else { |
| 1996 |
$amount = 0; |
| 1997 |
} |
| 1998 |
if ( 'authorized' === $status && ! empty( $log['created_at'] ) ) { |
| 1999 |
$datetime = date_i18n( 'Y-m-d H:i:s', strtotime( $log['created_at'] . ' +9hour' ) ); |
| 2000 |
} else { |
| 2001 |
$datetime = date_i18n( 'Y-m-d H:i:s' ); |
| 2002 |
} |
| 2003 |
$query = $wpdb->prepare( |
| 2004 |
"INSERT INTO {$wpdb->prefix}usces_acting_log ( `datetime`, `log`, `acting`, `status`, `result`, `amount`, `order_id`, `tracking_id` ) VALUES ( %s, %s, %s, %s, %s, %f, %d, %s )", |
| 2005 |
$datetime, |
| 2006 |
usces_serialize( $log ), |
| 2007 |
$acting, |
| 2008 |
$status, |
| 2009 |
$result, |
| 2010 |
$amount, |
| 2011 |
$order_id, |
| 2012 |
$trans_id |
| 2013 |
); |
| 2014 |
$res = $wpdb->query( $query ); |
| 2015 |
return $res; |
| 2016 |
} |
| 2017 |
|
| 2018 |
/** |
| 2019 |
* 最新処理取得 |
| 2020 |
* |
| 2021 |
* @param int $order_id Order number. |
| 2022 |
* @param string $trans_id Transaction ID. |
| 2023 |
* @param string $result Result. |
| 2024 |
* @return array |
| 2025 |
*/ |
| 2026 |
public function get_acting_latest_log( $order_id, $trans_id, $result = 'OK' ) { |
| 2027 |
$log_data = $this->get_acting_log( $order_id, $trans_id, $result ); |
| 2028 |
if ( $log_data ) { |
| 2029 |
$data = current( $log_data ); |
| 2030 |
$log = usces_unserialize( $data['log'] ); |
| 2031 |
$payment_id = ( isset( $log['id'] ) ) ? $log['id'] : ''; |
| 2032 |
$latest_log = array( |
| 2033 |
'log' => $log, |
| 2034 |
'acting' => $data['acting'], |
| 2035 |
'status' => $data['status'], |
| 2036 |
'result' => $data['result'], |
| 2037 |
'amount' => $data['amount'], |
| 2038 |
'order_id' => $data['order_id'], |
| 2039 |
'trans_id' => $data['tracking_id'], |
| 2040 |
'payment_id' => $payment_id, |
| 2041 |
); |
| 2042 |
} else { |
| 2043 |
$latest_log = array(); |
| 2044 |
} |
| 2045 |
return $latest_log; |
| 2046 |
} |
| 2047 |
|
| 2048 |
/** |
| 2049 |
* 決済ステータス取得 |
| 2050 |
* |
| 2051 |
* @param int $order_id Order number. |
| 2052 |
* @param string $trans_id Transaction ID. |
| 2053 |
* @return string |
| 2054 |
*/ |
| 2055 |
private function get_payment_status( $order_id, $trans_id ) { |
| 2056 |
global $wpdb; |
| 2057 |
|
| 2058 |
$payment_status = ''; |
| 2059 |
$latest_log = $this->get_acting_latest_log( $order_id, $trans_id, 'ALL' ); |
| 2060 |
if ( isset( $latest_log['status'] ) ) { |
| 2061 |
$refund = strpos( $latest_log['status'], 'refund' ); |
| 2062 |
if ( false !== $refund ) { |
| 2063 |
$payment_status = 'capture'; |
| 2064 |
} else { |
| 2065 |
$payment_status = $latest_log['status']; |
| 2066 |
} |
| 2067 |
} |
| 2068 |
return $payment_status; |
| 2069 |
} |
| 2070 |
|
| 2071 |
/** |
| 2072 |
* 処理区分名称取得 |
| 2073 |
* |
| 2074 |
* @param string $payment_status Payment status code. |
| 2075 |
* @return string |
| 2076 |
*/ |
| 2077 |
private function get_status_name( $payment_status ) { |
| 2078 |
$status_name = ''; |
| 2079 |
switch ( $payment_status ) { |
| 2080 |
case 'retrieve_error': |
| 2081 |
$status_name = 'RETRIEVE ERROR'; |
| 2082 |
break; |
| 2083 |
case 'authorized_error': |
| 2084 |
$status_name = 'AUTHORIZED ERROR'; |
| 2085 |
break; |
| 2086 |
case 'closed_error': |
| 2087 |
$status_name = 'CLOSED ERROR'; |
| 2088 |
break; |
| 2089 |
case 'capture_error': |
| 2090 |
$status_name = 'CAPTURE ERROR'; |
| 2091 |
break; |
| 2092 |
case 'refund_error': |
| 2093 |
$status_name = 'REFUND ERROR'; |
| 2094 |
break; |
| 2095 |
default: |
| 2096 |
$status_name = strtoupper( $payment_status ); |
| 2097 |
} |
| 2098 |
return $status_name; |
| 2099 |
} |
| 2100 |
|
| 2101 |
/** |
| 2102 |
* 処理区分取得 |
| 2103 |
* |
| 2104 |
* @param string $payment_status Payment status code. |
| 2105 |
* @return string |
| 2106 |
*/ |
| 2107 |
private function get_status( $payment_status ) { |
| 2108 |
$status = ''; |
| 2109 |
switch ( $payment_status ) { |
| 2110 |
case 'retrieve_error': |
| 2111 |
$status = 'retrieve-error'; |
| 2112 |
break; |
| 2113 |
case 'authorized_error': |
| 2114 |
$status = 'authorized-error'; |
| 2115 |
break; |
| 2116 |
case 'closed_error': |
| 2117 |
$status = 'closed-error'; |
| 2118 |
break; |
| 2119 |
case 'capture_error': |
| 2120 |
$status = 'capture-error'; |
| 2121 |
break; |
| 2122 |
case 'refund_error': |
| 2123 |
$status = 'refund-error'; |
| 2124 |
break; |
| 2125 |
default: |
| 2126 |
$status = $payment_status; |
| 2127 |
} |
| 2128 |
return $status; |
| 2129 |
} |
| 2130 |
|
| 2131 |
/** |
| 2132 |
* Retrieve API. |
| 2133 |
* |
| 2134 |
* @param string $payment_id Payment ID. |
| 2135 |
* @param bool $history All history retrieval. |
| 2136 |
* @return array |
| 2137 |
*/ |
| 2138 |
public function api_retrieve( $payment_id, $history = false ) { |
| 2139 |
$acting_opts = $this->get_acting_settings(); |
| 2140 |
$api_url = $acting_opts['api_url'] . $payment_id; |
| 2141 |
$params = array( |
| 2142 |
'method' => 'GET', |
| 2143 |
'headers' => array( |
| 2144 |
'Content-Type' => 'application/json;charset=utf-8', |
| 2145 |
'Authorization' => 'Bearer ' . $acting_opts['secret_key'], |
| 2146 |
'Paidy-Version' => '2018-04-10', |
| 2147 |
), |
| 2148 |
); |
| 2149 |
$response = wp_remote_get( $api_url, $params ); |
| 2150 |
if ( is_wp_error( $response ) ) { |
| 2151 |
$response_data = array(); |
| 2152 |
} else { |
| 2153 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 2154 |
if ( $history ) { |
| 2155 |
$amount = $response_data['amount']; |
| 2156 |
$capture_id = ''; |
| 2157 |
if ( isset( $response_data['captures'] ) ) { |
| 2158 |
$captures = $response_data['captures']; |
| 2159 |
foreach ( (array) $captures as $capture ) { |
| 2160 |
if ( isset( $capture['id'] ) ) { |
| 2161 |
$capture_id = $capture['id']; |
| 2162 |
} |
| 2163 |
} |
| 2164 |
$response_data['capture_id'] = $capture_id; |
| 2165 |
} |
| 2166 |
if ( isset( $response_data['refunds'] ) ) { |
| 2167 |
$refunds = $response_data['refunds']; |
| 2168 |
foreach ( (array) $refunds as $refund ) { |
| 2169 |
if ( isset( $refund['amount'] ) ) { |
| 2170 |
$amount -= (int) $refund['amount']; |
| 2171 |
} |
| 2172 |
} |
| 2173 |
} |
| 2174 |
if ( 'closed' === $response_data['status'] && empty( $capture_id ) ) { |
| 2175 |
$amount = 0; |
| 2176 |
} |
| 2177 |
$response_data['final_amount'] = $amount; |
| 2178 |
} |
| 2179 |
} |
| 2180 |
return $response_data; |
| 2181 |
} |
| 2182 |
|
| 2183 |
/** |
| 2184 |
* Captures API. |
| 2185 |
* |
| 2186 |
* @param string $payment_id Payment ID. |
| 2187 |
* @return array |
| 2188 |
*/ |
| 2189 |
public function api_capture( $payment_id ) { |
| 2190 |
$acting_opts = $this->get_acting_settings(); |
| 2191 |
$api_url = $acting_opts['api_url'] . $payment_id . '/captures'; |
| 2192 |
$body = array( |
| 2193 |
'metadata' => array( 'Platform' => 'Welcart' ), |
| 2194 |
); |
| 2195 |
$params = array( |
| 2196 |
'method' => 'POST', |
| 2197 |
'headers' => array( |
| 2198 |
'Content-Type' => 'application/json;charset=utf-8', |
| 2199 |
'Authorization' => 'Bearer ' . $acting_opts['secret_key'], |
| 2200 |
'Paidy-Version' => '2018-04-10', |
| 2201 |
), |
| 2202 |
'body' => wp_json_encode( $body ), |
| 2203 |
); |
| 2204 |
$response = wp_remote_post( $api_url, $params ); |
| 2205 |
if ( is_wp_error( $response ) ) { |
| 2206 |
$response_data = array(); |
| 2207 |
} else { |
| 2208 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 2209 |
} |
| 2210 |
return $response_data; |
| 2211 |
} |
| 2212 |
|
| 2213 |
/** |
| 2214 |
* Refunds API. |
| 2215 |
* |
| 2216 |
* @param string $payment_id Payment ID. |
| 2217 |
* @param string $capture_id Capture ID. |
| 2218 |
* @param float $amount 返金金額. |
| 2219 |
* @return array |
| 2220 |
*/ |
| 2221 |
public function api_refund( $payment_id, $capture_id, $amount = 0 ) { |
| 2222 |
$acting_opts = $this->get_acting_settings(); |
| 2223 |
$api_url = $acting_opts['api_url'] . $payment_id . '/refunds'; |
| 2224 |
$body = array( |
| 2225 |
'metadata' => array( 'Platform' => 'Welcart' ), |
| 2226 |
'capture_id' => $capture_id, |
| 2227 |
); |
| 2228 |
if ( ! empty( $amount ) ) { |
| 2229 |
$body['amount'] = $amount; |
| 2230 |
} |
| 2231 |
$params = array( |
| 2232 |
'method' => 'POST', |
| 2233 |
'headers' => array( |
| 2234 |
'Content-Type' => 'application/json;charset=utf-8', |
| 2235 |
'Authorization' => 'Bearer ' . $acting_opts['secret_key'], |
| 2236 |
'Paidy-Version' => '2018-04-10', |
| 2237 |
), |
| 2238 |
'body' => wp_json_encode( $body ), |
| 2239 |
); |
| 2240 |
$response = wp_remote_post( $api_url, $params ); |
| 2241 |
if ( is_wp_error( $response ) ) { |
| 2242 |
$response_data = array(); |
| 2243 |
} else { |
| 2244 |
if ( isset( $response_data['response']['code'] ) && '2' === substr( $response['response']['code'], 0, 1 ) ) { |
| 2245 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 2246 |
} else { |
| 2247 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 2248 |
} |
| 2249 |
} |
| 2250 |
return $response_data; |
| 2251 |
} |
| 2252 |
|
| 2253 |
/** |
| 2254 |
* Close API. |
| 2255 |
* |
| 2256 |
* @param string $payment_id Payment ID. |
| 2257 |
* @return array |
| 2258 |
*/ |
| 2259 |
public function api_close( $payment_id ) { |
| 2260 |
$acting_opts = $this->get_acting_settings(); |
| 2261 |
$api_url = $acting_opts['api_url'] . $payment_id . '/close'; |
| 2262 |
$body = array( |
| 2263 |
'metadata' => array( 'Platform' => 'Welcart' ), |
| 2264 |
); |
| 2265 |
$params = array( |
| 2266 |
'method' => 'POST', |
| 2267 |
'headers' => array( |
| 2268 |
'Content-Type' => 'application/json;charset=utf-8', |
| 2269 |
'Authorization' => 'Bearer ' . $acting_opts['secret_key'], |
| 2270 |
'Paidy-Version' => '2018-04-10', |
| 2271 |
), |
| 2272 |
'body' => wp_json_encode( $body ), |
| 2273 |
); |
| 2274 |
$response = wp_remote_get( $api_url, $params ); |
| 2275 |
if ( is_wp_error( $response ) ) { |
| 2276 |
$response_data = array(); |
| 2277 |
} else { |
| 2278 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 2279 |
} |
| 2280 |
return $response_data; |
| 2281 |
} |
| 2282 |
} |
| 2283 |
|