| 1 |
<?php |
| 2 |
/** |
| 3 |
* Settlement Class. |
| 4 |
* PayPal |
| 5 |
* |
| 6 |
* @package Welcart |
| 7 |
* @author Collne Inc. |
| 8 |
* @version 1.1.0 |
| 9 |
* @since 2.1.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* PayPal Commerce Platform |
| 14 |
*/ |
| 15 |
class PAYPAL_CP_SETTLEMENT { |
| 16 |
|
| 17 |
const API_BN_CODE_PCP = 'Welcart_Cart_PCP_JP'; |
| 18 |
const API_BN_CODE_ACDC = 'Collne_Cart_ACDC_JP'; |
| 19 |
const API_FRAUDNET_S = 'Collne_T7SS625X3B32Q_RT'; |
| 20 |
const API_URL = 'https://api-m.paypal.com'; |
| 21 |
const API_SANDBOX_URL = 'https://api-m.sandbox.paypal.com'; |
| 22 |
const API_TIMEOUT = 30; |
| 23 |
|
| 24 |
/** |
| 25 |
* Instance of this class. |
| 26 |
* |
| 27 |
* @var object |
| 28 |
*/ |
| 29 |
protected static $instance = null; |
| 30 |
|
| 31 |
/** |
| 32 |
* 決済代行会社ID |
| 33 |
* |
| 34 |
* @var string |
| 35 |
*/ |
| 36 |
protected $paymod_id; |
| 37 |
|
| 38 |
/** |
| 39 |
* 決済種別 |
| 40 |
* |
| 41 |
* @var string |
| 42 |
*/ |
| 43 |
protected $pay_method; |
| 44 |
|
| 45 |
/** |
| 46 |
* 決済代行会社略称 |
| 47 |
* |
| 48 |
* @var string |
| 49 |
*/ |
| 50 |
protected $acting_name; |
| 51 |
|
| 52 |
/** |
| 53 |
* 決済代行会社正式名称 |
| 54 |
* |
| 55 |
* @var string |
| 56 |
*/ |
| 57 |
protected $acting_formal_name; |
| 58 |
|
| 59 |
/** |
| 60 |
* 決済代行会社URL |
| 61 |
* |
| 62 |
* @var string |
| 63 |
*/ |
| 64 |
protected $acting_company_url; |
| 65 |
|
| 66 |
/** |
| 67 |
* 併用不可決済モジュール |
| 68 |
* |
| 69 |
* @var array |
| 70 |
*/ |
| 71 |
protected $unavailable_method; |
| 72 |
|
| 73 |
/** |
| 74 |
* エラーメッセージ |
| 75 |
* |
| 76 |
* @var string |
| 77 |
*/ |
| 78 |
protected $error_mes; |
| 79 |
|
| 80 |
/** |
| 81 |
* 自動継続課金処理結果メール |
| 82 |
* |
| 83 |
* @var array |
| 84 |
*/ |
| 85 |
protected $continuation_charging_mail; |
| 86 |
|
| 87 |
/** |
| 88 |
* Construct. |
| 89 |
*/ |
| 90 |
public function __construct() { |
| 91 |
|
| 92 |
$this->paymod_id = 'paypal_cp'; |
| 93 |
$this->pay_method = array( |
| 94 |
'acting_paypal_cp', |
| 95 |
'acting_paypal_card', |
| 96 |
); |
| 97 |
$this->acting_name = 'PayPal(CP)'; |
| 98 |
$this->acting_formal_name = 'PayPal Commerce Platform'; |
| 99 |
|
| 100 |
$this->initialize_data(); |
| 101 |
|
| 102 |
add_action( 'init', array( $this, 'init' ), 20 ); |
| 103 |
add_filter( 'http_headers_useragent', array( $this, 'http_headers_useragent' ), 10, 2 ); |
| 104 |
if ( $this->is_validity_acting() ) { |
| 105 |
add_action( 'template_redirect', array( $this, 'respond_to_ipn' ), 1 ); |
| 106 |
} |
| 107 |
|
| 108 |
if ( is_admin() ) { |
| 109 |
add_action( 'wp_ajax_onboarded', array( $this, 'onboarded' ) ); |
| 110 |
add_action( 'usces_action_admin_ajax', array( $this, 'admin_ajax' ) ); |
| 111 |
add_action( 'admin_print_footer_scripts', array( $this, 'admin_scripts' ) ); |
| 112 |
add_action( 'usces_action_admin_settlement_update', array( $this, 'settlement_update' ) ); |
| 113 |
add_action( 'usces_action_settlement_tab_title', array( $this, 'settlement_tab_title' ) ); |
| 114 |
add_action( 'usces_action_settlement_tab_body', array( $this, 'settlement_tab_body' ) ); |
| 115 |
} |
| 116 |
|
| 117 |
if ( $this->is_validity_acting() ) { |
| 118 |
add_action( 'wp_ajax_create_billing_agreement', array( $this, 'create_billing_agreement' ) ); |
| 119 |
add_action( 'wp_ajax_nopriv_create_billing_agreement', array( $this, 'create_billing_agreement' ) ); |
| 120 |
add_action( 'wp_ajax_create_order', array( $this, 'create_order' ) ); |
| 121 |
add_action( 'wp_ajax_nopriv_create_order', array( $this, 'create_order' ) ); |
| 122 |
if ( $this->is_validity_acting( 'card' ) ) { |
| 123 |
add_action( 'wp_ajax_create_order_card', array( $this, 'create_order_card' ) ); |
| 124 |
add_action( 'wp_ajax_nopriv_create_order_card', array( $this, 'create_order_card' ) ); |
| 125 |
add_action( 'wp_ajax_create_order_member', array( $this, 'create_order_member' ) ); |
| 126 |
add_action( 'wp_ajax_nopriv_create_order_member', array( $this, 'create_order_member' ) ); |
| 127 |
add_action( 'wp_ajax_show_order_details_card', array( $this, 'show_order_details_card' ) ); |
| 128 |
add_action( 'wp_ajax_nopriv_show_order_details_card', array( $this, 'show_order_details_card' ) ); |
| 129 |
add_filter( 'usces_filter_payments_str', array( $this, 'payments_str' ), 10, 2 ); |
| 130 |
add_filter( 'usces_filter_payments_arr', array( $this, 'payments_arr' ), 10, 2 ); |
| 131 |
add_filter( 'usces_filter_delivery_secure_form_loop', array( $this, 'delivery_secure_form_loop' ), 10, 2 ); |
| 132 |
add_filter( 'usces_filter_delivery_check', array( $this, 'delivery_check' ), 15 ); |
| 133 |
add_action( 'usces_action_confirm_page_point_inform', array( $this, 'e_point_inform' ), 10, 5 ); |
| 134 |
add_filter( 'usces_filter_confirm_point_inform', array( $this, 'point_inform' ), 10, 5 ); |
| 135 |
if ( defined( 'WCEX_COUPON' ) ) { |
| 136 |
add_filter( 'wccp_filter_coupon_inform', array( $this, 'point_inform' ), 10, 5 ); |
| 137 |
} |
| 138 |
add_filter( 'usces_filter_get_error_settlement', array( $this, 'error_page_message' ) ); |
| 139 |
add_filter( 'usces_filter_template_redirect', array( $this, 'member_update_settlement' ), 1 ); |
| 140 |
add_action( 'usces_action_member_submenu_list', array( $this, 'e_update_settlement' ) ); |
| 141 |
add_filter( 'usces_filter_member_submenu_list', array( $this, 'update_settlement' ), 10, 2 ); |
| 142 |
add_action( 'usces_action_pre_delete_memberdata', array( $this, 'delete_member' ) ); |
| 143 |
} |
| 144 |
add_filter( 'usces_filter_confirm_inform', array( $this, 'confirm_inform' ), 10, 5 ); |
| 145 |
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
| 146 |
add_action( 'wp_print_footer_scripts', array( $this, 'footer_scripts' ) ); |
| 147 |
add_action( 'usces_action_acting_processing', array( $this, 'acting_processing' ), 10, 2 ); |
| 148 |
add_filter( 'usces_filter_check_acting_return_results', array( $this, 'acting_return' ) ); |
| 149 |
add_action( 'usces_action_reg_orderdata', array( $this, 'register_orderdata' ) ); |
| 150 |
add_filter( 'usces_filter_is_complete_settlement', array( $this, 'is_complete_settlement' ), 10, 3 ); |
| 151 |
add_filter( 'usces_filter_delete_member_check', array( $this, 'delete_member_check' ), 10, 2 ); |
| 152 |
add_filter( 'usces_filter_delete_member_check_front', array( $this, 'delete_member_check' ), 10, 2 ); |
| 153 |
if ( is_admin() ) { |
| 154 |
add_filter( 'usces_filter_settle_info_field_meta_keys', array( $this, 'settlement_info_field_meta_keys' ) ); |
| 155 |
add_filter( 'usces_filter_settle_info_field_keys', array( $this, 'settlement_info_field_keys' ), 10, 2 ); |
| 156 |
add_filter( 'usces_filter_settle_info_field_value', array( $this, 'settlement_info_field_value' ), 10, 3 ); |
| 157 |
add_filter( 'usces_filter_orderlist_detail_value', array( $this, 'orderlist_settlement_status' ), 10, 4 ); |
| 158 |
add_action( 'usces_action_order_edit_form_status_block_middle', array( $this, 'settlement_status' ), 10, 3 ); |
| 159 |
add_action( 'usces_action_order_edit_form_settle_info', array( $this, 'settlement_information' ), 10, 2 ); |
| 160 |
add_action( 'usces_action_endof_order_edit_form', array( $this, 'settlement_dialog' ), 10, 2 ); |
| 161 |
add_action( 'usces_action_admin_member_info', array( $this, 'admin_member_info' ), 10, 3 ); |
| 162 |
add_action( 'usces_action_post_update_memberdata', array( $this, 'admin_update_memberdata' ), 10, 2 ); |
| 163 |
} |
| 164 |
|
| 165 |
/* WCEX DL Seller */ |
| 166 |
if ( defined( 'WCEX_DLSELLER' ) ) { |
| 167 |
add_filter( 'usces_filter_the_continue_payment_method', array( $this, 'continuation_payment_method' ) ); |
| 168 |
add_filter( 'dlseller_action_reg_continuationdata', array( $this, 'register_continuationdata' ) ); |
| 169 |
add_filter( 'dlseller_filter_first_charging', array( $this, 'first_charging_date' ), 9, 5 ); |
| 170 |
add_filter( 'dlseller_filter_the_payment_method_restriction', array( $this, 'payment_method_restriction' ), 10, 2 ); |
| 171 |
add_filter( 'dlseller_filter_continue_memberlist_column', array( $this, 'continue_memberlist_column' ), 10, 2 ); |
| 172 |
add_filter( 'dlseller_filter_continue_memberlist_sql_jointable', array( $this, 'continue_memberlist_sql_jointable' ), 10, 2 ); |
| 173 |
add_filter( 'dlseller_filter_continue_memberlist_sql_select', array( $this, 'continue_memberlist_sql_select' ), 10, 3 ); |
| 174 |
add_filter( 'dlseller_filter_continue_member_list_condition', array( $this, 'continue_member_list_condition' ), 10, 4 ); |
| 175 |
add_action( 'dlseller_action_continue_member_list_page', array( $this, 'continue_member_list_page' ) ); |
| 176 |
add_action( 'dlseller_action_do_continuation_charging', array( $this, 'auto_continuation_charging' ), 10, 4 ); |
| 177 |
add_action( 'dlseller_action_do_continuation', array( $this, 'do_auto_continuation' ), 10, 2 ); |
| 178 |
add_filter( 'dlseller_filter_reminder_mail_body', array( $this, 'reminder_mail_body' ), 10, 3 ); |
| 179 |
add_filter( 'dlseller_filter_contract_renewal_mail_body', array( $this, 'contract_renewal_mail_body' ), 10, 3 ); |
| 180 |
add_filter( 'usces_filter_order_confirm_mail_payment', array( $this, 'continue_order_mail_payment' ), 11, 4 ); |
| 181 |
add_filter( 'usces_filter_send_order_mail_payment', array( $this, 'continue_order_mail_payment' ), 11, 4 ); |
| 182 |
} |
| 183 |
|
| 184 |
/* WCEX Auto Delivery */ |
| 185 |
if ( defined( 'WCEX_AUTO_DELIVERY' ) ) { |
| 186 |
add_filter( 'wcad_action_reg_regulardata', array( $this, 'register_regulardata' ) ); |
| 187 |
add_filter( 'wcad_filter_shippinglist_acting', array( $this, 'set_shippinglist_acting' ) ); |
| 188 |
add_filter( 'wcad_filter_available_regular_payment_method', array( $this, 'available_regular_payment_method' ) ); |
| 189 |
add_filter( 'wcad_filter_the_payment_method_restriction', array( $this, 'payment_method_restriction' ), 10, 2 ); |
| 190 |
add_action( 'wcad_action_reg_auto_orderdata', array( $this, 'register_auto_orderdata' ) ); |
| 191 |
add_filter( 'wcad_filter_send_settlement_error_mail_message_head', array( $this, 'settlement_error_mail_message_header' ), 10, 2 ); |
| 192 |
if ( version_compare( WCEX_AUTO_DELIVERY_VERSION, '1.2.5', '>=' ) ) { |
| 193 |
add_filter( 'wcad_filter_send_settlement_error_mail_message', array( $this, 'settlement_error_mail_message' ), 10, 3 ); |
| 194 |
} |
| 195 |
add_action( 'wcad_action_regular_information_edit_form', array( $this, 'regular_information_edit_form' ) ); |
| 196 |
add_filter( 'usces_filter_order_confirm_mail_payment', array( $this, 'regular_order_mail_payment' ), 11, 4 ); |
| 197 |
add_filter( 'usces_filter_send_order_mail_payment', array( $this, 'regular_order_mail_payment' ), 11, 4 ); |
| 198 |
add_filter( 'wcad_filter_order_confirm_mail_payment', array( $this, 'regular_order_mail_payment' ), 11, 4 ); |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* Return an instance of this class. |
| 205 |
*/ |
| 206 |
public static function get_instance() { |
| 207 |
if ( is_null( self::$instance ) ) { |
| 208 |
self::$instance = new self(); |
| 209 |
} |
| 210 |
return self::$instance; |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Initialize. |
| 215 |
*/ |
| 216 |
public function initialize_data() { |
| 217 |
$options = get_option( 'usces', array() ); |
| 218 |
$options['acting_settings']['paypal_cp']['activate'] = ( isset( $options['acting_settings']['paypal_cp']['activate'] ) ) ? $options['acting_settings']['paypal_cp']['activate'] : 'off'; |
| 219 |
$options['acting_settings']['paypal_cp']['cp_activate'] = ( isset( $options['acting_settings']['paypal_cp']['cp_activate'] ) ) ? $options['acting_settings']['paypal_cp']['cp_activate'] : 'off'; |
| 220 |
$options['acting_settings']['paypal_cp']['card_activate'] = ( isset( $options['acting_settings']['paypal_cp']['card_activate'] ) ) ? $options['acting_settings']['paypal_cp']['card_activate'] : 'off'; |
| 221 |
$options['acting_settings']['paypal_cp']['card_vault'] = ( isset( $options['acting_settings']['paypal_cp']['card_vault'] ) ) ? $options['acting_settings']['paypal_cp']['card_vault'] : 'off'; |
| 222 |
$options['acting_settings']['paypal_cp']['card_prefix'] = ( isset( $options['acting_settings']['paypal_cp']['card_prefix'] ) ) ? $options['acting_settings']['paypal_cp']['card_prefix'] : ''; |
| 223 |
$options['acting_settings']['paypal_cp']['card_3ds'] = ( isset( $options['acting_settings']['paypal_cp']['card_3ds'] ) ) ? $options['acting_settings']['paypal_cp']['card_3ds'] : 'off'; |
| 224 |
$options['acting_settings']['paypal_cp']['environment'] = ( isset( $options['acting_settings']['paypal_cp']['environment'] ) ) ? $options['acting_settings']['paypal_cp']['environment'] : 'live'; |
| 225 |
$options['acting_settings']['paypal_cp']['bncode'] = ( isset( $options['acting_settings']['paypal_cp']['bncode'] ) ) ? $options['acting_settings']['paypal_cp']['bncode'] : ''; |
| 226 |
$options['acting_settings']['paypal_cp']['client_id'] = ( isset( $options['acting_settings']['paypal_cp']['client_id'] ) ) ? $options['acting_settings']['paypal_cp']['client_id'] : ''; |
| 227 |
$options['acting_settings']['paypal_cp']['secret'] = ( isset( $options['acting_settings']['paypal_cp']['secret'] ) ) ? $options['acting_settings']['paypal_cp']['secret'] : ''; |
| 228 |
$options['acting_settings']['paypal_cp']['intent'] = ( isset( $options['acting_settings']['paypal_cp']['intent'] ) ) ? $options['acting_settings']['paypal_cp']['intent'] : 'CAPTURE'; |
| 229 |
$options['acting_settings']['paypal_cp']['autobilling_intent'] = ( isset( $options['acting_settings']['paypal_cp']['autobilling_intent'] ) ) ? $options['acting_settings']['paypal_cp']['autobilling_intent'] : 'CAPTURE'; |
| 230 |
$options['acting_settings']['paypal_cp']['autobilling_email'] = ( isset( $options['acting_settings']['paypal_cp']['autobilling_email'] ) ) ? $options['acting_settings']['paypal_cp']['autobilling_email'] : 'off'; |
| 231 |
$options['acting_settings']['paypal_cp']['button_layout'] = ( isset( $options['acting_settings']['paypal_cp']['button_layout'] ) ) ? $options['acting_settings']['paypal_cp']['button_layout'] : 'vertical'; |
| 232 |
$options['acting_settings']['paypal_cp']['button_color'] = ( isset( $options['acting_settings']['paypal_cp']['button_color'] ) ) ? $options['acting_settings']['paypal_cp']['button_color'] : 'gold'; |
| 233 |
$options['acting_settings']['paypal_cp']['button_shape'] = ( isset( $options['acting_settings']['paypal_cp']['button_shape'] ) ) ? $options['acting_settings']['paypal_cp']['button_shape'] : 'rect'; |
| 234 |
$options['acting_settings']['paypal_cp']['button_label'] = ( isset( $options['acting_settings']['paypal_cp']['button_label'] ) ) ? $options['acting_settings']['paypal_cp']['button_label'] : 'paypal'; |
| 235 |
$options['acting_settings']['paypal_cp']['agree'] = ( isset( $options['acting_settings']['paypal_cp']['agree'] ) ) ? $options['acting_settings']['paypal_cp']['agree'] : ''; |
| 236 |
update_option( 'usces', $options ); |
| 237 |
|
| 238 |
$available_settlement = get_option( 'usces_available_settlement', array() ); |
| 239 |
if ( ! in_array( $this->paymod_id, $available_settlement ) ) { |
| 240 |
$available_settlement[ $this->paymod_id ] = $this->acting_formal_name; |
| 241 |
update_option( 'usces_available_settlement', $available_settlement ); |
| 242 |
} |
| 243 |
|
| 244 |
$this->unavailable_method = array( 'acting_paypal_ec', 'acting_paypal_wpp' ); |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* 決済有効判定 |
| 249 |
* 支払方法で使用している場合に true |
| 250 |
* |
| 251 |
* @param string $type Module type. |
| 252 |
* @return boolean |
| 253 |
*/ |
| 254 |
public function is_validity_acting( $type = '' ) { |
| 255 |
$acting_opts = $this->get_acting_settings(); |
| 256 |
if ( empty( $acting_opts ) ) { |
| 257 |
return false; |
| 258 |
} |
| 259 |
|
| 260 |
$payment_method = usces_get_system_option( 'usces_payment_method', 'sort' ); |
| 261 |
$method = false; |
| 262 |
|
| 263 |
switch ( $type ) { |
| 264 |
case 'cp': |
| 265 |
foreach ( $payment_method as $payment ) { |
| 266 |
if ( 'acting_paypal_cp' === $payment['settlement'] && 'activate' === $payment['use'] ) { |
| 267 |
$method = true; |
| 268 |
break; |
| 269 |
} |
| 270 |
} |
| 271 |
if ( $method && $this->is_activate_paypal_cp() ) { |
| 272 |
return true; |
| 273 |
} else { |
| 274 |
return false; |
| 275 |
} |
| 276 |
case 'card': |
| 277 |
foreach ( $payment_method as $payment ) { |
| 278 |
if ( 'acting_paypal_card' === $payment['settlement'] && 'activate' === $payment['use'] ) { |
| 279 |
$method = true; |
| 280 |
break; |
| 281 |
} |
| 282 |
} |
| 283 |
if ( $method && $this->is_activate_paypal_card() ) { |
| 284 |
return true; |
| 285 |
} else { |
| 286 |
return false; |
| 287 |
} |
| 288 |
break; |
| 289 |
default: |
| 290 |
if ( 'on' === $acting_opts['activate'] ) { |
| 291 |
return true; |
| 292 |
} else { |
| 293 |
return false; |
| 294 |
} |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
/** |
| 299 |
* 決済利用判定 |
| 300 |
* PayPal CP を「利用する」のとき true |
| 301 |
* |
| 302 |
* @return boolean |
| 303 |
*/ |
| 304 |
public function is_activate_paypal_cp() { |
| 305 |
$acting_opts = $this->get_acting_settings(); |
| 306 |
if ( ( isset( $acting_opts['activate'] ) && 'on' === $acting_opts['activate'] ) && |
| 307 |
( isset( $acting_opts['cp_activate'] ) && 'on' === $acting_opts['cp_activate'] ) ) { |
| 308 |
$res = true; |
| 309 |
} else { |
| 310 |
$res = false; |
| 311 |
} |
| 312 |
return $res; |
| 313 |
} |
| 314 |
|
| 315 |
/** |
| 316 |
* 決済利用判定 |
| 317 |
* PayPal カード決済を「利用する」のとき true |
| 318 |
* |
| 319 |
* @return boolean |
| 320 |
*/ |
| 321 |
public function is_activate_paypal_card() { |
| 322 |
$acting_opts = $this->get_acting_settings(); |
| 323 |
if ( ( isset( $acting_opts['activate'] ) && 'on' === $acting_opts['activate'] ) && |
| 324 |
( isset( $acting_opts['card_activate'] ) && 'on' === $acting_opts['card_activate'] ) ) { |
| 325 |
$res = true; |
| 326 |
} else { |
| 327 |
$res = false; |
| 328 |
} |
| 329 |
return $res; |
| 330 |
} |
| 331 |
|
| 332 |
/** |
| 333 |
* Resolve conflicts. |
| 334 |
* init |
| 335 |
*/ |
| 336 |
public function init() { |
| 337 |
global $usces; |
| 338 |
|
| 339 |
$payment_method = usces_get_system_option( 'usces_payment_method', 'sort' ); |
| 340 |
foreach ( $payment_method as $payment ) { |
| 341 |
if ( 'acting_paypal_ec' === $payment['settlement'] && 'activate' === $payment['use'] ) { |
| 342 |
$payment['use'] = 'deactivate'; |
| 343 |
usces_update_system_option( 'usces_payment_method', $payment['id'], $payment ); |
| 344 |
} elseif ( 'acting_paypal_wpp' === $payment['settlement'] && 'activate' === $payment['use'] ) { |
| 345 |
$payment['use'] = 'deactivate'; |
| 346 |
usces_update_system_option( 'usces_payment_method', $payment['id'], $payment ); |
| 347 |
} |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
/** |
| 352 |
* Respond to PayPal IPN with HTTP 200. |
| 353 |
* |
| 354 |
* Billing Agreements created before the notify_url removal |
| 355 |
* still trigger IPN on each recurring payment. Since PayPal CP |
| 356 |
* does not use IPN, simply return HTTP 200 to stop failure alerts. |
| 357 |
* |
| 358 |
* @return void |
| 359 |
*/ |
| 360 |
public function respond_to_ipn() { |
| 361 |
if ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) { |
| 362 |
return; |
| 363 |
} |
| 364 |
if ( ! isset( $_POST['ipn_track_id'] ) || ! isset( $_POST['txn_type'] ) ) { |
| 365 |
return; |
| 366 |
} |
| 367 |
status_header( 200 ); |
| 368 |
exit; |
| 369 |
} |
| 370 |
|
| 371 |
/** |
| 372 |
* Filters the user agent value sent with an HTTP request. |
| 373 |
* http_headers_useragent |
| 374 |
* |
| 375 |
* @param string $user_agent WordPress user agent string. |
| 376 |
* @param string $url The request URL. |
| 377 |
*/ |
| 378 |
public function http_headers_useragent( $user_agent, $url ) { |
| 379 |
if ( false !== strpos( $url, self::API_URL ) || false !== strpos( $url, self::API_SANDBOX_URL ) ) { |
| 380 |
$user_agent = 'Welcart/' . USCES_VERSION . '; ' . get_bloginfo( 'url' ); |
| 381 |
} |
| 382 |
return $user_agent; |
| 383 |
} |
| 384 |
|
| 385 |
/** |
| 386 |
* 管理画面スクリプト |
| 387 |
* admin_print_footer_scripts |
| 388 |
*/ |
| 389 |
public function admin_scripts() { |
| 390 |
global $usces, $usces_settings; |
| 391 |
|
| 392 |
$admin_page = ( isset( $_GET['page'] ) ) ? wp_unslash( $_GET['page'] ) : ''; |
| 393 |
switch ( $admin_page ) : |
| 394 |
/* クレジット決済設定画面 */ |
| 395 |
case 'usces_settlement': |
| 396 |
$settlement_selected = get_option( 'usces_settlement_selected', array() ); |
| 397 |
if ( in_array( $this->paymod_id, (array) $settlement_selected ) ) : |
| 398 |
$acting_opts = $this->get_acting_settings(); |
| 399 |
$cp_activate = ( isset( $acting_opts['cp_activate'] ) ) ? $acting_opts['cp_activate'] : 'off'; |
| 400 |
$card_activate = ( isset( $acting_opts['card_activate'] ) ) ? $acting_opts['card_activate'] : 'off'; |
| 401 |
$cp_environment = ( isset( $acting_opts['environment'] ) ) ? $acting_opts['environment'] : 'live'; |
| 402 |
?> |
| 403 |
<script src="https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js" id="paypal-js"></script> |
| 404 |
<script type="text/javascript"> |
| 405 |
jQuery( document ).ready( function( $ ) { |
| 406 |
var card_activate = "<?php echo esc_js( $card_activate ); ?>"; |
| 407 |
if ( "on" == card_activate ) { |
| 408 |
$( ".paypal_card_form" ).css( "display", "" ); |
| 409 |
} else { |
| 410 |
$( ".paypal_card_form" ).css( "display", "none" ); |
| 411 |
} |
| 412 |
$( document ).on( "change", ".activate_paypal_card", function() { |
| 413 |
if ( "on" == $( this ).val() ) { |
| 414 |
$( ".paypal_card_form" ).css( "display", "" ); |
| 415 |
} else { |
| 416 |
$( ".paypal_card_form" ).css( "display", "none" ); |
| 417 |
} |
| 418 |
}); |
| 419 |
|
| 420 |
var environment_cp = "<?php echo esc_js( $cp_environment ); ?>"; |
| 421 |
if ( "live" == environment_cp ) { |
| 422 |
$( "#upfront_onboarding_paypal_cp" ).prop( "disabled", false ); |
| 423 |
} else { |
| 424 |
$( "#upfront_onboarding_paypal_cp" ).prop( "disabled", true ); |
| 425 |
} |
| 426 |
$( document ).on( "change", ".cp_environment", function() { |
| 427 |
if ( "live" == $( this ).val() ) { |
| 428 |
$( "#upfront_onboarding_paypal_cp" ).prop( "disabled", false ); |
| 429 |
} else { |
| 430 |
$( "#upfront_onboarding_paypal_cp" ).prop( "disabled", true ); |
| 431 |
} |
| 432 |
}); |
| 433 |
|
| 434 |
$( document ).on( "change", ".button_color_paypal_cp", function() { |
| 435 |
if ( "gold" == $( this ).val() ) { |
| 436 |
$( "#button_preview_paypal_cp" ).addClass( "color-gold" ); |
| 437 |
$( "#button_preview_paypal_cp" ).removeClass( "color-blue" ); |
| 438 |
$( "#button_preview_paypal_cp" ).removeClass( "color-silver" ); |
| 439 |
$( "#button_preview_paypal_cp" ).removeClass( "color-white" ); |
| 440 |
$( "#button_preview_paypal_cp" ).removeClass( "color-black" ); |
| 441 |
} else if ( "blue" == $( this ).val() ) { |
| 442 |
$( "#button_preview_paypal_cp" ).removeClass( "color-gold" ); |
| 443 |
$( "#button_preview_paypal_cp" ).addClass( "color-blue" ); |
| 444 |
$( "#button_preview_paypal_cp" ).removeClass( "color-silver" ); |
| 445 |
$( "#button_preview_paypal_cp" ).removeClass( "color-white" ); |
| 446 |
$( "#button_preview_paypal_cp" ).removeClass( "color-black" ); |
| 447 |
} else if ( "silver" == $( this ).val() ) { |
| 448 |
$( "#button_preview_paypal_cp" ).removeClass( "color-gold" ); |
| 449 |
$( "#button_preview_paypal_cp" ).removeClass( "color-blue" ); |
| 450 |
$( "#button_preview_paypal_cp" ).addClass( "color-silver" ); |
| 451 |
$( "#button_preview_paypal_cp" ).removeClass( "color-white" ); |
| 452 |
$( "#button_preview_paypal_cp" ).removeClass( "color-black" ); |
| 453 |
} else if ( "white" == $( this ).val() ) { |
| 454 |
$( "#button_preview_paypal_cp" ).removeClass( "color-gold" ); |
| 455 |
$( "#button_preview_paypal_cp" ).removeClass( "color-blue" ); |
| 456 |
$( "#button_preview_paypal_cp" ).removeClass( "color-silver" ); |
| 457 |
$( "#button_preview_paypal_cp" ).addClass( "color-white" ); |
| 458 |
$( "#button_preview_paypal_cp" ).removeClass( "color-black" ); |
| 459 |
} else if ( "black" == $( this ).val() ) { |
| 460 |
$( "#button_preview_paypal_cp" ).removeClass( "color-gold" ); |
| 461 |
$( "#button_preview_paypal_cp" ).removeClass( "color-blue" ); |
| 462 |
$( "#button_preview_paypal_cp" ).removeClass( "color-silver" ); |
| 463 |
$( "#button_preview_paypal_cp" ).removeClass( "color-white" ); |
| 464 |
$( "#button_preview_paypal_cp" ).addClass( "color-black" ); |
| 465 |
} |
| 466 |
}); |
| 467 |
|
| 468 |
$( document ).on( "change", ".button_shape_paypal_cp", function() { |
| 469 |
if ( "rect" == $( this ).val() ) { |
| 470 |
$( "#button_preview_paypal_cp" ).addClass( "shape-rect" ); |
| 471 |
$( "#button_preview_paypal_cp" ).removeClass( "shape-pill" ); |
| 472 |
} else if ( "pill" == $( this ).val() ) { |
| 473 |
$( "#button_preview_paypal_cp" ).removeClass( "shape-rect" ); |
| 474 |
$( "#button_preview_paypal_cp" ).addClass( "shape-pill" ); |
| 475 |
} |
| 476 |
}); |
| 477 |
|
| 478 |
$( document ).on( "change", ".button_label_paypal_cp", function() { |
| 479 |
if ( "paypal" == $( this ).val() ) { |
| 480 |
$( "#button_preview_paypal_cp" ).addClass( "label-paypal" ); |
| 481 |
$( "#button_preview_paypal_cp" ).removeClass( "label-checkout" ); |
| 482 |
$( "#button_preview_paypal_cp" ).removeClass( "label-buynow" ); |
| 483 |
$( "#button_preview_paypal_cp" ).removeClass( "label-pay" ); |
| 484 |
} else if ( "checkout" == $( this ).val() ) { |
| 485 |
$( "#button_preview_paypal_cp" ).removeClass( "label-paypal" ); |
| 486 |
$( "#button_preview_paypal_cp" ).addClass( "label-checkout" ); |
| 487 |
$( "#button_preview_paypal_cp" ).removeClass( "label-buynow" ); |
| 488 |
$( "#button_preview_paypal_cp" ).removeClass( "label-pay" ); |
| 489 |
} else if ( "buynow" == $( this ).val() ) { |
| 490 |
$( "#button_preview_paypal_cp" ).removeClass( "label-paypal" ); |
| 491 |
$( "#button_preview_paypal_cp" ).removeClass( "label-checkout" ); |
| 492 |
$( "#button_preview_paypal_cp" ).addClass( "label-buynow" ); |
| 493 |
$( "#button_preview_paypal_cp" ).removeClass( "label-pay" ); |
| 494 |
} else if ( "pay" == $( this ).val() ) { |
| 495 |
$( "#button_preview_paypal_cp" ).removeClass( "label-paypal" ); |
| 496 |
$( "#button_preview_paypal_cp" ).removeClass( "label-checkout" ); |
| 497 |
$( "#button_preview_paypal_cp" ).removeClass( "label-buynow" ); |
| 498 |
$( "#button_preview_paypal_cp" ).addClass( "label-pay" ); |
| 499 |
} |
| 500 |
}); |
| 501 |
|
| 502 |
$( document ).on( "click", "#upfront_onboarding_paypal_cp", function() { |
| 503 |
$.ajax({ |
| 504 |
url: ajaxurl, |
| 505 |
type: "POST", |
| 506 |
cache: false, |
| 507 |
dataType: "json", |
| 508 |
data: { |
| 509 |
action: "usces_admin_ajax", |
| 510 |
mode: "upfront_onboarding", |
| 511 |
wc_nonce: $( "#wc_nonce" ).val() |
| 512 |
} |
| 513 |
}).done( function( retVal, dataType ) { |
| 514 |
var action_url = retVal.action_url; |
| 515 |
$( "#seller_nonce" ).val( retVal.seller_nonce ); |
| 516 |
$( '#onboarding' ).attr( 'href', action_url + '&displayMode=minibrowser' ); |
| 517 |
$( '#onboarding' )[0].click(); |
| 518 |
}).fail( function( jqXHR, textStatus, errorThrown ) { |
| 519 |
console.log( textStatus ); |
| 520 |
console.log( jqXHR.status ); |
| 521 |
console.log( errorThrown.message ); |
| 522 |
}); |
| 523 |
return false; |
| 524 |
}); |
| 525 |
}); |
| 526 |
</script> |
| 527 |
<?php |
| 528 |
endif; |
| 529 |
break; |
| 530 |
|
| 531 |
/* 受注編集画面・継続課金会員詳細画面 */ |
| 532 |
case 'usces_orderlist': |
| 533 |
case 'usces_continue': |
| 534 |
$order_id = ''; |
| 535 |
$acting_flg = ''; |
| 536 |
$order_action = ( isset( $_GET['order_action'] ) ) ? wp_unslash( $_GET['order_action'] ) : ''; |
| 537 |
$continue_action = ( isset( $_GET['continue_action'] ) ) ? wp_unslash( $_GET['continue_action'] ) : ''; |
| 538 |
if ( ( 'usces_orderlist' === $admin_page && ( 'edit' === $order_action || 'editpost' === $order_action || 'newpost' === $order_action ) ) || |
| 539 |
( 'usces_continue' === $admin_page && 'settlement_paypal_cp' === $continue_action ) ) { |
| 540 |
$order_id = ( isset( $_REQUEST['order_id'] ) ) ? wp_unslash( $_REQUEST['order_id'] ) : ''; |
| 541 |
if ( ! empty( $order_id ) ) { |
| 542 |
$acting_flg = $this->get_order_acting_flg( $order_id ); |
| 543 |
} |
| 544 |
} |
| 545 |
if ( in_array( $acting_flg, $this->pay_method ) ) : |
| 546 |
$args = compact( 'order_id', 'acting_flg', 'admin_page' ); |
| 547 |
$cr = $usces->options['system']['currency']; |
| 548 |
if ( isset( $usces_settings['currency'][ $cr ] ) ) { |
| 549 |
list( $crcode, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ]; |
| 550 |
if ( 'JPY' === $crcode ) { |
| 551 |
$currency = __( $crcode, 'usces' ); |
| 552 |
} else { |
| 553 |
$currency = ( usces_is_entity( $symbol ) ) ? mb_convert_encoding( $symbol, 'UTF-8', 'HTML-ENTITIES' ) : $symbol; |
| 554 |
} |
| 555 |
} else { |
| 556 |
$currency = ''; |
| 557 |
} |
| 558 |
if ( defined( 'WCEX_AUTO_DELIVERY' ) && 'acting_paypal_cp' === $acting_flg ) { |
| 559 |
$reg_id = $this->get_regular_id( $order_id ); |
| 560 |
} else { |
| 561 |
$reg_id = ''; |
| 562 |
} |
| 563 |
?> |
| 564 |
<script type="text/javascript"> |
| 565 |
jQuery( document ).ready( function( $ ) { |
| 566 |
adminOrderEdit = { |
| 567 |
getPayPalCP : function() { |
| 568 |
$( "#settlement-response" ).html( "" ); |
| 569 |
$( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' ); |
| 570 |
var order_num = $( "#order_num" ).val(); |
| 571 |
$.ajax({ |
| 572 |
url: ajaxurl, |
| 573 |
type: "POST", |
| 574 |
cache: false, |
| 575 |
dataType: "json", |
| 576 |
data: { |
| 577 |
action: "usces_admin_ajax", |
| 578 |
mode: "get_paypal_cp", |
| 579 |
order_id: $( "#order_id" ).val(), |
| 580 |
order_num: order_num, |
| 581 |
tracking_id: $( "#tracking_id" ).val(), |
| 582 |
member_id: $( "#member_id" ).val(), |
| 583 |
<?php if ( 'usces_continue' === $admin_page && 'acting_paypal_cp' === $acting_flg ) : ?> |
| 584 |
con_id: $( "#con_id" ).val(), |
| 585 |
<?php endif; ?> |
| 586 |
<?php if ( ! empty( $reg_id ) ) : ?> |
| 587 |
reg_id: $( "#reg_id" ).val(), |
| 588 |
<?php endif; ?> |
| 589 |
acting: $( "#acting" ).val(), |
| 590 |
wc_nonce: $( "#wc_nonce" ).val() |
| 591 |
} |
| 592 |
}).done( function( retVal, dataType ) { |
| 593 |
if ( retVal.result ) { |
| 594 |
$( "#settlement-response" ).html( retVal.result ); |
| 595 |
} |
| 596 |
$( "#settlement-response-loading" ).html( "" ); |
| 597 |
}).fail( function( jqXHR, textStatus, errorThrown ) { |
| 598 |
console.log( textStatus ); |
| 599 |
console.log( jqXHR.status ); |
| 600 |
console.log( errorThrown.message ); |
| 601 |
$( "#settlement-response-loading" ).html( "" ); |
| 602 |
}); |
| 603 |
return false; |
| 604 |
}, |
| 605 |
capturePayPalCP : function( amount ) { |
| 606 |
$( "#settlement-response" ).html( "" ); |
| 607 |
$( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' ); |
| 608 |
var order_num = $( "#order_num" ).val(); |
| 609 |
$.ajax({ |
| 610 |
url: ajaxurl, |
| 611 |
type: "POST", |
| 612 |
cache: false, |
| 613 |
dataType: "json", |
| 614 |
data: { |
| 615 |
action: "usces_admin_ajax", |
| 616 |
mode: "capture_paypal_cp", |
| 617 |
order_id: $( "#order_id" ).val(), |
| 618 |
order_num: order_num, |
| 619 |
tracking_id: $( "#tracking_id" ).val(), |
| 620 |
member_id: $( "#member_id" ).val(), |
| 621 |
amount: amount, |
| 622 |
<?php if ( 'usces_continue' === $admin_page ) : ?> |
| 623 |
con_id: $( "#con_id" ).val(), |
| 624 |
<?php endif; ?> |
| 625 |
acting: $( "#acting" ).val(), |
| 626 |
wc_nonce: $( "#wc_nonce" ).val() |
| 627 |
} |
| 628 |
}).done( function( retVal, dataType ) { |
| 629 |
if ( retVal.result ) { |
| 630 |
$( "#settlement-response" ).html( retVal.result ); |
| 631 |
$( "#settlement-status-" + order_num ).html( retVal.acting_status ); |
| 632 |
} |
| 633 |
$( "#settlement-response-loading" ).html( "" ); |
| 634 |
}).fail( function( jqXHR, textStatus, errorThrown ) { |
| 635 |
console.log( textStatus ); |
| 636 |
console.log( jqXHR.status ); |
| 637 |
console.log( errorThrown.message ); |
| 638 |
$( "#settlement-response-loading" ).html( "" ); |
| 639 |
}); |
| 640 |
return false; |
| 641 |
}, |
| 642 |
voidPayPalCP : function() { |
| 643 |
$( "#settlement-response" ).html( "" ); |
| 644 |
$( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' ); |
| 645 |
var order_num = $( "#order_num" ).val(); |
| 646 |
$.ajax({ |
| 647 |
url: ajaxurl, |
| 648 |
type: "POST", |
| 649 |
cache: false, |
| 650 |
dataType: "json", |
| 651 |
data: { |
| 652 |
action: "usces_admin_ajax", |
| 653 |
mode: "void_paypal_cp", |
| 654 |
order_id: $( "#order_id" ).val(), |
| 655 |
order_num: order_num, |
| 656 |
tracking_id: $( "#tracking_id" ).val(), |
| 657 |
member_id: $( "#member_id" ).val(), |
| 658 |
<?php if ( 'usces_continue' === $admin_page ) : ?> |
| 659 |
con_id: $( "#con_id" ).val(), |
| 660 |
<?php endif; ?> |
| 661 |
acting: $( "#acting" ).val(), |
| 662 |
wc_nonce: $( "#wc_nonce" ).val() |
| 663 |
} |
| 664 |
}).done( function( retVal, dataType ) { |
| 665 |
if ( retVal.result ) { |
| 666 |
$( "#settlement-response" ).html( retVal.result ); |
| 667 |
$( "#settlement-status-" + order_num ).html( retVal.acting_status ); |
| 668 |
} |
| 669 |
$( "#settlement-response-loading" ).html( "" ); |
| 670 |
}).fail( function( jqXHR, textStatus, errorThrown ) { |
| 671 |
console.log( textStatus ); |
| 672 |
console.log( jqXHR.status ); |
| 673 |
console.log( errorThrown.message ); |
| 674 |
$( "#settlement-response-loading" ).html( "" ); |
| 675 |
}); |
| 676 |
return false; |
| 677 |
}, |
| 678 |
refundPayPalCP : function( amount ) { |
| 679 |
$( "#settlement-response" ).html( "" ); |
| 680 |
$( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' ); |
| 681 |
var order_num = $( "#order_num" ).val(); |
| 682 |
$.ajax({ |
| 683 |
url: ajaxurl, |
| 684 |
type: "POST", |
| 685 |
cache: false, |
| 686 |
dataType: "json", |
| 687 |
data: { |
| 688 |
action: "usces_admin_ajax", |
| 689 |
mode: "refund_paypal_cp", |
| 690 |
order_id: $( "#order_id" ).val(), |
| 691 |
order_num: order_num, |
| 692 |
tracking_id: $( "#tracking_id" ).val(), |
| 693 |
member_id: $( "#member_id" ).val(), |
| 694 |
amount: amount, |
| 695 |
<?php if ( 'usces_continue' === $admin_page ) : ?> |
| 696 |
con_id: $( "#con_id" ).val(), |
| 697 |
<?php endif; ?> |
| 698 |
acting: $( "#acting" ).val(), |
| 699 |
wc_nonce: $( "#wc_nonce" ).val() |
| 700 |
} |
| 701 |
}).done( function( retVal, dataType ) { |
| 702 |
if ( retVal.result ) { |
| 703 |
$( "#settlement-response" ).html( retVal.result ); |
| 704 |
$( "#settlement-status-" + order_num ).html( retVal.acting_status ); |
| 705 |
} |
| 706 |
$( "#settlement-response-loading" ).html( "" ); |
| 707 |
}).fail( function( jqXHR, textStatus, errorThrown ) { |
| 708 |
console.log( textStatus ); |
| 709 |
console.log( jqXHR.status ); |
| 710 |
console.log( errorThrown.message ); |
| 711 |
$( "#settlement-response-loading" ).html( "" ); |
| 712 |
}); |
| 713 |
return false; |
| 714 |
}, |
| 715 |
reSettlementPayPalCP : function( amount, intent ) { |
| 716 |
$( "#settlement-response" ).html( "" ); |
| 717 |
$( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' ); |
| 718 |
var order_num = $( "#order_num" ).val(); |
| 719 |
$.ajax({ |
| 720 |
url: ajaxurl, |
| 721 |
type: "POST", |
| 722 |
cache: false, |
| 723 |
dataType: "json", |
| 724 |
data: { |
| 725 |
action: "usces_admin_ajax", |
| 726 |
mode: "re_settlement_paypal_cp", |
| 727 |
order_id: $( "#order_id" ).val(), |
| 728 |
order_num: order_num, |
| 729 |
tracking_id: $( "#tracking_id" ).val(), |
| 730 |
member_id: $( "#member_id" ).val(), |
| 731 |
amount: amount, |
| 732 |
intent: intent, |
| 733 |
<?php if ( 'usces_continue' === $admin_page ) : ?> |
| 734 |
con_id: $( "#con_id" ).val(), |
| 735 |
<?php endif; ?> |
| 736 |
<?php if ( ! empty( $reg_id ) ) : ?> |
| 737 |
reg_id: $( "#reg_id" ).val(), |
| 738 |
<?php endif; ?> |
| 739 |
acting: $( "#acting" ).val(), |
| 740 |
wc_nonce: $( "#wc_nonce" ).val() |
| 741 |
} |
| 742 |
}).done( function( retVal, dataType ) { |
| 743 |
if ( retVal.result ) { |
| 744 |
$( "#settlement-response" ).html( retVal.result ); |
| 745 |
$( "#settlement-status-" + order_num ).html( retVal.acting_status ); |
| 746 |
} |
| 747 |
$( "#settlement-response-loading" ).html( "" ); |
| 748 |
}).fail( function( jqXHR, textStatus, errorThrown ) { |
| 749 |
console.log( textStatus ); |
| 750 |
console.log( jqXHR.status ); |
| 751 |
console.log( errorThrown.message ); |
| 752 |
$( "#settlement-response-loading" ).html( "" ); |
| 753 |
}); |
| 754 |
return false; |
| 755 |
}, |
| 756 |
}; |
| 757 |
|
| 758 |
$( "#settlement_dialog" ).dialog({ |
| 759 |
dialogClass: "admin-paypal-dialog", |
| 760 |
bgiframe: true, |
| 761 |
autoOpen: false, |
| 762 |
height: "auto", |
| 763 |
width: 800, |
| 764 |
resizable: true, |
| 765 |
modal: true, |
| 766 |
buttons: { |
| 767 |
"<?php esc_html_e( 'Close' ); ?>": function() { |
| 768 |
$( this ).dialog( "close" ); |
| 769 |
} |
| 770 |
}, |
| 771 |
open: function() { |
| 772 |
adminOrderEdit.getPayPalCP(); |
| 773 |
}, |
| 774 |
close: function() { |
| 775 |
<?php do_action( 'usces_action_paypalcp_settlement_dialog_close', $args ); ?> |
| 776 |
} |
| 777 |
}); |
| 778 |
|
| 779 |
$( document ).on( "click", ".settlement-information", function() { |
| 780 |
var tracking_id = $( this ).attr( "data-tracking_id" ); |
| 781 |
var order_num = $( this ).attr( "data-num" ); |
| 782 |
$( "#tracking_id" ).val( tracking_id ); |
| 783 |
$( "#order_num" ).val( order_num ); |
| 784 |
$( "#settlement_dialog" ).dialog( "option", "title", "<?php echo esc_js( __( 'PayPal Commerce Platform', 'usces' ) ); ?>" ); |
| 785 |
$( "#settlement_dialog" ).dialog( "open" ); |
| 786 |
}); |
| 787 |
|
| 788 |
$( document ).on( "click", "#capture-settlement", function() { |
| 789 |
var amount_original = parseFloat( $( "#amount_original" ).val() ) || 0; |
| 790 |
var amount_refund = parseFloat( $( "#amount_refund" ).val() ) || 0; |
| 791 |
var amount_capture = amount_original - amount_refund; |
| 792 |
if ( 0 == amount_capture ) { |
| 793 |
return; |
| 794 |
} |
| 795 |
if ( amount_capture == amount_original ) { |
| 796 |
if ( ! confirm( "<?php esc_html_e( 'Execute the capture payment process. Are you sure?', 'usces' ); ?>" ) ) { |
| 797 |
return; |
| 798 |
} |
| 799 |
} else { |
| 800 |
if ( ! confirm( <?php printf( __( "'Execute the refund payment process for %s' + amount_refund + '. Are you sure?'", 'usces' ), $currency ); ?> ) ) { |
| 801 |
return; |
| 802 |
} |
| 803 |
} |
| 804 |
adminOrderEdit.capturePayPalCP( amount_capture ); |
| 805 |
}); |
| 806 |
|
| 807 |
$( document ).on( "click", "#void-settlement", function() { |
| 808 |
if ( ! confirm( "<?php esc_html_e( 'Execute the void payment process. Are you sure?', 'usces' ); ?>" ) ) { |
| 809 |
return; |
| 810 |
} |
| 811 |
adminOrderEdit.voidPayPalCP(); |
| 812 |
}); |
| 813 |
|
| 814 |
$( document ).on( "click", "#refund-settlement", function() { |
| 815 |
var amount_original = parseFloat( $( "#amount_original" ).val() ) || 0; |
| 816 |
var amount_refund = parseFloat( $( "#amount_refund" ).val() ) || 0; |
| 817 |
if ( 0 == amount_refund ) { |
| 818 |
return; |
| 819 |
} |
| 820 |
if ( amount_refund > amount_original ) { |
| 821 |
alert( "<?php esc_html_e( 'Amounts in excess of the transaction amount are not refundable.', 'usces' ); ?>" ); |
| 822 |
return; |
| 823 |
} |
| 824 |
if ( amount_refund == amount_original ) { |
| 825 |
if ( ! confirm( "<?php esc_html_e( 'Execute the refund payment process. Are you sure?', 'usces' ); ?>" ) ) { |
| 826 |
return; |
| 827 |
} |
| 828 |
} else { |
| 829 |
if ( ! confirm( <?php printf( __( "'Execute the refund payment process for %s' + amount_refund + '. Are you sure?'", 'usces' ), $currency ); ?> ) ) { |
| 830 |
return; |
| 831 |
} |
| 832 |
} |
| 833 |
adminOrderEdit.refundPayPalCP( amount_refund ); |
| 834 |
}); |
| 835 |
|
| 836 |
$( document ).on( "click", "#re-authorize-settlement", function() { |
| 837 |
var amount_authorize = parseFloat( $( "#amount_resettlement" ).val() ) || 0; |
| 838 |
if ( 0 == amount_authorize ) { |
| 839 |
return; |
| 840 |
} |
| 841 |
if ( ! confirm( <?php printf( __( "'Execute the void payment process for %s' + amount_authorize + '. Are you sure?'", 'usces' ), $currency ); ?> ) ) { |
| 842 |
return; |
| 843 |
} |
| 844 |
adminOrderEdit.reSettlementPayPalCP( amount_authorize, 'AUTHORIZE' ); |
| 845 |
}); |
| 846 |
|
| 847 |
$( document ).on( "click", "#re-capture-settlement", function() { |
| 848 |
var amount_capture = parseFloat( $( "#amount_resettlement" ).val() ) || 0.0; |
| 849 |
if ( 0 == amount_capture ) { |
| 850 |
return; |
| 851 |
} |
| 852 |
if ( ! confirm( <?php printf( __( "'Execute the capture payment process for %s' + amount_capture + '. Are you sure?'", 'usces' ), $currency ); ?> ) ) { |
| 853 |
return; |
| 854 |
} |
| 855 |
adminOrderEdit.reSettlementPayPalCP( amount_capture, 'CAPTURE' ); |
| 856 |
}); |
| 857 |
|
| 858 |
$( document ).on( "keydown", ".amount", function( e ) { |
| 859 |
var halfVal = $( this ).val().replace( /[!-~]/g, |
| 860 |
function( tmpStr ) { |
| 861 |
return String.fromCharCode( tmpStr.charCodeAt(0) - 0xFEE0 ); |
| 862 |
} |
| 863 |
); |
| 864 |
$( this ).val( halfVal.replace( /[^0-9]/g, '' ) ); |
| 865 |
}); |
| 866 |
$( document ).on( "keyup", ".amount", function() { |
| 867 |
this.value = this.value.replace( /[^0-9]+/i, '' ); |
| 868 |
this.value = Number( this.value ) || 0; |
| 869 |
}); |
| 870 |
$( document ).on( "blur", ".amount", function() { |
| 871 |
this.value = this.value.replace( /[^0-9]+/i, '' ); |
| 872 |
}); |
| 873 |
<?php if ( 'usces_continue' === $admin_page ) : ?> |
| 874 |
adminContinuation = { |
| 875 |
update : function() { |
| 876 |
$.ajax({ |
| 877 |
url: ajaxurl, |
| 878 |
type: "POST", |
| 879 |
cache: false, |
| 880 |
dataType: 'json', |
| 881 |
data: { |
| 882 |
action: "usces_admin_ajax", |
| 883 |
mode: "continuation_update", |
| 884 |
member_id: $( "#member_id" ).val(), |
| 885 |
order_id: $( "#order_id" ).val(), |
| 886 |
contracted_year: $( "#contracted-year option:selected" ).val(), |
| 887 |
contracted_month: $( "#contracted-month option:selected" ).val(), |
| 888 |
contracted_day: $( "#contracted-day option:selected" ).val(), |
| 889 |
charged_year: $( "#charged-year option:selected" ).val(), |
| 890 |
charged_month: $( "#charged-month option:selected" ).val(), |
| 891 |
charged_day: $( "#charged-day option:selected" ).val(), |
| 892 |
price: $( "#price" ).val(), |
| 893 |
status: $( "#dlseller-status" ).val(), |
| 894 |
wc_nonce: $( "#wc_nonce" ).val() |
| 895 |
} |
| 896 |
}).done( function( retVal, dataType ) { |
| 897 |
if ( "OK" == retVal.status ) { |
| 898 |
adminOperation.setActionStatus( "success", "<?php esc_html_e( 'The update was completed.', 'usces' ); ?>" ); |
| 899 |
} else { |
| 900 |
var message = ( retVal.message != "" ) ? retVal.message : "<?php esc_html_e( 'failure in update', 'usces' ); ?>"; |
| 901 |
adminOperation.setActionStatus( "error", message ); |
| 902 |
} |
| 903 |
}).fail( function( jqXHR, textStatus, errorThrown ) { |
| 904 |
console.log( textStatus ); |
| 905 |
console.log( jqXHR.status ); |
| 906 |
console.log( errorThrown.message ); |
| 907 |
adminOperation.setActionStatus( "error", "<?php esc_html_e( 'failure in update', 'usces' ); ?>" ); |
| 908 |
}); |
| 909 |
return false; |
| 910 |
} |
| 911 |
}; |
| 912 |
|
| 913 |
$( document ).on( "click", "#continuation-update", function() { |
| 914 |
var status = $( "#dlseller-status option:selected" ).val(); |
| 915 |
if ( "continuation" == status ) { |
| 916 |
var year = $( "#charged-year option:selected" ).val(); |
| 917 |
var month = $( "#charged-month option:selected" ).val(); |
| 918 |
var day = $( "#charged-day option:selected" ).val(); |
| 919 |
if ( 0 == year || 0 == month || 0 == day ) { |
| 920 |
alert( "<?php esc_html_e( 'Data have deficiency.', 'usces' ); ?>" ); |
| 921 |
$( "#charged-year" ).focus(); |
| 922 |
return; |
| 923 |
} |
| 924 |
if ( "" == $( "#price" ).val() || 0 == parseFloat( $( "#price" ).val() ) ) { |
| 925 |
alert( "<?php printf( __( 'Input the %s', 'usces' ), esc_html__( 'Amount', 'dlseller' ) ); ?>" ); |
| 926 |
$( "#price" ).focus(); |
| 927 |
return; |
| 928 |
} |
| 929 |
} |
| 930 |
if ( ! confirm( "<?php esc_html_e( 'Are you sure you want to update the settings?', 'usces' ); ?>" ) ) { |
| 931 |
return; |
| 932 |
} |
| 933 |
adminContinuation.update(); |
| 934 |
}); |
| 935 |
<?php endif; ?> |
| 936 |
}); |
| 937 |
</script> |
| 938 |
<?php |
| 939 |
endif; |
| 940 |
break; |
| 941 |
endswitch; |
| 942 |
} |
| 943 |
|
| 944 |
/** |
| 945 |
* 決済オプション登録・更新 |
| 946 |
* usces_action_admin_settlement_update |
| 947 |
*/ |
| 948 |
public function settlement_update() { |
| 949 |
global $usces; |
| 950 |
|
| 951 |
if ( $this->paymod_id != wp_unslash( $_POST['acting'] ) ) { |
| 952 |
return; |
| 953 |
} |
| 954 |
|
| 955 |
$this->error_mes = ''; |
| 956 |
$options = get_option( 'usces', array() ); |
| 957 |
$payment_method = usces_get_system_option( 'usces_payment_method', 'settlement' ); |
| 958 |
$post_data = wp_unslash( $_POST ); |
| 959 |
|
| 960 |
unset( $options['acting_settings']['paypal_cp'] ); |
| 961 |
$options['acting_settings']['paypal_cp']['cp_activate'] = ( isset( $post_data['cp_activate'] ) ) ? $post_data['cp_activate'] : 'off'; |
| 962 |
$options['acting_settings']['paypal_cp']['card_activate'] = ( isset( $post_data['card_activate'] ) ) ? $post_data['card_activate'] : 'off'; |
| 963 |
$options['acting_settings']['paypal_cp']['card_vault'] = ( isset( $post_data['card_vault'] ) ) ? $post_data['card_vault'] : 'off'; |
| 964 |
$options['acting_settings']['paypal_cp']['card_prefix'] = ( isset( $post_data['card_prefix'] ) ) ? $post_data['card_prefix'] : ''; |
| 965 |
$options['acting_settings']['paypal_cp']['card_3ds'] = ( isset( $post_data['card_3ds'] ) ) ? $post_data['card_3ds'] : 'off'; |
| 966 |
$options['acting_settings']['paypal_cp']['environment'] = ( isset( $post_data['cp_environment'] ) ) ? $post_data['cp_environment'] : 'live'; |
| 967 |
$options['acting_settings']['paypal_cp']['client_id'] = ( isset( $post_data['cp_client_id'] ) ) ? trim( $post_data['cp_client_id'] ) : ''; |
| 968 |
$options['acting_settings']['paypal_cp']['secret'] = ( isset( $post_data['cp_secret'] ) ) ? trim( $post_data['cp_secret'] ) : ''; |
| 969 |
$options['acting_settings']['paypal_cp']['intent'] = ( isset( $post_data['cp_intent'] ) ) ? $post_data['cp_intent'] : 'CAPTURE'; |
| 970 |
$options['acting_settings']['paypal_cp']['autobilling_intent'] = ( isset( $post_data['cp_autobilling_intent'] ) ) ? $post_data['cp_autobilling_intent'] : 'CAPTURE'; |
| 971 |
$options['acting_settings']['paypal_cp']['autobilling_email'] = ( isset( $post_data['cp_autobilling_email'] ) ) ? $post_data['cp_autobilling_email'] : 'off'; |
| 972 |
$options['acting_settings']['paypal_cp']['button_layout'] = ( isset( $post_data['cp_button_layout'] ) ) ? $post_data['cp_button_layout'] : 'vertical'; |
| 973 |
$options['acting_settings']['paypal_cp']['button_color'] = ( isset( $post_data['cp_button_color'] ) ) ? $post_data['cp_button_color'] : 'gold'; |
| 974 |
$options['acting_settings']['paypal_cp']['button_shape'] = ( isset( $post_data['cp_button_shape'] ) ) ? $post_data['cp_button_shape'] : 'rect'; |
| 975 |
$options['acting_settings']['paypal_cp']['button_label'] = ( isset( $post_data['cp_button_label'] ) ) ? $post_data['cp_button_label'] : 'paypal'; |
| 976 |
$options['acting_settings']['paypal_cp']['agree'] = ( isset( $post_data['cp_agree'] ) ) ? $post_data['cp_agree'] : ''; |
| 977 |
|
| 978 |
if ( 'on' === $options['acting_settings']['paypal_cp']['cp_activate'] || 'on' === $options['acting_settings']['paypal_cp']['card_activate'] ) { |
| 979 |
$unavailable_activate = false; |
| 980 |
foreach ( $payment_method as $settlement => $payment ) { |
| 981 |
if ( in_array( $settlement, $this->unavailable_method ) && 'deactivate' !== $payment['use'] ) { |
| 982 |
$unavailable_activate = true; |
| 983 |
break; |
| 984 |
} |
| 985 |
} |
| 986 |
|
| 987 |
if ( $unavailable_activate ) { |
| 988 |
$this->error_mes .= __( '* Settlement that can not be used together is activated.', 'usces' ) . '<br />'; |
| 989 |
} else { |
| 990 |
if ( WCUtils::is_blank( $post_data['cp_client_id'] ) ) { |
| 991 |
$this->error_mes .= __( '* Enter Client ID.', 'usces' ) . '<br />'; |
| 992 |
} |
| 993 |
if ( WCUtils::is_blank( $post_data['cp_secret'] ) ) { |
| 994 |
$this->error_mes .= __( '* Enter Secret.', 'usces' ) . '<br />'; |
| 995 |
} |
| 996 |
if ( 'on' === $options['acting_settings']['paypal_cp']['card_activate'] && 'on' === $options['acting_settings']['paypal_cp']['card_vault'] ) { |
| 997 |
if ( ! $this->check_prefix( $options['acting_settings']['paypal_cp']['card_prefix'] ) ) { |
| 998 |
$this->error_mes .= __( '* The prefix must be at least one and no more than four single-byte uppercase alphabetic characters.', 'usces' ) . '<br />'; |
| 999 |
} |
| 1000 |
} |
| 1001 |
if ( empty( $options['acting_settings']['paypal_cp']['agree'] ) ) { |
| 1002 |
$this->error_mes .= __( '* There was no agreement on terms of use.', 'usces' ) . '<br />'; |
| 1003 |
} |
| 1004 |
} |
| 1005 |
} |
| 1006 |
|
| 1007 |
if ( '' === $this->error_mes ) { |
| 1008 |
$usces->action_status = 'success'; |
| 1009 |
$usces->action_message = __( 'Options are updated.', 'usces' ); |
| 1010 |
if ( 'on' === $options['acting_settings']['paypal_cp']['cp_activate'] || 'on' === $options['acting_settings']['paypal_cp']['card_activate'] ) { |
| 1011 |
$options['acting_settings']['paypal_cp']['activate'] = 'on'; |
| 1012 |
if ( 'live' === $options['acting_settings']['paypal_cp']['environment'] ) { |
| 1013 |
$options['acting_settings']['paypal_cp']['api_request_url'] = self::API_URL; |
| 1014 |
} else { |
| 1015 |
$options['acting_settings']['paypal_cp']['api_request_url'] = self::API_SANDBOX_URL; |
| 1016 |
} |
| 1017 |
$toactive = array(); |
| 1018 |
if ( 'on' === $options['acting_settings']['paypal_cp']['cp_activate'] ) { |
| 1019 |
$usces->payment_structure['acting_paypal_cp'] = $this->acting_name; |
| 1020 |
foreach ( $payment_method as $settlement => $payment ) { |
| 1021 |
if ( 'acting_paypal_cp' === $settlement && 'activate' !== $payment['use'] ) { |
| 1022 |
$toactive[] = $payment['name']; |
| 1023 |
} |
| 1024 |
} |
| 1025 |
} |
| 1026 |
if ( 'on' === $options['acting_settings']['paypal_cp']['card_activate'] ) { |
| 1027 |
$usces->payment_structure['acting_paypal_card'] = __( 'PayPal(CreditCard)', 'usces' ); |
| 1028 |
foreach ( $payment_method as $settlement => $payment ) { |
| 1029 |
if ( 'acting_paypal_card' === $settlement && 'activate' !== $payment['use'] ) { |
| 1030 |
$toactive[] = $payment['name']; |
| 1031 |
} |
| 1032 |
} |
| 1033 |
} |
| 1034 |
if ( 0 < count( $toactive ) ) { |
| 1035 |
$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' ); |
| 1036 |
} |
| 1037 |
usces_admin_orderlist_show_wc_trans_id(); |
| 1038 |
$this->setting_update_notification( $options ); |
| 1039 |
} else { |
| 1040 |
$options['acting_settings']['paypal_cp']['activate'] = 'off'; |
| 1041 |
unset( $usces->payment_structure['acting_paypal_cp'] ); |
| 1042 |
unset( $usces->payment_structure['acting_paypal_card'] ); |
| 1043 |
$deactivate = array(); |
| 1044 |
foreach ( $payment_method as $settlement => $payment ) { |
| 1045 |
if ( ! array_key_exists( $settlement, $usces->payment_structure ) ) { |
| 1046 |
if ( 'deactivate' !== $payment['use'] ) { |
| 1047 |
$payment['use'] = 'deactivate'; |
| 1048 |
$deactivate[] = $payment['name']; |
| 1049 |
usces_update_system_option( 'usces_payment_method', $payment['id'], $payment ); |
| 1050 |
} |
| 1051 |
} |
| 1052 |
} |
| 1053 |
if ( 0 < count( $deactivate ) ) { |
| 1054 |
$deactivate_message = sprintf( __( '"Deactivate" %s of payment method.', 'usces' ), implode( ',', $deactivate ) ); |
| 1055 |
$usces->action_message .= $deactivate_message; |
| 1056 |
} |
| 1057 |
} |
| 1058 |
} else { |
| 1059 |
$usces->action_status = 'error'; |
| 1060 |
$usces->action_message = __( 'Data have deficiency.', 'usces' ); |
| 1061 |
$options = get_option( 'usces', array() ); |
| 1062 |
$options['acting_settings']['paypal_cp']['activate'] = 'off'; |
| 1063 |
$options['acting_settings']['paypal_cp']['agree'] = ''; |
| 1064 |
unset( $usces->payment_structure['acting_paypal_cp'] ); |
| 1065 |
unset( $usces->payment_structure['acting_paypal_card'] ); |
| 1066 |
$deactivate = array(); |
| 1067 |
foreach ( $payment_method as $settlement => $payment ) { |
| 1068 |
if ( in_array( $settlement, $this->pay_method ) ) { |
| 1069 |
if ( 'deactivate' !== $payment['use'] ) { |
| 1070 |
$payment['use'] = 'deactivate'; |
| 1071 |
$deactivate[] = $payment['name']; |
| 1072 |
usces_update_system_option( 'usces_payment_method', $payment['id'], $payment ); |
| 1073 |
} |
| 1074 |
} |
| 1075 |
} |
| 1076 |
if ( 0 < count( $deactivate ) ) { |
| 1077 |
$deactivate_message = sprintf( __( '"Deactivate" %s of payment method.', 'usces' ), implode( ',', $deactivate ) ); |
| 1078 |
$usces->action_message .= $deactivate_message . __( 'Please complete the setup and update the payment method to "Activate".', 'usces' ); |
| 1079 |
} |
| 1080 |
} |
| 1081 |
ksort( $usces->payment_structure ); |
| 1082 |
update_option( 'usces', $options ); |
| 1083 |
update_option( 'usces_payment_structure', $usces->payment_structure ); |
| 1084 |
} |
| 1085 |
|
| 1086 |
/** |
| 1087 |
* 決済設定通知 |
| 1088 |
* |
| 1089 |
* @param array $options Setting values. |
| 1090 |
*/ |
| 1091 |
private function setting_update_notification( $options ) { |
| 1092 |
$message = 'サイト名/屋号:' . html_entity_decode( get_option( 'blogname' ) ) . "\n" . |
| 1093 |
'サイトURL:' . esc_url( home_url( '/' ) ) . "\n" . |
| 1094 |
'Eメールアドレス:' . get_option( 'admin_email' ) . "\n" . |
| 1095 |
'動作環境:' . $options['acting_settings']['paypal_cp']['environment'] . "\n"; |
| 1096 |
$sendmail_params = array( |
| 1097 |
'to_name' => 'PayPal', |
| 1098 |
'to_address' => 'welcart-setting-update@paypal.com', |
| 1099 |
'from_name' => get_option( 'blogname' ), |
| 1100 |
'from_address' => get_option( 'admin_email' ), |
| 1101 |
'reply_name' => get_option( 'blogname' ), |
| 1102 |
'reply_to' => usces_get_first_order_mail(), |
| 1103 |
'return_path' => get_option( 'admin_email' ), |
| 1104 |
'subject' => '[Welcart]PayPal決済設定通知', |
| 1105 |
'message' => do_shortcode( $message ), |
| 1106 |
); |
| 1107 |
usces_send_mail( $sendmail_params ); |
| 1108 |
} |
| 1109 |
|
| 1110 |
/** |
| 1111 |
* クレジット決済設定画面タブ |
| 1112 |
* usces_action_settlement_tab_title |
| 1113 |
*/ |
| 1114 |
public function settlement_tab_title() { |
| 1115 |
$settlement_selected = get_option( 'usces_settlement_selected', array() ); |
| 1116 |
if ( in_array( $this->paymod_id, (array) $settlement_selected ) ) { |
| 1117 |
echo '<li><a href="#uscestabs_' . esc_html( $this->paymod_id ) . '">' . esc_html( $this->acting_name ) . '</a></li>'; |
| 1118 |
} |
| 1119 |
} |
| 1120 |
|
| 1121 |
/** |
| 1122 |
* クレジット決済設定画面フォーム |
| 1123 |
* usces_action_settlement_tab_body |
| 1124 |
*/ |
| 1125 |
public function settlement_tab_body() { |
| 1126 |
global $usces; |
| 1127 |
|
| 1128 |
$acting_opts = $this->get_acting_settings(); |
| 1129 |
$settlement_selected = get_option( 'usces_settlement_selected', array() ); |
| 1130 |
if ( in_array( $this->paymod_id, (array) $settlement_selected ) ) : |
| 1131 |
$cp_activate = ( isset( $acting_opts['cp_activate'] ) && 'on' === $acting_opts['cp_activate'] ) ? 'on' : 'off'; |
| 1132 |
$card_activate = ( isset( $acting_opts['card_activate'] ) && 'on' === $acting_opts['card_activate'] ) ? 'on' : 'off'; |
| 1133 |
$card_vault = ( isset( $acting_opts['card_vault'] ) && 'on' === $acting_opts['card_vault'] ) ? 'on' : 'off'; |
| 1134 |
$card_prefix = ( isset( $acting_opts['card_prefix'] ) ) ? $acting_opts['card_prefix'] : ''; |
| 1135 |
$card_3ds = ( isset( $acting_opts['card_3ds'] ) && 'on' === $acting_opts['card_3ds'] ) ? 'on' : 'off'; |
| 1136 |
$cp_environment = ( isset( $acting_opts['environment'] ) && 'live' === $acting_opts['environment'] ) ? 'live' : 'sandbox'; |
| 1137 |
$cp_client_id = ( isset( $acting_opts['client_id'] ) ) ? $acting_opts['client_id'] : ''; |
| 1138 |
$cp_secret = ( isset( $acting_opts['secret'] ) ) ? $acting_opts['secret'] : ''; |
| 1139 |
$cp_intent = ( isset( $acting_opts['intent'] ) ) ? $acting_opts['intent'] : ''; |
| 1140 |
if ( defined( 'WCEX_DLSELLER' ) ) { |
| 1141 |
$cp_autobilling_intent = ( isset( $acting_opts['autobilling_intent'] ) ) ? $acting_opts['autobilling_intent'] : ''; |
| 1142 |
$cp_autobilling_email = ( isset( $acting_opts['autobilling_email'] ) && 'on' === $acting_opts['autobilling_email'] ) ? 'on' : 'off'; |
| 1143 |
} |
| 1144 |
$cp_button_layout = ( isset( $acting_opts['button_layout'] ) && 'horizontal' === $acting_opts['button_layout'] ) ? 'horizontal' : 'vertical'; |
| 1145 |
$class_button_color = ''; |
| 1146 |
$cp_button_color_gold = ''; |
| 1147 |
$cp_button_color_blue = ''; |
| 1148 |
$cp_button_color_silver = ''; |
| 1149 |
$cp_button_color_white = ''; |
| 1150 |
$cp_button_color_black = ''; |
| 1151 |
if ( isset( $acting_opts['button_color'] ) && 'blue' === $acting_opts['button_color'] ) { |
| 1152 |
$cp_button_color_blue = ' checked="checked"'; |
| 1153 |
$class_button_color = ' color-blue'; |
| 1154 |
} elseif ( isset( $acting_opts['button_color'] ) && 'silver' === $acting_opts['button_color'] ) { |
| 1155 |
$cp_button_color_silver = ' checked="checked"'; |
| 1156 |
$class_button_color = ' color-silver'; |
| 1157 |
} elseif ( isset( $acting_opts['button_color'] ) && 'white' === $acting_opts['button_color'] ) { |
| 1158 |
$cp_button_color_white = ' checked="checked"'; |
| 1159 |
$class_button_color = ' color-white'; |
| 1160 |
} elseif ( isset( $acting_opts['button_color'] ) && 'black' === $acting_opts['button_color'] ) { |
| 1161 |
$cp_button_color_black = ' checked="checked"'; |
| 1162 |
$class_button_color = ' color-black'; |
| 1163 |
} else { |
| 1164 |
$cp_button_color_gold = ' checked="checked"'; /* default */ |
| 1165 |
$class_button_color = ' color-gold'; |
| 1166 |
} |
| 1167 |
$class_button_shape = ''; |
| 1168 |
$cp_button_shape_rect = ''; |
| 1169 |
$cp_button_shape_pill = ''; |
| 1170 |
if ( isset( $acting_opts['button_shape'] ) && 'pill' === $acting_opts['button_shape'] ) { |
| 1171 |
$cp_button_shape_pill = ' checked="checked"'; |
| 1172 |
$class_button_shape = ' shape-pill'; |
| 1173 |
} else { |
| 1174 |
$cp_button_shape_rect = ' checked="checked"'; /* default */ |
| 1175 |
$class_button_shape = ' shape-rect'; |
| 1176 |
} |
| 1177 |
$class_button_label = ''; |
| 1178 |
$cp_button_label_paypal = ''; |
| 1179 |
$cp_button_label_checkout = ''; |
| 1180 |
$cp_button_label_buynow = ''; |
| 1181 |
$cp_button_label_pay = ''; |
| 1182 |
if ( isset( $acting_opts['button_label'] ) && 'checkout' === $acting_opts['button_label'] ) { |
| 1183 |
$cp_button_label_checkout = ' checked="checked"'; |
| 1184 |
$class_button_label = ' label-checkout'; |
| 1185 |
} elseif ( isset( $acting_opts['button_label'] ) && 'buynow' === $acting_opts['button_label'] ) { |
| 1186 |
$cp_button_label_buynow = ' checked="checked"'; |
| 1187 |
$class_button_label = ' label-buynow'; |
| 1188 |
} elseif ( isset( $acting_opts['button_label'] ) && 'pay' === $acting_opts['button_label'] ) { |
| 1189 |
$cp_button_label_pay = ' checked="checked"'; |
| 1190 |
$class_button_label = ' label-pay'; |
| 1191 |
} else { |
| 1192 |
$cp_button_label_paypal = ' checked="checked"'; /* default */ |
| 1193 |
$class_button_label = ' label-paypal'; |
| 1194 |
} |
| 1195 |
$cp_agree = ( isset( $acting_opts['agree'] ) && 'agree' === $acting_opts['agree'] ) ? 'agree' : ''; |
| 1196 |
?> |
| 1197 |
<div id="uscestabs_paypal_cp"> |
| 1198 |
<div class="settlement_service"><span class="service_title"><?php esc_html_e( 'PayPal Commerce Platform', 'usces' ); ?></span></div> |
| 1199 |
<?php |
| 1200 |
if ( isset( $_POST['acting'] ) && $this->paymod_id === wp_unslash( $_POST['acting'] ) ) : |
| 1201 |
if ( ! empty( $this->error_mes ) ) : |
| 1202 |
?> |
| 1203 |
<div class="error_message"><?php wel_esc_script_e( $this->error_mes ); ?></div> |
| 1204 |
<?php |
| 1205 |
elseif ( isset( $acting_opts['activate'] ) && 'on' === $acting_opts['activate'] ) : |
| 1206 |
?> |
| 1207 |
<div class="message"><?php esc_html_e( 'Test thoroughly before use.', 'usces' ); ?></div> |
| 1208 |
<?php |
| 1209 |
endif; |
| 1210 |
endif; |
| 1211 |
?> |
| 1212 |
<form action="" method="post" name="paypal_cp_form" id="paypal_cp_form"> |
| 1213 |
<table class="settle_table"> |
| 1214 |
<tr> |
| 1215 |
<th><?php esc_html_e( 'PayPal Commerce Platform', 'usces' ); ?></th> |
| 1216 |
<td><label><input type="radio" class="activate_paypal_cp" name="cp_activate" value="on"<?php checked( $cp_activate, 'on' ); ?>/><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br /> |
| 1217 |
<label><input type="radio" class="activate_paypal_cp" name="cp_activate" value="off"<?php checked( $cp_activate, 'off' ); ?>/><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label> |
| 1218 |
</td> |
| 1219 |
</tr> |
| 1220 |
<tr> |
| 1221 |
<th><a class="explanation-label" id="label_ex_card_activate_paypal_cp"><?php esc_html_e( 'Credit card settlement', 'usces' ); ?></a></th> |
| 1222 |
<td><label><input type="radio" class="activate_paypal_card" name="card_activate" value="on"<?php checked( $card_activate, 'on' ); ?>/><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br /> |
| 1223 |
<label><input type="radio" class="activate_paypal_card" name="card_activate" value="off"<?php checked( $card_activate, 'off' ); ?>/><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label> |
| 1224 |
</td> |
| 1225 |
</tr> |
| 1226 |
<tr id="ex_card_activate_paypal_cp" class="explanation"><td colspan="2"><?php esc_html_e( 'Advanced credit and debit cards requires that your business account be evaluated and approved by PayPal.', 'usces' ); ?></td></tr> |
| 1227 |
<tr class="paypal_card_form"> |
| 1228 |
<th><a class="explanation-label" id="label_ex_card_vault_paypal_cp"><?php esc_html_e( 'Save credit card information', 'usces' ); ?></a></th> |
| 1229 |
<td><label><input type="radio" name="card_vault" value="on"<?php checked( $card_vault, 'on' ); ?>/><span><?php esc_html_e( 'Save', 'usces' ); ?></span></label> |
| 1230 |
<label><input type="text" name="card_prefix" value="<?php echo esc_attr( $card_prefix ); ?>" class="small-text"><span><?php esc_html_e( '* Prefix', 'usces' ); ?></span></label><br /> |
| 1231 |
<label><input type="radio" name="card_vault" value="off"<?php checked( $card_vault, 'off' ); ?>/><span><?php esc_html_e( 'Not save', 'usces' ); ?></span></label> |
| 1232 |
</td> |
| 1233 |
</tr> |
| 1234 |
<tr id="ex_card_vault_paypal_cp" class="explanation paypal_card_form"><td colspan="2"><?php esc_html_e( 'To use this feature, you need to apply for a Client ID with PayPal.', 'usces' ); ?><br /><?php esc_html_e( 'Also need to use the Welcart membership system.', 'usces' ); ?></td></tr> |
| 1235 |
<tr class="paypal_card_form"> |
| 1236 |
<th><?php esc_html_e( '3D Secure', 'usces' ); ?></th> |
| 1237 |
<td><label><input type="radio" name="card_3ds" value="on"<?php checked( $card_3ds, 'on' ); ?>/><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br /> |
| 1238 |
<label><input type="radio" name="card_3ds" value="off"<?php checked( $card_3ds, 'off' ); ?>/><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label> |
| 1239 |
</td> |
| 1240 |
</tr> |
| 1241 |
<tr class="paypal_cp_form"> |
| 1242 |
<th><a class="explanation-label" id="label_ex_environment_paypal_cp"><?php esc_html_e( 'Operation Environment', 'usces' ); ?></a></th> |
| 1243 |
<td><div><label><input type="radio" class="cp_environment" name="cp_environment" value="live"<?php checked( $cp_environment, 'live' ); ?>/><span><?php esc_html_e( 'Live environment', 'usces' ); ?></span></label> |
| 1244 |
<script> |
| 1245 |
function onboardedCallback( authCode, sharedId ) { |
| 1246 |
let params = new URLSearchParams(); |
| 1247 |
params.append( "action", "onboarded" ); |
| 1248 |
params.append( "authCode", authCode ); |
| 1249 |
params.append( "sharedId", sharedId ); |
| 1250 |
params.append( "seller_nonce", document.getElementById( "seller_nonce" ).value ); |
| 1251 |
params.append( "wc_nonce", document.getElementById( "wc_nonce" ).value ); |
| 1252 |
return fetch( ajaxurl, { |
| 1253 |
method: 'POST', |
| 1254 |
body: params |
| 1255 |
}).then( function( res ) { |
| 1256 |
return res.json(); |
| 1257 |
}).then( function( data ) { |
| 1258 |
if ( data.client_id ) { |
| 1259 |
document.getElementById( "cp_client_id" ).value = data.client_id; |
| 1260 |
} |
| 1261 |
if ( data.client_secret ) { |
| 1262 |
document.getElementById( "cp_secret" ).value = data.client_secret; |
| 1263 |
} |
| 1264 |
}); |
| 1265 |
} |
| 1266 |
</script> |
| 1267 |
<a target="_blank" data-paypal-onboard-complete="onboardedCallback" href="" data-paypal-button="true" id="onboarding"></a> |
| 1268 |
<input type="hidden" id="seller_nonce"> |
| 1269 |
<button type="button" id="upfront_onboarding_paypal_cp" value="upfront_onboarding" class="button"><?php esc_html_e( 'Sign up for PayPal', 'usces' ); ?></button> |
| 1270 |
</div> |
| 1271 |
<label><input type="radio" class="cp_environment" name="cp_environment" value="sandbox"<?php checked( $cp_environment, 'sandbox' ); ?>/><span><?php esc_html_e( 'Test environment (Sandbox)', 'usces' ); ?></span></label> |
| 1272 |
</td> |
| 1273 |
</tr> |
| 1274 |
<tr id="ex_environment_paypal_cp" class="explanation paypal_cp_form"><td colspan="2"><?php esc_html_e( 'In the "production environment", you can "connect to PayPal account" to automatically retrieve the "Client ID" and "Secret". In the "test environment (Sandbox)", please manually obtain the Sandbox "Client ID" and "Secret".', 'usces' ); ?></td></tr> |
| 1275 |
<tr class="paypal_cp_form"> |
| 1276 |
<th><?php esc_html_e( 'Client ID', 'usces' ); ?></th> |
| 1277 |
<td><textarea name="cp_client_id" id="cp_client_id" class="regular-text code"><?php echo esc_attr( $cp_client_id ); ?></textarea></td> |
| 1278 |
</tr> |
| 1279 |
<tr class="paypal_cp_form"> |
| 1280 |
<th><?php esc_html_e( 'Secret', 'usces' ); ?></th> |
| 1281 |
<td><textarea name="cp_secret" id="cp_secret" class="regular-text code"><?php echo esc_attr( $cp_secret ); ?></textarea></td> |
| 1282 |
</tr> |
| 1283 |
<tr class="paypal_cp_form"> |
| 1284 |
<th><a class="explanation-label" id="label_ex_intent_paypal_cp"><?php esc_html_e( 'Intent', 'usces' ); ?></a></th> |
| 1285 |
<td><label><input type="radio" name="cp_intent" value="CAPTURE"<?php checked( $cp_intent, 'CAPTURE' ); ?>/><span><?php esc_html_e( 'Capture', 'usces' ); ?></span></label><br /> |
| 1286 |
<label><input type="radio" name="cp_intent" value="AUTHORIZE"<?php checked( $cp_intent, 'AUTHORIZE' ); ?>/><span><?php esc_html_e( 'Authorize', 'usces' ); ?></span></label> |
| 1287 |
</td> |
| 1288 |
</tr> |
| 1289 |
<tr id="ex_intent_paypal_cp" class="explanation paypal_cp_form"><td colspan="2"><?php esc_html_e( 'Select whether to capture sales (CAPTURE) at the time of payment or only perform authorization (AUTHORIZE).', 'usces' ); ?></td></tr> |
| 1290 |
<?php if ( defined( 'WCEX_DLSELLER' ) ) : ?> |
| 1291 |
<tr class="paypal_cp_form"> |
| 1292 |
<th><a class="explanation-label" id="label_ex_autobilling_intent_cp"><?php esc_html_e( 'Automatic recurring billing intent', 'usces' ); ?></a></th> |
| 1293 |
<td><label><input type="radio" name="cp_autobilling_intent" value="CAPTURE"<?php checked( $cp_autobilling_intent, 'CAPTURE' ); ?>/><span><?php esc_html_e( 'Capture', 'usces' ); ?></span></label><br /> |
| 1294 |
<label><input type="radio" name="cp_autobilling_intent" value="AUTHORIZE"<?php checked( $cp_autobilling_intent, 'AUTHORIZE' ); ?>/><span><?php esc_html_e( 'Authorize', 'usces' ); ?></span></label> |
| 1295 |
</td> |
| 1296 |
</tr> |
| 1297 |
<tr id="ex_autobilling_intent_cp" class="explanation paypal_cp_form"><td colspan="2"><?php esc_html_e( 'Processing classification when automatic continuing charging (required WCEX DLSeller).', 'usces' ); ?></td></tr> |
| 1298 |
<tr class="paypal_cp_form"> |
| 1299 |
<th><a class="explanation-label" id="label_ex_autobilling_email_paypal_cp"><?php esc_html_e( 'Automatic Continuing Charging Completion Mail', 'usces' ); ?></a></th> |
| 1300 |
<td><label><input type="radio" name="cp_autobilling_email" value="on"<?php checked( $cp_autobilling_email, 'on' ); ?>/><span><?php esc_html_e( 'Send', 'usces' ); ?></span></label><br /> |
| 1301 |
<label><input type="radio" name="cp_autobilling_email" value="off"<?php checked( $cp_autobilling_email, 'off' ); ?>/><span><?php esc_html_e( "Don't send", 'usces' ); ?></span></label> |
| 1302 |
</td> |
| 1303 |
</tr> |
| 1304 |
<tr id="ex_autobilling_email_paypal_cp" class="explanation paypal_cp_form"><td colspan="2"><?php esc_html_e( 'Send billing completion mail to the member on which automatic continuing charging processing (required WCEX DLSeller) is executed.', 'usces' ); ?></td></tr> |
| 1305 |
<?php endif; ?> |
| 1306 |
</table> |
| 1307 |
<table class="settle_table paypal_cp_form"> |
| 1308 |
<tr> |
| 1309 |
<th rowspan="4"><?php esc_html_e( 'Customize the PayPal Buttons', 'usces' ); ?> |
| 1310 |
<div id="button_preview_paypal_cp" class="<?php echo esc_attr( $class_button_color ); ?><?php echo esc_attr( $class_button_shape ); ?><?php echo esc_attr( $class_button_label ); ?>"><span></span></div> |
| 1311 |
</th> |
| 1312 |
<td><span><?php esc_html_e( 'Layout', 'usces' ); ?></span><br /> |
| 1313 |
<label><input type="radio" name="cp_button_layout" value="vertical"<?php checked( $cp_button_layout, 'vertical' ); ?>/><span><?php esc_html_e( 'Arrange the buttons vertically.', 'usces' ); ?></span></label><br /> |
| 1314 |
<label><input type="radio" name="cp_button_layout" value="horizontal"<?php checked( $cp_button_layout, 'horizontal' ); ?>/><span><?php esc_html_e( 'Arrange the buttons horizontally.', 'usces' ); ?></span></label> |
| 1315 |
</td> |
| 1316 |
</tr> |
| 1317 |
<tr> |
| 1318 |
<td><span><?php esc_html_e( 'Color', 'usces' ); ?></span><br /> |
| 1319 |
<label><input type="radio" name="cp_button_color" class="button_color_paypal_cp" value="gold"<?php echo esc_attr( $cp_button_color_gold ); ?>/><span><?php esc_html_e( 'Gold', 'usces' ); ?></span></label><br /> |
| 1320 |
<label><input type="radio" name="cp_button_color" class="button_color_paypal_cp" value="blue"<?php echo esc_attr( $cp_button_color_blue ); ?>/><span><?php esc_html_e( 'Blue', 'usces' ); ?></span></label><br /> |
| 1321 |
<label><input type="radio" name="cp_button_color" class="button_color_paypal_cp" value="silver"<?php echo esc_attr( $cp_button_color_silver ); ?>/><span><?php esc_html_e( 'Silver', 'usces' ); ?></span></label><br /> |
| 1322 |
<label><input type="radio" name="cp_button_color" class="button_color_paypal_cp" value="white"<?php echo esc_attr( $cp_button_color_white ); ?>/><span><?php esc_html_e( 'White', 'usces' ); ?></span></label><br /> |
| 1323 |
<label><input type="radio" name="cp_button_color" class="button_color_paypal_cp" value="black"<?php echo esc_attr( $cp_button_color_black ); ?>/><span><?php esc_html_e( 'Black', 'usces' ); ?></span></label> |
| 1324 |
</td> |
| 1325 |
</tr> |
| 1326 |
<tr> |
| 1327 |
<td><span><?php esc_html_e( 'Shape', 'usces' ); ?></span><br /> |
| 1328 |
<label><input type="radio" name="cp_button_shape" class="button_shape_paypal_cp" value="rect"<?php echo esc_attr( $cp_button_shape_rect ); ?>/><span><?php esc_html_e( 'Rect', 'usces' ); ?></span></label><br /> |
| 1329 |
<label><input type="radio" name="cp_button_shape" class="button_shape_paypal_cp" value="pill"<?php echo esc_attr( $cp_button_shape_pill ); ?>/><span><?php esc_html_e( 'Pill', 'usces' ); ?></span></label> |
| 1330 |
</td> |
| 1331 |
</tr> |
| 1332 |
<tr> |
| 1333 |
<td><span><?php esc_html_e( 'Label', 'usces' ); ?></span><br /> |
| 1334 |
<label><input type="radio" name="cp_button_label" class="button_label_paypal_cp" value="paypal"<?php echo esc_attr( $cp_button_label_paypal ); ?>/><span><?php esc_html_e( 'Display the PayPal logo.', 'usces' ); ?></span></label><br /> |
| 1335 |
<label><input type="radio" name="cp_button_label" class="button_label_paypal_cp" value="checkout"<?php echo esc_attr( $cp_button_label_checkout ); ?>/><span><?php esc_html_e( 'Display the PayPal Checkout button.', 'usces' ); ?></span></label><br /> |
| 1336 |
<label><input type="radio" name="cp_button_label" class="button_label_paypal_cp" value="buynow"<?php echo esc_attr( $cp_button_label_buynow ); ?>/><span><?php esc_html_e( 'Display the PayPal Buy Now button.', 'usces' ); ?></span></label><br /> |
| 1337 |
<label><input type="radio" name="cp_button_label" class="button_label_paypal_cp" value="pay"<?php echo esc_attr( $cp_button_label_pay ); ?>/><span><?php esc_html_e( 'Display the Pay With PayPal button.', 'usces' ); ?></span></label> |
| 1338 |
</td> |
| 1339 |
</tr> |
| 1340 |
</table> |
| 1341 |
<input name="acting" type="hidden" value="paypal_cp" /> |
| 1342 |
<input name="usces_option_update" id="paypal_cp" type="submit" class="button button-primary" value="<?php esc_html_e( 'Update the PayPal Commerce Platform settings', 'usces' ); ?>" /> |
| 1343 |
<span class="paypal_cp_form_agree"><label><input type="checkbox" name="cp_agree" value="agree"<?php checked( $cp_agree, 'agree' ); ?> /><span><?php esc_html_e( 'I agree to the following terms and conditions of use.', 'usces' ); ?></span></label></span> |
| 1344 |
<p class="paypal_cp_form_agree"><?php esc_html_e( 'You agree that the information you submit during the application process will be provided to our partner company PayPal Pte. Ltd. and will be used by PayPal to evaluate, improve and enhance its services and for marketing purposes and PayPal Pte. Ltd. may send you information for marketing and promotional purposes (including sending e-mails, etc.).', 'usces' ); ?></p> |
| 1345 |
<?php wp_nonce_field( 'admin_settlement', 'wc_nonce' ); ?> |
| 1346 |
</form> |
| 1347 |
<div class="settle_exp"> |
| 1348 |
<p><strong><?php esc_html_e( 'PayPal Commerce Platform', 'usces' ); ?></strong></p> |
| 1349 |
<p>問い合わせ� |
| 1350 |
�<br /> |
| 1351 |
新規ビジネス・サービス導� |
| 1352 |
�・お申込専用ライン<br /> |
| 1353 |
Tel:03-6739-7135 9:30~17:30(土日祝休)※通話料がかかります</p> |
| 1354 |
<p>すでにペイパルアカウントをお持ちの方(カスタマーサービス)<br /> |
| 1355 |
Tel:0120-271-888 または 03-6739-7360(携帯電話と海外からはこちら)※通話料がかかります<br /> |
| 1356 |
9:00~18:00(土日休)</p> |
| 1357 |
<p><a href="https://www.paypal.com/jp/webapps/mpp/corporate/contact">WEBでのお問い合わせ</a> |
| 1358 |
<?php |
| 1359 |
$wcex = ''; |
| 1360 |
$billing = ''; |
| 1361 |
if ( defined( 'WCEX_DLSELLER' ) ) { |
| 1362 |
$wcex = 'WCEX DLSeller での自動継続課金'; |
| 1363 |
$billing = '自動継続課金'; |
| 1364 |
} elseif ( defined( 'WCEX_AUTO_DELIVERY' ) ) { |
| 1365 |
$wcex = 'WCEX Auto Delivery での定期購� |
| 1366 |
�'; |
| 1367 |
$billing = '定期購� |
| 1368 |
�'; |
| 1369 |
} |
| 1370 |
if ( '' !== $wcex ) : |
| 1371 |
?> |
| 1372 |
<p><?php echo esc_html( $wcex ); ?>を行う場合は、ペイパルへの「従量課金」の利用申請・審査が� |
| 1373 |
要となります。<br /> |
| 1374 |
利用申請については、<a href="https://www.paypal.com/jp/smarthelp/contact-us">こちら</a>からお問い合わせください。<br /> |
| 1375 |
※上記の問い合わせページで「その他のお問い合わせ方法」の下にある「メッセージを送る」を選択ください。<br /> |
| 1376 |
※メッセージボックスに、「Welcart にて Reference Transaction を利用するための審査・設定をしてほしい」旨をご記� |
| 1377 |
�ください。</p> |
| 1378 |
<?php |
| 1379 |
endif; |
| 1380 |
?> |
| 1381 |
<p>クレジットカード決済のご利用には別途ペイパルへのお申込みと審査が� |
| 1382 |
要です。<br /> |
| 1383 |
クレジットカード決済の申込みは<a href="https://www.paypal.com/jp/webapps/mpp/contact-sales">こちら</a>から行えます。</p> |
| 1384 |
</div> |
| 1385 |
</div><!--uscestabs_paypal_cp--> |
| 1386 |
<?php |
| 1387 |
endif; |
| 1388 |
} |
| 1389 |
|
| 1390 |
/** |
| 1391 |
* 支払方法 JavaScript 用決済名追加 |
| 1392 |
* usces_filter_payments_str |
| 1393 |
* |
| 1394 |
* @param string $payments_str Payments. |
| 1395 |
* @param array $payment Selected payment. |
| 1396 |
* @return string |
| 1397 |
*/ |
| 1398 |
public function payments_str( $payments_str, $payment ) { |
| 1399 |
if ( 'acting_paypal_card' === $payment['settlement'] && 'activate' === $payment['use'] ) { |
| 1400 |
$payments_str .= "'" . $payment['name'] . "': 'paypal_card_form', "; |
| 1401 |
} |
| 1402 |
return $payments_str; |
| 1403 |
} |
| 1404 |
|
| 1405 |
/** |
| 1406 |
* 支払方法 JavaScript 用決済追加 |
| 1407 |
* usces_filter_payments_arr |
| 1408 |
* |
| 1409 |
* @param array $payments_arr Payments. |
| 1410 |
* @param array $payment Selected payment. |
| 1411 |
* @return array |
| 1412 |
*/ |
| 1413 |
public function payments_arr( $payments_arr, $payment ) { |
| 1414 |
if ( 'acting_paypal_card' === $payment['settlement'] && 'activate' === $payment['use'] ) { |
| 1415 |
$payments_arr[] = 'paypal_card_form'; |
| 1416 |
} |
| 1417 |
return $payments_arr; |
| 1418 |
} |
| 1419 |
|
| 1420 |
/** |
| 1421 |
* 支払方法ページ用� |
| 1422 |
�力フォーム |
| 1423 |
* usces_filter_delivery_secure_form_loop |
| 1424 |
* |
| 1425 |
* @param string $nouse Empty. |
| 1426 |
* @param array $payment Payment data. |
| 1427 |
* @return string |
| 1428 |
*/ |
| 1429 |
public function delivery_secure_form_loop( $nouse, $payment ) { |
| 1430 |
global $usces; |
| 1431 |
|
| 1432 |
$form = ''; |
| 1433 |
if ( isset( $payment['settlement'] ) && 'acting_paypal_card' === $payment['settlement'] && 'activate' === $payment['use'] ) { |
| 1434 |
$acting_opts = $this->get_acting_settings(); |
| 1435 |
$card_vault = 'off'; |
| 1436 |
$payment_token_id = ''; |
| 1437 |
$payment_token_last_digits = ''; |
| 1438 |
$payment_token_brand = ''; |
| 1439 |
if ( usces_is_member_system() && usces_is_login() ) { |
| 1440 |
$card_vault = ( isset( $acting_opts['card_vault'] ) ) ? $acting_opts['card_vault'] : 'off'; |
| 1441 |
if ( 'on' === $card_vault ) { |
| 1442 |
$member = $usces->get_member(); |
| 1443 |
|
| 1444 |
/* Get Access Token */ |
| 1445 |
$access_token = $this->get_access_token(); |
| 1446 |
|
| 1447 |
$payment_tokens = $this->api_get_payment_tokens( $access_token, $member['ID'] ); |
| 1448 |
if ( ! empty( $payment_tokens['payment_tokens'] ) && is_array( $payment_tokens['payment_tokens'] ) ) { |
| 1449 |
$tokens_count = count( $payment_tokens['payment_tokens'] ); |
| 1450 |
if ( 1 === $tokens_count ) { |
| 1451 |
$payment_token = current( $payment_tokens['payment_tokens'] ); |
| 1452 |
$payment_token_id = $payment_token['id']; |
| 1453 |
$payment_token_last_digits = $payment_token['source']['card']['last_digits']; |
| 1454 |
$payment_token_brand = $payment_token['source']['card']['brand']; |
| 1455 |
} else { |
| 1456 |
foreach ( $payment_tokens['payment_tokens'] as $payment_token ) { |
| 1457 |
$delete_status = $this->api_delete_payment_tokens( $access_token, $payment_token['id'] ); |
| 1458 |
} |
| 1459 |
} |
| 1460 |
} |
| 1461 |
} |
| 1462 |
} |
| 1463 |
$tracking_id = usces_acting_key(); |
| 1464 |
|
| 1465 |
ob_start(); |
| 1466 |
?> |
| 1467 |
<table class="customer_form" id="paypal_card_form"> |
| 1468 |
<tbody><tr> |
| 1469 |
<th scope="row"><em><?php esc_html_e( '*', 'usces' ); ?></em><?php esc_html_e( 'Credit card information', 'usces' ); ?></th> |
| 1470 |
<td> |
| 1471 |
<?php if ( 'on' === $card_vault && ! empty( $payment_token_id ) ) : ?> |
| 1472 |
<div class="card_selection"><input type="radio" id="paypal_payment_card_vault" name="paypal_payment_card" value="vault" checked /><label for="paypal_payment_card_vault"><?php esc_html_e( 'Pay with vaulted card', 'usces' ); ?></label> |
| 1473 |
<p class="card_last_digits"><?php echo esc_html( $payment_token_brand ); ?> <?php esc_html_e( 'Lower 4 digits', 'usces' ); ?>:<?php echo esc_html( $payment_token_last_digits ); ?></p> |
| 1474 |
</div> |
| 1475 |
<div class="card_selection"><input type="radio" id="paypal_payment_card_another" name="paypal_payment_card" value="another"><label for="paypal_payment_card_another"><?php esc_html_e( 'Pay with another card', 'usces' ); ?></label></div> |
| 1476 |
<?php endif; ?> |
| 1477 |
<div class="card_container"> |
| 1478 |
<div> |
| 1479 |
<label for="card-number"><?php esc_html_e( 'Card Number', 'usces' ); ?></label> |
| 1480 |
<div id="card-number" class="card_field"></div> |
| 1481 |
</div> |
| 1482 |
<div> |
| 1483 |
<label for="expiration-date"><?php esc_html_e( 'Expiration Date', 'usces' ); ?></label> |
| 1484 |
<div id="expiration-date" class="card_field"></div> |
| 1485 |
</div> |
| 1486 |
<div> |
| 1487 |
<label for="cvv"><?php esc_html_e( 'CVV', 'usces' ); ?></label> |
| 1488 |
<div id="cvv" class="card_field"></div> |
| 1489 |
</div> |
| 1490 |
<?php if ( 'on' === $card_vault ) : ?> |
| 1491 |
<div> |
| 1492 |
<input type="checkbox" id="vault" name="paypal_vault" value="vault"> |
| 1493 |
<label for="vault"><?php esc_html_e( 'Save your card', 'usces' ); ?></label> |
| 1494 |
</div> |
| 1495 |
<?php else : ?> |
| 1496 |
<input type="hidden" id="vault" value=""> |
| 1497 |
<?php endif; ?> |
| 1498 |
</div> |
| 1499 |
<input type="hidden" id="paypal_tracking_id" name="paypal_tracking_id" value="<?php echo esc_attr( $tracking_id ); ?>" /> |
| 1500 |
<input type="hidden" id="paypal_resource_id" name="paypal_resource_id" value="" /> |
| 1501 |
<input type="hidden" id="paypal_payment_token_id " name="paypal_payment_token_id" value="<?php echo esc_attr( $payment_token_id ); ?>" /> |
| 1502 |
<input type="hidden" id="paypal_f" name="paypal_f" value="" /> |
| 1503 |
</td></tr></tbody> |
| 1504 |
</table> |
| 1505 |
<?php |
| 1506 |
$form = ob_get_contents(); |
| 1507 |
ob_end_clean(); |
| 1508 |
} |
| 1509 |
return $form; |
| 1510 |
} |
| 1511 |
|
| 1512 |
/** |
| 1513 |
* 支払方法チェック |
| 1514 |
* usces_filter_delivery_check |
| 1515 |
* |
| 1516 |
* @param string $mes Validation check message. |
| 1517 |
* @return string |
| 1518 |
*/ |
| 1519 |
public function delivery_check( $mes ) { |
| 1520 |
if ( ! isset( $_POST['offer']['payment_name'] ) ) { |
| 1521 |
return $mes; |
| 1522 |
} |
| 1523 |
|
| 1524 |
if ( ! empty( $mes ) ) { |
| 1525 |
return $mes; |
| 1526 |
} |
| 1527 |
|
| 1528 |
$payment = usces_get_payments_by_name( wp_unslash( $_POST['offer']['payment_name'] ) ); |
| 1529 |
if ( isset( $payment['settlement'] ) && 'acting_paypal_card' === $payment['settlement'] ) { |
| 1530 |
if ( isset( $_POST['paypal_payment_card'] ) && 'vault' === wp_unslash( $_POST['paypal_payment_card'] ) ) { |
| 1531 |
} else { |
| 1532 |
if ( isset( $_POST['paypal_resource_id'] ) && empty( $_POST['paypal_resource_id'] ) ) { |
| 1533 |
$mes .= __( 'Please enter the card information correctly.', 'usces' ) . '<br />'; |
| 1534 |
} else { |
| 1535 |
if ( ! wel_check_credit_security() ) { |
| 1536 |
$mes .= __( 'Update has been locked. Please contact the store administrator.', 'usces' ) . '<br />'; |
| 1537 |
} |
| 1538 |
} |
| 1539 |
} |
| 1540 |
} |
| 1541 |
return $mes; |
| 1542 |
} |
| 1543 |
|
| 1544 |
/** |
| 1545 |
* � |
| 1546 |
容確認ページ ポイントフォーム |
| 1547 |
* usces_action_confirm_page_point_inform |
| 1548 |
*/ |
| 1549 |
public function e_point_inform() { |
| 1550 |
$html = $this->point_inform( '' ); |
| 1551 |
wel_esc_script_e( $html ); |
| 1552 |
} |
| 1553 |
|
| 1554 |
/** |
| 1555 |
* � |
| 1556 |
容確認ページ ポイントフォーム |
| 1557 |
* usces_filter_confirm_point_inform |
| 1558 |
* |
| 1559 |
* @param string $html Input point form. |
| 1560 |
* @return string |
| 1561 |
*/ |
| 1562 |
public function point_inform( $html ) { |
| 1563 |
global $usces; |
| 1564 |
|
| 1565 |
$entry = $usces->cart->get_entry(); |
| 1566 |
$payment = usces_get_payments_by_name( $entry['order']['payment_name'] ); |
| 1567 |
if ( isset( $payment['settlement'] ) && 'acting_paypal_card' === $payment['settlement'] ) { |
| 1568 |
if ( isset( $_POST['paypal_tracking_id'] ) ) { |
| 1569 |
$html .= '<input type="hidden" name="paypal_tracking_id" value="' . esc_attr( sanitize_text_field( wp_unslash( $_POST['paypal_tracking_id'] ) ) ) . '">'; |
| 1570 |
} |
| 1571 |
if ( isset( $_POST['paypal_resource_id'] ) ) { |
| 1572 |
$html .= '<input type="hidden" name="paypal_resource_id" value="' . esc_attr( sanitize_text_field( wp_unslash( $_POST['paypal_resource_id'] ) ) ) . '">'; |
| 1573 |
} |
| 1574 |
if ( isset( $_POST['paypal_payment_card'] ) ) { |
| 1575 |
$html .= '<input type="hidden" name="paypal_payment_card" value="' . esc_attr( sanitize_text_field( wp_unslash( $_POST['paypal_payment_card'] ) ) ) . '">'; |
| 1576 |
} |
| 1577 |
if ( isset( $_POST['paypal_payment_token_id'] ) ) { |
| 1578 |
$html .= '<input type="hidden" name="paypal_payment_token_id" value="' . esc_attr( sanitize_text_field( wp_unslash( $_POST['paypal_payment_token_id'] ) ) ) . '">'; |
| 1579 |
} |
| 1580 |
if ( isset( $_POST['paypal_vault'] ) ) { |
| 1581 |
$html .= '<input type="hidden" name="paypal_vault" value="' . esc_attr( sanitize_text_field( wp_unslash( $_POST['paypal_vault'] ) ) ) . '">'; |
| 1582 |
} |
| 1583 |
if ( isset( $_POST['paypal_f'] ) ) { |
| 1584 |
$html .= '<input type="hidden" name="paypal_f" value="' . esc_attr( sanitize_text_field( wp_unslash( $_POST['paypal_f'] ) ) ) . '">'; |
| 1585 |
} |
| 1586 |
if ( isset( $_POST['paypal_liability_shift'] ) ) { |
| 1587 |
$html .= '<input type="hidden" name="paypal_liability_shift" value="' . esc_attr( sanitize_text_field( wp_unslash( $_POST['paypal_liability_shift'] ) ) ) . '">'; |
| 1588 |
} |
| 1589 |
if ( isset( $_POST['paypal_enrollment_status'] ) ) { |
| 1590 |
$html .= '<input type="hidden" name="paypal_enrollment_status" value="' . esc_attr( sanitize_text_field( wp_unslash( $_POST['paypal_enrollment_status'] ) ) ) . '">'; |
| 1591 |
} |
| 1592 |
if ( isset( $_POST['paypal_authentication_status'] ) ) { |
| 1593 |
$html .= '<input type="hidden" name="paypal_authentication_status" value="' . esc_attr( sanitize_text_field( wp_unslash( $_POST['paypal_authentication_status'] ) ) ) . '">'; |
| 1594 |
} |
| 1595 |
} |
| 1596 |
return $html; |
| 1597 |
} |
| 1598 |
|
| 1599 |
/** |
| 1600 |
* � |
| 1601 |
容確認ページ [注文する] ボタン |
| 1602 |
* usces_filter_confirm_inform |
| 1603 |
* |
| 1604 |
* @param string $form Purchase post form. |
| 1605 |
* @param array $payment Payment method info. |
| 1606 |
* @param string $acting_flg Payment type. |
| 1607 |
* @param string $rand Welcart transaction key. |
| 1608 |
* @param string $purchase_disabled Disable purchase button. |
| 1609 |
* @return string |
| 1610 |
*/ |
| 1611 |
public function confirm_inform( $form, $payment, $acting_flg, $rand, $purchase_disabled ) { |
| 1612 |
global $usces; |
| 1613 |
|
| 1614 |
$entry = $usces->cart->get_entry(); |
| 1615 |
$cart = $usces->cart->get_cart(); |
| 1616 |
if ( empty( $entry ) || empty( $cart ) ) { |
| 1617 |
return $form; |
| 1618 |
} |
| 1619 |
if ( empty( $entry['order']['total_full_price'] ) ) { |
| 1620 |
return $form; |
| 1621 |
} |
| 1622 |
|
| 1623 |
if ( 'acting_paypal_cp' === $acting_flg ) { |
| 1624 |
usces_save_order_acting_data( $rand ); |
| 1625 |
$form = '<form name="purchase_form" action="' . USCES_CART_URL . '" method="post" onKeyDown="if(event.keyCode == 13){return false;}"> |
| 1626 |
<input type="hidden" name="purchase" value="' . $acting_flg . '"> |
| 1627 |
<input type="hidden" name="tracking_id" value="' . $rand . '"> |
| 1628 |
<input type="hidden" name="resource_id"> |
| 1629 |
<input type="hidden" name="billing_token"> |
| 1630 |
<input type="hidden" name="_nonce" value="' . wp_create_nonce( $acting_flg ) . '"> |
| 1631 |
<div class="send paypal-cp-send"><div id="checkout_paypal_cp"></div></div> |
| 1632 |
</form> |
| 1633 |
<form action="' . USCES_CART_URL . '" method="post" onKeyDown="if(event.keyCode == 13){return false;}"> |
| 1634 |
<div class="send"> |
| 1635 |
' . apply_filters( 'usces_filter_confirm_before_backbutton', '', $payment, $acting_flg, $rand ) . ' |
| 1636 |
<input name="backDelivery" type="submit" id="back_button" class="back_to_delivery_button" value="' . __( 'Back', 'usces' ) . '"' . apply_filters( 'usces_filter_confirm_prebutton', '' ) . ' /> |
| 1637 |
</div>'; |
| 1638 |
|
| 1639 |
} elseif ( 'acting_paypal_card' === $acting_flg ) { |
| 1640 |
$tracking_id = ( isset( $_POST['paypal_tracking_id'] ) ) ? sanitize_text_field( wp_unslash( $_POST['paypal_tracking_id'] ) ) : ''; |
| 1641 |
$resource_id = ( isset( $_POST['paypal_resource_id'] ) ) ? sanitize_text_field( wp_unslash( $_POST['paypal_resource_id'] ) ) : ''; |
| 1642 |
$payment_card = ( isset( $_POST['paypal_payment_card'] ) ) ? sanitize_text_field( wp_unslash( $_POST['paypal_payment_card'] ) ) : ''; |
| 1643 |
$payment_token_id = ( isset( $_POST['paypal_payment_token_id'] ) ) ? sanitize_text_field( wp_unslash( $_POST['paypal_payment_token_id'] ) ) : ''; |
| 1644 |
$vault = ( isset( $_POST['paypal_vault'] ) ) ? sanitize_text_field( wp_unslash( $_POST['paypal_vault'] ) ) : ''; |
| 1645 |
$correlation_id = ( isset( $_POST['paypal_f'] ) ) ? sanitize_text_field( wp_unslash( $_POST['paypal_f'] ) ) : ''; |
| 1646 |
$liability_shift = ( isset( $_POST['paypal_liability_shift'] ) ) ? sanitize_text_field( wp_unslash( $_POST['paypal_liability_shift'] ) ) : ''; |
| 1647 |
$enrollment_status = ( isset( $_POST['paypal_enrollment_status'] ) ) ? sanitize_text_field( wp_unslash( $_POST['paypal_enrollment_status'] ) ) : ''; |
| 1648 |
$authentication_status = ( isset( $_POST['paypal_authentication_status'] ) ) ? sanitize_text_field( wp_unslash( $_POST['paypal_authentication_status'] ) ) : ''; |
| 1649 |
usces_save_order_acting_data( $tracking_id ); |
| 1650 |
$form = '<form name="purchase_form" action="' . USCES_CART_URL . '" method="post" onKeyDown="if(event.keyCode == 13){return false;}"> |
| 1651 |
<input type="hidden" name="purchase" value="' . $acting_flg . '"> |
| 1652 |
<input type="hidden" name="tracking_id" value="' . esc_attr( $tracking_id ) . '"> |
| 1653 |
<input type="hidden" name="resource_id" value="' . esc_attr( $resource_id ) . '"> |
| 1654 |
<input type="hidden" name="payment_card" value="' . esc_attr( $payment_card ) . '"> |
| 1655 |
<input type="hidden" name="payment_token_id" value="' . esc_attr( $payment_token_id ) . '"> |
| 1656 |
<input type="hidden" name="vault" value="' . esc_attr( $vault ) . '"> |
| 1657 |
<input type="hidden" name="correlation_id" value="' . esc_attr( $correlation_id ) . '"> |
| 1658 |
<input type="hidden" name="liability_shift" value="' . esc_attr( $liability_shift ) . '"> |
| 1659 |
<input type="hidden" name="enrollment_status" value="' . esc_attr( $enrollment_status ) . '"> |
| 1660 |
<input type="hidden" name="authentication_status" value="' . esc_attr( $authentication_status ) . '"> |
| 1661 |
<input type="hidden" name="_nonce" value="' . wp_create_nonce( $acting_flg ) . '"> |
| 1662 |
<div class="send">' . apply_filters( 'usces_filter_confirm_before_backbutton', null, $payment, $acting_flg, $tracking_id ) . ' |
| 1663 |
<input name="backDelivery" type="submit" id="back_button" class="back_to_delivery_button" value="' . __( 'Back', 'usces' ) . '"' . apply_filters( 'usces_filter_confirm_prebutton', null ) . ' /> |
| 1664 |
<input name="purchase" type="submit" id="purchase_button" class="checkout_button" value="' . apply_filters( 'usces_filter_confirm_checkout_button_value', __( 'Checkout', 'usces' ) ) . '"' . apply_filters( 'usces_filter_confirm_nextbutton', null ) . $purchase_disabled . ' /> |
| 1665 |
</div>'; |
| 1666 |
} |
| 1667 |
return $form; |
| 1668 |
} |
| 1669 |
|
| 1670 |
/** |
| 1671 |
* 決済エラーメッセージ |
| 1672 |
* usces_filter_get_error_settlement |
| 1673 |
* |
| 1674 |
* @param string $form Payment error message. |
| 1675 |
* @return string |
| 1676 |
*/ |
| 1677 |
public function error_page_message( $form ) { |
| 1678 |
$acting = ( isset( $_GET['acting'] ) ) ? wp_unslash( $_GET['acting'] ) : ''; |
| 1679 |
$acting_return = ( isset( $_GET['acting_return'] ) ) ? wp_unslash( $_GET['acting_return'] ) : ''; |
| 1680 |
if ( 'paypal_card' === $acting && '0' === $acting_return ) { |
| 1681 |
if ( isset( $_GET['retry'] ) ) { |
| 1682 |
$retry_url = add_query_arg( |
| 1683 |
array( |
| 1684 |
'backDelivery' => 'paypal_card', |
| 1685 |
're-enter' => 1, |
| 1686 |
), |
| 1687 |
USCES_CUSTOMER_URL |
| 1688 |
); |
| 1689 |
$form .= '<div class="support_box">' . __( 'Your credit card information is incorrect.', 'usces' ) . '<br />' . sprintf( __( 'Click <a href="%s">here</a> to re-enter your credit card number.', 'usces' ), $retry_url ) . '</div>'; |
| 1690 |
} |
| 1691 |
} |
| 1692 |
return $form; |
| 1693 |
} |
| 1694 |
|
| 1695 |
/** |
| 1696 |
* フロントスクリプト |
| 1697 |
* wp_enqueue_scripts |
| 1698 |
*/ |
| 1699 |
public function enqueue_scripts() { |
| 1700 |
global $usces; |
| 1701 |
|
| 1702 |
if ( ! is_admin() && $this->is_validity_acting( 'card' ) ) { |
| 1703 |
$usces_page = ( isset( $_GET['usces_page'] ) ) ? wp_unslash( $_GET['usces_page'] ) : ''; |
| 1704 |
if ( ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) && 'delivery' === $usces->page ) || |
| 1705 |
( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) && ( 'member_register_settlement' === $usces_page || 'member_update_settlement' === $usces_page ) ) ) { |
| 1706 |
$paypal_style_url = apply_filters( 'usces_filter_paypalcp_card_style', USCES_FRONT_PLUGIN_URL . '/css/paypal_style.css' ); |
| 1707 |
wp_enqueue_style( 'usces-paypal-style', $paypal_style_url, array() ); |
| 1708 |
wp_enqueue_style( 'usces-loading', USCES_FRONT_PLUGIN_URL . '/css/loading.css', array() ); |
| 1709 |
} |
| 1710 |
} |
| 1711 |
} |
| 1712 |
|
| 1713 |
/** |
| 1714 |
* フロントスクリプト |
| 1715 |
* wp_print_footer_scripts |
| 1716 |
*/ |
| 1717 |
public function footer_scripts() { |
| 1718 |
global $usces; |
| 1719 |
|
| 1720 |
if ( 'delivery' === $usces->page && $this->is_validity_acting( 'card' ) ) : |
| 1721 |
$entry = $usces->cart->get_entry(); |
| 1722 |
$cart = $usces->cart->get_cart(); |
| 1723 |
if ( empty( $cart ) || empty( $entry ) ) { |
| 1724 |
return; |
| 1725 |
} |
| 1726 |
|
| 1727 |
$continue = ( defined( 'WCEX_DLSELLER' ) ) ? usces_have_continue_charge( $cart ) : false; |
| 1728 |
$regular = ( defined( 'WCEX_AUTO_DELIVERY' ) ) ? usces_have_regular_order() : false; |
| 1729 |
if ( $continue || $regular ) { |
| 1730 |
return; |
| 1731 |
} |
| 1732 |
|
| 1733 |
$acting_opts = $this->get_acting_settings(); |
| 1734 |
$cp_client_id = ( isset( $acting_opts['client_id'] ) ) ? $acting_opts['client_id'] : ''; |
| 1735 |
$cp_intent = ( isset( $acting_opts['intent'] ) ) ? $acting_opts['intent'] : ''; |
| 1736 |
$cp_environment = ( isset( $acting_opts['environment'] ) ) ? $acting_opts['environment'] : 'live'; |
| 1737 |
$card_vault = ( isset( $acting_opts['card_vault'] ) ) ? $acting_opts['card_vault'] : 'off'; |
| 1738 |
$card_3ds = ( isset( $acting_opts['card_3ds'] ) ) ? $acting_opts['card_3ds'] : 'off'; |
| 1739 |
|
| 1740 |
$customer_id = ''; |
| 1741 |
if ( usces_is_login() && 'on' === $card_vault ) { |
| 1742 |
$member = $usces->get_member(); |
| 1743 |
$customer_id = $member['ID']; |
| 1744 |
} |
| 1745 |
|
| 1746 |
$paypal_card_name = ''; |
| 1747 |
$payment_method = usces_get_system_option( 'usces_payment_method', 'settlement' ); |
| 1748 |
if ( isset( $payment_method['acting_paypal_card'] ) ) { |
| 1749 |
$paypal_card_name = $payment_method['acting_paypal_card']['name']; |
| 1750 |
} |
| 1751 |
|
| 1752 |
$currency_code = $usces->get_currency_code(); |
| 1753 |
$query = array(); |
| 1754 |
$query['components'] = 'hosted-fields'; |
| 1755 |
$query['client-id'] = $cp_client_id; |
| 1756 |
$query['currency'] = $currency_code; |
| 1757 |
$query['locale'] = $this->get_locale(); |
| 1758 |
if ( 'AUTHORIZE' === $cp_intent ) { |
| 1759 |
$query['intent'] = 'authorize'; |
| 1760 |
} |
| 1761 |
$sdk_query = http_build_query( $query ); |
| 1762 |
$client_token = $this->get_client_token( $customer_id ); |
| 1763 |
if ( usces_is_login() && 'on' === $card_vault ) : |
| 1764 |
$fraudnet_session_id = $this->get_fraudnet_session_id(); |
| 1765 |
?> |
| 1766 |
<script type="application/json" fncls="fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99"> |
| 1767 |
{ |
| 1768 |
"f":"<?php echo esc_attr( $fraudnet_session_id ); ?>", |
| 1769 |
"s":"<?php echo self::API_FRAUDNET_S; ?>"<?php if ( 'live' !== $cp_environment ) : ?>, |
| 1770 |
"sandbox":true |
| 1771 |
<?php endif; ?>} |
| 1772 |
</script> |
| 1773 |
<script type="text/javascript" src="https://c.paypal.com/da/r/fb.js"></script> |
| 1774 |
<script type="text/javascript"> |
| 1775 |
document.getElementById( "paypal_f" ).value = "<?php echo esc_attr( $fraudnet_session_id ); ?>"; |
| 1776 |
</script><?php endif; ?> |
| 1777 |
<div id="welcart-overlay" style="display:none"><div id="welcart-loading"></div><div id="welcart-loading-text"><?php esc_html_e( 'Processing...', 'usces' ); ?></div></div> |
| 1778 |
<script src="https://www.paypal.com/sdk/js?<?php echo $sdk_query; // no escape due to fixed format. ?>" data-client-token="<?php echo $client_token; // no escape due to fixed format. ?>"></script> |
| 1779 |
<script type="text/javascript"> |
| 1780 |
jQuery(document).ready( function($) { |
| 1781 |
$( 'body input[type="submit"]' ).each( function( i, elem ) { |
| 1782 |
if ( "confirm" == $( this ).attr( "name" ) ) { |
| 1783 |
$( this ).parents( "form" ).attr( "id", "delivery-form" ); |
| 1784 |
$( this ).parents( "form" ).attr( "name", "delivery_form" ); |
| 1785 |
$( this ).attr( "id", "confirm" ); |
| 1786 |
} |
| 1787 |
}); |
| 1788 |
}); |
| 1789 |
</script> |
| 1790 |
<script type="text/javascript"> |
| 1791 |
document.getElementById( "welcart-overlay" ).style.display = 'none'; |
| 1792 |
let paypal_card_name = "<?php echo esc_js( $paypal_card_name ); ?>"; |
| 1793 |
if ( paypal.HostedFields.isEligible() ) { |
| 1794 |
paypal.HostedFields.render({ |
| 1795 |
createOrder: function() { |
| 1796 |
let params = new URLSearchParams(); |
| 1797 |
params.append( "action", "create_order_card" ); |
| 1798 |
params.append( "tracking_id", document.getElementById( "paypal_tracking_id" ).value ); |
| 1799 |
return fetch( uscesL10n.ajaxurl, { |
| 1800 |
method: "POST", |
| 1801 |
body: params |
| 1802 |
}).then( function( res ) { |
| 1803 |
return res.json(); |
| 1804 |
}).then( function( data ) { |
| 1805 |
if ( data.message ) { |
| 1806 |
alert( data.message ); |
| 1807 |
return false; |
| 1808 |
} |
| 1809 |
if ( data.stock && 'error' == data.stock ) { |
| 1810 |
location.href = "<?php echo esc_js( USCES_CART_URL ); ?>"; |
| 1811 |
} |
| 1812 |
document.getElementById( "paypal_resource_id" ).value = data.id; |
| 1813 |
return data.id; |
| 1814 |
}); |
| 1815 |
}, |
| 1816 |
fields: { |
| 1817 |
number: { |
| 1818 |
selector: "#card-number", |
| 1819 |
placeholder: "4111 1111 1111 1111" |
| 1820 |
}, |
| 1821 |
expirationDate: { |
| 1822 |
selector: "#expiration-date", |
| 1823 |
placeholder: "MM/YY" |
| 1824 |
}, |
| 1825 |
cvv: { |
| 1826 |
selector: "#cvv", |
| 1827 |
placeholder: "123" |
| 1828 |
} |
| 1829 |
}, |
| 1830 |
styles: { |
| 1831 |
'.valid': { |
| 1832 |
'color': 'green' |
| 1833 |
}, |
| 1834 |
'.invalid': { |
| 1835 |
'color': 'red' |
| 1836 |
} |
| 1837 |
} |
| 1838 |
}).then( function( hostedFieldsInstance ) { |
| 1839 |
document.querySelector( "#confirm" ).onclick = function( event ) { |
| 1840 |
var payment_name = document.getElementsByName( "offer[payment_name]" ); |
| 1841 |
for ( var select_payment = "", i = payment_name.length; i--; ) { |
| 1842 |
if ( payment_name[i].checked ) { |
| 1843 |
var select_payment = payment_name[i].value; |
| 1844 |
break; |
| 1845 |
} |
| 1846 |
} |
| 1847 |
<?php if ( 'on' === $card_vault ) : ?> |
| 1848 |
var payment_card = document.getElementsByName( "paypal_payment_card" ); |
| 1849 |
for ( var select_vault = "", i = payment_card.length; i--; ) { |
| 1850 |
if ( payment_card[i].checked ) { |
| 1851 |
var select_vault = payment_card[i].value; |
| 1852 |
break; |
| 1853 |
} |
| 1854 |
} |
| 1855 |
<?php else : ?> |
| 1856 |
var select_vault = ""; |
| 1857 |
<?php endif; ?> |
| 1858 |
if ( paypal_card_name == select_payment && "vault" != select_vault ) { |
| 1859 |
<?php if ( 'on' !== $card_3ds ) : ?> |
| 1860 |
document.getElementById( "welcart-overlay" ).style.display = "block"; |
| 1861 |
<?php endif; ?> |
| 1862 |
event.preventDefault(); |
| 1863 |
hostedFieldsInstance.submit(<?php if ( 'on' === $card_vault || 'on' === $card_3ds ) : ?>{ |
| 1864 |
<?php if ( 'on' === $card_vault ) : ?> |
| 1865 |
vault: document.querySelector( '#vault' ).checked<?php endif; ?><?php if ( 'on' === $card_vault && 'on' === $card_3ds ) : ?>, |
| 1866 |
<?php endif; ?> |
| 1867 |
<?php if ( 'on' === $card_3ds ) : ?> |
| 1868 |
contingencies: ['SCA_ALWAYS'] |
| 1869 |
<?php endif; ?> |
| 1870 |
}<?php endif; ?>).then( function( payload ) { |
| 1871 |
<?php if ( 'on' === $card_3ds ) : ?> |
| 1872 |
if ( "POSSIBLE" == payload.liabilityShift ) { |
| 1873 |
let params3ds = new URLSearchParams(); |
| 1874 |
params3ds.append( "action", "show_order_details_card" ); |
| 1875 |
params3ds.append( "tracking_id", document.getElementById( "paypal_tracking_id" ).value ); |
| 1876 |
params3ds.append( "resource_id", payload.orderId ); |
| 1877 |
return fetch( uscesL10n.ajaxurl, { |
| 1878 |
method: "POST", |
| 1879 |
body: params3ds |
| 1880 |
}).then( function( res ) { |
| 1881 |
return res.json(); |
| 1882 |
}).then( function( res3ds ) { |
| 1883 |
document.getElementById( "paypal_resource_id" ).value = payload.orderId; |
| 1884 |
var elem_liability_shift = document.createElement( "input" ); |
| 1885 |
elem_liability_shift.setAttribute( "type", "hidden" ); |
| 1886 |
elem_liability_shift.setAttribute( "name", "paypal_liability_shift" ); |
| 1887 |
elem_liability_shift.setAttribute( "value", res3ds.payment_source.card.authentication_result.liability_shift ); |
| 1888 |
document.delivery_form.appendChild( elem_liability_shift ); |
| 1889 |
var elem_enrollment_status = document.createElement( "input" ); |
| 1890 |
elem_enrollment_status.setAttribute( "type", "hidden" ); |
| 1891 |
elem_enrollment_status.setAttribute( "name", "paypal_enrollment_status" ); |
| 1892 |
elem_enrollment_status.setAttribute( "value", res3ds.payment_source.card.authentication_result.three_d_secure.enrollment_status ); |
| 1893 |
document.delivery_form.appendChild( elem_enrollment_status ); |
| 1894 |
var elem_authentication_status = document.createElement( "input" ); |
| 1895 |
elem_authentication_status.setAttribute( "type", "hidden" ); |
| 1896 |
elem_authentication_status.setAttribute( "name", "paypal_authentication_status" ); |
| 1897 |
elem_authentication_status.setAttribute( "value", res3ds.payment_source.card.authentication_result.three_d_secure.authentication_status ); |
| 1898 |
document.delivery_form.appendChild( elem_authentication_status ); |
| 1899 |
var elem_confirm = document.createElement( "input" ); |
| 1900 |
elem_confirm.setAttribute( "type", "hidden" ); |
| 1901 |
elem_confirm.setAttribute( "name", "confirm" ); |
| 1902 |
elem_confirm.setAttribute( "value", "confirm" ); |
| 1903 |
document.delivery_form.appendChild( elem_confirm ); |
| 1904 |
document.delivery_form.submit(); |
| 1905 |
}); |
| 1906 |
} else { |
| 1907 |
alert( "3D Secure authorization failed. Please try another card number." ); |
| 1908 |
return false; |
| 1909 |
} |
| 1910 |
<?php else : ?> |
| 1911 |
document.getElementById( "paypal_resource_id" ).value = payload.orderId; |
| 1912 |
var elem_confirm = document.createElement( "input" ); |
| 1913 |
elem_confirm.setAttribute( "type", "hidden" ); |
| 1914 |
elem_confirm.setAttribute( "name", "confirm" ); |
| 1915 |
elem_confirm.setAttribute( "value", "confirm" ); |
| 1916 |
document.delivery_form.appendChild( elem_confirm ); |
| 1917 |
document.delivery_form.submit(); |
| 1918 |
<?php endif; ?> |
| 1919 |
}).catch(( reason ) => { |
| 1920 |
document.getElementById( "welcart-overlay" ).style.display = 'none'; |
| 1921 |
alert( 'Payment could not be captured! ' + reason.name + ' ' + reason.message ); |
| 1922 |
return false; |
| 1923 |
}); |
| 1924 |
} |
| 1925 |
} |
| 1926 |
}).catch( function( err ) { |
| 1927 |
if ( err ) { |
| 1928 |
alert( 'Payment could not be captured! ' + JSON.stringify( err ) ); |
| 1929 |
return false; |
| 1930 |
} |
| 1931 |
}); |
| 1932 |
} else { |
| 1933 |
document.querySelector( "#paypal_card_form" ).style = 'display: none'; |
| 1934 |
} |
| 1935 |
</script> |
| 1936 |
<?php |
| 1937 |
elseif ( 'confirm' === $usces->page ) : |
| 1938 |
$entry = $usces->cart->get_entry(); |
| 1939 |
$cart = $usces->cart->get_cart(); |
| 1940 |
if ( empty( $cart ) || empty( $entry['order']['total_full_price'] ) ) { |
| 1941 |
return; |
| 1942 |
} |
| 1943 |
|
| 1944 |
$payment = usces_get_payments_by_name( $entry['order']['payment_name'] ); |
| 1945 |
|
| 1946 |
/* PayPal CP */ |
| 1947 |
if ( 'acting_paypal_cp' === $payment['settlement'] && 'activate' === $payment['use'] ) : |
| 1948 |
$continue = ( defined( 'WCEX_DLSELLER' ) ) ? usces_have_continue_charge( $cart ) : false; |
| 1949 |
$regular = ( defined( 'WCEX_AUTO_DELIVERY' ) ) ? usces_have_regular_order() : false; |
| 1950 |
|
| 1951 |
$acting_opts = $this->get_acting_settings(); |
| 1952 |
$cp_client_id = ( isset( $acting_opts['client_id'] ) ) ? $acting_opts['client_id'] : ''; |
| 1953 |
$cp_intent = ( isset( $acting_opts['intent'] ) ) ? $acting_opts['intent'] : ''; |
| 1954 |
$cp_button_layout = ( isset( $acting_opts['button_layout'] ) ) ? $acting_opts['button_layout'] : 'vertical'; |
| 1955 |
$cp_button_color = ( isset( $acting_opts['button_color'] ) ) ? $acting_opts['button_color'] : 'gold'; |
| 1956 |
$cp_button_shape = ( isset( $acting_opts['button_shape'] ) ) ? $acting_opts['button_shape'] : 'rect'; |
| 1957 |
$cp_button_label = ( isset( $acting_opts['button_label'] ) ) ? $acting_opts['button_label'] : 'paypal'; |
| 1958 |
|
| 1959 |
$currency_code = $usces->get_currency_code(); |
| 1960 |
$query = array(); |
| 1961 |
$query['client-id'] = $cp_client_id; |
| 1962 |
$query['currency'] = $currency_code; |
| 1963 |
$query['locale'] = $this->get_locale(); |
| 1964 |
if ( $continue || $regular ) { |
| 1965 |
$query['vault'] = 'true'; |
| 1966 |
$query['intent'] = 'tokenize'; |
| 1967 |
$billing = ( $continue ) ? 'continue' : 'regular'; |
| 1968 |
} else { |
| 1969 |
if ( 'AUTHORIZE' === $cp_intent ) { |
| 1970 |
$query['intent'] = 'authorize'; |
| 1971 |
} |
| 1972 |
} |
| 1973 |
$sdk_query = http_build_query( $query ); |
| 1974 |
?> |
| 1975 |
<script src="https://www.paypal.com/sdk/js?<?php echo $sdk_query; // no escape due to fixed format. ?>"></script> |
| 1976 |
<script> |
| 1977 |
paypal.Buttons({ |
| 1978 |
style: { |
| 1979 |
layout: "<?php echo esc_html( $cp_button_layout ); ?>", |
| 1980 |
color: "<?php echo esc_html( $cp_button_color ); ?>", |
| 1981 |
shape: "<?php echo esc_html( $cp_button_shape ); ?>", |
| 1982 |
label: "<?php echo esc_html( $cp_button_label ); ?>" |
| 1983 |
},<?php if ( $continue || $regular ) : ?> |
| 1984 |
createBillingAgreement: function() { |
| 1985 |
let params = new URLSearchParams(); |
| 1986 |
params.append( "action", "create_billing_agreement" ); |
| 1987 |
params.append( "tracking_id", document.getElementsByName( "tracking_id" )[0].value ); |
| 1988 |
params.append( "billing", "<?php echo esc_html( $billing ); ?>" ); |
| 1989 |
return fetch( uscesL10n.ajaxurl, { |
| 1990 |
method: "POST", |
| 1991 |
body: params |
| 1992 |
}).then( function( res ) { |
| 1993 |
return res.json(); |
| 1994 |
}).then( function( data ) { |
| 1995 |
if ( data.stock && 'error' == data.stock ) { |
| 1996 |
location.href = "<?php echo esc_js( USCES_CART_URL ); ?>"; |
| 1997 |
} |
| 1998 |
return data.token_id; |
| 1999 |
}); |
| 2000 |
}, |
| 2001 |
onApprove: function( data ) { |
| 2002 |
document.getElementById( "checkout_paypal_cp" ).style.pointerEvents = "none"; |
| 2003 |
var purchase_form = document.forms.purchase_form; |
| 2004 |
purchase_form.resource_id.value = data.orderID; |
| 2005 |
purchase_form.billing_token.value = data.billingToken; |
| 2006 |
purchase_form.submit(); |
| 2007 |
},<?php else : ?> |
| 2008 |
createOrder: function() { |
| 2009 |
let params = new URLSearchParams(); |
| 2010 |
params.append( "action", "create_order" ); |
| 2011 |
params.append( "tracking_id", document.getElementsByName( "tracking_id" )[0].value ); |
| 2012 |
return fetch( uscesL10n.ajaxurl, { |
| 2013 |
method: "POST", |
| 2014 |
body: params |
| 2015 |
}).then( function( res ) { |
| 2016 |
return res.json(); |
| 2017 |
}).then( function( data ) { |
| 2018 |
if ( data.stock && 'error' == data.stock ) { |
| 2019 |
location.href = "<?php echo esc_js( USCES_CART_URL ); ?>"; |
| 2020 |
} |
| 2021 |
return data.id; |
| 2022 |
}); |
| 2023 |
}, |
| 2024 |
onApprove: function( data ) { |
| 2025 |
document.getElementById( "checkout_paypal_cp" ).style.pointerEvents = "none"; |
| 2026 |
var purchase_form = document.forms.purchase_form; |
| 2027 |
purchase_form.resource_id.value = data.orderID; |
| 2028 |
purchase_form.submit(); |
| 2029 |
},<?php endif; ?> |
| 2030 |
onCancel: function( data ) { |
| 2031 |
}, |
| 2032 |
onError: function( err ) { |
| 2033 |
alert( err ); |
| 2034 |
} |
| 2035 |
}).render( "#checkout_paypal_cp" ); |
| 2036 |
</script> |
| 2037 |
<?php |
| 2038 |
endif; |
| 2039 |
elseif ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) && ( $this->is_validity_acting( 'cp' ) || $this->is_validity_acting( 'card' ) ) ) : |
| 2040 |
$member = $usces->get_member(); |
| 2041 |
if ( usces_have_member_continue_order( $member['ID'] ) || usces_have_member_regular_order( $member['ID'] ) ) : |
| 2042 |
?> |
| 2043 |
<script type="text/javascript"> |
| 2044 |
jQuery( document ).ready( function( $ ) { |
| 2045 |
$( "input[name='deletemember']" ).css( "display", "none" ); |
| 2046 |
}); |
| 2047 |
</script> |
| 2048 |
<?php |
| 2049 |
endif; |
| 2050 |
$usces_page = ( isset( $_GET['usces_page'] ) ) ? wp_unslash( $_GET['usces_page'] ) : ''; |
| 2051 |
if ( $this->is_validity_acting( 'card' ) && ( 'member_update_settlement' === $usces_page || 'member_register_settlement' === $usces_page ) ) : |
| 2052 |
$acting_opts = $this->get_acting_settings(); |
| 2053 |
$cp_client_id = ( isset( $acting_opts['client_id'] ) ) ? $acting_opts['client_id'] : ''; |
| 2054 |
$card_vault = ( isset( $acting_opts['card_vault'] ) ) ? $acting_opts['card_vault'] : 'off'; |
| 2055 |
if ( 'on' !== $card_vault ) { |
| 2056 |
return; |
| 2057 |
} |
| 2058 |
|
| 2059 |
$member = $usces->get_member(); |
| 2060 |
$currency_code = $usces->get_currency_code(); |
| 2061 |
|
| 2062 |
$query = array(); |
| 2063 |
$query['components'] = 'hosted-fields'; |
| 2064 |
$query['client-id'] = $cp_client_id; |
| 2065 |
$query['currency'] = $currency_code; |
| 2066 |
$query['locale'] = $this->get_locale(); |
| 2067 |
$query['intent'] = 'authorize'; |
| 2068 |
$sdk_query = http_build_query( $query ); |
| 2069 |
$client_token = $this->get_client_token( $member['ID'] ); |
| 2070 |
?> |
| 2071 |
<div id="welcart-overlay" style="display:none"><div id="welcart-loading"></div><div id="welcart-loading-text"><?php esc_html_e( 'Processing...', 'usces' ); ?></div></div> |
| 2072 |
<script src="https://www.paypal.com/sdk/js?<?php echo $sdk_query; // no escape due to fixed format. ?>" data-client-token="<?php echo $client_token; // no escape due to fixed format. ?>"></script> |
| 2073 |
<script> |
| 2074 |
document.getElementById( "welcart-overlay" ).style.display = 'none'; |
| 2075 |
if ( paypal.HostedFields.isEligible() ) { |
| 2076 |
paypal.HostedFields.render({ |
| 2077 |
createOrder: function() { |
| 2078 |
let params = new URLSearchParams(); |
| 2079 |
params.append( "action", "create_order_member" ); |
| 2080 |
params.append( "tracking_id", document.getElementById( "paypal_tracking_id" ).value ); |
| 2081 |
return fetch( uscesL10n.ajaxurl, { |
| 2082 |
method: "POST", |
| 2083 |
body: params |
| 2084 |
}).then( function( res ) { |
| 2085 |
return res.json(); |
| 2086 |
}).then( function( data ) { |
| 2087 |
if ( data.message ) { |
| 2088 |
alert( data.message ); |
| 2089 |
return false; |
| 2090 |
} |
| 2091 |
document.getElementById( "paypal_resource_id" ).value = data.id; |
| 2092 |
return data.id; |
| 2093 |
}); |
| 2094 |
}, |
| 2095 |
fields: { |
| 2096 |
number: { |
| 2097 |
selector: "#card-number", |
| 2098 |
placeholder: "4111 1111 1111 1111" |
| 2099 |
}, |
| 2100 |
expirationDate: { |
| 2101 |
selector: "#expiration-date", |
| 2102 |
placeholder: "MM/YY" |
| 2103 |
}, |
| 2104 |
cvv: { |
| 2105 |
selector: "#cvv", |
| 2106 |
placeholder: "123" |
| 2107 |
} |
| 2108 |
}, |
| 2109 |
styles: { |
| 2110 |
'.valid': { |
| 2111 |
'color': 'green' |
| 2112 |
}, |
| 2113 |
'.invalid': { |
| 2114 |
'color': 'red' |
| 2115 |
} |
| 2116 |
} |
| 2117 |
}).then( function( hostedFieldsInstance ) { |
| 2118 |
document.querySelector( "#card-update" ).onclick = function( event ) { |
| 2119 |
document.getElementById( "welcart-overlay" ).style.display = 'block'; |
| 2120 |
event.preventDefault(); |
| 2121 |
hostedFieldsInstance.submit({ |
| 2122 |
vault: true |
| 2123 |
}).then( function( payload ) { |
| 2124 |
document.getElementById( "paypal_resource_id" ).value = payload.orderId; |
| 2125 |
document.member_card_update.submit(); |
| 2126 |
}).catch(( reason ) => { |
| 2127 |
document.getElementById( "welcart-overlay" ).style.display = 'none'; |
| 2128 |
alert( 'Credit card could not be renewed! ' + reason.name + ' ' + reason.message ); |
| 2129 |
}); |
| 2130 |
} |
| 2131 |
}).catch( function( err ) { |
| 2132 |
if ( err ) { |
| 2133 |
alert( 'Credit card could not be renewed! ' + JSON.stringify( err ) ); |
| 2134 |
} |
| 2135 |
}); |
| 2136 |
} else { |
| 2137 |
document.querySelector( "#paypal_card_form" ).style = 'display: none'; |
| 2138 |
} |
| 2139 |
</script> |
| 2140 |
<?php |
| 2141 |
print_google_recaptcha_response( $usces->page, 'member-card-update', 'member_card_update' ); |
| 2142 |
endif; |
| 2143 |
endif; |
| 2144 |
} |
| 2145 |
|
| 2146 |
/** |
| 2147 |
* Get FraudNet Session Identifier. |
| 2148 |
*/ |
| 2149 |
private function get_fraudnet_session_id() { |
| 2150 |
$session_id = substr( base_convert( hash( 'sha256', uniqid() ), 16, 36 ), 0, 32 ); |
| 2151 |
return $session_id; |
| 2152 |
} |
| 2153 |
|
| 2154 |
/** |
| 2155 |
* Get seller nonce. |
| 2156 |
* S256 - The code verifier must be high-entropy cryptographic random string with a byte length of 43-128 range. |
| 2157 |
*/ |
| 2158 |
private function get_seller_nonce() { |
| 2159 |
$seller_nonce = substr( base_convert( hash( 'sha256', uniqid() ), 16, 36 ), 0, 48 ); |
| 2160 |
return $seller_nonce; |
| 2161 |
} |
| 2162 |
|
| 2163 |
/** |
| 2164 |
* Get Access Token. |
| 2165 |
*/ |
| 2166 |
private function get_access_token() { |
| 2167 |
$acting_opts = $this->get_acting_settings(); |
| 2168 |
$cp_client_id = ( isset( $acting_opts['client_id'] ) ) ? $acting_opts['client_id'] : ''; |
| 2169 |
$cp_secret = ( isset( $acting_opts['secret'] ) ) ? $acting_opts['secret'] : ''; |
| 2170 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 2171 |
$headers = array( |
| 2172 |
'Content-Type: application/x-www-form-urlencoded;application/json', |
| 2173 |
'Accept: application/json', |
| 2174 |
); |
| 2175 |
$ch = curl_init(); |
| 2176 |
curl_setopt( $ch, CURLOPT_URL, $api_request_url . '/v1/oauth2/token' ); |
| 2177 |
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
| 2178 |
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); |
| 2179 |
curl_setopt( $ch, CURLOPT_USERPWD, $cp_client_id . ':' . $cp_secret ); |
| 2180 |
curl_setopt( $ch, CURLOPT_POST, true ); |
| 2181 |
curl_setopt( $ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials' ); |
| 2182 |
|
| 2183 |
$result = curl_exec( $ch ); |
| 2184 |
if ( ! $result ) { |
| 2185 |
$error = curl_error( $ch ); |
| 2186 |
unset( $ch ); |
| 2187 |
return json_decode( $error, true ); |
| 2188 |
} |
| 2189 |
unset( $ch ); |
| 2190 |
return json_decode( $result, true ); |
| 2191 |
} |
| 2192 |
|
| 2193 |
/** |
| 2194 |
* Get Client Token. |
| 2195 |
* |
| 2196 |
* @param string $customer_id Member ID. |
| 2197 |
* @return string |
| 2198 |
*/ |
| 2199 |
private function get_client_token( $customer_id = '' ) { |
| 2200 |
$acting_opts = $this->get_acting_settings(); |
| 2201 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 2202 |
$card_prefix = ( isset( $acting_opts['card_prefix'] ) ) ? $acting_opts['card_prefix'] : ''; |
| 2203 |
|
| 2204 |
/* Get Access Token */ |
| 2205 |
$access_token = $this->get_access_token(); |
| 2206 |
|
| 2207 |
$params = array( |
| 2208 |
'method' => 'POST', |
| 2209 |
'headers' => array( |
| 2210 |
'Content-Type' => 'application/json;charset=utf-8', |
| 2211 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 2212 |
), |
| 2213 |
'timeout' => self::API_TIMEOUT, |
| 2214 |
); |
| 2215 |
if ( ! empty( $customer_id ) ) { |
| 2216 |
$body = array(); |
| 2217 |
$body['customer_id'] = $card_prefix . $customer_id; |
| 2218 |
$params['body'] = wp_json_encode( $body ); |
| 2219 |
} |
| 2220 |
$response = wp_remote_post( $api_request_url . '/v1/identity/generate-token', $params ); |
| 2221 |
$response_data = json_decode( wp_remote_retrieve_body( $response ) ); |
| 2222 |
return $response_data->client_token; |
| 2223 |
} |
| 2224 |
|
| 2225 |
/** |
| 2226 |
* Onboarded. |
| 2227 |
* Get seller REST API credentials. |
| 2228 |
*/ |
| 2229 |
public function onboarded() { |
| 2230 |
if ( ! current_user_can( 'wel_manage_setting' ) ) { |
| 2231 |
wp_send_json_error( array( 'message' => 'Forbidden' ), 403 ); |
| 2232 |
} |
| 2233 |
check_ajax_referer( 'admin_settlement', 'wc_nonce' ); |
| 2234 |
|
| 2235 |
$acting_opts = $this->get_acting_settings(); |
| 2236 |
$api_request_url = self::API_URL; |
| 2237 |
|
| 2238 |
$seller_nonce = $this->get_seller_nonce(); |
| 2239 |
$auth_code = $_POST['authCode']; |
| 2240 |
$shared_id = $_POST['sharedId']; |
| 2241 |
$seller_nonce = $_POST['seller_nonce']; |
| 2242 |
|
| 2243 |
$headers = array( |
| 2244 |
'Content-Type: application/x-www-form-urlencoded;application/json', |
| 2245 |
'Accept: application/json', |
| 2246 |
); |
| 2247 |
$ch = curl_init(); |
| 2248 |
curl_setopt( $ch, CURLOPT_URL, $api_request_url . '/v1/oauth2/token' ); |
| 2249 |
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
| 2250 |
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); |
| 2251 |
curl_setopt( $ch, CURLOPT_USERPWD, $shared_id . ':' ); |
| 2252 |
curl_setopt( $ch, CURLOPT_POST, true ); |
| 2253 |
curl_setopt( $ch, CURLOPT_POSTFIELDS, 'grant_type=authorization_code&code=' . $auth_code . '&code_verifier=' . $seller_nonce ); |
| 2254 |
|
| 2255 |
$result = curl_exec( $ch ); |
| 2256 |
unset( $ch ); |
| 2257 |
$seller_access_token = json_decode( $result, true ); |
| 2258 |
if ( isset( $seller_access_token['access_token'] ) ) { |
| 2259 |
$partner_merchant_id = 'T7SS625X3B32Q'; |
| 2260 |
$params = array( |
| 2261 |
'method' => 'GET', |
| 2262 |
'headers' => array( |
| 2263 |
'Content-Type' => 'application/json;charset=utf-8', |
| 2264 |
'Authorization' => 'Bearer ' . $seller_access_token['access_token'], |
| 2265 |
), |
| 2266 |
'timeout' => self::API_TIMEOUT, |
| 2267 |
); |
| 2268 |
$response = wp_remote_get( $api_request_url . '/v1/customer/partners/' . $partner_merchant_id . '/merchant-integrations/credentials/', $params ); |
| 2269 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 2270 |
wp_send_json( $response_data ); |
| 2271 |
} else { |
| 2272 |
wp_send_json( $seller_access_token ); |
| 2273 |
} |
| 2274 |
} |
| 2275 |
|
| 2276 |
/** |
| 2277 |
* Create billing agreement. |
| 2278 |
*/ |
| 2279 |
/** |
| 2280 |
* A5 (Layer 3 / uscesid removal): reopen the shopper's shop session from its own |
| 2281 |
* same-origin session cookie (USCES_KEY) instead of decoding a crafted `uscesid` GET |
| 2282 |
* param through uscesdc()/session_id(). These nopriv admin-ajax handlers run under |
| 2283 |
* admin-ajax.php, where usces_close_session() (admin_init) has closed the bootstrap |
| 2284 |
* session, so session_status() is PHP_SESSION_NONE here. get_entry()/get_cart()/ |
| 2285 |
* get_member() read $_SESSION live, so reattaching before they run restores the |
| 2286 |
* shopper's cart/entry/member. Mirrors A2 (cart-monitor) / A6 (Zeus enrol). |
| 2287 |
* The uk session cookie is HttpOnly but is still sent on same-origin fetch() |
| 2288 |
* (default credentials: 'same-origin') and readable via $_COOKIE. |
| 2289 |
* See .docs/welcart2.x/security-remediation_uscesid-layer3-a3-a6-design.md A5. |
| 2290 |
*/ |
| 2291 |
private function reattach_shop_session() { |
| 2292 |
if ( PHP_SESSION_NONE === session_status() ) { |
| 2293 |
$usces_options = get_option( 'usces' ); |
| 2294 |
$sess_name = defined( 'USCES_KEY' ) ? USCES_KEY : ( isset( $usces_options['usces_key'] ) ? $usces_options['usces_key'] : '' ); |
| 2295 |
if ( '' !== $sess_name && ! empty( $_COOKIE[ $sess_name ] ) ) { |
| 2296 |
$sess_id = preg_replace( '/[^A-Za-z0-9,\-]/', '', wp_unslash( $_COOKIE[ $sess_name ] ) ); |
| 2297 |
session_id( $sess_id ); |
| 2298 |
@session_start(); // phpcs:ignore |
| 2299 |
} |
| 2300 |
} |
| 2301 |
} |
| 2302 |
|
| 2303 |
public function create_billing_agreement() { |
| 2304 |
global $usces; |
| 2305 |
|
| 2306 |
$this->reattach_shop_session(); |
| 2307 |
$entry = $usces->cart->get_entry(); |
| 2308 |
$cart = $usces->cart->get_cart(); |
| 2309 |
|
| 2310 |
$usces->error_message = $usces->zaiko_check(); |
| 2311 |
if ( ! empty( $usces->error_message ) || 0 === (int) $usces->cart->num_row() ) { |
| 2312 |
wp_send_json( array( 'stock' => 'error' ) ); |
| 2313 |
} |
| 2314 |
|
| 2315 |
$tracking_id = wp_unslash( $_POST['tracking_id'] ); |
| 2316 |
$billing = wp_unslash( $_POST['billing'] ); /* continue|regular */ |
| 2317 |
$shipping = usces_have_shipped( $cart ); |
| 2318 |
|
| 2319 |
$acting_opts = $this->get_acting_settings(); |
| 2320 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 2321 |
|
| 2322 |
/* Get Access Token */ |
| 2323 |
$access_token = $this->get_access_token(); |
| 2324 |
|
| 2325 |
if ( 'continue' === $billing ) { |
| 2326 |
$description = __( '[ Automatic recurring billing ]', 'usces' ); |
| 2327 |
} elseif ( 'regular' === $billing ) { |
| 2328 |
$description = __( '[ Regular Purchase ]', 'usces' ); |
| 2329 |
} else { |
| 2330 |
$description = 'Billing Agreement.'; |
| 2331 |
} |
| 2332 |
|
| 2333 |
$body = array(); |
| 2334 |
$body['description'] = $description; |
| 2335 |
$body['payer']['payment_method'] = 'PAYPAL'; |
| 2336 |
$body['plan']['type'] = 'MERCHANT_INITIATED_BILLING'; |
| 2337 |
$body['plan']['merchant_preferences']['return_url'] = USCES_CART_URL; |
| 2338 |
$body['plan']['merchant_preferences']['cancel_url'] = USCES_CART_URL; |
| 2339 |
$body['plan']['merchant_preferences']['accepted_pymt_type'] = 'INSTANT'; |
| 2340 |
if ( $shipping ) { |
| 2341 |
$name = usces_localized_name( trim( $entry['delivery']['name1'] ), trim( $entry['delivery']['name2'] ), 'return' ); |
| 2342 |
$country = ( ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : usces_get_base_country(); |
| 2343 |
$country_code = apply_filters( 'usces_filter_paypalcp_shipping_country_code', $country ); |
| 2344 |
$shipping_address = array(); |
| 2345 |
$body['shipping_address']['line2'] = trim( $entry['delivery']['address3'] ); |
| 2346 |
$body['shipping_address']['line1'] = trim( $entry['delivery']['address2'] ); |
| 2347 |
$body['shipping_address']['city'] = trim( $entry['delivery']['address1'] ); |
| 2348 |
$body['shipping_address']['state'] = trim( $entry['delivery']['pref'] ); |
| 2349 |
$body['shipping_address']['postal_code'] = trim( $entry['delivery']['zipcode'] ); |
| 2350 |
$body['shipping_address']['country_code'] = $country_code; |
| 2351 |
$body['shipping_address']['recipient_name'] = $name; |
| 2352 |
$body['plan']['merchant_preferences']['skip_shipping_address'] = false; |
| 2353 |
$body['plan']['merchant_preferences']['immutable_shipping_address'] = true; |
| 2354 |
} else { |
| 2355 |
$body['plan']['merchant_preferences']['skip_shipping_address'] = true; |
| 2356 |
$body['plan']['merchant_preferences']['immutable_shipping_address'] = false; |
| 2357 |
} |
| 2358 |
|
| 2359 |
$params = array( |
| 2360 |
'method' => 'POST', |
| 2361 |
'headers' => array( |
| 2362 |
'Content-Type' => 'application/json;charset=utf-8', |
| 2363 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 2364 |
'PayPal-Partner-Attribution-Id' => self::API_BN_CODE_PCP, |
| 2365 |
'PayPal-Request-Id' => $tracking_id, |
| 2366 |
), |
| 2367 |
'timeout' => self::API_TIMEOUT, |
| 2368 |
'body' => wp_json_encode( $body ), |
| 2369 |
); |
| 2370 |
$response = wp_remote_post( $api_request_url . '/v1/billing-agreements/agreement-tokens', $params ); |
| 2371 |
$response_data = json_decode( wp_remote_retrieve_body( $response ) ); |
| 2372 |
wp_send_json( $response_data ); |
| 2373 |
} |
| 2374 |
|
| 2375 |
/** |
| 2376 |
* Create order. |
| 2377 |
*/ |
| 2378 |
public function create_order() { |
| 2379 |
global $usces; |
| 2380 |
|
| 2381 |
$this->reattach_shop_session(); |
| 2382 |
$entry = $usces->cart->get_entry(); |
| 2383 |
$cart = $usces->cart->get_cart(); |
| 2384 |
|
| 2385 |
$usces->error_message = $usces->zaiko_check(); |
| 2386 |
if ( ! empty( $usces->error_message ) || 0 === (int) $usces->cart->num_row() ) { |
| 2387 |
wp_send_json( array( 'stock' => 'error' ) ); |
| 2388 |
} |
| 2389 |
|
| 2390 |
$bn_code = self::API_BN_CODE_PCP; |
| 2391 |
$tracking_id = wp_unslash( $_POST['tracking_id'] ); |
| 2392 |
|
| 2393 |
/* Get Access Token */ |
| 2394 |
$access_token = $this->get_access_token(); |
| 2395 |
|
| 2396 |
/* Create order */ |
| 2397 |
$response_data = $this->api_create_order( $access_token, $bn_code, '', $tracking_id, $entry, $cart, false ); |
| 2398 |
wp_send_json( $response_data ); |
| 2399 |
} |
| 2400 |
|
| 2401 |
/** |
| 2402 |
* Create order. |
| 2403 |
*/ |
| 2404 |
public function create_order_card() { |
| 2405 |
global $usces; |
| 2406 |
|
| 2407 |
$this->reattach_shop_session(); |
| 2408 |
$entry = $usces->cart->get_entry(); |
| 2409 |
$cart = $usces->cart->get_cart(); |
| 2410 |
|
| 2411 |
$usces->error_message = $usces->zaiko_check(); |
| 2412 |
if ( ! empty( $usces->error_message ) || 0 === (int) $usces->cart->num_row() ) { |
| 2413 |
wp_send_json( array( 'stock' => 'error' ) ); |
| 2414 |
} |
| 2415 |
|
| 2416 |
$bn_code = self::API_BN_CODE_ACDC; |
| 2417 |
$tracking_id = wp_unslash( $_POST['tracking_id'] ); |
| 2418 |
$entry['order']['total_items_price'] = $usces->get_total_price( $cart ); |
| 2419 |
$entry['pre_card_order'] = true; |
| 2420 |
|
| 2421 |
/* Get Access Token */ |
| 2422 |
$access_token = $this->get_access_token(); |
| 2423 |
|
| 2424 |
/* Create order */ |
| 2425 |
$response_data = $this->api_create_order( $access_token, $bn_code, '', $tracking_id, $entry, $cart, false ); |
| 2426 |
wp_send_json( $response_data ); |
| 2427 |
} |
| 2428 |
|
| 2429 |
/** |
| 2430 |
* Create order. |
| 2431 |
*/ |
| 2432 |
public function create_order_member() { |
| 2433 |
global $usces; |
| 2434 |
|
| 2435 |
$this->reattach_shop_session(); |
| 2436 |
$acting_opts = $this->get_acting_settings(); |
| 2437 |
$tracking_id = wp_unslash( $_POST['tracking_id'] ); |
| 2438 |
|
| 2439 |
/* Get Access Token */ |
| 2440 |
$access_token = $this->get_access_token(); |
| 2441 |
|
| 2442 |
/* Create order */ |
| 2443 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 2444 |
$currency_code = $usces->get_currency_code(); |
| 2445 |
|
| 2446 |
$body = array(); |
| 2447 |
$body['intent'] = 'AUTHORIZE'; |
| 2448 |
$purchase_units = array(); |
| 2449 |
$purchase_units['reference_id'] = $tracking_id; |
| 2450 |
$purchase_units['amount']['currency_code'] = $currency_code; |
| 2451 |
$purchase_units['amount']['value'] = 10; |
| 2452 |
$body['purchase_units'] = array( $purchase_units ); |
| 2453 |
|
| 2454 |
$member = $usces->get_member(); |
| 2455 |
$payer = array(); |
| 2456 |
$phone = ( ! empty( $member['tel'] ) ) ? str_replace( array( '-', '+', ' ' ), '', mb_convert_kana( $member['tel'], 'a', 'UTF-8' ) ) : ''; |
| 2457 |
$country = ( ! empty( $member['country'] ) ) ? $member['country'] : usces_get_base_country(); |
| 2458 |
$country_code = apply_filters( 'usces_filter_paypalcp_customer_country_code', $country ); |
| 2459 |
$payer['name']['given_name'] = trim( $member['name2'] ); |
| 2460 |
$payer['name']['surname'] = trim( $member['name1'] ); |
| 2461 |
$payer['email_address'] = trim( $member['mailaddress1'] ); |
| 2462 |
if ( ! empty( $phone ) ) { |
| 2463 |
$payer['phone']['phone_number']['national_number'] = ltrim( $phone, '0' ); |
| 2464 |
} |
| 2465 |
if ( ! empty( $member['address1'] ) ) { |
| 2466 |
$payer['address']['address_line_2'] = trim( $member['address3'] ); |
| 2467 |
$payer['address']['address_line_1'] = trim( $member['address2'] ); |
| 2468 |
$payer['address']['admin_area_2'] = trim( $member['address1'] ); |
| 2469 |
} |
| 2470 |
if ( ! empty( $member['pref'] ) ) { |
| 2471 |
$payer['address']['admin_area_1'] = trim( $member['pref'] ); |
| 2472 |
} |
| 2473 |
if ( ! empty( $member['zipcode'] ) ) { |
| 2474 |
$payer['address']['postal_code'] = trim( mb_convert_kana( $member['zipcode'], 'a', 'UTF-8' ) ); |
| 2475 |
} |
| 2476 |
$payer['address']['country_code'] = $country_code; |
| 2477 |
$body['payer'] = $payer; |
| 2478 |
|
| 2479 |
$params = array( |
| 2480 |
'method' => 'POST', |
| 2481 |
'headers' => array( |
| 2482 |
'Content-Type' => 'application/json;charset=utf-8', |
| 2483 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 2484 |
'PayPal-Partner-Attribution-Id' => self::API_BN_CODE_ACDC, |
| 2485 |
'PayPal-Request-Id' => $tracking_id, |
| 2486 |
), |
| 2487 |
'timeout' => self::API_TIMEOUT, |
| 2488 |
'body' => wp_json_encode( $body ), |
| 2489 |
); |
| 2490 |
$response = wp_remote_post( $api_request_url . '/v2/checkout/orders', $params ); |
| 2491 |
if ( isset( $response['response']['code'] ) && ( '200' === (string) $response['response']['code'] || '201' === (string) $response['response']['code'] ) ) { |
| 2492 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 2493 |
} else { |
| 2494 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 2495 |
if ( is_array( $response_data ) && ! isset( $response_data['status'] ) && ! isset( $response_data['name'] ) ) { |
| 2496 |
$response_data['name'] = 'CREATE ORDER ERROR'; |
| 2497 |
} |
| 2498 |
} |
| 2499 |
wp_send_json( $response_data ); |
| 2500 |
} |
| 2501 |
|
| 2502 |
/** |
| 2503 |
* Show Order Details. |
| 2504 |
*/ |
| 2505 |
public function show_order_details_card() { |
| 2506 |
$bn_code = self::API_BN_CODE_ACDC; |
| 2507 |
$tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : ''; /* rand|reference_id */ |
| 2508 |
$resource_id = ( isset( $_POST['resource_id'] ) ) ? wp_unslash( $_POST['resource_id'] ) : ''; |
| 2509 |
|
| 2510 |
/* Get Access Token */ |
| 2511 |
$access_token = $this->get_access_token(); |
| 2512 |
|
| 2513 |
/* Get order */ |
| 2514 |
$response_data = $this->api_get_order( $access_token, $bn_code, $tracking_id, $resource_id ); |
| 2515 |
wp_send_json( $response_data ); |
| 2516 |
} |
| 2517 |
|
| 2518 |
/** |
| 2519 |
* 決済処理 |
| 2520 |
* usces_action_acting_processing |
| 2521 |
* |
| 2522 |
* @param string $acting_flg Payment type. |
| 2523 |
* @param array $post_query Post data. |
| 2524 |
*/ |
| 2525 |
public function acting_processing( $acting_flg, $post_query ) { |
| 2526 |
global $usces; |
| 2527 |
|
| 2528 |
if ( 'acting_paypal_cp' === $acting_flg ) { |
| 2529 |
parse_str( $post_query, $post_data ); |
| 2530 |
$tracking_id = ( isset( $post_data['tracking_id'] ) ) ? $post_data['tracking_id'] : ''; /* rand|reference_id */ |
| 2531 |
$resource_id = ( isset( $post_data['resource_id'] ) ) ? $post_data['resource_id'] : ''; |
| 2532 |
$billing_token = ( isset( $post_data['billing_token'] ) ) ? $post_data['billing_token'] : ''; |
| 2533 |
|
| 2534 |
if ( empty( $tracking_id ) ) { |
| 2535 |
$log = array( |
| 2536 |
'acting' => $this->paymod_id, |
| 2537 |
'key' => '(empty)', |
| 2538 |
'result' => 'ON APPROVE ERROR', |
| 2539 |
'data' => $post_data, |
| 2540 |
); |
| 2541 |
usces_save_order_acting_error( $log ); |
| 2542 |
wp_redirect( |
| 2543 |
add_query_arg( |
| 2544 |
array( |
| 2545 |
'acting' => $this->paymod_id, |
| 2546 |
'acting_return' => 0, |
| 2547 |
'result' => 0, |
| 2548 |
), |
| 2549 |
USCES_CART_URL |
| 2550 |
) |
| 2551 |
); |
| 2552 |
exit(); |
| 2553 |
} |
| 2554 |
|
| 2555 |
$acting_opts = $this->get_acting_settings(); |
| 2556 |
$cp_intent = ( isset( $acting_opts['intent'] ) ) ? $acting_opts['intent'] : ''; |
| 2557 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 2558 |
$bn_code = self::API_BN_CODE_PCP; |
| 2559 |
$correlation_id = ''; |
| 2560 |
$payment_source = array(); |
| 2561 |
|
| 2562 |
/* Get Access Token */ |
| 2563 |
$access_token = $this->get_access_token(); |
| 2564 |
|
| 2565 |
if ( $billing_token ) { |
| 2566 |
$params_billing_agreements = array( |
| 2567 |
'method' => 'POST', |
| 2568 |
'headers' => array( |
| 2569 |
'Content-Type' => 'application/json;charset=utf-8', |
| 2570 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 2571 |
'PayPal-Partner-Attribution-Id' => $bn_code, |
| 2572 |
'PayPal-Request-Id' => $tracking_id, |
| 2573 |
), |
| 2574 |
'timeout' => self::API_TIMEOUT, |
| 2575 |
); |
| 2576 |
$response_billing_agreements = wp_remote_post( $api_request_url . '/v1/billing-agreements/' . $billing_token . '/agreements', $params_billing_agreements ); |
| 2577 |
$response_billing_agreements_data = json_decode( wp_remote_retrieve_body( $response_billing_agreements ), true ); |
| 2578 |
if ( isset( $response_billing_agreements['response']['code'] ) && '201' === (string) $response_billing_agreements['response']['code'] && isset( $response_billing_agreements_data['id'] ) ) { |
| 2579 |
$ba_id = $response_billing_agreements_data['id']; |
| 2580 |
$payment_source['token'] = array( |
| 2581 |
'id' => $ba_id, |
| 2582 |
'type' => 'BILLING_AGREEMENT', |
| 2583 |
); |
| 2584 |
$entry = $usces->cart->get_entry(); |
| 2585 |
$cart = $usces->cart->get_cart(); |
| 2586 |
$continue = ( defined( 'WCEX_DLSELLER' ) ) ? usces_have_continue_charge( $cart ) : false; |
| 2587 |
$regular = ( defined( 'WCEX_AUTO_DELIVERY' ) ) ? usces_have_regular_order() : false; |
| 2588 |
|
| 2589 |
if ( $continue ) { |
| 2590 |
$chargingday = $usces->getItemChargingDay( $cart[0]['post_id'] ); |
| 2591 |
/* 受注日課金 */ |
| 2592 |
if ( 99 !== (int) $chargingday ) { |
| 2593 |
$cp_intent = 'AUTHORIZE'; |
| 2594 |
} |
| 2595 |
} |
| 2596 |
|
| 2597 |
/* Create order */ |
| 2598 |
$response_order_data = $this->api_create_order( $access_token, $bn_code, $cp_intent, $tracking_id, $entry, $cart ); |
| 2599 |
if ( isset( $response_order_data['id'] ) && isset( $response_order_data['status'] ) && 'CREATED' === $response_order_data['status'] ) { |
| 2600 |
$resource_id = $response_order_data['id']; |
| 2601 |
} else { |
| 2602 |
$result = 'CREATE ORDER ERROR'; |
| 2603 |
$params_cancel_agreements = array( |
| 2604 |
'method' => 'POST', |
| 2605 |
'headers' => array( |
| 2606 |
'Content-Type' => 'application/json;charset=utf-8', |
| 2607 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 2608 |
'PayPal-Partner-Attribution-Id' => $bn_code, |
| 2609 |
'PayPal-Request-Id' => $tracking_id, |
| 2610 |
), |
| 2611 |
'timeout' => self::API_TIMEOUT, |
| 2612 |
); |
| 2613 |
$response_cancel_agreements = wp_remote_post( $api_request_url . '/v1/billing-agreements/agreements/' . $ba_id . '/cancel', $params_cancel_agreements ); |
| 2614 |
if ( isset( $response_cancel_agreements['response']['code'] ) && '200' === (string) $response_cancel_agreements['response']['code'] ) { |
| 2615 |
$result .= ' (BILLING AGREEMENT CANCEL COMPLETED)'; |
| 2616 |
} |
| 2617 |
$log = array( |
| 2618 |
'acting' => $this->paymod_id, |
| 2619 |
'key' => $tracking_id, |
| 2620 |
'result' => $result, |
| 2621 |
'data' => $response_order_data, |
| 2622 |
); |
| 2623 |
usces_save_order_acting_error( $log ); |
| 2624 |
wp_redirect( |
| 2625 |
add_query_arg( |
| 2626 |
array( |
| 2627 |
'acting' => $this->paymod_id, |
| 2628 |
'acting_return' => 0, |
| 2629 |
'result' => 0, |
| 2630 |
), |
| 2631 |
USCES_CART_URL |
| 2632 |
) |
| 2633 |
); |
| 2634 |
exit(); |
| 2635 |
} |
| 2636 |
} else { |
| 2637 |
$log = array( |
| 2638 |
'acting' => $this->paymod_id, |
| 2639 |
'key' => $tracking_id, |
| 2640 |
'result' => 'BILLING AGREEMENT ERROR', |
| 2641 |
'data' => $response_billing_agreements_data, |
| 2642 |
); |
| 2643 |
usces_save_order_acting_error( $log ); |
| 2644 |
wp_redirect( |
| 2645 |
add_query_arg( |
| 2646 |
array( |
| 2647 |
'acting' => $this->paymod_id, |
| 2648 |
'acting_return' => 0, |
| 2649 |
'result' => 0, |
| 2650 |
), |
| 2651 |
USCES_CART_URL |
| 2652 |
) |
| 2653 |
); |
| 2654 |
exit(); |
| 2655 |
} |
| 2656 |
} else { |
| 2657 |
/* Get Order */ |
| 2658 |
$response_order_data = $this->api_get_order( $access_token, $bn_code, $tracking_id, $resource_id ); |
| 2659 |
if ( isset( $response_order_data['intent'] ) && $cp_intent === $response_order_data['intent'] && isset( $response_order_data['status'] ) && 'APPROVED' === $response_order_data['status'] ) { |
| 2660 |
} else { |
| 2661 |
/** |
| 2662 |
* GET ORDER ERROR frequent, avoid because not required. |
| 2663 |
if ( empty( $response_order_data ) ) { |
| 2664 |
$response_order_data = $post_data; |
| 2665 |
} |
| 2666 |
$log = array( |
| 2667 |
'acting' => $this->paymod_id, |
| 2668 |
'key' => $tracking_id, |
| 2669 |
'result' => 'GET ORDER ERROR', |
| 2670 |
'data' => $response_order_data, |
| 2671 |
); |
| 2672 |
usces_save_order_acting_error( $log ); |
| 2673 |
wp_redirect( |
| 2674 |
add_query_arg( |
| 2675 |
array( |
| 2676 |
'acting' => $this->paymod_id, |
| 2677 |
'acting_return' => 0, |
| 2678 |
'result' => 0, |
| 2679 |
), |
| 2680 |
USCES_CART_URL |
| 2681 |
) |
| 2682 |
); |
| 2683 |
exit(); |
| 2684 |
*/ |
| 2685 |
usces_log( '[' . $this->paymod_id . '] GET ORDER ERROR : ' . print_r( $response_order_data, true ), 'acting_transaction.log' ); |
| 2686 |
} |
| 2687 |
} |
| 2688 |
|
| 2689 |
$usces->error_message = $usces->zaiko_check(); |
| 2690 |
if ( ! empty( $usces->error_message ) || 0 === (int) $usces->cart->num_row() ) { |
| 2691 |
wp_redirect( USCES_CART_URL ); |
| 2692 |
exit(); |
| 2693 |
} |
| 2694 |
|
| 2695 |
if ( 'CAPTURE' === $cp_intent ) { |
| 2696 |
/* Capture */ |
| 2697 |
$response_data = $this->api_capture_order( $access_token, $bn_code, $tracking_id, $resource_id, $correlation_id, $payment_source ); |
| 2698 |
} elseif ( 'AUTHORIZE' === $cp_intent ) { |
| 2699 |
/* Authorize */ |
| 2700 |
$response_data = $this->api_authorize_order( $access_token, $bn_code, $tracking_id, $resource_id, $correlation_id, $payment_source ); |
| 2701 |
} |
| 2702 |
if ( isset( $response_data['id'] ) && isset( $response_data['status'] ) && 'COMPLETED' === $response_data['status'] ) { |
| 2703 |
if ( ! empty( $ba_id ) ) { |
| 2704 |
$response_data['ba_id'] = $ba_id; |
| 2705 |
} |
| 2706 |
|
| 2707 |
/* Welcart order data registration */ |
| 2708 |
$res = $usces->order_processing( $response_data ); |
| 2709 |
if ( 'ordercompletion' === $res ) { |
| 2710 |
wp_redirect( |
| 2711 |
add_query_arg( |
| 2712 |
array( |
| 2713 |
'acting' => $this->paymod_id, |
| 2714 |
'acting_return' => 1, |
| 2715 |
'result' => 1, |
| 2716 |
'_nonce' => $post_data['_nonce'], |
| 2717 |
), |
| 2718 |
USCES_CART_URL |
| 2719 |
) |
| 2720 |
); |
| 2721 |
} else { |
| 2722 |
$log = array( |
| 2723 |
'acting' => $this->paymod_id, |
| 2724 |
'key' => $tracking_id, |
| 2725 |
'result' => 'ORDER DATA REGISTRATION ERROR', |
| 2726 |
'data' => $response_data, |
| 2727 |
); |
| 2728 |
usces_save_order_acting_error( $log ); |
| 2729 |
wp_redirect( |
| 2730 |
add_query_arg( |
| 2731 |
array( |
| 2732 |
'acting' => $this->paymod_id, |
| 2733 |
'acting_return' => 0, |
| 2734 |
'result' => 0, |
| 2735 |
), |
| 2736 |
USCES_CART_URL |
| 2737 |
) |
| 2738 |
); |
| 2739 |
} |
| 2740 |
exit(); |
| 2741 |
} else { |
| 2742 |
$log = array( |
| 2743 |
'acting' => $this->paymod_id, |
| 2744 |
'key' => $tracking_id, |
| 2745 |
'result' => $cp_intent . ' ERROR', |
| 2746 |
'data' => $response_data, |
| 2747 |
); |
| 2748 |
usces_save_order_acting_error( $log ); |
| 2749 |
wp_redirect( |
| 2750 |
add_query_arg( |
| 2751 |
array( |
| 2752 |
'acting' => $this->paymod_id, |
| 2753 |
'acting_return' => 0, |
| 2754 |
'result' => 0, |
| 2755 |
), |
| 2756 |
USCES_CART_URL |
| 2757 |
) |
| 2758 |
); |
| 2759 |
exit(); |
| 2760 |
} |
| 2761 |
} elseif ( 'acting_paypal_card' === $acting_flg ) { |
| 2762 |
$entry = $usces->cart->get_entry(); |
| 2763 |
$cart = $usces->cart->get_cart(); |
| 2764 |
if ( empty( $cart ) || empty( $entry ) ) { |
| 2765 |
return; |
| 2766 |
} |
| 2767 |
|
| 2768 |
parse_str( $post_query, $post_data ); |
| 2769 |
$tracking_id = ( isset( $post_data['tracking_id'] ) ) ? $post_data['tracking_id'] : ''; /* rand|reference_id */ |
| 2770 |
$resource_id = ( isset( $post_data['resource_id'] ) ) ? $post_data['resource_id'] : ''; |
| 2771 |
$payment_card = ( isset( $post_data['payment_card'] ) ) ? $post_data['payment_card'] : ''; |
| 2772 |
$payment_token_id = ( isset( $post_data['payment_token_id'] ) ) ? $post_data['payment_token_id'] : ''; |
| 2773 |
$vault = ( isset( $post_data['vault'] ) ) ? $post_data['vault'] : ''; |
| 2774 |
|
| 2775 |
if ( 'vault' === $payment_card && ! empty( $payment_token_id ) ) { |
| 2776 |
if ( empty( $tracking_id ) ) { |
| 2777 |
$log = array( |
| 2778 |
'acting' => 'paypal_card', |
| 2779 |
'key' => '(empty)', |
| 2780 |
'result' => 'VAULT ORDER ERROR', |
| 2781 |
'data' => $post_data, |
| 2782 |
); |
| 2783 |
usces_save_order_acting_error( $log ); |
| 2784 |
wp_redirect( |
| 2785 |
add_query_arg( |
| 2786 |
array( |
| 2787 |
'acting' => 'paypal_card', |
| 2788 |
'acting_return' => 0, |
| 2789 |
'result' => 0, |
| 2790 |
), |
| 2791 |
USCES_CART_URL |
| 2792 |
) |
| 2793 |
); |
| 2794 |
exit(); |
| 2795 |
} |
| 2796 |
} else { |
| 2797 |
if ( empty( $tracking_id ) || empty( $resource_id ) ) { |
| 2798 |
$log = array( |
| 2799 |
'acting' => 'paypal_card', |
| 2800 |
'key' => '(empty)', |
| 2801 |
'result' => 'CREATE ORDER ERROR', |
| 2802 |
'data' => $post_data, |
| 2803 |
); |
| 2804 |
usces_save_order_acting_error( $log ); |
| 2805 |
wp_redirect( |
| 2806 |
add_query_arg( |
| 2807 |
array( |
| 2808 |
'acting' => 'paypal_card', |
| 2809 |
'acting_return' => 0, |
| 2810 |
'result' => 0, |
| 2811 |
), |
| 2812 |
USCES_CART_URL |
| 2813 |
) |
| 2814 |
); |
| 2815 |
exit(); |
| 2816 |
} |
| 2817 |
} |
| 2818 |
|
| 2819 |
$acting_opts = $this->get_acting_settings(); |
| 2820 |
$cp_intent = ( isset( $acting_opts['intent'] ) ) ? $acting_opts['intent'] : ''; |
| 2821 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 2822 |
$bn_code = self::API_BN_CODE_ACDC; |
| 2823 |
|
| 2824 |
/* Get Access Token */ |
| 2825 |
$access_token = $this->get_access_token(); |
| 2826 |
|
| 2827 |
$correlation_id = ''; |
| 2828 |
$payment_source = array(); |
| 2829 |
|
| 2830 |
if ( 'vault' === $payment_card && ! empty( $payment_token_id ) ) { |
| 2831 |
$correlation_id = ( isset( $post_data['correlation_id'] ) ) ? $post_data['correlation_id'] : ''; |
| 2832 |
$payment_source['token'] = array( |
| 2833 |
'id' => $payment_token_id, |
| 2834 |
'type' => 'PAYMENT_METHOD_TOKEN', |
| 2835 |
); |
| 2836 |
$entry['correlation_id'] = $correlation_id; |
| 2837 |
|
| 2838 |
/* Create order */ |
| 2839 |
$response_order_data = $this->api_create_order( $access_token, $bn_code, $cp_intent, $tracking_id, $entry, $cart ); |
| 2840 |
if ( isset( $response_order_data['id'] ) && isset( $response_order_data['status'] ) && 'CREATED' === $response_order_data['status'] ) { |
| 2841 |
$resource_id = $response_order_data['id']; |
| 2842 |
} else { |
| 2843 |
$log = array( |
| 2844 |
'acting' => 'paypal_card', |
| 2845 |
'key' => $tracking_id, |
| 2846 |
'result' => 'CREATE ORDER ERROR', |
| 2847 |
'data' => $response_order_data, |
| 2848 |
); |
| 2849 |
usces_save_order_acting_error( $log ); |
| 2850 |
wp_redirect( |
| 2851 |
add_query_arg( |
| 2852 |
array( |
| 2853 |
'acting' => 'paypal_card', |
| 2854 |
'acting_return' => 0, |
| 2855 |
'result' => 0, |
| 2856 |
), |
| 2857 |
USCES_CART_URL |
| 2858 |
) |
| 2859 |
); |
| 2860 |
exit(); |
| 2861 |
} |
| 2862 |
} else { |
| 2863 |
$currency_code = $usces->get_currency_code(); |
| 2864 |
$cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0; |
| 2865 |
$item_total = (float) $entry['order']['total_items_price']; |
| 2866 |
$shipping = usces_have_shipped( $cart ); |
| 2867 |
$shipping_charge = ( $shipping && isset( $entry['order']['shipping_charge'] ) && 0.0 !== (float) $entry['order']['shipping_charge'] ) ? (float) $entry['order']['shipping_charge'] : 0; |
| 2868 |
$multiple_shipping = ( defined( 'WCEX_MSA' ) && isset( $entry['delivery']['delivery_flag'] ) && 2 === (int) $entry['delivery']['delivery_flag'] ) ? true : false; |
| 2869 |
$fee = ( isset( $entry['order']['cod_fee'] ) && 0.0 !== (float) $entry['order']['cod_fee'] ) ? (float) $entry['order']['cod_fee'] : 0; |
| 2870 |
$tax = ( isset( $entry['order']['tax'] ) && 'exclude' === usces_get_tax_mode() ) ? (float) $entry['order']['tax'] : 0; |
| 2871 |
$discount = ( isset( $entry['order']['discount'] ) && 0.0 !== (float) $entry['order']['discount'] ) ? ( (float) $entry['order']['discount'] * -1 ) : 0; |
| 2872 |
if ( usces_is_member_system() && usces_is_member_system_point() && isset( $entry['order']['usedpoint'] ) && 0 !== (int) $entry['order']['usedpoint'] ) { |
| 2873 |
$discount += (float) $entry['order']['usedpoint']; |
| 2874 |
} |
| 2875 |
|
| 2876 |
$body = array(); |
| 2877 |
$body[0]['op'] = 'replace'; |
| 2878 |
$body[0]['path'] = "/purchase_units/@reference_id=='" . $tracking_id . "'"; |
| 2879 |
|
| 2880 |
$purchase_units['reference_id'] = $tracking_id; |
| 2881 |
$purchase_units['amount']['currency_code'] = $currency_code; |
| 2882 |
$purchase_units['amount']['value'] = usces_crform( $entry['order']['total_full_price'], false, false, 'return', false ); |
| 2883 |
if ( 0 < $item_total ) { |
| 2884 |
$breakdown = array(); |
| 2885 |
$breakdown['item_total']['currency_code'] = $currency_code; |
| 2886 |
$breakdown['item_total']['value'] = usces_crform( $item_total, false, false, 'return', false ); |
| 2887 |
if ( $shipping && 0 < $shipping_charge ) { |
| 2888 |
$breakdown['shipping']['currency_code'] = $currency_code; |
| 2889 |
$breakdown['shipping']['value'] = usces_crform( $shipping_charge, false, false, 'return', false ); |
| 2890 |
} |
| 2891 |
if ( 0 < $fee ) { |
| 2892 |
$breakdown['handling']['currency_code'] = $currency_code; |
| 2893 |
$breakdown['handling']['value'] = usces_crform( $fee, false, false, 'return', false ); |
| 2894 |
} |
| 2895 |
if ( 0 < $tax ) { |
| 2896 |
$breakdown['tax_total']['currency_code'] = $currency_code; |
| 2897 |
$breakdown['tax_total']['value'] = usces_crform( $tax, false, false, 'return', false ); |
| 2898 |
} |
| 2899 |
if ( 0 < $discount ) { |
| 2900 |
$breakdown['discount']['currency_code'] = $currency_code; |
| 2901 |
$breakdown['discount']['value'] = usces_crform( $discount, false, false, 'return', false ); |
| 2902 |
} |
| 2903 |
$purchase_units['amount']['breakdown'] = $breakdown; |
| 2904 |
$items = array(); |
| 2905 |
for ( $i = 0; $i < $cart_count; $i++ ) { |
| 2906 |
$cart_row = $cart[ $i ]; |
| 2907 |
$item_name = $usces->getItemName( $cart_row['post_id'] ); |
| 2908 |
if ( 60 < mb_strlen( $item_name, 'UTF-8' ) ) { |
| 2909 |
$item_name = mb_substr( $item_name, 0, 60, 'UTF-8' ) . '...'; |
| 2910 |
} |
| 2911 |
$items[ $i ]['name'] = $item_name; |
| 2912 |
$items[ $i ]['unit_amount']['currency_code'] = $currency_code; |
| 2913 |
$items[ $i ]['unit_amount']['value'] = usces_crform( $cart_row['price'], false, false, 'return', false ); |
| 2914 |
$items[ $i ]['quantity'] = $cart_row['quantity']; |
| 2915 |
$options = ( isset( $cart_row['options'] ) && is_array( $cart_row['options'] ) ) ? $cart_row['options'] : array(); |
| 2916 |
if ( 0 < count( $options ) ) { |
| 2917 |
$description = ''; |
| 2918 |
foreach ( $options as $key => $value ) { |
| 2919 |
if ( ! empty( $key ) ) { |
| 2920 |
$key = urldecode( $key ); |
| 2921 |
$value = wel_safe_maybe_unserialize( $value ); |
| 2922 |
if ( is_array( $value ) ) { |
| 2923 |
$c = ''; |
| 2924 |
$description .= $key . ' : '; |
| 2925 |
foreach ( $value as $v ) { |
| 2926 |
$description .= $c . urldecode( $v ); |
| 2927 |
$c = ', '; |
| 2928 |
} |
| 2929 |
$description .= "\r\n"; |
| 2930 |
} else { |
| 2931 |
$description .= $key . ' : ' . urldecode( $value ) . "\r\n"; |
| 2932 |
} |
| 2933 |
} |
| 2934 |
} |
| 2935 |
if ( '' !== $description ) { |
| 2936 |
if ( 60 < mb_strlen( $description, 'UTF-8' ) ) { |
| 2937 |
$description = mb_substr( $description, 0, 60, 'UTF-8' ) . '...'; |
| 2938 |
} |
| 2939 |
$items[ $i ]['description'] = $description; |
| 2940 |
} |
| 2941 |
} |
| 2942 |
$items[ $i ]['sku'] = $usces->getItemCode( $cart_row['post_id'] ) . ' ' . urldecode( $cart_row['sku'] ); |
| 2943 |
} |
| 2944 |
$purchase_units['items'] = $items; |
| 2945 |
} |
| 2946 |
|
| 2947 |
$application_context = array(); |
| 2948 |
if ( $multiple_shipping && false === $array ) { |
| 2949 |
$msacart = ( isset( $_SESSION['msa_cart'] ) ) ? current( $_SESSION['msa_cart'] ) : array(); |
| 2950 |
if ( isset( $msacart['delivery']['destination_id'] ) ) { |
| 2951 |
$member = $usces->get_member(); |
| 2952 |
$msadelivery = msa_get_destination( $member['ID'], $msacart['delivery']['destination_id'] ); |
| 2953 |
$name = usces_localized_name( trim( $msadelivery['msa_name'] ), trim( $msadelivery['msa_name2'] ), 'return' ); |
| 2954 |
$purchase_units['shipping']['name']['full_name'] = $name; |
| 2955 |
$purchase_units['shipping']['address']['address_line_2'] = trim( $msadelivery['msa_address3'] ); |
| 2956 |
$purchase_units['shipping']['address']['address_line_1'] = trim( $msadelivery['msa_address2'] ); |
| 2957 |
$purchase_units['shipping']['address']['admin_area_2'] = trim( $msadelivery['msa_address1'] ); |
| 2958 |
$purchase_units['shipping']['address']['admin_area_1'] = trim( $msadelivery['msa_pref'] ); |
| 2959 |
$purchase_units['shipping']['address']['postal_code'] = trim( mb_convert_kana( $msadelivery['msa_zip'], 'a', 'UTF-8' ) ); |
| 2960 |
$purchase_units['shipping']['address']['country_code'] = 'JP'; |
| 2961 |
$application_context['shipping_preference'] = 'SET_PROVIDED_ADDRESS'; |
| 2962 |
} else { |
| 2963 |
$application_context['shipping_preference'] = 'NO_SHIPPING'; |
| 2964 |
} |
| 2965 |
} elseif ( $shipping ) { |
| 2966 |
$name = usces_localized_name( trim( $entry['delivery']['name1'] ), trim( $entry['delivery']['name2'] ), 'return' ); |
| 2967 |
$country = ( ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : usces_get_base_country(); |
| 2968 |
$country_code = apply_filters( 'usces_filter_paypalcp_shipping_country_code', $country ); |
| 2969 |
$purchase_units['shipping']['name']['full_name'] = $name; |
| 2970 |
$purchase_units['shipping']['address']['address_line_2'] = trim( $entry['delivery']['address3'] ); |
| 2971 |
$purchase_units['shipping']['address']['address_line_1'] = trim( $entry['delivery']['address2'] ); |
| 2972 |
$purchase_units['shipping']['address']['admin_area_2'] = trim( $entry['delivery']['address1'] ); |
| 2973 |
$purchase_units['shipping']['address']['admin_area_1'] = trim( $entry['delivery']['pref'] ); |
| 2974 |
$purchase_units['shipping']['address']['postal_code'] = trim( mb_convert_kana( $entry['delivery']['zipcode'], 'a', 'UTF-8' ) ); |
| 2975 |
$purchase_units['shipping']['address']['country_code'] = $country_code; |
| 2976 |
$application_context['shipping_preference'] = 'SET_PROVIDED_ADDRESS'; |
| 2977 |
} else { |
| 2978 |
$application_context['shipping_preference'] = 'NO_SHIPPING'; |
| 2979 |
} |
| 2980 |
// $body['application_context'] = $application_context; |
| 2981 |
|
| 2982 |
$body[0]['value'] = $purchase_units; |
| 2983 |
|
| 2984 |
/* Update Order */ |
| 2985 |
$params = array( |
| 2986 |
'method' => 'PATCH', |
| 2987 |
'headers' => array( |
| 2988 |
'Content-Type' => 'application/json', |
| 2989 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 2990 |
'PayPal-Partner-Attribution-Id' => $bn_code, |
| 2991 |
'PayPal-Request-Id' => $tracking_id, |
| 2992 |
), |
| 2993 |
'timeout' => self::API_TIMEOUT, |
| 2994 |
'body' => wp_json_encode( $body, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ), |
| 2995 |
); |
| 2996 |
$response = wp_remote_request( $api_request_url . '/v2/checkout/orders/' . $resource_id, $params ); |
| 2997 |
if ( isset( $response['response']['code'] ) && '204' === (string) $response['response']['code'] ) { |
| 2998 |
/* A successful request returns the HTTP 204 No Content status code with an empty object in the JSON response body. */ |
| 2999 |
} else { |
| 3000 |
$log = array( |
| 3001 |
'acting' => 'paypal_card', |
| 3002 |
'key' => $tracking_id, |
| 3003 |
'result' => 'UPDATE ORDER ERROR', |
| 3004 |
'data' => $response, |
| 3005 |
); |
| 3006 |
usces_save_order_acting_error( $log ); |
| 3007 |
wp_redirect( |
| 3008 |
add_query_arg( |
| 3009 |
array( |
| 3010 |
'acting' => 'paypal_card', |
| 3011 |
'acting_return' => 0, |
| 3012 |
'result' => 0, |
| 3013 |
), |
| 3014 |
USCES_CART_URL |
| 3015 |
) |
| 3016 |
); |
| 3017 |
exit(); |
| 3018 |
} |
| 3019 |
} |
| 3020 |
|
| 3021 |
$usces->error_message = $usces->zaiko_check(); |
| 3022 |
if ( ! empty( $usces->error_message ) || 0 === (int) $usces->cart->num_row() ) { |
| 3023 |
wp_redirect( USCES_CART_URL ); |
| 3024 |
exit(); |
| 3025 |
} |
| 3026 |
|
| 3027 |
if ( 'CAPTURE' === $cp_intent ) { |
| 3028 |
/* Capture */ |
| 3029 |
$response_data = $this->api_capture_order( $access_token, $bn_code, $tracking_id, $resource_id, $correlation_id, $payment_source ); |
| 3030 |
} elseif ( 'AUTHORIZE' === $cp_intent ) { |
| 3031 |
/* Authorize */ |
| 3032 |
$response_data = $this->api_authorize_order( $access_token, $bn_code, $tracking_id, $resource_id, $correlation_id, $payment_source ); |
| 3033 |
} |
| 3034 |
if ( isset( $response_data['status'] ) ) { |
| 3035 |
$status = $response_data['status']; |
| 3036 |
} else { |
| 3037 |
$status = $cp_intent . ' ERROR'; |
| 3038 |
} |
| 3039 |
if ( isset( $response_data['purchase_units'] ) ) { |
| 3040 |
$purchase_units = $response_data['purchase_units'][0]; |
| 3041 |
if ( isset( $purchase_units['payments']['captures'] ) ) { |
| 3042 |
$payments = $purchase_units['payments']['captures'][0]; |
| 3043 |
if ( isset( $payments['status'] ) ) { |
| 3044 |
if ( 'COMPLETED' !== $payments['status'] && 'PENDING' !== $payments['status'] ) { |
| 3045 |
$status = $payments['status']; |
| 3046 |
} |
| 3047 |
} |
| 3048 |
} elseif ( isset( $purchase_units['payments']['authorizations'] ) ) { |
| 3049 |
$payments = $purchase_units['payments']['authorizations'][0]; |
| 3050 |
if ( isset( $payments['status'] ) ) { |
| 3051 |
if ( 'CREATED' !== $payments['status'] && 'PENDING' !== $payments['status'] ) { |
| 3052 |
$status = $payments['status']; |
| 3053 |
} |
| 3054 |
} |
| 3055 |
} |
| 3056 |
} |
| 3057 |
if ( isset( $response_data['id'] ) && 'COMPLETED' === $status ) { |
| 3058 |
if ( 'vault' === $vault && 'another' === $payment_card && ! empty( $payment_token_id ) ) { |
| 3059 |
$delete_status = $this->api_delete_payment_tokens( $access_token, $payment_token_id ); |
| 3060 |
} |
| 3061 |
if ( isset( $acting_opts['card_3ds'] ) && 'on' === $acting_opts['card_3ds'] ) { |
| 3062 |
$response_data['card_3ds']['liability_shift'] = ( isset( $post_data['liability_shift'] ) ) ? $post_data['liability_shift'] : ''; |
| 3063 |
$response_data['card_3ds']['enrollment_status'] = ( isset( $post_data['enrollment_status'] ) ) ? $post_data['enrollment_status'] : ''; |
| 3064 |
$response_data['card_3ds']['authentication_status'] = ( isset( $post_data['authentication_status'] ) ) ? $post_data['authentication_status'] : ''; |
| 3065 |
} |
| 3066 |
|
| 3067 |
/* Welcart order data registration */ |
| 3068 |
$res = $usces->order_processing( $response_data ); |
| 3069 |
if ( 'ordercompletion' === $res ) { |
| 3070 |
wp_redirect( |
| 3071 |
add_query_arg( |
| 3072 |
array( |
| 3073 |
'acting' => 'paypal_card', |
| 3074 |
'acting_return' => 1, |
| 3075 |
'result' => 1, |
| 3076 |
'_nonce' => $post_data['_nonce'], |
| 3077 |
), |
| 3078 |
USCES_CART_URL |
| 3079 |
) |
| 3080 |
); |
| 3081 |
} else { |
| 3082 |
$log = array( |
| 3083 |
'acting' => 'paypal_card', |
| 3084 |
'key' => $tracking_id, |
| 3085 |
'result' => 'ORDER DATA REGISTRATION ERROR', |
| 3086 |
'data' => $response_data, |
| 3087 |
); |
| 3088 |
usces_save_order_acting_error( $log ); |
| 3089 |
wp_redirect( |
| 3090 |
add_query_arg( |
| 3091 |
array( |
| 3092 |
'acting' => 'paypal_card', |
| 3093 |
'acting_return' => 0, |
| 3094 |
'result' => 0, |
| 3095 |
), |
| 3096 |
USCES_CART_URL |
| 3097 |
) |
| 3098 |
); |
| 3099 |
} |
| 3100 |
exit(); |
| 3101 |
} else { |
| 3102 |
$log = array( |
| 3103 |
'acting' => 'paypal_card', |
| 3104 |
'key' => $tracking_id, |
| 3105 |
'result' => $cp_intent . ' ERROR', |
| 3106 |
'data' => $response_data, |
| 3107 |
); |
| 3108 |
usces_save_order_acting_error( $log ); |
| 3109 |
wp_redirect( |
| 3110 |
add_query_arg( |
| 3111 |
array( |
| 3112 |
'acting' => 'paypal_card', |
| 3113 |
'acting_return' => 0, |
| 3114 |
'retry' => 1, |
| 3115 |
), |
| 3116 |
USCES_CART_URL |
| 3117 |
) |
| 3118 |
); |
| 3119 |
exit(); |
| 3120 |
} |
| 3121 |
} |
| 3122 |
} |
| 3123 |
|
| 3124 |
/** |
| 3125 |
* Orders API. |
| 3126 |
* /v2/checkout/orders |
| 3127 |
* |
| 3128 |
* @param array $access_token API Access Token. |
| 3129 |
* @param string $bn_code BN Code. |
| 3130 |
* @param string $intent AUTHORIZE|CAPTURE. |
| 3131 |
* @param string $tracking_id Tracking ID. |
| 3132 |
* @param array $entry Entry data. |
| 3133 |
* @param array $cart Cart data. |
| 3134 |
* @param boolean $array Associative true|false. |
| 3135 |
* @return array|object |
| 3136 |
*/ |
| 3137 |
public function api_create_order( $access_token, $bn_code, $intent, $tracking_id, $entry, $cart, $array = true ) { |
| 3138 |
global $usces; |
| 3139 |
|
| 3140 |
$correlation_id = ( ! empty( $entry['correlation_id'] ) ) ? $entry['correlation_id'] : ''; // Purchase using a saved card. |
| 3141 |
$pre_card_order = ( isset( $entry['pre_card_order'] ) && '' === $correlation_id ) ? true : false; // Pre-Order. Orders will be updated later. |
| 3142 |
|
| 3143 |
$acting_opts = $this->get_acting_settings(); |
| 3144 |
if ( empty( $intent ) ) { |
| 3145 |
$intent = ( isset( $acting_opts['intent'] ) ) ? $acting_opts['intent'] : ''; |
| 3146 |
} |
| 3147 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 3148 |
$currency_code = $usces->get_currency_code(); |
| 3149 |
$cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0; |
| 3150 |
if ( 0 < $cart_count && isset( $entry['order']['total_items_price'] ) ) { |
| 3151 |
$item_total = (float) $entry['order']['total_items_price']; |
| 3152 |
$shipping = usces_have_shipped( $cart ); |
| 3153 |
$shipping_charge = ( $shipping && isset( $entry['order']['shipping_charge'] ) && 0.0 !== (float) $entry['order']['shipping_charge'] ) ? (float) $entry['order']['shipping_charge'] : 0; |
| 3154 |
$multiple_shipping = ( defined( 'WCEX_MSA' ) && isset( $entry['delivery']['delivery_flag'] ) && 2 === (int) $entry['delivery']['delivery_flag'] ) ? true : false; |
| 3155 |
$fee = ( isset( $entry['order']['cod_fee'] ) && 0.0 !== (float) $entry['order']['cod_fee'] ) ? (float) $entry['order']['cod_fee'] : 0; |
| 3156 |
$tax = ( isset( $entry['order']['tax'] ) && 'exclude' === usces_get_tax_mode() ) ? (float) $entry['order']['tax'] : 0; |
| 3157 |
$discount = ( isset( $entry['order']['discount'] ) && 0.0 !== (float) $entry['order']['discount'] ) ? ( (float) $entry['order']['discount'] * -1 ) : 0; |
| 3158 |
if ( usces_is_member_system() && usces_is_member_system_point() && isset( $entry['order']['usedpoint'] ) && 0 !== (int) $entry['order']['usedpoint'] ) { |
| 3159 |
$discount += (float) $entry['order']['usedpoint']; |
| 3160 |
} |
| 3161 |
} else { |
| 3162 |
$item_total = 0; |
| 3163 |
$shipping = false; |
| 3164 |
$multiple_shipping = false; |
| 3165 |
} |
| 3166 |
|
| 3167 |
$body = array(); |
| 3168 |
$body['intent'] = $intent; |
| 3169 |
$purchase_units = array(); |
| 3170 |
$purchase_units['reference_id'] = $tracking_id; |
| 3171 |
if ( $pre_card_order ) { |
| 3172 |
$purchase_units['amount']['currency_code'] = $currency_code; |
| 3173 |
$purchase_units['amount']['value'] = $item_total; |
| 3174 |
} else { |
| 3175 |
$purchase_units['amount']['currency_code'] = $currency_code; |
| 3176 |
$purchase_units['amount']['value'] = usces_crform( $entry['order']['total_full_price'], false, false, 'return', false ); |
| 3177 |
if ( 0 < $item_total ) { |
| 3178 |
$breakdown = array(); |
| 3179 |
$breakdown['item_total']['currency_code'] = $currency_code; |
| 3180 |
$breakdown['item_total']['value'] = usces_crform( $item_total, false, false, 'return', false ); |
| 3181 |
if ( $shipping && 0 < $shipping_charge ) { |
| 3182 |
$breakdown['shipping']['currency_code'] = $currency_code; |
| 3183 |
$breakdown['shipping']['value'] = usces_crform( $shipping_charge, false, false, 'return', false ); |
| 3184 |
} |
| 3185 |
if ( 0 < $fee ) { |
| 3186 |
$breakdown['handling']['currency_code'] = $currency_code; |
| 3187 |
$breakdown['handling']['value'] = usces_crform( $fee, false, false, 'return', false ); |
| 3188 |
} |
| 3189 |
if ( 0 < $tax ) { |
| 3190 |
$breakdown['tax_total']['currency_code'] = $currency_code; |
| 3191 |
$breakdown['tax_total']['value'] = usces_crform( $tax, false, false, 'return', false ); |
| 3192 |
} |
| 3193 |
if ( 0 < $discount ) { |
| 3194 |
$breakdown['discount']['currency_code'] = $currency_code; |
| 3195 |
$breakdown['discount']['value'] = usces_crform( $discount, false, false, 'return', false ); |
| 3196 |
} |
| 3197 |
$purchase_units['amount']['breakdown'] = $breakdown; |
| 3198 |
$items = array(); |
| 3199 |
for ( $i = 0; $i < $cart_count; $i++ ) { |
| 3200 |
$cart_row = $cart[ $i ]; |
| 3201 |
$item_name = $usces->getItemName( $cart_row['post_id'] ); |
| 3202 |
if ( 60 < mb_strlen( $item_name, 'UTF-8' ) ) { |
| 3203 |
$item_name = mb_substr( $item_name, 0, 60, 'UTF-8' ) . '...'; |
| 3204 |
} |
| 3205 |
$items[ $i ]['name'] = $item_name; |
| 3206 |
$items[ $i ]['unit_amount']['currency_code'] = $currency_code; |
| 3207 |
$items[ $i ]['unit_amount']['value'] = usces_crform( $cart_row['price'], false, false, 'return', false ); |
| 3208 |
$items[ $i ]['quantity'] = $cart_row['quantity']; |
| 3209 |
$options = ( isset( $cart_row['options'] ) && is_array( $cart_row['options'] ) ) ? $cart_row['options'] : array(); |
| 3210 |
if ( 0 < count( $options ) ) { |
| 3211 |
$description = ''; |
| 3212 |
foreach ( $options as $key => $value ) { |
| 3213 |
if ( ! empty( $key ) ) { |
| 3214 |
$key = urldecode( $key ); |
| 3215 |
$value = wel_safe_maybe_unserialize( $value ); |
| 3216 |
if ( is_array( $value ) ) { |
| 3217 |
$c = ''; |
| 3218 |
$description .= $key . ' : '; |
| 3219 |
foreach ( $value as $v ) { |
| 3220 |
$description .= $c . urldecode( $v ); |
| 3221 |
$c = ', '; |
| 3222 |
} |
| 3223 |
$description .= "\r\n"; |
| 3224 |
} else { |
| 3225 |
$description .= $key . ' : ' . urldecode( $value ) . "\r\n"; |
| 3226 |
} |
| 3227 |
} |
| 3228 |
} |
| 3229 |
if ( '' !== $description ) { |
| 3230 |
if ( 60 < mb_strlen( $description, 'UTF-8' ) ) { |
| 3231 |
$description = mb_substr( $description, 0, 60, 'UTF-8' ) . '...'; |
| 3232 |
} |
| 3233 |
$items[ $i ]['description'] = $description; |
| 3234 |
} |
| 3235 |
} |
| 3236 |
$items[ $i ]['sku'] = $usces->getItemCode( $cart_row['post_id'] ) . ' ' . urldecode( $cart_row['sku'] ); |
| 3237 |
} |
| 3238 |
$purchase_units['items'] = $items; |
| 3239 |
} |
| 3240 |
} |
| 3241 |
if ( false === $array ) { |
| 3242 |
$payer = array(); |
| 3243 |
$name = usces_localized_name( trim( $entry['customer']['name1'] ), trim( $entry['customer']['name2'] ), 'return' ); |
| 3244 |
$phone = str_replace( array( '-', '+', ' ' ), '', mb_convert_kana( $entry['customer']['tel'], 'a', 'UTF-8' ) ); |
| 3245 |
$country = ( ! empty( $entry['customer']['country'] ) ) ? $entry['customer']['country'] : usces_get_base_country(); |
| 3246 |
$country_code = apply_filters( 'usces_filter_paypalcp_customer_country_code', $country ); |
| 3247 |
$payer['name']['given_name'] = trim( $entry['customer']['name2'] ); |
| 3248 |
$payer['name']['surname'] = trim( $entry['customer']['name1'] ); |
| 3249 |
$payer['email_address'] = trim( $entry['customer']['mailaddress1'] ); |
| 3250 |
if ( ! empty( $phone ) ) { |
| 3251 |
$payer['phone']['phone_number']['national_number'] = ltrim( $phone, '0' ); |
| 3252 |
} |
| 3253 |
if ( ! empty( $entry['customer']['address1'] ) ) { |
| 3254 |
$payer['address']['address_line_2'] = trim( $entry['customer']['address3'] ); |
| 3255 |
$payer['address']['address_line_1'] = trim( $entry['customer']['address2'] ); |
| 3256 |
$payer['address']['admin_area_2'] = trim( $entry['customer']['address1'] ); |
| 3257 |
} |
| 3258 |
if ( ! empty( $entry['customer']['pref'] ) ) { |
| 3259 |
$payer['address']['admin_area_1'] = trim( $entry['customer']['pref'] ); |
| 3260 |
} |
| 3261 |
if ( ! empty( $entry['customer']['zipcode'] ) ) { |
| 3262 |
$payer['address']['postal_code'] = trim( mb_convert_kana( $entry['customer']['zipcode'], 'a', 'UTF-8' ) ); |
| 3263 |
} |
| 3264 |
$payer['address']['country_code'] = $country_code; |
| 3265 |
$body['payer'] = $payer; |
| 3266 |
} |
| 3267 |
if ( ! $pre_card_order ) { |
| 3268 |
$application_context = array(); |
| 3269 |
if ( $multiple_shipping && false === $array ) { |
| 3270 |
$msacart = ( isset( $_SESSION['msa_cart'] ) ) ? current( $_SESSION['msa_cart'] ) : array(); |
| 3271 |
if ( isset( $msacart['delivery']['destination_id'] ) ) { |
| 3272 |
$member = $usces->get_member(); |
| 3273 |
$msadelivery = msa_get_destination( $member['ID'], $msacart['delivery']['destination_id'] ); |
| 3274 |
$name = usces_localized_name( trim( $msadelivery['msa_name'] ), trim( $msadelivery['msa_name2'] ), 'return' ); |
| 3275 |
$purchase_units['shipping']['name']['full_name'] = $name; |
| 3276 |
$purchase_units['shipping']['address']['address_line_2'] = trim( $msadelivery['msa_address3'] ); |
| 3277 |
$purchase_units['shipping']['address']['address_line_1'] = trim( $msadelivery['msa_address2'] ); |
| 3278 |
$purchase_units['shipping']['address']['admin_area_2'] = trim( $msadelivery['msa_address1'] ); |
| 3279 |
$purchase_units['shipping']['address']['admin_area_1'] = trim( $msadelivery['msa_pref'] ); |
| 3280 |
$purchase_units['shipping']['address']['postal_code'] = trim( mb_convert_kana( $msadelivery['msa_zip'], 'a', 'UTF-8' ) ); |
| 3281 |
$purchase_units['shipping']['address']['country_code'] = 'JP'; |
| 3282 |
$application_context['shipping_preference'] = 'SET_PROVIDED_ADDRESS'; |
| 3283 |
} else { |
| 3284 |
$application_context['shipping_preference'] = 'NO_SHIPPING'; |
| 3285 |
} |
| 3286 |
} elseif ( $shipping ) { |
| 3287 |
$name = usces_localized_name( trim( $entry['delivery']['name1'] ), trim( $entry['delivery']['name2'] ), 'return' ); |
| 3288 |
$country = ( ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : usces_get_base_country(); |
| 3289 |
$country_code = apply_filters( 'usces_filter_paypalcp_shipping_country_code', $country ); |
| 3290 |
$purchase_units['shipping']['name']['full_name'] = $name; |
| 3291 |
$purchase_units['shipping']['address']['address_line_2'] = trim( $entry['delivery']['address3'] ); |
| 3292 |
$purchase_units['shipping']['address']['address_line_1'] = trim( $entry['delivery']['address2'] ); |
| 3293 |
$purchase_units['shipping']['address']['admin_area_2'] = trim( $entry['delivery']['address1'] ); |
| 3294 |
$purchase_units['shipping']['address']['admin_area_1'] = trim( $entry['delivery']['pref'] ); |
| 3295 |
$purchase_units['shipping']['address']['postal_code'] = trim( mb_convert_kana( $entry['delivery']['zipcode'], 'a', 'UTF-8' ) ); |
| 3296 |
$purchase_units['shipping']['address']['country_code'] = $country_code; |
| 3297 |
$application_context['shipping_preference'] = 'SET_PROVIDED_ADDRESS'; |
| 3298 |
} else { |
| 3299 |
$application_context['shipping_preference'] = 'NO_SHIPPING'; |
| 3300 |
} |
| 3301 |
} |
| 3302 |
$body['purchase_units'] = array( $purchase_units ); |
| 3303 |
if ( ! $pre_card_order ) { |
| 3304 |
$body['application_context'] = $application_context; |
| 3305 |
} |
| 3306 |
|
| 3307 |
$params = array( |
| 3308 |
'method' => 'POST', |
| 3309 |
'headers' => array( |
| 3310 |
'Content-Type' => 'application/json;charset=utf-8', |
| 3311 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 3312 |
'PayPal-Partner-Attribution-Id' => $bn_code, |
| 3313 |
'PayPal-Request-Id' => $tracking_id, |
| 3314 |
), |
| 3315 |
'timeout' => self::API_TIMEOUT, |
| 3316 |
'body' => wp_json_encode( $body ), |
| 3317 |
); |
| 3318 |
if ( ! empty( $correlation_id ) ) { |
| 3319 |
$params['headers']['PayPal-Client-Metadata-Id'] = $correlation_id; |
| 3320 |
} |
| 3321 |
$response = wp_remote_post( $api_request_url . '/v2/checkout/orders', $params ); |
| 3322 |
if ( isset( $response['response']['code'] ) && ( '200' === (string) $response['response']['code'] || '201' === (string) $response['response']['code'] ) ) { |
| 3323 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), $array ); |
| 3324 |
} else { |
| 3325 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), $array ); |
| 3326 |
if ( is_array( $response_data ) && ! isset( $response_data['status'] ) && ! isset( $response_data['name'] ) ) { |
| 3327 |
$response_data['name'] = 'CREATE ORDER ERROR'; |
| 3328 |
} |
| 3329 |
} |
| 3330 |
return $response_data; |
| 3331 |
} |
| 3332 |
|
| 3333 |
/** |
| 3334 |
* Orders API. |
| 3335 |
* /v2/checkout/orders/{id} |
| 3336 |
* |
| 3337 |
* @param array $access_token API Access Token. |
| 3338 |
* @param string $bn_code BN Code. |
| 3339 |
* @param string $tracking_id Tracking ID. |
| 3340 |
* @param string $resource_id order ID. |
| 3341 |
* @param boolean $array Associative true|false. |
| 3342 |
* @return array |
| 3343 |
*/ |
| 3344 |
public function api_get_order( $access_token, $bn_code, $tracking_id, $resource_id, $array = true ) { |
| 3345 |
$acting_opts = $this->get_acting_settings(); |
| 3346 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 3347 |
|
| 3348 |
$params = array( |
| 3349 |
'method' => 'GET', |
| 3350 |
'headers' => array( |
| 3351 |
'Content-Type' => 'application/json;charset=utf-8', |
| 3352 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 3353 |
'PayPal-Partner-Attribution-Id' => $bn_code, |
| 3354 |
'PayPal-Request-Id' => $tracking_id, |
| 3355 |
), |
| 3356 |
'timeout' => self::API_TIMEOUT, |
| 3357 |
); |
| 3358 |
$response = wp_remote_get( $api_request_url . '/v2/checkout/orders/' . $resource_id, $params ); |
| 3359 |
if ( is_wp_error( $response ) ) { |
| 3360 |
$response_data = array(); |
| 3361 |
} else { |
| 3362 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), $array ); |
| 3363 |
} |
| 3364 |
return $response_data; |
| 3365 |
} |
| 3366 |
|
| 3367 |
/** |
| 3368 |
* Orders API. |
| 3369 |
* /v2/checkout/orders/{id}/capture |
| 3370 |
* |
| 3371 |
* @param array $access_token API Access Token. |
| 3372 |
* @param string $bn_code BN Code. |
| 3373 |
* @param string $tracking_id Tracking ID. |
| 3374 |
* @param string $resource_id order ID. |
| 3375 |
* @param string $correlation_id Correlation ID (CMID, Session Identifier f). |
| 3376 |
* @param array $payment_source Billing Agreement ID. |
| 3377 |
* @param boolean $array Associative true|false. |
| 3378 |
* @return array |
| 3379 |
*/ |
| 3380 |
public function api_capture_order( $access_token, $bn_code, $tracking_id, $resource_id, $correlation_id, $payment_source, $array = true ) { |
| 3381 |
$acting_opts = $this->get_acting_settings(); |
| 3382 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 3383 |
|
| 3384 |
$params = array( |
| 3385 |
'method' => 'POST', |
| 3386 |
'headers' => array( |
| 3387 |
'Content-Type' => 'application/json;charset=utf-8', |
| 3388 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 3389 |
'PayPal-Partner-Attribution-Id' => $bn_code, |
| 3390 |
'PayPal-Request-Id' => $tracking_id, |
| 3391 |
), |
| 3392 |
'timeout' => self::API_TIMEOUT, |
| 3393 |
); |
| 3394 |
if ( ! empty( $correlation_id ) ) { |
| 3395 |
$params['headers']['PayPal-Client-Metadata-Id'] = $correlation_id; |
| 3396 |
} |
| 3397 |
if ( ! empty( $payment_source ) ) { |
| 3398 |
$body = array(); |
| 3399 |
$body['payment_source'] = $payment_source; |
| 3400 |
$params['body'] = wp_json_encode( $body ); |
| 3401 |
} |
| 3402 |
$response = wp_remote_get( $api_request_url . '/v2/checkout/orders/' . $resource_id . '/capture', $params ); |
| 3403 |
if ( is_wp_error( $response ) ) { |
| 3404 |
$response_data = array(); |
| 3405 |
} else { |
| 3406 |
if ( isset( $response['response']['code'] ) && ( '200' === (string) $response['response']['code'] || '201' === (string) $response['response']['code'] ) ) { |
| 3407 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), $array ); |
| 3408 |
} else { |
| 3409 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), $array ); |
| 3410 |
if ( ! isset( $response_data['status'] ) && ! isset( $response_data['name'] ) ) { |
| 3411 |
$response_data['name'] = 'CAPTURE ERROR'; |
| 3412 |
} |
| 3413 |
} |
| 3414 |
} |
| 3415 |
return $response_data; |
| 3416 |
} |
| 3417 |
|
| 3418 |
/** |
| 3419 |
* Orders API. |
| 3420 |
* /v2/checkout/orders/{id}/authorize |
| 3421 |
* |
| 3422 |
* @param array $access_token API Access Token. |
| 3423 |
* @param string $bn_code BN Code. |
| 3424 |
* @param string $tracking_id Tracking ID. |
| 3425 |
* @param string $resource_id order ID. |
| 3426 |
* @param string $correlation_id Correlation ID (CMID, Session Identifier f). |
| 3427 |
* @param array $payment_source Billing Agreement ID. |
| 3428 |
* @param boolean $array Associative true|false. |
| 3429 |
* @return array |
| 3430 |
*/ |
| 3431 |
public function api_authorize_order( $access_token, $bn_code, $tracking_id, $resource_id, $correlation_id, $payment_source, $array = true ) { |
| 3432 |
$acting_opts = $this->get_acting_settings(); |
| 3433 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 3434 |
|
| 3435 |
$params = array( |
| 3436 |
'method' => 'POST', |
| 3437 |
'headers' => array( |
| 3438 |
'Content-Type' => 'application/json;charset=utf-8', |
| 3439 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 3440 |
'PayPal-Partner-Attribution-Id' => $bn_code, |
| 3441 |
'PayPal-Request-Id' => $tracking_id, |
| 3442 |
), |
| 3443 |
'timeout' => self::API_TIMEOUT, |
| 3444 |
); |
| 3445 |
if ( ! empty( $correlation_id ) ) { |
| 3446 |
$params['headers']['PayPal-Client-Metadata-Id'] = $correlation_id; |
| 3447 |
} |
| 3448 |
if ( ! empty( $payment_source ) ) { |
| 3449 |
$body = array(); |
| 3450 |
$body['payment_source'] = $payment_source; |
| 3451 |
$params['body'] = wp_json_encode( $body ); |
| 3452 |
} |
| 3453 |
$response = wp_remote_get( $api_request_url . '/v2/checkout/orders/' . $resource_id . '/authorize', $params ); |
| 3454 |
if ( is_wp_error( $response ) ) { |
| 3455 |
$response_data = array(); |
| 3456 |
} else { |
| 3457 |
if ( isset( $response['response']['code'] ) && ( '200' === (string) $response['response']['code'] || '201' === (string) $response['response']['code'] ) ) { |
| 3458 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), $array ); |
| 3459 |
} else { |
| 3460 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), $array ); |
| 3461 |
if ( ! isset( $response_data['status'] ) && ! isset( $response_data['name'] ) ) { |
| 3462 |
$response_data['name'] = 'AUTHORIZE ERROR'; |
| 3463 |
} |
| 3464 |
} |
| 3465 |
} |
| 3466 |
return $response_data; |
| 3467 |
} |
| 3468 |
|
| 3469 |
/** |
| 3470 |
* Orders API. |
| 3471 |
* /v2/payments/authorizations/{id}/void |
| 3472 |
* |
| 3473 |
* @param array $access_token API Access Token. |
| 3474 |
* @param string $bn_code BN Code. |
| 3475 |
* @param string $tracking_id Tracking ID. |
| 3476 |
* @param string $id ID. |
| 3477 |
* @return string |
| 3478 |
*/ |
| 3479 |
public function api_authorize_void( $access_token, $bn_code, $tracking_id, $id ) { |
| 3480 |
$acting_opts = $this->get_acting_settings(); |
| 3481 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 3482 |
$void_status = ''; |
| 3483 |
|
| 3484 |
$params = array( |
| 3485 |
'method' => 'POST', |
| 3486 |
'headers' => array( |
| 3487 |
'Content-Type' => 'application/json;charset=utf-8', |
| 3488 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 3489 |
'PayPal-Partner-Attribution-Id' => $bn_code, |
| 3490 |
'PayPal-Request-Id' => $tracking_id, |
| 3491 |
), |
| 3492 |
'timeout' => self::API_TIMEOUT, |
| 3493 |
); |
| 3494 |
$response = wp_remote_get( $api_request_url . '/v2/payments/authorizations/' . $id . '/void', $params ); |
| 3495 |
if ( is_wp_error( $response ) ) { |
| 3496 |
$void_status = 'VOID ERROR'; |
| 3497 |
} elseif ( isset( $response['response']['code'] ) && '204' === (string) $response['response']['code'] ) { |
| 3498 |
$void_status = 'COMPLETED'; |
| 3499 |
} else { |
| 3500 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 3501 |
if ( isset( $response_data['status'] ) ) { |
| 3502 |
$void_status = $response_data['status']; |
| 3503 |
} elseif ( isset( $response_data['name'] ) ) { |
| 3504 |
$void_status = $response_data['name']; |
| 3505 |
} else { |
| 3506 |
$void_status = 'VOID ERROR'; |
| 3507 |
} |
| 3508 |
} |
| 3509 |
return $void_status; |
| 3510 |
} |
| 3511 |
|
| 3512 |
/** |
| 3513 |
* Payment Method Tokens API. |
| 3514 |
* /v2/vault/payment-tokens/ |
| 3515 |
* /v2/vault/payment-tokens/{id} |
| 3516 |
* |
| 3517 |
* @param array $access_token API Access Token. |
| 3518 |
* @param string $customer_id Member ID. |
| 3519 |
* @param string $payment_token_id Payment Token ID. |
| 3520 |
* @return array |
| 3521 |
*/ |
| 3522 |
public function api_get_payment_tokens( $access_token, $customer_id, $payment_token_id = '' ) { |
| 3523 |
$acting_opts = $this->get_acting_settings(); |
| 3524 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 3525 |
$card_prefix = ( isset( $acting_opts['card_prefix'] ) ) ? $acting_opts['card_prefix'] : ''; |
| 3526 |
|
| 3527 |
$params = array( |
| 3528 |
'method' => 'GET', |
| 3529 |
'headers' => array( |
| 3530 |
'Content-Type' => 'application/json;charset=utf-8', |
| 3531 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 3532 |
'PayPal-Partner-Attribution-Id' => self::API_BN_CODE_ACDC, |
| 3533 |
), |
| 3534 |
'timeout' => self::API_TIMEOUT, |
| 3535 |
); |
| 3536 |
if ( ! empty( $payment_token_id ) ) { |
| 3537 |
$response = wp_remote_get( $api_request_url . '/v2/vault/payment-tokens/' . $payment_token_id, $params ); |
| 3538 |
} else { |
| 3539 |
$response = wp_remote_get( $api_request_url . '/v2/vault/payment-tokens?customer_id=' . $card_prefix . $customer_id . '&total_required=true', $params ); |
| 3540 |
} |
| 3541 |
if ( is_wp_error( $response ) ) { |
| 3542 |
$response_data = array(); |
| 3543 |
} else { |
| 3544 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 3545 |
} |
| 3546 |
return $response_data; |
| 3547 |
} |
| 3548 |
|
| 3549 |
/** |
| 3550 |
* Payment Method Tokens API. |
| 3551 |
* /v2/vault/payment-tokens/{id} |
| 3552 |
* |
| 3553 |
* @param array $access_token API Access Token. |
| 3554 |
* @param string $payment_token_id Payment Token ID. |
| 3555 |
* @return string |
| 3556 |
*/ |
| 3557 |
public function api_delete_payment_tokens( $access_token, $payment_token_id ) { |
| 3558 |
$acting_opts = $this->get_acting_settings(); |
| 3559 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 3560 |
$delete_status = ''; |
| 3561 |
|
| 3562 |
$params = array( |
| 3563 |
'method' => 'DELETE', |
| 3564 |
'headers' => array( |
| 3565 |
'Content-Type' => 'application/json;charset=utf-8', |
| 3566 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 3567 |
'PayPal-Partner-Attribution-Id' => self::API_BN_CODE_ACDC, |
| 3568 |
), |
| 3569 |
'timeout' => self::API_TIMEOUT, |
| 3570 |
); |
| 3571 |
$response = wp_remote_request( $api_request_url . '/v2/vault/payment-tokens/' . $payment_token_id, $params ); |
| 3572 |
if ( is_wp_error( $response ) ) { |
| 3573 |
$delete_status = 'DELETE ERROR'; |
| 3574 |
} elseif ( isset( $response['response']['code'] ) && '204' === (string) $response['response']['code'] ) { |
| 3575 |
$delete_status = 'COMPLETED'; |
| 3576 |
} else { |
| 3577 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 3578 |
if ( isset( $response_data['status'] ) ) { |
| 3579 |
$delete_status = $response_data['status']; |
| 3580 |
} elseif ( isset( $response_data['name'] ) ) { |
| 3581 |
$delete_status = $response_data['name']; |
| 3582 |
} else { |
| 3583 |
$delete_status = 'DELETE ERROR'; |
| 3584 |
} |
| 3585 |
} |
| 3586 |
return $delete_status; |
| 3587 |
} |
| 3588 |
|
| 3589 |
/** |
| 3590 |
* 決済完了ページ制御 |
| 3591 |
* usces_filter_check_acting_return_results |
| 3592 |
* |
| 3593 |
* @param array $results Results data. |
| 3594 |
* @return array |
| 3595 |
*/ |
| 3596 |
public function acting_return( $results ) { |
| 3597 |
$acting_flg = ( isset( $results['acting'] ) ) ? 'acting_' . $results['acting'] : ''; |
| 3598 |
if ( ! in_array( $acting_flg, $this->pay_method ) ) { |
| 3599 |
return $results; |
| 3600 |
} |
| 3601 |
if ( isset( $results['acting_return'] ) && 1 !== (int) $results['acting_return'] ) { |
| 3602 |
return $results; |
| 3603 |
} |
| 3604 |
if ( ! isset( $results['_nonce'] ) || ! wp_verify_nonce( $results['_nonce'], $acting_flg ) ) { |
| 3605 |
wp_redirect( home_url() ); |
| 3606 |
exit(); |
| 3607 |
} |
| 3608 |
$results['reg_order'] = false; |
| 3609 |
return $results; |
| 3610 |
} |
| 3611 |
|
| 3612 |
/** |
| 3613 |
* 受注データ登録 |
| 3614 |
* Called by usces_reg_orderdata() and usces_new_orderdata(). |
| 3615 |
* usces_action_reg_orderdata |
| 3616 |
* |
| 3617 |
* @param array $args Compact array( $cart, $entry, $order_id, $member_id, $payments, $charging_type, $results ). |
| 3618 |
*/ |
| 3619 |
public function register_orderdata( $args ) { |
| 3620 |
global $usces; |
| 3621 |
extract( $args ); |
| 3622 |
|
| 3623 |
$acting_flg = $payments['settlement']; |
| 3624 |
if ( ! in_array( $acting_flg, $this->pay_method ) ) { |
| 3625 |
return; |
| 3626 |
} |
| 3627 |
if ( ! $entry['order']['total_full_price'] ) { |
| 3628 |
return; |
| 3629 |
} |
| 3630 |
|
| 3631 |
if ( isset( $results['id'] ) && isset( $results['purchase_units'] ) ) { |
| 3632 |
$acting = substr( $acting_flg, 7 ); |
| 3633 |
$usces->set_order_meta_value( 'resource_id', $results['id'], $order_id ); |
| 3634 |
$purchase_units = $results['purchase_units'][0]; |
| 3635 |
if ( isset( $purchase_units['reference_id'] ) ) { |
| 3636 |
$tracking_id = $purchase_units['reference_id']; /* rand */ |
| 3637 |
$usces->set_order_meta_value( 'reference_id', $tracking_id, $order_id ); |
| 3638 |
} |
| 3639 |
if ( isset( $purchase_units['payments'] ) ) { |
| 3640 |
if ( isset( $purchase_units['payments']['captures'] ) ) { |
| 3641 |
$acting_status = 'CAPTURE'; |
| 3642 |
$payments = $purchase_units['payments']['captures'][0]; |
| 3643 |
} elseif ( isset( $purchase_units['payments']['authorizations'] ) ) { |
| 3644 |
$acting_status = 'AUTHORIZE'; |
| 3645 |
$payments = $purchase_units['payments']['authorizations'][0]; |
| 3646 |
} |
| 3647 |
if ( ! empty( $payments['id'] ) ) { |
| 3648 |
$usces->set_order_meta_value( 'wc_trans_id', $payments['id'], $order_id ); /* 決済ID */ |
| 3649 |
$usces->set_order_meta_value( 'trans_id', $payments['id'], $order_id ); /* 取引ID */ |
| 3650 |
} |
| 3651 |
if ( isset( $results['status'] ) && ! empty( $tracking_id ) ) { |
| 3652 |
$results = apply_filters( 'usces_filter_paypal_cp_register_orderdata_log', $results, $args ); |
| 3653 |
$this->save_acting_log( $results, $acting, $acting_status, $results['status'], $entry['order']['total_full_price'], $order_id, $tracking_id ); |
| 3654 |
} |
| 3655 |
} |
| 3656 |
$results['acting'] = $acting; |
| 3657 |
$usces->set_order_meta_value( $acting_flg, usces_serialize( $results ), $order_id ); |
| 3658 |
if ( isset( $results['card_3ds'] ) ) { |
| 3659 |
$usces->set_order_meta_value( 'liability_shift', $results['card_3ds']['liability_shift'], $order_id ); |
| 3660 |
$usces->set_order_meta_value( 'enrollment_status', $results['card_3ds']['enrollment_status'], $order_id ); |
| 3661 |
$usces->set_order_meta_value( 'authentication_status', $results['card_3ds']['authentication_status'], $order_id ); |
| 3662 |
} |
| 3663 |
} |
| 3664 |
} |
| 3665 |
|
| 3666 |
/** |
| 3667 |
* ポイント即時付与 |
| 3668 |
* usces_filter_is_complete_settlement |
| 3669 |
* |
| 3670 |
* @param boolean $complete Always give points immediately. |
| 3671 |
* @param string $payment_name Payment name. |
| 3672 |
* @param string $status Payment status. |
| 3673 |
* @return boolean |
| 3674 |
*/ |
| 3675 |
public function is_complete_settlement( $complete, $payment_name, $status ) { |
| 3676 |
$payment = usces_get_payments_by_name( $payment_name ); |
| 3677 |
if ( isset( $payment['settlement'] ) && in_array( $payment['settlement'], $this->pay_method ) ) { |
| 3678 |
$complete = true; |
| 3679 |
} |
| 3680 |
return $complete; |
| 3681 |
} |
| 3682 |
|
| 3683 |
/** |
| 3684 |
* 会員データ削除チェック |
| 3685 |
* usces_filter_delete_member_check |
| 3686 |
* |
| 3687 |
* @param boolean $del Removable|unavailable. |
| 3688 |
* @param int $member_id Member ID. |
| 3689 |
* @return boolean |
| 3690 |
*/ |
| 3691 |
public function delete_member_check( $del, $member_id ) { |
| 3692 |
if ( usces_have_member_continue_order( $member_id ) || usces_have_member_regular_order( $member_id ) ) { |
| 3693 |
$del = false; |
| 3694 |
} |
| 3695 |
return $del; |
| 3696 |
} |
| 3697 |
|
| 3698 |
/** |
| 3699 |
* 会員データ削除 |
| 3700 |
* usces_action_pre_delete_memberdata |
| 3701 |
* |
| 3702 |
* @param string $member_id Member ID. |
| 3703 |
*/ |
| 3704 |
public function delete_member( $member_id ) { |
| 3705 |
|
| 3706 |
/* Get Access Token */ |
| 3707 |
$access_token = $this->get_access_token(); |
| 3708 |
|
| 3709 |
$payment_tokens = $this->api_get_payment_tokens( $access_token, $member_id ); |
| 3710 |
if ( ! empty( $payment_tokens['payment_tokens'] ) && is_array( $payment_tokens['payment_tokens'] ) ) { |
| 3711 |
foreach ( $payment_tokens['payment_tokens'] as $payment_token ) { |
| 3712 |
$delete_status = $this->api_delete_payment_tokens( $access_token, $payment_token['id'] ); |
| 3713 |
} |
| 3714 |
} |
| 3715 |
} |
| 3716 |
|
| 3717 |
/** |
| 3718 |
* クレジットカード登録・変更ページ表示 |
| 3719 |
* usces_filter_template_redirect |
| 3720 |
*/ |
| 3721 |
public function member_update_settlement() { |
| 3722 |
global $usces; |
| 3723 |
|
| 3724 |
if ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) { |
| 3725 |
if ( ! usces_is_membersystem_state() || ! usces_is_login() ) { |
| 3726 |
return; |
| 3727 |
} |
| 3728 |
$acting_opts = $this->get_acting_settings(); |
| 3729 |
if ( 'on' !== $acting_opts['card_vault'] ) { |
| 3730 |
return; |
| 3731 |
} |
| 3732 |
$usces_page = ( isset( $_REQUEST['usces_page'] ) ) ? wp_unslash( $_REQUEST['usces_page'] ) : ''; |
| 3733 |
if ( 'member_update_settlement' === $usces_page ) { |
| 3734 |
add_filter( 'usces_filter_states_form_js', array( $this, 'states_form_js' ) ); |
| 3735 |
$usces->page = 'member_update_settlement'; |
| 3736 |
$this->member_update_settlement_form(); |
| 3737 |
exit(); |
| 3738 |
} elseif ( 'member_register_settlement' === $usces_page ) { |
| 3739 |
add_filter( 'usces_filter_states_form_js', array( $this, 'states_form_js' ) ); |
| 3740 |
$usces->page = 'member_register_settlement'; |
| 3741 |
$this->member_update_settlement_form(); |
| 3742 |
exit(); |
| 3743 |
} |
| 3744 |
} |
| 3745 |
// return false; |
| 3746 |
} |
| 3747 |
|
| 3748 |
/** |
| 3749 |
* クレジットカード登録・変更ページ表示 |
| 3750 |
* usces_filter_states_form_js |
| 3751 |
* |
| 3752 |
* @param string $js Scripts. |
| 3753 |
* @return string |
| 3754 |
*/ |
| 3755 |
public function states_form_js( $js ) { |
| 3756 |
return ''; |
| 3757 |
} |
| 3758 |
|
| 3759 |
/** |
| 3760 |
* クレジットカード登録・変更ページリンク |
| 3761 |
* usces_action_member_submenu_list |
| 3762 |
*/ |
| 3763 |
public function e_update_settlement() { |
| 3764 |
global $usces; |
| 3765 |
|
| 3766 |
$member = $usces->get_member(); |
| 3767 |
$form = $this->update_settlement( '', $member ); |
| 3768 |
echo $form; // no escape. |
| 3769 |
} |
| 3770 |
|
| 3771 |
/** |
| 3772 |
* クレジットカード登録・変更ページリンク |
| 3773 |
* usces_filter_member_submenu_list |
| 3774 |
* |
| 3775 |
* @param string $form Submenu area of the member page. |
| 3776 |
* @param array $member Member information. |
| 3777 |
* @return string |
| 3778 |
*/ |
| 3779 |
public function update_settlement( $form, $member ) { |
| 3780 |
$acting_opts = $this->get_acting_settings(); |
| 3781 |
if ( isset( $acting_opts['card_activate'] ) && 'off' !== $acting_opts['card_activate'] && 'on' === $acting_opts['card_vault'] && ! empty( $member['ID'] ) ) { |
| 3782 |
|
| 3783 |
/* Get Access Token */ |
| 3784 |
$access_token = $this->get_access_token(); |
| 3785 |
|
| 3786 |
$payment_tokens = $this->api_get_payment_tokens( $access_token, $member['ID'] ); |
| 3787 |
if ( ! empty( $payment_tokens['payment_tokens'] ) ) { |
| 3788 |
$update_settlement_url = add_query_arg( |
| 3789 |
array( |
| 3790 |
'usces_page' => 'member_update_settlement', |
| 3791 |
're-enter' => 1, |
| 3792 |
), |
| 3793 |
USCES_MEMBER_URL |
| 3794 |
); |
| 3795 |
$form .= '<li class="settlement-update gotoedit"><a href="' . $update_settlement_url . '">' . __( 'Change the credit card is here >>', 'usces' ) . '</a></li>'; |
| 3796 |
} else { |
| 3797 |
$register_settlement_url = add_query_arg( |
| 3798 |
array( |
| 3799 |
'usces_page' => 'member_register_settlement', |
| 3800 |
're-enter' => 1, |
| 3801 |
), |
| 3802 |
USCES_MEMBER_URL |
| 3803 |
); |
| 3804 |
$form .= '<li class="settlement-register gotoedit"><a href="' . $register_settlement_url . '">' . __( 'Credit card registration is here >>', 'usces' ) . '</a></li>'; |
| 3805 |
} |
| 3806 |
} |
| 3807 |
return $form; |
| 3808 |
} |
| 3809 |
|
| 3810 |
/** |
| 3811 |
* クレジットカード登録・変更ページ |
| 3812 |
*/ |
| 3813 |
public function member_update_settlement_form() { |
| 3814 |
global $usces; |
| 3815 |
|
| 3816 |
$member = $usces->get_member(); |
| 3817 |
$acting_opts = $this->get_acting_settings(); |
| 3818 |
|
| 3819 |
$bn_code = self::API_BN_CODE_ACDC; |
| 3820 |
$script = ''; |
| 3821 |
$done_message = ''; |
| 3822 |
$update_settlement_url = add_query_arg( |
| 3823 |
array( |
| 3824 |
'usces_page' => $usces->page, |
| 3825 |
'settlement' => 1, |
| 3826 |
're-enter' => 1, |
| 3827 |
), |
| 3828 |
USCES_MEMBER_URL |
| 3829 |
); |
| 3830 |
|
| 3831 |
$update_mode = ( isset( $_POST['update_mode'] ) ) ? wp_unslash( $_POST['update_mode'] ) : ''; |
| 3832 |
if ( 'card-register' === $update_mode ) { |
| 3833 |
check_admin_referer( 'member_update_settlement', 'wc_nonce' ); |
| 3834 |
$verify_action = wel_verify_update_settlement( $member['ID'] ); |
| 3835 |
if ( ! $verify_action ) { |
| 3836 |
$usces->error_message .= '<p>' . __( 'Update has been locked. Please contact the store administrator.', 'usces' ) . '</p>'; |
| 3837 |
} else { |
| 3838 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 3839 |
$tracking_id = ( isset( $_POST['paypal_tracking_id'] ) ) ? wp_unslash( $_POST['paypal_tracking_id'] ) : ''; |
| 3840 |
$resource_id = ( isset( $_POST['paypal_resource_id'] ) ) ? wp_unslash( $_POST['paypal_resource_id'] ) : ''; |
| 3841 |
|
| 3842 |
/* Get Access Token */ |
| 3843 |
$access_token = $this->get_access_token(); |
| 3844 |
|
| 3845 |
$correlation_id = ''; |
| 3846 |
$payment_source = array(); |
| 3847 |
|
| 3848 |
/* Authorize */ |
| 3849 |
$response_data = $this->api_authorize_order( $access_token, $bn_code, $tracking_id, $resource_id, $correlation_id, $payment_source ); |
| 3850 |
if ( isset( $response_data['id'] ) && isset( $response_data['status'] ) && 'COMPLETED' === $response_data['status'] ) { |
| 3851 |
$done_message = __( 'Successfully registered.', 'usces' ); |
| 3852 |
$purchase_units = $response_data['purchase_units'][0]; |
| 3853 |
if ( isset( $purchase_units['payments']['authorizations'] ) ) { |
| 3854 |
$payments = $purchase_units['payments']['authorizations'][0]; |
| 3855 |
if ( ! empty( $payments['id'] ) ) { |
| 3856 |
$void_status = $this->api_authorize_void( $access_token, $bn_code, $tracking_id, $payments['id'] ); |
| 3857 |
} |
| 3858 |
} |
| 3859 |
} else { |
| 3860 |
$done_message = __( 'Registration failed.', 'usces' ); |
| 3861 |
} |
| 3862 |
} |
| 3863 |
} elseif ( 'card-update' === $update_mode ) { |
| 3864 |
check_admin_referer( 'member_update_settlement', 'wc_nonce' ); |
| 3865 |
$verify_action = wel_verify_update_settlement( $member['ID'] ); |
| 3866 |
if ( ! $verify_action ) { |
| 3867 |
$usces->error_message .= '<p>' . __( 'Update has been locked. Please contact the store administrator.', 'usces' ) . '</p>'; |
| 3868 |
} else { |
| 3869 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 3870 |
$tracking_id = ( isset( $_POST['paypal_tracking_id'] ) ) ? wp_unslash( $_POST['paypal_tracking_id'] ) : ''; |
| 3871 |
$resource_id = ( isset( $_POST['paypal_resource_id'] ) ) ? wp_unslash( $_POST['paypal_resource_id'] ) : ''; |
| 3872 |
$payment_token_id = ( isset( $_POST['paypal_payment_token_id'] ) ) ? wp_unslash( $_POST['paypal_payment_token_id'] ) : ''; |
| 3873 |
if ( ! empty( $payment_token_id ) ) { |
| 3874 |
|
| 3875 |
/* Get Access Token */ |
| 3876 |
$access_token = $this->get_access_token(); |
| 3877 |
|
| 3878 |
$delete_status = $this->api_delete_payment_tokens( $access_token, $payment_token_id ); |
| 3879 |
if ( 'COMPLETED' === $delete_status ) { |
| 3880 |
$correlation_id = ''; |
| 3881 |
$payment_source = array(); |
| 3882 |
|
| 3883 |
/* Authorize */ |
| 3884 |
$response_data = $this->api_authorize_order( $access_token, $bn_code, $tracking_id, $resource_id, $correlation_id, $payment_source ); |
| 3885 |
if ( isset( $response_data['id'] ) && isset( $response_data['status'] ) && 'COMPLETED' === $response_data['status'] ) { |
| 3886 |
$this->send_update_settlement_mail(); |
| 3887 |
$done_message = __( 'Successfully updated.', 'usces' ); |
| 3888 |
$purchase_units = $response_data['purchase_units'][0]; |
| 3889 |
if ( isset( $purchase_units['payments']['authorizations'] ) ) { |
| 3890 |
$payments = $purchase_units['payments']['authorizations'][0]; |
| 3891 |
if ( ! empty( $payments['id'] ) ) { |
| 3892 |
$void_status = $this->api_authorize_void( $access_token, $bn_code, $tracking_id, $payments['id'] ); |
| 3893 |
} |
| 3894 |
} |
| 3895 |
} else { |
| 3896 |
$done_message = __( 'Update failed.', 'usces' ); |
| 3897 |
} |
| 3898 |
} else { |
| 3899 |
$done_message = __( 'Update failed.', 'usces' ); |
| 3900 |
} |
| 3901 |
} else { |
| 3902 |
$done_message = __( 'Update failed.', 'usces' ); |
| 3903 |
} |
| 3904 |
} |
| 3905 |
} elseif ( 'card-delete' === $update_mode ) { |
| 3906 |
check_admin_referer( 'member_update_settlement', 'wc_nonce' ); |
| 3907 |
$payment_token_id = ( isset( $_POST['paypal_payment_token_id'] ) ) ? wp_unslash( $_POST['paypal_payment_token_id'] ) : ''; |
| 3908 |
if ( ! empty( $payment_token_id ) ) { |
| 3909 |
|
| 3910 |
/* Get Access Token */ |
| 3911 |
$access_token = $this->get_access_token(); |
| 3912 |
|
| 3913 |
$delete_status = $this->api_delete_payment_tokens( $access_token, $payment_token_id ); |
| 3914 |
if ( 'COMPLETED' === $delete_status ) { |
| 3915 |
$done_message = __( 'Successfully deleted.', 'usces' ); |
| 3916 |
} else { |
| 3917 |
$done_message = __( 'Deletion failed.', 'usces' ); |
| 3918 |
} |
| 3919 |
} else { |
| 3920 |
$done_message = __( 'Deletion failed.', 'usces' ); |
| 3921 |
} |
| 3922 |
} |
| 3923 |
|
| 3924 |
if ( '' !== $done_message ) { |
| 3925 |
$script .= ' |
| 3926 |
<script type="text/javascript"> |
| 3927 |
jQuery.event.add( window, "load", function() { |
| 3928 |
alert( "' . $done_message . '" ); |
| 3929 |
}); |
| 3930 |
</script>'; |
| 3931 |
} |
| 3932 |
$error_message = apply_filters( 'usces_filter_member_update_settlement_error_message', $usces->error_message ); |
| 3933 |
|
| 3934 |
$payment_token_id = ''; |
| 3935 |
$payment_token_last_digits = ''; |
| 3936 |
$payment_token_brand = ''; |
| 3937 |
|
| 3938 |
/* Get Access Token */ |
| 3939 |
$access_token = $this->get_access_token(); |
| 3940 |
|
| 3941 |
$payment_tokens = $this->api_get_payment_tokens( $access_token, $member['ID'] ); |
| 3942 |
if ( ! empty( $payment_tokens['payment_tokens'] ) && is_array( $payment_tokens['payment_tokens'] ) ) { |
| 3943 |
$tokens_count = count( $payment_tokens['payment_tokens'] ); |
| 3944 |
if ( 1 === $tokens_count ) { |
| 3945 |
$payment_token = current( $payment_tokens['payment_tokens'] ); |
| 3946 |
$payment_token_id = $payment_token['id']; |
| 3947 |
$payment_token_last_digits = $payment_token['source']['card']['last_digits']; |
| 3948 |
$payment_token_brand = $payment_token['source']['card']['brand']; |
| 3949 |
$register = false; |
| 3950 |
} else { |
| 3951 |
foreach ( $payment_tokens['payment_tokens'] as $payment_token ) { |
| 3952 |
$delete_status = $this->api_delete_payment_tokens( $access_token, $payment_token['id'] ); |
| 3953 |
} |
| 3954 |
$register = true; |
| 3955 |
} |
| 3956 |
} else { |
| 3957 |
$register = true; |
| 3958 |
} |
| 3959 |
|
| 3960 |
$tracking_id = usces_acting_key(); |
| 3961 |
|
| 3962 |
ob_start(); |
| 3963 |
get_header(); |
| 3964 |
if ( '' !== $script ) { |
| 3965 |
echo $script; // no escape due to script. |
| 3966 |
} |
| 3967 |
?> |
| 3968 |
<div id="content" class="two-column"> |
| 3969 |
<div class="catbox"> |
| 3970 |
<?php |
| 3971 |
if ( have_posts() ) : |
| 3972 |
usces_remove_filter(); |
| 3973 |
?> |
| 3974 |
<div class="post" id="wc_member_update_settlement"> |
| 3975 |
<?php if ( $register ) : ?> |
| 3976 |
<h1 class="member_page_title"><?php esc_html_e( 'Credit card registration', 'usces' ); ?></h1> |
| 3977 |
<?php else : ?> |
| 3978 |
<h1 class="member_page_title"><?php esc_html_e( 'Credit card update', 'usces' ); ?></h1> |
| 3979 |
<?php endif; ?> |
| 3980 |
<div class="entry"> |
| 3981 |
<div id="memberpages"> |
| 3982 |
<div class="whitebox"> |
| 3983 |
<div id="memberinfo"> |
| 3984 |
<div class="header_explanation"></div> |
| 3985 |
<div class="error_message"><?php wel_esc_script_e( $error_message ); ?></div> |
| 3986 |
<form id="member-card-update" name="member_card_update" action="<?php echo esc_url( $update_settlement_url ); ?>" method="post" onKeyDown="if(event.keyCode == 13) {return false;}"> |
| 3987 |
<table class="customer_form" id="paypal_card_form"> |
| 3988 |
<tbody><tr><td> |
| 3989 |
<?php if ( ! $register ) : ?> |
| 3990 |
<div class="card_container"> |
| 3991 |
<p><?php esc_html_e( 'Your registered credit card', 'usces' ); ?></p> |
| 3992 |
<p><?php echo esc_html( $payment_token_brand ); ?> <?php esc_html_e( 'Lower 4 digits', 'usces' ); ?>:<?php echo esc_html( $payment_token_last_digits ); ?></p> |
| 3993 |
</div> |
| 3994 |
</td></tr><tr><td> |
| 3995 |
<?php endif; ?> |
| 3996 |
<div class="card_container"> |
| 3997 |
<div> |
| 3998 |
<label for="card-number"><?php esc_html_e( 'Card Number', 'usces' ); ?></label> |
| 3999 |
<div id="card-number" class="card_field"></div> |
| 4000 |
</div> |
| 4001 |
<div> |
| 4002 |
<label for="expiration-date"><?php esc_html_e( 'Expiration Date', 'usces' ); ?></label> |
| 4003 |
<div id="expiration-date" class="card_field"></div> |
| 4004 |
</div> |
| 4005 |
<div> |
| 4006 |
<label for="cvv"><?php esc_html_e( 'CVV', 'usces' ); ?></label> |
| 4007 |
<div id="cvv" class="card_field"></div> |
| 4008 |
</div> |
| 4009 |
</div> |
| 4010 |
</td></tr></tbody> |
| 4011 |
</table> |
| 4012 |
<input type="hidden" id="paypal_tracking_id" name="paypal_tracking_id" value="<?php echo esc_attr( $tracking_id ); ?>" /> |
| 4013 |
<input type="hidden" id="paypal_resource_id" name="paypal_resource_id" value="" /> |
| 4014 |
<input type="hidden" id="paypal_payment_token_id " name="paypal_payment_token_id" value="<?php echo esc_attr( $payment_token_id ); ?>" /> |
| 4015 |
<input type="hidden" id="paypal_f" name="paypal_f" value="" /> |
| 4016 |
<div class="send"> |
| 4017 |
<?php if ( $register ) : ?> |
| 4018 |
<input type="submit" id="card-update" class="card-update" value="<?php esc_attr_e( 'Register', 'usces' ); ?>" /> |
| 4019 |
<input type="hidden" id="update-mode" name="update_mode" value="card-register" /> |
| 4020 |
<?php else : ?> |
| 4021 |
<input type="submit" id="card-update" class="card-update" value="<?php esc_attr_e( 'Update', 'usces' ); ?>" /> |
| 4022 |
<input type="submit" id="card-delete" class="card-update" value="<?php esc_attr_e( 'Delete', 'usces' ); ?>" /> |
| 4023 |
<input type="hidden" id="update-mode" name="update_mode" value="card-update" /> |
| 4024 |
<?php endif; ?> |
| 4025 |
<input type="button" name="back" value="<?php esc_attr_e( 'Back to the member page.', 'usces' ); ?>" onclick="location.href='<?php echo esc_url( USCES_MEMBER_URL ); ?>'" /> |
| 4026 |
<input type="button" name="top" value="<?php esc_attr_e( 'Back to the top page.', 'usces' ); ?>" onclick="location.href='<?php echo esc_url( home_url() ); ?>'" /> |
| 4027 |
</div> |
| 4028 |
<?php wp_nonce_field( 'member_update_settlement', 'wc_nonce' ); ?> |
| 4029 |
</form> |
| 4030 |
<div class="footer_explanation"></div> |
| 4031 |
</div><!-- end of memberinfo --> |
| 4032 |
</div><!-- end of whitebox --> |
| 4033 |
</div><!-- end of memberpages --> |
| 4034 |
</div><!-- end of entry --> |
| 4035 |
</div><!-- end of post --> |
| 4036 |
<?php else : ?> |
| 4037 |
<p><?php esc_html_e( 'Sorry, no posts matched your criteria.', 'usces' ); ?></p> |
| 4038 |
<?php endif; ?> |
| 4039 |
</div><!-- end of catbox --> |
| 4040 |
</div><!-- end of content --> |
| 4041 |
<?php |
| 4042 |
$sidebar = apply_filters( 'usces_filter_member_update_settlement_page_sidebar', 'cartmember' ); |
| 4043 |
if ( ! empty( $sidebar ) ) { |
| 4044 |
get_sidebar( $sidebar ); |
| 4045 |
} |
| 4046 |
get_footer(); |
| 4047 |
$contents = ob_get_contents(); |
| 4048 |
ob_end_clean(); |
| 4049 |
echo $contents; // no escape. |
| 4050 |
} |
| 4051 |
|
| 4052 |
/** |
| 4053 |
* クレジットカード変更メール |
| 4054 |
*/ |
| 4055 |
public function send_update_settlement_mail() { |
| 4056 |
global $usces; |
| 4057 |
|
| 4058 |
$member = $usces->get_member(); |
| 4059 |
|
| 4060 |
$subject = apply_filters( 'usces_filter_send_update_settlement_mail_subject', __( 'Confirmation of credit card update', 'usces' ), $member ); |
| 4061 |
$mail_header = __( 'Your credit card information has been updated on the membership page.', 'usces' ) . "\r\n\r\n"; |
| 4062 |
$mail_footer = get_option( 'blogname' ) . "\r\n"; |
| 4063 |
$name = usces_localized_name( $member['name1'], $member['name2'], 'return' ); |
| 4064 |
|
| 4065 |
$message = '--------------------------------' . "\r\n"; |
| 4066 |
$message .= __( 'Member ID', 'usces' ) . ' : ' . $member['ID'] . "\r\n"; |
| 4067 |
$message .= __( 'Name', 'usces' ) . ' : ' . sprintf( _x( '%s', 'honorific', 'usces' ), $name ) . "\r\n"; |
| 4068 |
$message .= __( 'e-mail adress', 'usces' ) . ' : ' . $member['mailaddress1'] . "\r\n"; |
| 4069 |
$message .= '--------------------------------' . "\r\n\r\n"; |
| 4070 |
$message .= __( 'If you have not requested this email, sorry to trouble you, but please contact us.', 'usces' ) . "\r\n\r\n"; |
| 4071 |
$message = apply_filters( 'usces_filter_send_update_settlement_mail_message', $message, $member ); |
| 4072 |
$message = apply_filters( 'usces_filter_send_update_settlement_mail_message_head', $mail_header, $member ) . $message . apply_filters( 'usces_filter_send_update_settlement_mail_message_foot', $mail_footer, $member ) . "\r\n"; |
| 4073 |
$message = sprintf( __( 'Dear %s', 'usces' ), $name ) . "\r\n\r\n" . $message; |
| 4074 |
|
| 4075 |
$send_para = array( |
| 4076 |
'to_name' => sprintf( _x( '%s', 'honorific', 'usces' ), $name ), |
| 4077 |
'to_address' => $member['mailaddress1'], |
| 4078 |
'from_name' => get_option( 'blogname' ), |
| 4079 |
'from_address' => $usces->options['sender_mail'], |
| 4080 |
'reply_name' => get_option( 'blogname' ), |
| 4081 |
'reply_to' => usces_get_first_order_mail(), |
| 4082 |
'return_path' => $usces->options['sender_mail'], |
| 4083 |
'subject' => $subject, |
| 4084 |
'message' => do_shortcode( $message ), |
| 4085 |
); |
| 4086 |
usces_send_mail( $send_para ); |
| 4087 |
|
| 4088 |
$admin_message = $mail_header; |
| 4089 |
$admin_message .= '--------------------------------' . "\r\n"; |
| 4090 |
$admin_message .= __( 'Member ID', 'usces' ) . ' : ' . $member['ID'] . "\r\n"; |
| 4091 |
$admin_message .= __( 'Name', 'usces' ) . ' : ' . sprintf( _x( '%s', 'honorific', 'usces' ), $name ) . "\r\n"; |
| 4092 |
$admin_message .= __( 'e-mail adress', 'usces' ) . ' : ' . $member['mailaddress1'] . "\r\n"; |
| 4093 |
$admin_message .= '--------------------------------' . "\r\n\r\n"; |
| 4094 |
$admin_message .= |
| 4095 |
"\r\n----------------------------------------------------\r\n" . |
| 4096 |
'REMOTE_ADDR : ' . wp_unslash( $_SERVER['REMOTE_ADDR'] ) . |
| 4097 |
"\r\n----------------------------------------------------\r\n"; |
| 4098 |
|
| 4099 |
$admin_para = array( |
| 4100 |
'to_name' => apply_filters( 'usces_filter_bccmail_to_admin_name', 'Shop Admin' ), |
| 4101 |
'to_address' => $usces->options['order_mail'], |
| 4102 |
'from_name' => apply_filters( 'usces_filter_bccmail_from_admin_name', 'Welcart Auto BCC' ), |
| 4103 |
'from_address' => $usces->options['sender_mail'], |
| 4104 |
'reply_name' => get_option( 'blogname' ), |
| 4105 |
'reply_to' => usces_get_first_order_mail(), |
| 4106 |
'return_path' => $usces->options['sender_mail'], |
| 4107 |
'subject' => $subject . '( ' . sprintf( _x( '%s', 'honorific', 'usces' ), $name ) . ' )', |
| 4108 |
'message' => do_shortcode( $admin_message ), |
| 4109 |
); |
| 4110 |
usces_send_mail( $admin_para ); |
| 4111 |
} |
| 4112 |
|
| 4113 |
/** |
| 4114 |
* 管理画面決済処理 |
| 4115 |
* usces_action_admin_ajax |
| 4116 |
*/ |
| 4117 |
public function admin_ajax() { |
| 4118 |
global $usces; |
| 4119 |
|
| 4120 |
$mode = wp_unslash( $_POST['mode'] ); |
| 4121 |
$data = array(); |
| 4122 |
|
| 4123 |
switch ( $mode ) { |
| 4124 |
/* Upfront Onboarding */ |
| 4125 |
case 'upfront_onboarding': |
| 4126 |
check_admin_referer( 'admin_settlement', 'wc_nonce' ); |
| 4127 |
|
| 4128 |
/* Get Access Token */ |
| 4129 |
$cp_client_id = 'AYbgr2xC4qFsOLqWriUhmUrTLVKQZl_LsO4lLRQ1hkWYaqalZ-DY9n6L4edGt-T0Gnwem9_jKjSgbKc8'; |
| 4130 |
$cp_secret = 'EE_9-oMggvZjksDF2zpdmAafq_v7LZutPWgE1W6yu_KKU4sbeFIswcVjoDUeyA3Szywjs3xQ3qRdTDoj'; |
| 4131 |
$api_request_url = self::API_URL; |
| 4132 |
|
| 4133 |
$headers = array( |
| 4134 |
'Content-Type: application/x-www-form-urlencoded;application/json', |
| 4135 |
'Accept: application/json', |
| 4136 |
); |
| 4137 |
$ch = curl_init(); |
| 4138 |
curl_setopt( $ch, CURLOPT_URL, $api_request_url . '/v1/oauth2/token' ); |
| 4139 |
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
| 4140 |
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); |
| 4141 |
curl_setopt( $ch, CURLOPT_USERPWD, $cp_client_id . ':' . $cp_secret ); |
| 4142 |
curl_setopt( $ch, CURLOPT_POST, true ); |
| 4143 |
curl_setopt( $ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials' ); |
| 4144 |
|
| 4145 |
$result = curl_exec( $ch ); |
| 4146 |
if ( ! $result ) { |
| 4147 |
$error = curl_error( $ch ); |
| 4148 |
wp_send_json( json_decode( $error, true ) ); |
| 4149 |
} |
| 4150 |
unset( $ch ); |
| 4151 |
$access_token = json_decode( $result, true ); |
| 4152 |
|
| 4153 |
$seller_nonce = $this->get_seller_nonce(); |
| 4154 |
$features = array( 'PAYMENT', 'REFUND', 'VAULT' ); |
| 4155 |
$operations = array(); |
| 4156 |
$operations['operation'] = 'API_INTEGRATION'; |
| 4157 |
$operations['api_integration_preference']['rest_api_integration']['integration_method'] = 'PAYPAL'; |
| 4158 |
$operations['api_integration_preference']['rest_api_integration']['integration_type'] = 'FIRST_PARTY'; |
| 4159 |
$operations['api_integration_preference']['rest_api_integration']['first_party_details']['features'] = $features; |
| 4160 |
$operations['api_integration_preference']['rest_api_integration']['first_party_details']['seller_nonce'] = $seller_nonce; |
| 4161 |
$products = array( 'EXPRESS_CHECKOUT' ); |
| 4162 |
$legal_consents = array(); |
| 4163 |
$legal_consents['type'] = 'SHARE_DATA_CONSENT'; |
| 4164 |
$legal_consents['granted'] = true; |
| 4165 |
|
| 4166 |
$body = array(); |
| 4167 |
if ( 'ja' === usces_get_local_language() ) { |
| 4168 |
$body['preferred_language_code'] = 'ja-JP'; |
| 4169 |
$addresses = array( 'country_code' => 'JP' ); |
| 4170 |
$body['business_entity'] = array( $addresses ); |
| 4171 |
} |
| 4172 |
$body['operations'] = array( $operations ); |
| 4173 |
$body['products'] = $products; |
| 4174 |
$body['legal_consents'] = array( $legal_consents ); |
| 4175 |
|
| 4176 |
$params = array( |
| 4177 |
'method' => 'POST', |
| 4178 |
'headers' => array( |
| 4179 |
'Content-Type' => 'application/json;charset=utf-8', |
| 4180 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 4181 |
), |
| 4182 |
'timeout' => self::API_TIMEOUT, |
| 4183 |
'body' => wp_json_encode( $body ), |
| 4184 |
); |
| 4185 |
$response = wp_remote_post( $api_request_url . '/v2/customer/partner-referrals', $params ); |
| 4186 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 4187 |
|
| 4188 |
$action_url = ''; |
| 4189 |
$res = ''; |
| 4190 |
if ( isset( $response_data['links'] ) ) { |
| 4191 |
foreach ( (array) $response_data['links'] as $links ) { |
| 4192 |
if ( isset( $links['rel'] ) && 'action_url' === $links['rel'] && isset( $links['href'] ) ) { |
| 4193 |
$action_url = $links['href']; |
| 4194 |
} |
| 4195 |
} |
| 4196 |
} |
| 4197 |
if ( '' === $action_url && isset( $response_data['name'] ) ) { |
| 4198 |
$res = $response_data['name']; |
| 4199 |
} |
| 4200 |
wp_send_json( |
| 4201 |
array( |
| 4202 |
'action_url' => $action_url, |
| 4203 |
'res' => $res, |
| 4204 |
'seller_nonce' => $seller_nonce, |
| 4205 |
) |
| 4206 |
); |
| 4207 |
break; |
| 4208 |
|
| 4209 |
/* 参� |
| 4210 |
� */ |
| 4211 |
case 'get_paypal_cp': |
| 4212 |
check_admin_referer( 'order_edit', 'wc_nonce' ); |
| 4213 |
$order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : ''; |
| 4214 |
$order_num = ( isset( $_POST['order_num'] ) ) ? wp_unslash( $_POST['order_num'] ) : 1; |
| 4215 |
$tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : ''; /* rand|reference_id */ |
| 4216 |
$member_id = ( isset( $_POST['member_id'] ) ) ? wp_unslash( $_POST['member_id'] ) : 0; |
| 4217 |
$con_id = ( defined( 'WCEX_DLSELLER' ) && isset( $_POST['con_id'] ) ) ? wp_unslash( $_POST['con_id'] ) : 0; |
| 4218 |
$reg_id = ( defined( 'WCEX_AUTO_DELIVERY' ) && isset( $_POST['reg_id'] ) ) ? wp_unslash( $_POST['reg_id'] ) : 0; |
| 4219 |
$acting = ( isset( $_POST['acting'] ) ) ? wp_unslash( $_POST['acting'] ) : 'paypal_cp'; |
| 4220 |
if ( empty( $order_id ) || empty( $tracking_id ) ) { |
| 4221 |
wp_send_json( $data ); |
| 4222 |
break; |
| 4223 |
} |
| 4224 |
|
| 4225 |
if ( 1 === (int) $order_num ) { |
| 4226 |
$resource_id = $usces->get_order_meta_value( 'resource_id', $order_id ); |
| 4227 |
} else { |
| 4228 |
$resource_id = dlseller_get_continuation_meta_value( 'resource_' . $tracking_id, $con_id ); |
| 4229 |
} |
| 4230 |
|
| 4231 |
$bn_code = ( 'paypal_card' === $acting ) ? self::API_BN_CODE_ACDC : self::API_BN_CODE_PCP; |
| 4232 |
$result = ''; |
| 4233 |
|
| 4234 |
/* Get Access Token */ |
| 4235 |
$access_token = $this->get_access_token(); |
| 4236 |
|
| 4237 |
/* Get Order */ |
| 4238 |
$response_data = $this->api_get_order( $access_token, $bn_code, $tracking_id, $resource_id ); |
| 4239 |
if ( $response_data ) { |
| 4240 |
if ( isset( $response_data['name'] ) && isset( $response_data['message'] ) && isset( $response_data['debug_id'] ) ) { |
| 4241 |
// $result .= '<div class="paypal-settlement-admin paypal-error">' . $response_data['name'] . '</div>'; |
| 4242 |
$acting_status = $this->get_acting_status( $order_id, $tracking_id ); |
| 4243 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 4244 |
$result .= '<div class="paypal-settlement-admin' . $class . '">' . __( $acting_status, 'usces' ) . '</div>'; |
| 4245 |
$log = $this->get_entry_log( $tracking_id ); |
| 4246 |
if ( isset( $log['entry'] ) && isset( $log['cart'] ) ) { |
| 4247 |
$amount = $this->get_latest_amount( $order_id, $tracking_id ); |
| 4248 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4249 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4250 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4251 |
</tr>'; |
| 4252 |
if ( empty( $amount ) ) { |
| 4253 |
if ( defined( 'WCEX_DLSELLER' ) && ! empty( $con_id ) ) { |
| 4254 |
$amount = $this->get_continuation_amount( $con_id ); |
| 4255 |
} elseif ( defined( 'WCEX_AUTO_DELIVERY' ) && ! empty( $reg_id ) ) { |
| 4256 |
$amount = $this->get_order_amount( $order_id ); |
| 4257 |
} |
| 4258 |
} |
| 4259 |
$result .= ' |
| 4260 |
<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th> |
| 4261 |
<td><input type="tel" class="settlement-amount amount" id="amount_resettlement" value="' . usces_crform( $amount, false, false, 'return', false ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4262 |
</tr> |
| 4263 |
</table>'; |
| 4264 |
if ( 'paypal_cp' === $acting ) { |
| 4265 |
$result .= '<div class="paypal-settlement-admin-button"> |
| 4266 |
<input id="re-authorize-settlement" type="button" class="button" value="' . __( 'AUTHORIZE', 'usces' ) . '" /> |
| 4267 |
<input id="re-capture-settlement" type="button" class="button" value="' . __( 'CAPTURE', 'usces' ) . '" /> |
| 4268 |
</div>'; |
| 4269 |
} |
| 4270 |
} |
| 4271 |
} else { |
| 4272 |
$pending = false; |
| 4273 |
$amount = $this->get_latest_amount( $order_id, $tracking_id ); |
| 4274 |
|
| 4275 |
$latest_log = $this->get_acting_latest_log( $order_id, $tracking_id, 'ALL' ); |
| 4276 |
if ( isset( $latest_log['result'] ) && 'COMPLETED' !== $latest_log['result'] && 'PENDING' !== $latest_log['result'] ) { |
| 4277 |
$acting_status = $this->get_acting_status( $order_id, $tracking_id ); |
| 4278 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 4279 |
$result .= '<div class="paypal-settlement-admin' . $class . '">' . __( $acting_status, 'usces' ) . '</div>'; |
| 4280 |
$log = $this->get_entry_log( $tracking_id ); |
| 4281 |
if ( isset( $log['entry'] ) && isset( $log['cart'] ) ) { |
| 4282 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4283 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4284 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4285 |
</tr>'; |
| 4286 |
if ( empty( $amount ) ) { |
| 4287 |
if ( defined( 'WCEX_DLSELLER' ) && ! empty( $con_id ) ) { |
| 4288 |
$amount = $this->get_continuation_amount( $con_id ); |
| 4289 |
} elseif ( defined( 'WCEX_AUTO_DELIVERY' ) && ! empty( $reg_id ) ) { |
| 4290 |
$amount = $this->get_order_amount( $order_id ); |
| 4291 |
} |
| 4292 |
} |
| 4293 |
$result .= ' |
| 4294 |
<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th> |
| 4295 |
<td><input type="tel" class="settlement-amount amount" id="amount_resettlement" value="' . usces_crform( $amount, false, false, 'return', false ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4296 |
</tr> |
| 4297 |
</table>'; |
| 4298 |
if ( 'paypal_cp' === $acting ) { |
| 4299 |
$result .= '<div class="paypal-settlement-admin-button"> |
| 4300 |
<input id="re-authorize-settlement" type="button" class="button" value="' . __( 'AUTHORIZE', 'usces' ) . '" /> |
| 4301 |
<input id="re-capture-settlement" type="button" class="button" value="' . __( 'CAPTURE', 'usces' ) . '" /> |
| 4302 |
</div>'; |
| 4303 |
} |
| 4304 |
} |
| 4305 |
$result .= $this->settlement_history( $order_id, $tracking_id ); |
| 4306 |
$data['result'] = $result; |
| 4307 |
wp_send_json( $data ); |
| 4308 |
break; |
| 4309 |
} |
| 4310 |
|
| 4311 |
if ( isset( $response_data['intent'] ) && isset( $response_data['purchase_units'] ) ) { |
| 4312 |
$acting_status = $response_data['intent']; |
| 4313 |
$purchase_units = $response_data['purchase_units'][0]; |
| 4314 |
if ( isset( $purchase_units['payments']['captures'] ) ) { |
| 4315 |
$payments = $purchase_units['payments']['captures'][0]; |
| 4316 |
$payments_status = ( isset( $payments['status'] ) ) ? $payments['status'] : ''; |
| 4317 |
if ( 'REFUNDED' === $payments_status ) { |
| 4318 |
$acting_status = 'REFUNDED'; |
| 4319 |
} elseif ( 'COMPLETED' === $payments_status || 'PARTIALLY_REFUNDED' === $payments_status || 'PENDING' === $payments_status ) { |
| 4320 |
$acting_status = 'CAPTURE'; |
| 4321 |
if ( 'PENDING' === $payments_status ) { |
| 4322 |
$pending = true; |
| 4323 |
} |
| 4324 |
} |
| 4325 |
} elseif ( isset( $purchase_units['payments']['authorizations'] ) ) { |
| 4326 |
$payments = $purchase_units['payments']['authorizations'][0]; |
| 4327 |
$payments_status = ( isset( $payments['status'] ) ) ? $payments['status'] : ''; |
| 4328 |
if ( 'VOIDED' === $payments_status ) { |
| 4329 |
$acting_status = 'VOIDED'; |
| 4330 |
$amount = 0; |
| 4331 |
} elseif ( 'CREATED' === $payments_status || 'PENDING' === $payments_status ) { |
| 4332 |
$acting_status = 'AUTHORIZE'; |
| 4333 |
if ( 'PENDING' === $payments_status ) { |
| 4334 |
$pending = true; |
| 4335 |
} |
| 4336 |
} |
| 4337 |
} else { |
| 4338 |
$acting_status = $this->get_acting_status( $order_id, $tracking_id ); |
| 4339 |
} |
| 4340 |
} else { |
| 4341 |
$acting_status = $this->get_acting_status( $order_id, $tracking_id ); |
| 4342 |
} |
| 4343 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 4344 |
$acting_pending = ( $pending ) ? ' ' . __( '[ PENDING ]', 'usces' ) : ''; |
| 4345 |
$result .= '<div class="paypal-settlement-admin' . $class . '">' . __( $acting_status, 'usces' ) . $acting_pending . '</div>'; |
| 4346 |
if ( 0 < $amount ) { |
| 4347 |
if ( 'AUTHORIZE' === $acting_status ) { |
| 4348 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4349 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4350 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . usces_crform( $amount, false, false, 'return', false ) . '" /></td> |
| 4351 |
</tr> |
| 4352 |
<tr><th>' . __( 'Refund amount', 'usces' ) . '</th> |
| 4353 |
<td><input type="tel" class="settlement-amount amount" id="amount_refund" value="" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4354 |
</tr> |
| 4355 |
</table>'; |
| 4356 |
$result .= '<div class="paypal-settlement-admin-button"> |
| 4357 |
<input id="capture-settlement" type="button" class="button" value="' . __( 'CAPTURE', 'usces' ) . '" /> |
| 4358 |
<input id="void-settlement" type="button" class="button" value="' . __( 'VOID', 'usces' ) . '" /> |
| 4359 |
</div>'; |
| 4360 |
} elseif ( 'CAPTURE' === $acting_status ) { |
| 4361 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4362 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4363 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . usces_crform( $amount, false, false, 'return', false ) . '" /></td> |
| 4364 |
</tr> |
| 4365 |
<tr><th>' . __( 'Refund amount', 'usces' ) . '</th> |
| 4366 |
<td><input type="tel" class="settlement-amount amount" id="amount_refund" value="" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4367 |
</tr> |
| 4368 |
</table>'; |
| 4369 |
$result .= '<div class="paypal-settlement-admin-button"> |
| 4370 |
<input id="refund-settlement" type="button" class="button" value="' . __( 'REFUND', 'usces' ) . '" /> |
| 4371 |
</div>'; |
| 4372 |
} |
| 4373 |
} else { |
| 4374 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4375 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4376 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4377 |
</tr></table>'; |
| 4378 |
} |
| 4379 |
} |
| 4380 |
} else { |
| 4381 |
$acting_status = $this->get_acting_status( $order_id, $tracking_id ); |
| 4382 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 4383 |
$result .= '<div class="paypal-settlement-admin' . $class . '">' . __( $acting_status, 'usces' ) . '</div>'; |
| 4384 |
$log = $this->get_entry_log( $tracking_id ); |
| 4385 |
if ( isset( $log['entry'] ) && isset( $log['cart'] ) ) { |
| 4386 |
$amount = $this->get_latest_amount( $order_id, $tracking_id ); |
| 4387 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4388 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4389 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4390 |
</tr>'; |
| 4391 |
if ( empty( $amount ) ) { |
| 4392 |
if ( defined( 'WCEX_DLSELLER' ) && ! empty( $con_id ) ) { |
| 4393 |
$amount = $this->get_continuation_amount( $con_id ); |
| 4394 |
} elseif ( defined( 'WCEX_AUTO_DELIVERY' ) && ! empty( $reg_id ) ) { |
| 4395 |
$amount = $this->get_order_amount( $order_id ); |
| 4396 |
} |
| 4397 |
} |
| 4398 |
$result .= ' |
| 4399 |
<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th> |
| 4400 |
<td><input type="tel" class="settlement-amount amount" id="amount_resettlement" value="' . usces_crform( $amount, false, false, 'return', false ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4401 |
</tr> |
| 4402 |
</table>'; |
| 4403 |
if ( 'paypal_cp' === $acting ) { |
| 4404 |
$result .= '<div class="paypal-settlement-admin-button"> |
| 4405 |
<input id="re-authorize-settlement" type="button" class="button" value="' . __( 'AUTHORIZE', 'usces' ) . '" /> |
| 4406 |
<input id="re-capture-settlement" type="button" class="button" value="' . __( 'CAPTURE', 'usces' ) . '" /> |
| 4407 |
</div>'; |
| 4408 |
} |
| 4409 |
} |
| 4410 |
} |
| 4411 |
$result .= $this->settlement_history( $order_id, $tracking_id ); |
| 4412 |
$data['result'] = $result; |
| 4413 |
wp_send_json( $data ); |
| 4414 |
break; |
| 4415 |
|
| 4416 |
/* CAPTURE */ |
| 4417 |
case 'capture_paypal_cp': |
| 4418 |
check_admin_referer( 'order_edit', 'wc_nonce' ); |
| 4419 |
$order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : ''; |
| 4420 |
$order_num = ( isset( $_POST['order_num'] ) ) ? wp_unslash( $_POST['order_num'] ) : 1; |
| 4421 |
$tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : ''; |
| 4422 |
$capture_amount = ( isset( $_POST['amount'] ) ) ? wp_unslash( $_POST['amount'] ) : 0; |
| 4423 |
$con_id = ( defined( 'WCEX_DLSELLER' ) && isset( $_POST['con_id'] ) ) ? wp_unslash( $_POST['con_id'] ) : 0; |
| 4424 |
$acting = ( isset( $_POST['acting'] ) ) ? wp_unslash( $_POST['acting'] ) : 'paypal_cp'; |
| 4425 |
if ( empty( $order_id ) || empty( $tracking_id ) ) { |
| 4426 |
wp_send_json( $data ); |
| 4427 |
break; |
| 4428 |
} |
| 4429 |
|
| 4430 |
$acting_status = 'CAPTURE'; |
| 4431 |
$acting_opts = $this->get_acting_settings(); |
| 4432 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 4433 |
$bn_code = ( 'paypal_card' === $acting ) ? self::API_BN_CODE_ACDC : self::API_BN_CODE_PCP; |
| 4434 |
if ( 1 === (int) $order_num ) { |
| 4435 |
$trans_id = $usces->get_order_meta_value( 'trans_id', $order_id ); |
| 4436 |
} else { |
| 4437 |
$trans_id = dlseller_get_continuation_meta_value( 'trans_' . $tracking_id, $con_id ); |
| 4438 |
} |
| 4439 |
$amount = $this->get_latest_amount( $order_id, $tracking_id ); |
| 4440 |
$result = ''; |
| 4441 |
|
| 4442 |
/* Get Access Token */ |
| 4443 |
$access_token = $this->get_access_token(); |
| 4444 |
|
| 4445 |
$params = array( |
| 4446 |
'method' => 'POST', |
| 4447 |
'headers' => array( |
| 4448 |
'Content-Type' => 'application/json;charset=utf-8', |
| 4449 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 4450 |
'PayPal-Partner-Attribution-Id' => $bn_code, |
| 4451 |
'PayPal-Request-Id' => $tracking_id, |
| 4452 |
), |
| 4453 |
'timeout' => self::API_TIMEOUT, |
| 4454 |
); |
| 4455 |
if ( $amount > $capture_amount ) { |
| 4456 |
$amount = $capture_amount; |
| 4457 |
$body = array(); |
| 4458 |
$body['amount']['currency_code'] = $usces->get_currency_code(); |
| 4459 |
$body['amount']['value'] = $amount; |
| 4460 |
$body['final_capture'] = true; |
| 4461 |
$params['body'] = wp_json_encode( $body ); |
| 4462 |
} |
| 4463 |
$response = wp_remote_get( $api_request_url . '/v2/payments/authorizations/' . $trans_id . '/capture', $params ); |
| 4464 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 4465 |
if ( isset( $response['response']['code'] ) && '201' === (string) $response['response']['code'] ) { |
| 4466 |
$status = 'COMPLETED'; |
| 4467 |
} elseif ( isset( $response['response']['code'] ) && '200' === (string) $response['response']['code'] ) { |
| 4468 |
$status = 'RETRY'; |
| 4469 |
} else { |
| 4470 |
if ( isset( $response_data['status'] ) ) { |
| 4471 |
$status = $response_data['status']; |
| 4472 |
} elseif ( isset( $response_data['name'] ) ) { |
| 4473 |
$status = $response_data['name']; |
| 4474 |
} else { |
| 4475 |
$status = 'CAPTURE ERROR'; |
| 4476 |
} |
| 4477 |
} |
| 4478 |
$response_data = apply_filters( 'usces_filter_paypal_cp_capture_log', $response_data, $order_id, $status ); |
| 4479 |
if ( 'COMPLETED' === $status ) { |
| 4480 |
$this->save_acting_log( $response_data, $acting, $acting_status, $status, $capture_amount, $order_id, $tracking_id ); |
| 4481 |
if ( ! empty( $response_data['id'] ) ) { |
| 4482 |
if ( 1 === (int) $order_num ) { |
| 4483 |
$usces->set_order_meta_value( 'wc_trans_id', $response_data['id'], $order_id ); /* 決済ID */ |
| 4484 |
$usces->set_order_meta_value( 'trans_id', $response_data['id'], $order_id ); /* 取引ID */ |
| 4485 |
} else { |
| 4486 |
dlseller_set_continuation_meta_value( 'trans_' . $tracking_id, $response_data['id'], $con_id ); /* 取引ID */ |
| 4487 |
} |
| 4488 |
} |
| 4489 |
} else { |
| 4490 |
$this->save_acting_log( $response_data, $acting, 'ERROR', $status, 0, $order_id, $tracking_id ); |
| 4491 |
$acting_status = 'AUTHORIZE'; |
| 4492 |
} |
| 4493 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 4494 |
$result .= '<div class="paypal-settlement-admin' . $class . '">' . __( $acting_status, 'usces' ) . '</div>'; |
| 4495 |
if ( 'AUTHORIZE' === $acting_status ) { |
| 4496 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4497 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4498 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . usces_crform( $amount, false, false, 'return', false ) . '" /></td> |
| 4499 |
</tr> |
| 4500 |
<tr><th>' . __( 'Refund amount', 'usces' ) . '</th> |
| 4501 |
<td><input type="tel" class="settlement-amount amount" id="amount_refund" value="" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4502 |
</tr> |
| 4503 |
</table>'; |
| 4504 |
$result .= '<div class="paypal-settlement-admin-button"> |
| 4505 |
<input id="capture-settlement" type="button" class="button" value="' . __( 'CAPTURE', 'usces' ) . '" /> |
| 4506 |
<input id="void-settlement" type="button" class="button" value="' . __( 'VOID', 'usces' ) . '" /> |
| 4507 |
</div>'; |
| 4508 |
} elseif ( 'CAPTURE' === $acting_status ) { |
| 4509 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4510 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4511 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . usces_crform( $amount, false, false, 'return', false ) . '" /></td> |
| 4512 |
</tr> |
| 4513 |
<tr><th>' . __( 'Refund amount', 'usces' ) . '</th> |
| 4514 |
<td><input type="tel" class="settlement-amount amount" id="amount_refund" value="" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4515 |
</tr> |
| 4516 |
</table>'; |
| 4517 |
$result .= '<div class="paypal-settlement-admin-button"> |
| 4518 |
<input id="refund-settlement" type="button" class="button" value="' . __( 'REFUND', 'usces' ) . '" /> |
| 4519 |
</div>'; |
| 4520 |
} |
| 4521 |
$result .= '</div>'; |
| 4522 |
do_action( 'usces_action_admin_capture_paypal_cp', $response_data, $order_id, $status ); |
| 4523 |
$result .= $this->settlement_history( $order_id, $tracking_id ); |
| 4524 |
$data['result'] = $result; |
| 4525 |
$data['acting_status'] = '<span class="acting-status' . $class . '">' . __( $acting_status, 'usces' ) . '</span>'; |
| 4526 |
wp_send_json( $data ); |
| 4527 |
break; |
| 4528 |
|
| 4529 |
/* VOID */ |
| 4530 |
case 'void_paypal_cp': |
| 4531 |
check_admin_referer( 'order_edit', 'wc_nonce' ); |
| 4532 |
$order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : ''; |
| 4533 |
$order_num = ( isset( $_POST['order_num'] ) ) ? wp_unslash( $_POST['order_num'] ) : 1; |
| 4534 |
$tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : ''; |
| 4535 |
$con_id = ( defined( 'WCEX_DLSELLER' ) && isset( $_POST['con_id'] ) ) ? wp_unslash( $_POST['con_id'] ) : 0; |
| 4536 |
$acting = ( isset( $_POST['acting'] ) ) ? wp_unslash( $_POST['acting'] ) : 'paypal_cp'; |
| 4537 |
if ( empty( $order_id ) || empty( $tracking_id ) ) { |
| 4538 |
wp_send_json( $data ); |
| 4539 |
break; |
| 4540 |
} |
| 4541 |
|
| 4542 |
$acting_status = 'VOID'; |
| 4543 |
$acting_opts = $this->get_acting_settings(); |
| 4544 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 4545 |
$bn_code = ( 'paypal_card' === $acting ) ? self::API_BN_CODE_ACDC : self::API_BN_CODE_PCP; |
| 4546 |
if ( 1 === (int) $order_num ) { |
| 4547 |
$trans_id = $usces->get_order_meta_value( 'trans_id', $order_id ); |
| 4548 |
} else { |
| 4549 |
$trans_id = dlseller_get_continuation_meta_value( 'trans_' . $tracking_id, $con_id ); |
| 4550 |
} |
| 4551 |
$amount = $this->get_latest_amount( $order_id, $tracking_id ); |
| 4552 |
$result = ''; |
| 4553 |
|
| 4554 |
/* Get Access Token */ |
| 4555 |
$access_token = $this->get_access_token(); |
| 4556 |
|
| 4557 |
$params = array( |
| 4558 |
'method' => 'POST', |
| 4559 |
'headers' => array( |
| 4560 |
'Content-Type' => 'application/json;charset=utf-8', |
| 4561 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 4562 |
'PayPal-Partner-Attribution-Id' => $bn_code, |
| 4563 |
'PayPal-Request-Id' => $tracking_id, |
| 4564 |
), |
| 4565 |
'timeout' => self::API_TIMEOUT, |
| 4566 |
); |
| 4567 |
$response = wp_remote_get( $api_request_url . '/v2/payments/authorizations/' . $trans_id . '/void', $params ); |
| 4568 |
if ( isset( $response['response']['code'] ) && '204' === (string) $response['response']['code'] ) { |
| 4569 |
$status = 'COMPLETED'; |
| 4570 |
$response_data = apply_filters( 'usces_filter_paypal_cp_void_log', $response['response'], $order_id, $status ); |
| 4571 |
$this->save_acting_log( $response_data, $acting, $acting_status, $status, $amount * -1, $order_id, $tracking_id ); |
| 4572 |
$acting_status = 'VOIDED'; |
| 4573 |
$amount = 0; |
| 4574 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 4575 |
$result .= '<div class="paypal-settlement-admin' . $class . '">' . __( $acting_status, 'usces' ) . '</div>'; |
| 4576 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4577 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4578 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4579 |
</tr></table>'; |
| 4580 |
} else { |
| 4581 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 4582 |
if ( isset( $response_data['status'] ) ) { |
| 4583 |
$status = $response_data['status']; |
| 4584 |
} elseif ( isset( $response_data['name'] ) ) { |
| 4585 |
$status = $response_data['name']; |
| 4586 |
} else { |
| 4587 |
$status = 'VOID ERROR'; |
| 4588 |
} |
| 4589 |
$this->save_acting_log( $response_data, $acting, 'ERROR', $status, 0, $order_id, $tracking_id ); |
| 4590 |
$acting_status = 'AUTHORIZE'; |
| 4591 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 4592 |
$result .= '<div class="paypal-settlement-admin' . $class . '">' . __( $acting_status, 'usces' ) . '</div>'; |
| 4593 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4594 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4595 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . usces_crform( $amount, false, false, 'return', false ) . '" /></td> |
| 4596 |
</tr> |
| 4597 |
<tr><th>' . __( 'Refund amount', 'usces' ) . '</th> |
| 4598 |
<td><input type="tel" class="settlement-amount amount" id="amount_refund" value="" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4599 |
</tr> |
| 4600 |
</table>'; |
| 4601 |
$result .= '<div class="paypal-settlement-admin-button"> |
| 4602 |
<input id="capture-settlement" type="button" class="button" value="' . __( 'CAPTURE', 'usces' ) . '" /> |
| 4603 |
<input id="void-settlement" type="button" class="button" value="' . __( 'VOID', 'usces' ) . '" /> |
| 4604 |
</div>'; |
| 4605 |
} |
| 4606 |
do_action( 'usces_action_admin_void_paypal_cp', $response_data, $order_id, $status ); |
| 4607 |
$result .= $this->settlement_history( $order_id, $tracking_id ); |
| 4608 |
$data['result'] = $result; |
| 4609 |
$data['acting_status'] = '<span class="acting-status' . $class . '">' . __( $acting_status, 'usces' ) . '</span>'; |
| 4610 |
wp_send_json( $data ); |
| 4611 |
break; |
| 4612 |
|
| 4613 |
/* REFUND */ |
| 4614 |
case 'refund_paypal_cp': |
| 4615 |
check_admin_referer( 'order_edit', 'wc_nonce' ); |
| 4616 |
$order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : ''; |
| 4617 |
$order_num = ( isset( $_POST['order_num'] ) ) ? wp_unslash( $_POST['order_num'] ) : 1; |
| 4618 |
$tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : ''; |
| 4619 |
$refund_amount = ( isset( $_POST['amount'] ) ) ? wp_unslash( $_POST['amount'] ) : 0; |
| 4620 |
$con_id = ( defined( 'WCEX_DLSELLER' ) && isset( $_POST['con_id'] ) ) ? wp_unslash( $_POST['con_id'] ) : 0; |
| 4621 |
$acting = ( isset( $_POST['acting'] ) ) ? wp_unslash( $_POST['acting'] ) : 'paypal_cp'; |
| 4622 |
if ( empty( $order_id ) || empty( $tracking_id ) || empty( $refund_amount ) ) { |
| 4623 |
wp_send_json( $data ); |
| 4624 |
break; |
| 4625 |
} |
| 4626 |
|
| 4627 |
$acting_status = 'REFUND'; |
| 4628 |
$acting_opts = $this->get_acting_settings(); |
| 4629 |
$api_request_url = ( isset( $acting_opts['api_request_url'] ) ) ? $acting_opts['api_request_url'] : ''; |
| 4630 |
$bn_code = ( 'paypal_card' === $acting ) ? self::API_BN_CODE_ACDC : self::API_BN_CODE_PCP; |
| 4631 |
if ( 1 === (int) $order_num ) { |
| 4632 |
$trans_id = $usces->get_order_meta_value( 'trans_id', $order_id ); |
| 4633 |
} else { |
| 4634 |
$trans_id = dlseller_get_continuation_meta_value( 'trans_' . $tracking_id, $con_id ); |
| 4635 |
} |
| 4636 |
$currency_code = $usces->get_currency_code(); |
| 4637 |
$request_id = usces_acting_key(); /* Duplication Prevention */ |
| 4638 |
$result = ''; |
| 4639 |
|
| 4640 |
/* Get Access Token */ |
| 4641 |
$access_token = $this->get_access_token(); |
| 4642 |
|
| 4643 |
$body = array(); |
| 4644 |
$body['amount']['value'] = $refund_amount; |
| 4645 |
$body['amount']['currency_code'] = $currency_code; |
| 4646 |
$params = array( |
| 4647 |
'method' => 'POST', |
| 4648 |
'headers' => array( |
| 4649 |
'Content-Type' => 'application/json;charset=utf-8', |
| 4650 |
'Authorization' => 'Bearer ' . $access_token['access_token'], |
| 4651 |
'PayPal-Partner-Attribution-Id' => $bn_code, |
| 4652 |
'PayPal-Request-Id' => $request_id, |
| 4653 |
), |
| 4654 |
'timeout' => self::API_TIMEOUT, |
| 4655 |
'body' => wp_json_encode( $body ), |
| 4656 |
); |
| 4657 |
$response = wp_remote_get( $api_request_url . '/v2/payments/captures/' . $trans_id . '/refund', $params ); |
| 4658 |
$response_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 4659 |
if ( isset( $response['response']['code'] ) && '201' === (string) $response['response']['code'] ) { |
| 4660 |
$status = 'COMPLETED'; |
| 4661 |
} elseif ( isset( $response['response']['code'] ) && '200' === (string) $response['response']['code'] ) { |
| 4662 |
$status = 'RETRY'; |
| 4663 |
} else { |
| 4664 |
if ( isset( $response_data['status'] ) ) { |
| 4665 |
$status = $response_data['status']; |
| 4666 |
} elseif ( isset( $response_data['name'] ) ) { |
| 4667 |
$status = $response_data['name']; |
| 4668 |
} else { |
| 4669 |
$status = 'REFUND ERROR'; |
| 4670 |
} |
| 4671 |
} |
| 4672 |
$response_data = apply_filters( 'usces_filter_paypal_cp_refund_log', $response_data, $order_id, $status ); |
| 4673 |
if ( 'COMPLETED' === $status ) { |
| 4674 |
$this->save_acting_log( $response_data, $acting, $acting_status, $status, $refund_amount * -1, $order_id, $tracking_id ); |
| 4675 |
} else { |
| 4676 |
$this->save_acting_log( $response_data, $acting, 'ERROR', $status, 0, $order_id, $tracking_id ); |
| 4677 |
} |
| 4678 |
$amount = $this->get_latest_amount( $order_id, $tracking_id ); |
| 4679 |
if ( 0 < $amount ) { |
| 4680 |
$acting_status = 'CAPTURE'; |
| 4681 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 4682 |
$result .= '<div class="paypal-settlement-admin' . $class . '">' . __( $acting_status, 'usces' ) . '</div>'; |
| 4683 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4684 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4685 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . usces_crform( $amount, false, false, 'return', false ) . '" /></td> |
| 4686 |
</tr> |
| 4687 |
<tr><th>' . __( 'Refund amount', 'usces' ) . '</th> |
| 4688 |
<td><input type="tel" class="settlement-amount amount" id="amount_refund" value="" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4689 |
</tr> |
| 4690 |
</table>'; |
| 4691 |
$result .= '<div class="paypal-settlement-admin-button"> |
| 4692 |
<input id="refund-settlement" type="button" class="button" value="' . __( 'REFUND', 'usces' ) . '" /> |
| 4693 |
</div>'; |
| 4694 |
} else { |
| 4695 |
$acting_status = 'REFUNDED'; |
| 4696 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 4697 |
$result .= '<div class="paypal-settlement-admin' . $class . '">' . __( $acting_status, 'usces' ) . '</div>'; |
| 4698 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4699 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4700 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4701 |
</tr></table>'; |
| 4702 |
} |
| 4703 |
do_action( 'usces_action_admin_refund_paypal_cp', $response_data, $order_id, $status ); |
| 4704 |
$result .= $this->settlement_history( $order_id, $tracking_id ); |
| 4705 |
$data['result'] = $result; |
| 4706 |
$data['acting_status'] = '<span class="acting-status' . $class . '">' . __( $acting_status, 'usces' ) . '</span>'; |
| 4707 |
wp_send_json( $data ); |
| 4708 |
break; |
| 4709 |
|
| 4710 |
/* RE-SETTLEMENT */ |
| 4711 |
case 're_settlement_paypal_cp': |
| 4712 |
check_admin_referer( 'order_edit', 'wc_nonce' ); |
| 4713 |
$order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : ''; |
| 4714 |
$order_num = ( isset( $_POST['order_num'] ) ) ? wp_unslash( $_POST['order_num'] ) : 1; |
| 4715 |
$tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : ''; |
| 4716 |
$member_id = ( isset( $_POST['member_id'] ) ) ? wp_unslash( $_POST['member_id'] ) : 0; |
| 4717 |
$amount = ( isset( $_POST['amount'] ) ) ? wp_unslash( $_POST['amount'] ) : 0; |
| 4718 |
$cp_intent = ( isset( $_POST['intent'] ) ) ? wp_unslash( $_POST['intent'] ) : ''; |
| 4719 |
$con_id = ( defined( 'WCEX_DLSELLER' ) && isset( $_POST['con_id'] ) ) ? wp_unslash( $_POST['con_id'] ) : 0; |
| 4720 |
$reg_id = ( defined( 'WCEX_AUTO_DELIVERY' ) && isset( $_POST['reg_id'] ) ) ? wp_unslash( $_POST['reg_id'] ) : 0; |
| 4721 |
$acting = ( isset( $_POST['acting'] ) ) ? wp_unslash( $_POST['acting'] ) : 'paypal_cp'; |
| 4722 |
if ( empty( $order_id ) || empty( $tracking_id ) || empty( $amount ) || empty( $cp_intent ) ) { |
| 4723 |
wp_send_json( $data ); |
| 4724 |
break; |
| 4725 |
} |
| 4726 |
|
| 4727 |
$log = $this->get_entry_log( $tracking_id ); |
| 4728 |
if ( isset( $log['entry'] ) && isset( $log['cart'] ) ) { |
| 4729 |
$entry = $log['entry']; |
| 4730 |
$entry['order']['total_items_price'] = 0; |
| 4731 |
$entry['order']['total_full_price'] = $amount; |
| 4732 |
$cart = $log['cart']; |
| 4733 |
} else { |
| 4734 |
wp_send_json( $data ); |
| 4735 |
break; |
| 4736 |
} |
| 4737 |
|
| 4738 |
$result = ''; |
| 4739 |
$pending = false; |
| 4740 |
if ( defined( 'WCEX_DLSELLER' ) && ! empty( $con_id ) ) { |
| 4741 |
$ba_id = $this->get_continuation_ba_id( $member_id, $order_id ); |
| 4742 |
} elseif ( defined( 'WCEX_AUTO_DELIVERY' ) && ! empty( $reg_id ) ) { |
| 4743 |
$ba_id = $this->get_regular_ba_id( $member_id, $reg_id ); |
| 4744 |
} else { |
| 4745 |
$ba_id = ''; |
| 4746 |
} |
| 4747 |
if ( ! empty( $ba_id ) ) { |
| 4748 |
$bn_code = ( 'paypal_card' === $acting ) ? self::API_BN_CODE_ACDC : self::API_BN_CODE_PCP; |
| 4749 |
$request_id = usces_acting_key(); /* Duplication Prevention */ |
| 4750 |
|
| 4751 |
/* Get Access Token */ |
| 4752 |
$access_token = $this->get_access_token(); |
| 4753 |
|
| 4754 |
$shipping = usces_have_shipped( $cart ); |
| 4755 |
if ( $shipping ) { |
| 4756 |
$order_data = $usces->get_order_data( $order_id, 'direct' ); |
| 4757 |
$delivery = wel_safe_unserialize( $order_data['order_delivery'] ); |
| 4758 |
$entry['delivery']['name1'] = $delivery['name1']; |
| 4759 |
$entry['delivery']['name2'] = $delivery['name2']; |
| 4760 |
$entry['delivery']['country'] = $delivery['country']; |
| 4761 |
$entry['delivery']['zipcode'] = $delivery['zipcode']; |
| 4762 |
$entry['delivery']['pref'] = $delivery['pref']; |
| 4763 |
$entry['delivery']['address1'] = $delivery['address1']; |
| 4764 |
$entry['delivery']['address2'] = $delivery['address2']; |
| 4765 |
$entry['delivery']['address3'] = $delivery['address3']; |
| 4766 |
} |
| 4767 |
|
| 4768 |
/* Create order */ |
| 4769 |
$response_order_data = $this->api_create_order( $access_token, $bn_code, $cp_intent, $request_id, $entry, $cart ); |
| 4770 |
if ( isset( $response_order_data['id'] ) && isset( $response_order_data['status'] ) && 'CREATED' === $response_order_data['status'] ) { |
| 4771 |
$resource_id = $response_order_data['id']; |
| 4772 |
$correlation_id = ''; |
| 4773 |
$payment_source = array(); |
| 4774 |
$payment_source['token'] = array( |
| 4775 |
'id' => $ba_id, |
| 4776 |
'type' => 'BILLING_AGREEMENT', |
| 4777 |
); |
| 4778 |
dlseller_set_continuation_meta_value( 'resource_' . $tracking_id, $resource_id, $con_id ); |
| 4779 |
if ( 'CAPTURE' === $cp_intent ) { |
| 4780 |
/* Capture */ |
| 4781 |
$response_data = $this->api_capture_order( $access_token, $bn_code, $request_id, $resource_id, $correlation_id, $payment_source ); |
| 4782 |
} elseif ( 'AUTHORIZE' === $cp_intent ) { |
| 4783 |
/* Authorize */ |
| 4784 |
$response_data = $this->api_authorize_order( $access_token, $bn_code, $request_id, $resource_id, $correlation_id, $payment_source ); |
| 4785 |
} |
| 4786 |
if ( isset( $response_data['status'] ) ) { |
| 4787 |
$status = $response_data['status']; |
| 4788 |
} elseif ( isset( $response_data['name'] ) ) { |
| 4789 |
$status = $response_data['name']; |
| 4790 |
} else { |
| 4791 |
$status = $cp_intent . ' ERROR'; |
| 4792 |
} |
| 4793 |
if ( 'paypal_card' === $acting ) { |
| 4794 |
if ( isset( $response_data['purchase_units'] ) ) { |
| 4795 |
$purchase_units = $response_data['purchase_units'][0]; |
| 4796 |
if ( isset( $purchase_units['payments']['captures'] ) ) { |
| 4797 |
$payments = $purchase_units['payments']['captures'][0]; |
| 4798 |
} elseif ( isset( $purchase_units['payments']['authorizations'] ) ) { |
| 4799 |
$payments = $purchase_units['payments']['authorizations'][0]; |
| 4800 |
} |
| 4801 |
if ( ! empty( $payments['status'] ) ) { |
| 4802 |
if ( 'COMPLETED' !== $payments['status'] && 'PENDING' !== $payments['status'] ) { |
| 4803 |
$status = $payments['status']; |
| 4804 |
} |
| 4805 |
} |
| 4806 |
} |
| 4807 |
} |
| 4808 |
$response_data = apply_filters( 'usces_filter_paypal_cp_re_settlement_log', $response_data, $order_id, $status ); |
| 4809 |
if ( 'COMPLETED' === $status && isset( $response_data['purchase_units'] ) ) { |
| 4810 |
$this->save_acting_log( $response_data, $acting, $cp_intent, $status, $amount, $order_id, $tracking_id ); |
| 4811 |
$purchase_units = $response_data['purchase_units'][0]; |
| 4812 |
if ( isset( $purchase_units['payments']['captures'] ) ) { |
| 4813 |
$payments = $purchase_units['payments']['captures'][0]; |
| 4814 |
} elseif ( isset( $purchase_units['payments']['authorizations'] ) ) { |
| 4815 |
$payments = $purchase_units['payments']['authorizations'][0]; |
| 4816 |
} |
| 4817 |
if ( ! empty( $payments['status'] ) && 'PENDING' === $payments['status'] ) { |
| 4818 |
$pending = true; |
| 4819 |
} |
| 4820 |
if ( $con_id ) { |
| 4821 |
// dlseller_set_continuation_meta_value( 'resource_' . $tracking_id, $resource_id, $con_id ); |
| 4822 |
if ( ! empty( $payments['id'] ) ) { |
| 4823 |
dlseller_set_continuation_meta_value( 'trans_' . $tracking_id, $payments['id'], $con_id ); /* 取引ID */ |
| 4824 |
} |
| 4825 |
} elseif ( $reg_id ) { |
| 4826 |
$usces->set_order_meta_value( 'resource_id', $resource_id, $order_id ); |
| 4827 |
if ( ! empty( $payments['id'] ) ) { |
| 4828 |
$usces->set_order_meta_value( 'wc_trans_id', $payments['id'], $order_id ); /* 決済ID */ |
| 4829 |
$usces->set_order_meta_value( 'trans_id', $payments['id'], $order_id ); /* 取引ID */ |
| 4830 |
} |
| 4831 |
} |
| 4832 |
$this->del_entry_log( $tracking_id ); |
| 4833 |
} else { |
| 4834 |
$this->save_acting_log( $response_data, $acting, 'ERROR', $status, 0, $order_id, $tracking_id ); |
| 4835 |
} |
| 4836 |
} else { |
| 4837 |
if ( isset( $response_order_data['status'] ) ) { |
| 4838 |
$status = $response_order_data['status']; |
| 4839 |
} elseif ( isset( $response_order_data['name'] ) ) { |
| 4840 |
$status = $response_order_data['name']; |
| 4841 |
} else { |
| 4842 |
$status = 'CREATE ORDER ERROR'; |
| 4843 |
} |
| 4844 |
$this->save_acting_log( $response_order_data, $acting, 'ERROR', $status, 0, $order_id, $tracking_id ); |
| 4845 |
} |
| 4846 |
} else { |
| 4847 |
$status = 'RE-SETTLEMENT ERROR'; |
| 4848 |
$this->save_acting_log( array(), $acting, 'ERROR', $status, 0, $order_id, $tracking_id ); |
| 4849 |
} |
| 4850 |
if ( 'COMPLETED' === $status ) { |
| 4851 |
$acting_status = $cp_intent; |
| 4852 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 4853 |
$acting_pending = ( $pending ) ? ' ' . __( '[ PENDING ]', 'usces' ) : ''; |
| 4854 |
$result .= '<div class="paypal-settlement-admin' . $class . '">' . __( $acting_status, 'usces' ) . $acting_pending . '</div>'; |
| 4855 |
if ( 'AUTHORIZE' === $acting_status ) { |
| 4856 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4857 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4858 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . usces_crform( $amount, false, false, 'return', false ) . '" /></td> |
| 4859 |
</tr> |
| 4860 |
<tr><th>' . __( 'Refund amount', 'usces' ) . '</th> |
| 4861 |
<td><input type="tel" class="settlement-amount amount" id="amount_refund" value="" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4862 |
</tr> |
| 4863 |
</table>'; |
| 4864 |
$result .= '<div class="paypal-settlement-admin-button"> |
| 4865 |
<input id="capture-settlement" type="button" class="button" value="' . __( 'CAPTURE', 'usces' ) . '" /> |
| 4866 |
<input id="void-settlement" type="button" class="button" value="' . __( 'VOID', 'usces' ) . '" /> |
| 4867 |
</div>'; |
| 4868 |
} elseif ( 'CAPTURE' === $acting_status ) { |
| 4869 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4870 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4871 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . usces_crform( $amount, false, false, 'return', false ) . '" /></td> |
| 4872 |
</tr> |
| 4873 |
<tr><th>' . __( 'Refund amount', 'usces' ) . '</th> |
| 4874 |
<td><input type="tel" class="settlement-amount amount" id="amount_refund" value="" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4875 |
</tr> |
| 4876 |
</table>'; |
| 4877 |
$result .= '<div class="paypal-settlement-admin-button"> |
| 4878 |
<input id="refund-settlement" type="button" class="button" value="' . __( 'REFUND', 'usces' ) . '" /> |
| 4879 |
</div>'; |
| 4880 |
} |
| 4881 |
} else { |
| 4882 |
// $amount = 0; |
| 4883 |
$acting_status = 'ERROR'; |
| 4884 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 4885 |
$result .= '<div class="paypal-settlement-admin paypal-error">' . __( $acting_status, 'usces' ) . '</div>'; |
| 4886 |
$result .= '<table class="paypal-settlement-admin-table"> |
| 4887 |
<tr><th>' . __( 'Transaction amount', 'usces' ) . '</th> |
| 4888 |
<td><input type="tel" class="settlement-amount" value="' . usces_crform( $amount, false, false, 'return', true ) . '" readonly />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4889 |
</tr> |
| 4890 |
<tr><th>' . __( 'Settlement amount', 'usces' ) . '</th> |
| 4891 |
<td><input type="tel" class="settlement-amount amount" id="amount_resettlement" value="" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td> |
| 4892 |
</tr> |
| 4893 |
</table>'; |
| 4894 |
if ( 'paypal_cp' === $acting ) { |
| 4895 |
$result .= '<div class="paypal-settlement-admin-button"> |
| 4896 |
<input id="re-authorize-settlement" type="button" class="button" value="' . __( 'AUTHORIZE', 'usces' ) . '" /> |
| 4897 |
<input id="re-capture-settlement" type="button" class="button" value="' . __( 'CAPTURE', 'usces' ) . '" /> |
| 4898 |
</div>'; |
| 4899 |
} |
| 4900 |
} |
| 4901 |
if ( defined( 'WCEX_DLSELLER' ) && ! empty( $con_id ) ) { |
| 4902 |
do_action( 'usces_action_admin_re_settlement_paypal_cp', $response_data, $order_id, $status, $con_id ); |
| 4903 |
} elseif ( defined( 'WCEX_AUTO_DELIVERY' ) && ! empty( $reg_id ) ) { |
| 4904 |
do_action( 'usces_action_admin_re_settlement_paypal_cp', $response_data, $order_id, $status, $reg_id ); |
| 4905 |
} else { |
| 4906 |
do_action( 'usces_action_admin_re_settlement_paypal_cp', $response_data, $order_id, $status ); |
| 4907 |
} |
| 4908 |
$result .= $this->settlement_history( $order_id, $tracking_id ); |
| 4909 |
$data['result'] = $result; |
| 4910 |
$data['acting_status'] = '<span class="acting-status' . $class . '">' . __( $acting_status, 'usces' ) . '</span>'; |
| 4911 |
wp_send_json( $data ); |
| 4912 |
break; |
| 4913 |
|
| 4914 |
/* 継続課金� |
| 4915 |
報更新 */ |
| 4916 |
case 'continuation_update': |
| 4917 |
check_admin_referer( 'order_edit', 'wc_nonce' ); |
| 4918 |
$order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : ''; |
| 4919 |
$member_id = ( isset( $_POST['member_id'] ) ) ? wp_unslash( $_POST['member_id'] ) : ''; |
| 4920 |
$contracted_year = ( isset( $_POST['contracted_year'] ) ) ? wp_unslash( $_POST['contracted_year'] ) : ''; |
| 4921 |
$contracted_month = ( isset( $_POST['contracted_month'] ) ) ? wp_unslash( $_POST['contracted_month'] ) : ''; |
| 4922 |
$contracted_day = ( isset( $_POST['contracted_day'] ) ) ? wp_unslash( $_POST['contracted_day'] ) : ''; |
| 4923 |
$charged_year = ( isset( $_POST['charged_year'] ) ) ? wp_unslash( $_POST['charged_year'] ) : ''; |
| 4924 |
$charged_month = ( isset( $_POST['charged_month'] ) ) ? wp_unslash( $_POST['charged_month'] ) : ''; |
| 4925 |
$charged_day = ( isset( $_POST['charged_day'] ) ) ? wp_unslash( $_POST['charged_day'] ) : ''; |
| 4926 |
$price = ( isset( $_POST['price'] ) ) ? wp_unslash( $_POST['price'] ) : 0; |
| 4927 |
$status = ( isset( $_POST['status'] ) ) ? wp_unslash( $_POST['status'] ) : ''; |
| 4928 |
|
| 4929 |
$continue_data = $this->get_continuation_data( $member_id, $order_id ); |
| 4930 |
if ( ! $continue_data ) { |
| 4931 |
$data['status'] = 'NG'; |
| 4932 |
wp_send_json( $data ); |
| 4933 |
break; |
| 4934 |
} |
| 4935 |
|
| 4936 |
/* 継続中→停止 */ |
| 4937 |
if ( 'continuation' === $continue_data['status'] && 'cancellation' === $status ) { |
| 4938 |
$this->update_continuation_data( $member_id, $order_id, $continue_data, true ); |
| 4939 |
} else { |
| 4940 |
if ( ! empty( $contracted_year ) && ! empty( $contracted_month ) && ! empty( $contracted_day ) ) { |
| 4941 |
$contracted_date = ( empty( $continue_data['contractedday'] ) ) ? dlseller_next_contracting( $order_id ) : $continue_data['contractedday']; |
| 4942 |
if ( $contracted_date ) { |
| 4943 |
$new_contracted_date = $contracted_year . '-' . $contracted_month . '-' . $contracted_day; |
| 4944 |
if ( ! $this->isdate( $new_contracted_date ) ) { |
| 4945 |
$data['status'] = 'NG'; |
| 4946 |
$data['message'] = __( 'Next contract renewal date is incorrect.', 'dlseller' ); |
| 4947 |
wp_send_json( $data ); |
| 4948 |
} |
| 4949 |
} |
| 4950 |
} else { |
| 4951 |
$new_contracted_date = ''; |
| 4952 |
} |
| 4953 |
$new_charged_date = $charged_year . '-' . $charged_month . '-' . $charged_day; |
| 4954 |
if ( ! $this->isdate( $new_charged_date ) ) { |
| 4955 |
$data['status'] = 'NG'; |
| 4956 |
$data['message'] = __( 'Next settlement date is incorrect.', 'dlseller' ); |
| 4957 |
wp_send_json( $data ); |
| 4958 |
} |
| 4959 |
$tomorrow = date_i18n( 'Y-m-d', strtotime( '+1 day' ) ); |
| 4960 |
if ( $new_charged_date < $tomorrow ) { |
| 4961 |
$data['status'] = 'NG'; |
| 4962 |
$data['message'] = sprintf( __( 'The next settlement date must be after %s.', 'dlseller' ), $tomorrow ); |
| 4963 |
wp_send_json( $data ); |
| 4964 |
} |
| 4965 |
$continue_data['contractedday'] = $new_contracted_date; |
| 4966 |
$continue_data['chargedday'] = $new_charged_date; |
| 4967 |
$continue_data['price'] = usces_crform( $price, false, false, 'return', false ); |
| 4968 |
$continue_data['status'] = $status; |
| 4969 |
$this->update_continuation_data( $member_id, $order_id, $continue_data ); |
| 4970 |
} |
| 4971 |
$data['status'] = 'OK'; |
| 4972 |
wp_send_json( $data ); |
| 4973 |
break; |
| 4974 |
} |
| 4975 |
} |
| 4976 |
|
| 4977 |
/** |
| 4978 |
* 受注データから取得する決済� |
| 4979 |
報のキー |
| 4980 |
* usces_filter_settle_info_field_meta_keys |
| 4981 |
* |
| 4982 |
* @param array $keys Settlement information keys. |
| 4983 |
* @return array |
| 4984 |
*/ |
| 4985 |
public function settlement_info_field_meta_keys( $keys ) { |
| 4986 |
$keys = array_merge( $keys, array( 'reference_id', 'trans_id', 'liability_shift', 'enrollment_status', 'authentication_status' ) ); |
| 4987 |
return $keys; |
| 4988 |
} |
| 4989 |
|
| 4990 |
/** |
| 4991 |
* 受注編集画面に表示する決済� |
| 4992 |
報のキー |
| 4993 |
* usces_filter_settle_info_field_keys |
| 4994 |
* |
| 4995 |
* @param array $keys Settlement information keys. |
| 4996 |
* @param array $fields Settlement information fields. |
| 4997 |
* @return array |
| 4998 |
*/ |
| 4999 |
public function settlement_info_field_keys( $keys, $fields ) { |
| 5000 |
if ( isset( $fields['acting'] ) && ( 'paypal_cp' === $fields['acting'] || 'paypal_card' === $fields['acting'] ) ) { |
| 5001 |
$keys = array( 'acting', 'reference_id', 'trans_id', 'liability_shift', 'enrollment_status', 'authentication_status' ); |
| 5002 |
} |
| 5003 |
return $keys; |
| 5004 |
} |
| 5005 |
|
| 5006 |
/** |
| 5007 |
* 受注編集画面に表示する決済� |
| 5008 |
報の値整形 |
| 5009 |
* usces_filter_settle_info_field_value |
| 5010 |
* |
| 5011 |
* @param string $value Value. |
| 5012 |
* @param string $key Key. |
| 5013 |
* @param string $acting Acting type. |
| 5014 |
* @return string |
| 5015 |
*/ |
| 5016 |
public function settlement_info_field_value( $value, $key, $acting ) { |
| 5017 |
if ( 'acting' === $key ) { |
| 5018 |
if ( 'paypal_cp' === $value ) { |
| 5019 |
$value = $this->acting_name; |
| 5020 |
} elseif ( 'paypal_card' === $value ) { |
| 5021 |
$value = __( 'PayPal(CreditCard)', 'usces' ); |
| 5022 |
} |
| 5023 |
} |
| 5024 |
return $value; |
| 5025 |
} |
| 5026 |
|
| 5027 |
/** |
| 5028 |
* 決済状況 |
| 5029 |
* usces_filter_orderlist_detail_value |
| 5030 |
* |
| 5031 |
* @param string $detail HTML. |
| 5032 |
* @param string $value Value. |
| 5033 |
* @param string $key Key. |
| 5034 |
* @param int $order_id Order number. |
| 5035 |
* @return array |
| 5036 |
*/ |
| 5037 |
public function orderlist_settlement_status( $detail, $value, $key, $order_id ) { |
| 5038 |
global $usces; |
| 5039 |
|
| 5040 |
if ( 'wc_trans_id' !== $key || empty( $value ) ) { |
| 5041 |
return $detail; |
| 5042 |
} |
| 5043 |
|
| 5044 |
$acting_flg = $this->get_order_acting_flg( $order_id ); |
| 5045 |
if ( in_array( $acting_flg, $this->pay_method ) ) { |
| 5046 |
$tracking_id = $usces->get_order_meta_value( 'reference_id', $order_id ); |
| 5047 |
$acting_status = $this->get_acting_status( $order_id, $tracking_id ); |
| 5048 |
if ( ! empty( $acting_status ) ) { |
| 5049 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 5050 |
$detail = '<td>' . $value . '<span class="acting-status' . $class . '">' . __( $acting_status, 'usces' ) . '</span></td>'; |
| 5051 |
} |
| 5052 |
} |
| 5053 |
return $detail; |
| 5054 |
} |
| 5055 |
|
| 5056 |
/** |
| 5057 |
* 受注編集画面【ステータス】 |
| 5058 |
* usces_action_order_edit_form_status_block_middle |
| 5059 |
* |
| 5060 |
* @param array $data Order data. |
| 5061 |
* @param array $cscs_meta Custom field data. |
| 5062 |
* @param array $action_args Compact array( $order_action, $order_id, $cart ). |
| 5063 |
*/ |
| 5064 |
public function settlement_status( $data, $cscs_meta, $action_args ) { |
| 5065 |
global $usces; |
| 5066 |
extract( $action_args ); |
| 5067 |
|
| 5068 |
if ( 'new' !== $order_action && ! empty( $order_id ) ) { |
| 5069 |
$payment = usces_get_payments_by_name( $data['order_payment_name'] ); |
| 5070 |
$acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : ''; |
| 5071 |
if ( in_array( $acting_flg, $this->pay_method ) ) { |
| 5072 |
$tracking_id = $usces->get_order_meta_value( 'reference_id', $order_id ); |
| 5073 |
$acting_status = $this->get_acting_status( $order_id, $tracking_id ); |
| 5074 |
if ( ! empty( $acting_status ) ) { |
| 5075 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 5076 |
if ( ! empty( $acting_status ) ) { |
| 5077 |
echo ' |
| 5078 |
<tr> |
| 5079 |
<td class="label status">' . esc_html__( 'Settlement status', 'usces' ) . '</td> |
| 5080 |
<td class="col1 status"><span id="settlement-status-1"><span class="acting-status' . esc_attr( $class ) . '">' . esc_html__( $acting_status, 'usces' ) . '</span></span></td> |
| 5081 |
</tr>'; |
| 5082 |
} |
| 5083 |
} |
| 5084 |
} |
| 5085 |
} |
| 5086 |
} |
| 5087 |
|
| 5088 |
/** |
| 5089 |
* 受注編集画面【支払� |
| 5090 |
報】 |
| 5091 |
* usces_action_order_edit_form_settle_info |
| 5092 |
* |
| 5093 |
* @param array $data Order data. |
| 5094 |
* @param array $action_args Compact array( $order_action, $order_id, $cart ). |
| 5095 |
*/ |
| 5096 |
public function settlement_information( $data, $action_args ) { |
| 5097 |
global $usces; |
| 5098 |
extract( $action_args ); |
| 5099 |
|
| 5100 |
if ( 'new' !== $order_action && ! empty( $order_id ) ) { |
| 5101 |
$payment = usces_get_payments_by_name( $data['order_payment_name'] ); |
| 5102 |
if ( in_array( $payment['settlement'], $this->pay_method ) ) { |
| 5103 |
$tracking_id = $usces->get_order_meta_value( 'reference_id', $order_id ); |
| 5104 |
echo '<input type="button" class="button settlement-information" id="settlement-information-' . esc_attr( $tracking_id ) . '" data-tracking_id="' . esc_attr( $tracking_id ) . '" data-num="1" value="' . esc_html__( 'Settlement info', 'usces' ) . '">'; |
| 5105 |
} |
| 5106 |
} |
| 5107 |
} |
| 5108 |
|
| 5109 |
/** |
| 5110 |
* 決済� |
| 5111 |
報ダイアログ |
| 5112 |
* usces_action_endof_order_edit_form |
| 5113 |
* |
| 5114 |
* @param array $data Order data. |
| 5115 |
* @param array $action_args Compact array( $order_action, $order_id, $cart ). |
| 5116 |
*/ |
| 5117 |
public function settlement_dialog( $data, $action_args ) { |
| 5118 |
global $usces; |
| 5119 |
extract( $action_args ); |
| 5120 |
|
| 5121 |
if ( 'new' !== $order_action && ! empty( $order_id ) ) : |
| 5122 |
$payment = usces_get_payments_by_name( $data['order_payment_name'] ); |
| 5123 |
if ( in_array( $payment['settlement'], $this->pay_method ) ) : |
| 5124 |
$acting = substr( $payment['settlement'], 7 ); |
| 5125 |
if ( defined( 'WCEX_AUTO_DELIVERY' ) ) { |
| 5126 |
$reg_id = $this->get_regular_id( $order_id ); |
| 5127 |
} else { |
| 5128 |
$reg_id = ''; |
| 5129 |
} |
| 5130 |
?> |
| 5131 |
<div id="settlement_dialog" title=""> |
| 5132 |
<div id="settlement-response-loading"></div> |
| 5133 |
<fieldset> |
| 5134 |
<div id="settlement-response"></div> |
| 5135 |
<input type="hidden" id="order_num"> |
| 5136 |
<input type="hidden" id="tracking_id"> |
| 5137 |
<input type="hidden" id="acting" value="<?php echo esc_attr( $acting ); ?>"> |
| 5138 |
<?php if ( ! empty( $reg_id ) ) : ?> |
| 5139 |
<input type="hidden" id="reg_id" value="<?php echo esc_attr( $reg_id ); ?>"> |
| 5140 |
<?php endif; ?> |
| 5141 |
</fieldset> |
| 5142 |
</div> |
| 5143 |
<?php |
| 5144 |
endif; |
| 5145 |
endif; |
| 5146 |
} |
| 5147 |
|
| 5148 |
/** |
| 5149 |
* 会員データ編集画面 |
| 5150 |
* usces_action_admin_member_info |
| 5151 |
* |
| 5152 |
* @param array $member Member data. |
| 5153 |
* @param array $member_metas Member meta data. |
| 5154 |
* @param array $usces_member_history Member history data. |
| 5155 |
*/ |
| 5156 |
public function admin_member_info( $member, $member_metas, $usces_member_history ) { |
| 5157 |
if ( empty( $member['ID'] ) ) { |
| 5158 |
return; |
| 5159 |
} |
| 5160 |
if ( 0 < count( $member_metas ) ) : |
| 5161 |
if ( defined( 'WCEX_DLSELLER' ) ) : |
| 5162 |
if ( dlseller_have_member_continue_order( $member['ID'] ) ) : |
| 5163 |
?> |
| 5164 |
<tr> |
| 5165 |
<td class="label"><?php esc_html_e( '[ Automatic recurring billing ]', 'usces' ); ?></td> |
| 5166 |
<td><div class="rod_left shortm"><?php esc_html_e( 'Registered', 'usces' ); ?></div></td> |
| 5167 |
</tr> |
| 5168 |
<?php |
| 5169 |
endif; |
| 5170 |
endif; |
| 5171 |
if ( defined( 'WCEX_AUTO_DELIVERY' ) ) : |
| 5172 |
if ( wcad_have_member_regular_order( $member['ID'] ) ) : |
| 5173 |
?> |
| 5174 |
<tr> |
| 5175 |
<td class="label"><?php esc_html_e( '[ Regular Purchase ]', 'usces' ); ?></td> |
| 5176 |
<td><div class="rod_left shortm"><?php esc_html_e( 'Registered', 'usces' ); ?></div></td> |
| 5177 |
</tr> |
| 5178 |
<?php |
| 5179 |
endif; |
| 5180 |
endif; |
| 5181 |
endif; |
| 5182 |
|
| 5183 |
$acting_opts = $this->get_acting_settings(); |
| 5184 |
if ( $this->is_validity_acting( 'card' ) ) : |
| 5185 |
/* Get Access Token */ |
| 5186 |
$access_token = $this->get_access_token(); |
| 5187 |
|
| 5188 |
$payment_tokens = $this->api_get_payment_tokens( $access_token, $member['ID'] ); |
| 5189 |
if ( ! empty( $payment_tokens['payment_tokens'] ) && is_array( $payment_tokens['payment_tokens'] ) ) : |
| 5190 |
$tokens_count = count( $payment_tokens['payment_tokens'] ); |
| 5191 |
if ( 1 === $tokens_count ) : |
| 5192 |
$payment_token = current( $payment_tokens['payment_tokens'] ); |
| 5193 |
$payment_token_id = $payment_token['id']; |
| 5194 |
$payment_token_last_digits = $payment_token['source']['card']['last_digits']; |
| 5195 |
$payment_token_brand = $payment_token['source']['card']['brand']; |
| 5196 |
?> |
| 5197 |
<tr> |
| 5198 |
<td class="label"><?php esc_html_e( 'Last 4 digits of registered card', 'usces' ); ?></td> |
| 5199 |
<td><div class="rod_left shortm"><?php echo esc_html( $payment_token_last_digits ); ?></div></td> |
| 5200 |
</tr> |
| 5201 |
<tr> |
| 5202 |
<td class="label"><input type="hidden" name="paypal_payment_token_id" value="<?php echo esc_attr( $payment_token_id ); ?>" /></td> |
| 5203 |
<td><input type="checkbox" name="paypal_card_delete" id="paypal_card_delete" value="delete"><label for="paypal_card_delete"><?php esc_html_e( 'Credit Card Deletion', 'usces' ); ?></label></td> |
| 5204 |
</tr> |
| 5205 |
<?php |
| 5206 |
endif; |
| 5207 |
endif; |
| 5208 |
endif; |
| 5209 |
} |
| 5210 |
|
| 5211 |
/** |
| 5212 |
* 会員データ編集画面 カード� |
| 5213 |
報登録解除 |
| 5214 |
* usces_action_post_update_memberdata |
| 5215 |
* |
| 5216 |
* @param int $member_id Member ID. |
| 5217 |
* @param boolean $res Result. |
| 5218 |
*/ |
| 5219 |
public function admin_update_memberdata( $member_id, $res ) { |
| 5220 |
if ( ! $this->is_validity_acting( 'card' ) || false === $res ) { |
| 5221 |
return; |
| 5222 |
} |
| 5223 |
|
| 5224 |
if ( isset( $_POST['paypal_card_delete'] ) && 'delete' === wp_unslash( $_POST['paypal_card_delete'] ) && isset( $_POST['paypal_payment_token_id'] ) ) { |
| 5225 |
/* Get Access Token */ |
| 5226 |
$access_token = $this->get_access_token(); |
| 5227 |
$delete_status = $this->api_delete_payment_tokens( $access_token, wp_unslash( $_POST['paypal_payment_token_id'] ) ); |
| 5228 |
} |
| 5229 |
} |
| 5230 |
|
| 5231 |
/** |
| 5232 |
* 利用可能な支払方法(継続課金・定期購� |
| 5233 |
�) |
| 5234 |
* dlseller_filter_the_payment_method_restriction |
| 5235 |
* wcad_filter_the_payment_method_restriction |
| 5236 |
* |
| 5237 |
* @param array $payments_restriction Payment method. |
| 5238 |
* @param string $value Input value. |
| 5239 |
* @return array |
| 5240 |
*/ |
| 5241 |
public function payment_method_restriction( $payments_restriction, $value ) { |
| 5242 |
if ( ( usces_have_regular_order() || usces_have_continue_charge() ) && usces_is_login() ) { |
| 5243 |
$paypal_cp = false; |
| 5244 |
foreach ( (array) $payments_restriction as $key => $payment ) { |
| 5245 |
if ( 'acting_paypal_cp' === $payment['settlement'] ) { |
| 5246 |
$paypal_cp = true; |
| 5247 |
} |
| 5248 |
} |
| 5249 |
if ( ! $paypal_cp ) { |
| 5250 |
$payments = usces_get_system_option( 'usces_payment_method', 'settlement' ); |
| 5251 |
$payments_restriction[] = $payments['acting_paypal_cp']; |
| 5252 |
} |
| 5253 |
$sort = array(); |
| 5254 |
foreach ( (array) $payments_restriction as $key => $payment ) { |
| 5255 |
$sort[ $key ] = $payment['sort']; |
| 5256 |
} |
| 5257 |
array_multisort( $sort, SORT_ASC, $payments_restriction ); |
| 5258 |
} |
| 5259 |
return $payments_restriction; |
| 5260 |
} |
| 5261 |
|
| 5262 |
/** |
| 5263 |
* 利用可能な支払方法 |
| 5264 |
* usces_filter_the_continue_payment_method |
| 5265 |
* |
| 5266 |
* @param array $payment_method Payment method. |
| 5267 |
* @return array |
| 5268 |
*/ |
| 5269 |
public function continuation_payment_method( $payment_method ) { |
| 5270 |
if ( ! array_key_exists( 'acting_paypal_cp', $payment_method ) ) { |
| 5271 |
$payment_method[] = 'acting_paypal_cp'; |
| 5272 |
} |
| 5273 |
return $payment_method; |
| 5274 |
} |
| 5275 |
|
| 5276 |
/** |
| 5277 |
* 自動継続課金データ登録 |
| 5278 |
* dlseller_action_reg_continuationdata |
| 5279 |
* |
| 5280 |
* @param array $args Compact array( $cart, $entry, $order_id, $member_id, $payments, $charging_type, $results, $con_id ). |
| 5281 |
*/ |
| 5282 |
public function register_continuationdata( $args ) { |
| 5283 |
global $usces; |
| 5284 |
extract( $args ); |
| 5285 |
|
| 5286 |
if ( ! empty( $order_id ) && ! empty( $member_id ) && ! empty( $results['ba_id'] ) ) { |
| 5287 |
$this->set_continuation_ba_id( $member_id, $order_id, $results['ba_id'] ); |
| 5288 |
} |
| 5289 |
} |
| 5290 |
|
| 5291 |
/** |
| 5292 |
* 「初回引落し日」 |
| 5293 |
* dlseller_filter_first_charging |
| 5294 |
* |
| 5295 |
* @param object $time Datetime. |
| 5296 |
* @param int $post_id Post ID. |
| 5297 |
* @param array $usces_item Item data. |
| 5298 |
* @param int $order_id Order number. |
| 5299 |
* @param array $continue_data Continuation data. |
| 5300 |
* @return object |
| 5301 |
*/ |
| 5302 |
public function first_charging_date( $time, $post_id, $usces_item, $order_id, $continue_data ) { |
| 5303 |
if ( 99 === (int) $usces_item['item_chargingday'] ) { |
| 5304 |
if ( empty( $order_id ) ) { |
| 5305 |
$today = date_i18n( 'Y-m-d', current_time( 'timestamp' ) ); |
| 5306 |
list( $year, $month, $day ) = explode( '-', $today ); |
| 5307 |
$time = mktime( 0, 0, 0, (int) $month, (int) $day, (int) $year ); |
| 5308 |
} |
| 5309 |
} |
| 5310 |
return $time; |
| 5311 |
} |
| 5312 |
|
| 5313 |
/** |
| 5314 |
* 継続課金会員リスト「契約」 |
| 5315 |
* dlseller_filter_continue_member_list_continue_status |
| 5316 |
* |
| 5317 |
* @param string $status Continuation status. |
| 5318 |
* @param int $member_id Member ID. |
| 5319 |
* @param int $order_id Order number. |
| 5320 |
* @param array $meta_data Continuation data. |
| 5321 |
* @return string |
| 5322 |
*/ |
| 5323 |
public function continue_member_list_continue_status( $status, $member_id, $order_id, $meta_data ) { |
| 5324 |
return $status; |
| 5325 |
} |
| 5326 |
|
| 5327 |
/** |
| 5328 |
* 継続課金会員リスト Column |
| 5329 |
* dlseller_filter_continue_memberlist_column |
| 5330 |
* |
| 5331 |
* @param string $columns Continuation condition. |
| 5332 |
* @param object $continuationlist Continuation list class. |
| 5333 |
* @return string |
| 5334 |
*/ |
| 5335 |
public function continue_memberlist_column( $columns, $continuationlist ) { |
| 5336 |
$columns['ba_id'] = __( 'Billing Agreement ID', 'usces' ); |
| 5337 |
return $columns; |
| 5338 |
} |
| 5339 |
|
| 5340 |
/** |
| 5341 |
* 継続課金会員リスト Join table |
| 5342 |
* dlseller_filter_continue_memberlist_sql_jointable |
| 5343 |
* |
| 5344 |
* @param string $join Join query. |
| 5345 |
* @param object $continuationlist Continuation list class. |
| 5346 |
* @return string |
| 5347 |
*/ |
| 5348 |
public function continue_memberlist_sql_jointable( $join, $continuationlist ) { |
| 5349 |
global $wpdb; |
| 5350 |
|
| 5351 |
$join .= "LEFT JOIN {$wpdb->prefix}usces_member_meta AS `mm1` ON con_member_id = mm1.member_id AND mm1.meta_key = concat( 'paypal_continuation_', con_order_id ) "; |
| 5352 |
return $join; |
| 5353 |
} |
| 5354 |
|
| 5355 |
/** |
| 5356 |
* 継続課金会員リスト Select query |
| 5357 |
* dlseller_filter_continue_memberlist_sql_select |
| 5358 |
* |
| 5359 |
* @param string $query Select query. |
| 5360 |
* @param string $csod Custom query. |
| 5361 |
* @param object $continuationlist Continuation list class. |
| 5362 |
* @return string |
| 5363 |
*/ |
| 5364 |
public function continue_memberlist_sql_select( $query, $csod, $continuationlist ) { |
| 5365 |
global $wpdb; |
| 5366 |
|
| 5367 |
$query = "SELECT |
| 5368 |
`con_id` AS `ID`, |
| 5369 |
`con_order_id` AS `order_id`, |
| 5370 |
om.meta_value AS `deco_id`, |
| 5371 |
`con_member_id` AS `mem_id`, |
| 5372 |
mem.mem_email AS `email`, |
| 5373 |
mem.mem_name1 AS `name1`, |
| 5374 |
mem.mem_name2 AS `name2`, |
| 5375 |
mem.mem_name3 AS `name3`, |
| 5376 |
mem.mem_name4 AS `name4`, |
| 5377 |
IFNULL( mm.meta_value, '' ) AS `limitofcard`, |
| 5378 |
`con_price` AS `price`, |
| 5379 |
`con_acting` AS `acting`, |
| 5380 |
ord.order_payment_name AS `payment_name`, |
| 5381 |
DATE_FORMAT( ord.order_date, '%Y-%m-%d' ) AS `orderdate`, |
| 5382 |
DATE_FORMAT( con_startdate, '%Y-%m-%d' ) AS `startdate`, |
| 5383 |
DATE_FORMAT( con_next_contracting, '%Y-%m-%d' ) AS `contractedday`, |
| 5384 |
DATE_FORMAT( con_next_charging, '%Y-%m-%d' ) AS `chargedday`, |
| 5385 |
`con_status` AS `status`, |
| 5386 |
`con_condition` AS `condition` |
| 5387 |
{$csod}, |
| 5388 |
IFNULL( mm1.meta_value, '' ) AS `ba_id` |
| 5389 |
FROM {$continuationlist->table} "; |
| 5390 |
return $query; |
| 5391 |
} |
| 5392 |
|
| 5393 |
/** |
| 5394 |
* 継続課金会員リスト「状� |
| 5395 |
�」 |
| 5396 |
* dlseller_filter_continue_member_list_condition |
| 5397 |
* |
| 5398 |
* @param string $condition Continuation condition. |
| 5399 |
* @param int $member_id Member ID. |
| 5400 |
* @param int $order_id Order number. |
| 5401 |
* @param array $continue_data Continuation data. |
| 5402 |
* @return string |
| 5403 |
*/ |
| 5404 |
public function continue_member_list_condition( $condition, $member_id, $order_id, $continue_data ) { |
| 5405 |
global $usces; |
| 5406 |
|
| 5407 |
$acting_flg = $this->get_order_acting_flg( $order_id ); |
| 5408 |
if ( 'acting_paypal_cp' === $acting_flg ) { |
| 5409 |
$log_data = $this->get_acting_log( $order_id, 0, 'ALL' ); |
| 5410 |
if ( $log_data ) { |
| 5411 |
$url = admin_url( 'admin.php?page=usces_continue&continue_action=settlement_paypal_cp&member_id=' . esc_attr( $member_id ) . '&order_id=' . esc_attr( $order_id ) ); |
| 5412 |
$condition = '<a href="' . $url . '">' . __( 'Detail', 'usces' ) . '</a>'; |
| 5413 |
if ( 'continuation' === $continue_data['status'] ) { |
| 5414 |
$latest_log = $this->get_acting_latest_log( $order_id, 0, 'ALL' ); |
| 5415 |
if ( isset( $latest_log['status'] ) && 'ERROR' === $latest_log['status'] ) { |
| 5416 |
$condition .= '<div class="acting-status paypal-error">' . __( 'Settlement error', 'usces' ) . '</div>'; |
| 5417 |
} |
| 5418 |
} |
| 5419 |
} |
| 5420 |
} |
| 5421 |
return $condition; |
| 5422 |
} |
| 5423 |
|
| 5424 |
/** |
| 5425 |
* 継続課金会員決済状況ページ表示 |
| 5426 |
* dlseller_action_continue_member_list_page |
| 5427 |
* |
| 5428 |
* @param string $continue_action Continuation action. |
| 5429 |
*/ |
| 5430 |
public function continue_member_list_page( $continue_action ) { |
| 5431 |
if ( 'settlement_paypal_cp' === $continue_action ) { |
| 5432 |
$member_id = ( isset( $_GET['member_id'] ) ) ? wp_unslash( $_GET['member_id'] ) : ''; |
| 5433 |
$order_id = ( isset( $_GET['order_id'] ) ) ? wp_unslash( $_GET['order_id'] ) : ''; |
| 5434 |
if ( ! empty( $member_id ) && ! empty( $order_id ) ) { |
| 5435 |
$this->continue_member_settlement_info_page( $member_id, $order_id ); |
| 5436 |
exit(); |
| 5437 |
} |
| 5438 |
} |
| 5439 |
} |
| 5440 |
|
| 5441 |
/** |
| 5442 |
* 継続課金会員決済状況ページ |
| 5443 |
* |
| 5444 |
* @param int $member_id Member ID. |
| 5445 |
* @param int $order_id Order number. |
| 5446 |
*/ |
| 5447 |
public function continue_member_settlement_info_page( $member_id, $order_id ) { |
| 5448 |
global $usces; |
| 5449 |
|
| 5450 |
$order_data = $usces->get_order_data( $order_id, 'direct' ); |
| 5451 |
if ( ! $order_data ) { |
| 5452 |
return; |
| 5453 |
} |
| 5454 |
|
| 5455 |
$payment = $usces->getPayments( $order_data['order_payment_name'] ); |
| 5456 |
if ( 'acting_paypal_cp' !== $payment['settlement'] ) { |
| 5457 |
return; |
| 5458 |
} |
| 5459 |
|
| 5460 |
$continue_data = $this->get_continuation_data( $member_id, $order_id ); |
| 5461 |
$con_id = $continue_data['con_id']; |
| 5462 |
$curent_url = esc_url( $_SERVER['REQUEST_URI'] ); |
| 5463 |
$navibutton = '<a href="' . esc_url( $_SERVER['HTTP_REFERER'] ) . '" class="back-list"><span class="dashicons dashicons-list-view"></span>' . __( 'Back to the continue members list', 'dlseller' ) . '</a>'; |
| 5464 |
|
| 5465 |
$member_info = $usces->get_member_info( $member_id ); |
| 5466 |
$name = usces_localized_name( $member_info['mem_name1'], $member_info['mem_name2'], 'return' ); |
| 5467 |
|
| 5468 |
$contracted_date = ( empty( $continue_data['contractedday'] ) ) ? dlseller_next_contracting( $order_id ) : $continue_data['contractedday']; |
| 5469 |
if ( ! empty( $contracted_date ) ) { |
| 5470 |
list( $contracted_year, $contracted_month, $contracted_day ) = explode( '-', $contracted_date ); |
| 5471 |
} else { |
| 5472 |
$contracted_year = 0; |
| 5473 |
$contracted_month = 0; |
| 5474 |
$contracted_day = 0; |
| 5475 |
} |
| 5476 |
$charged_date = ( empty( $continue_data['chargedday'] ) ) ? dlseller_next_charging( $order_id ) : $continue_data['chargedday']; |
| 5477 |
if ( ! empty( $charged_date ) ) { |
| 5478 |
list( $charged_year, $charged_month, $charged_day ) = explode( '-', $charged_date ); |
| 5479 |
} else { |
| 5480 |
$charged_year = 0; |
| 5481 |
$charged_month = 0; |
| 5482 |
$charged_day = 0; |
| 5483 |
} |
| 5484 |
$this_year = substr( date_i18n( 'Y', current_time( 'timestamp' ) ), 0, 4 ); |
| 5485 |
|
| 5486 |
$log_data = $this->get_acting_log( $order_id, 0, 'ALL' ); |
| 5487 |
$num = ( $log_data ) ? count( $log_data ) : 1; |
| 5488 |
?> |
| 5489 |
<div class="wrap"> |
| 5490 |
<div class="usces_admin"> |
| 5491 |
<h1>Welcart Management <?php esc_html_e( 'Continuation charging member information', 'dlseller' ); ?></h1> |
| 5492 |
<p class="version_info">Version <?php echo esc_html( WCEX_DLSELLER_VERSION ); ?></p> |
| 5493 |
<?php usces_admin_action_status(); ?> |
| 5494 |
<div class="edit_pagenav"><?php wel_esc_script_e( $navibutton ); ?></div> |
| 5495 |
<div id="datatable"> |
| 5496 |
<div id="tablesearch" class="usces_tablesearch"> |
| 5497 |
<div id="searchBox" style="display:block"> |
| 5498 |
<table class="search_table"> |
| 5499 |
<tr> |
| 5500 |
<td class="label"><?php esc_html_e( 'Continuation charging information', 'dlseller' ); ?></td> |
| 5501 |
<td> |
| 5502 |
<table class="order_info"> |
| 5503 |
<tr> |
| 5504 |
<th><?php esc_html_e( 'Member ID', 'dlseller' ); ?></th> |
| 5505 |
<td><?php echo esc_html( $member_id ); ?></td> |
| 5506 |
<th><?php esc_html_e( 'Contractor name', 'dlseller' ); ?></th> |
| 5507 |
<td><?php echo esc_html( $name ); ?></td> |
| 5508 |
</tr> |
| 5509 |
<tr> |
| 5510 |
<th><?php esc_html_e( 'Order ID', 'dlseller' ); ?></th> |
| 5511 |
<td><?php echo esc_html( $order_id ); ?></td> |
| 5512 |
<th><?php esc_html_e( 'Application Date', 'dlseller' ); ?></th> |
| 5513 |
<td><?php echo esc_html( $order_data['order_date'] ); ?></td> |
| 5514 |
</tr> |
| 5515 |
<tr> |
| 5516 |
<th><?php esc_html_e( 'Renewal Date', 'dlseller' ); ?></th> |
| 5517 |
<td> |
| 5518 |
<?php |
| 5519 |
echo '<select id="contracted-year">'; |
| 5520 |
echo '<option value="0"' . selected( $contracted_year, 0, false ) . '></option>'; |
| 5521 |
for ( $i = 0; $i <= 10; $i++ ) { |
| 5522 |
$year = (int) $this_year + $i; |
| 5523 |
echo '<option value="' . esc_html( $year ) . '"' . selected( $contracted_year, $year, false ) . '>' . esc_html( $year ) . '</option>'; |
| 5524 |
} |
| 5525 |
echo '</select>-<select id="contracted-month">'; |
| 5526 |
echo '<option value="0"' . selected( $contracted_month, 0, false ) . '></option>'; |
| 5527 |
for ( $i = 1; $i <= 12; $i++ ) { |
| 5528 |
$month = sprintf( '%02d', $i ); |
| 5529 |
echo '<option value="' . esc_html( $month ) . '"' . selected( $contracted_month, $month, false ) . '>' . esc_html( $month ) . '</option>'; |
| 5530 |
} |
| 5531 |
echo '</select>-<select id="contracted-day">'; |
| 5532 |
echo '<option value="0"' . selected( $contracted_day, 0, false ) . '></option>'; |
| 5533 |
for ( $i = 1; $i <= 31; $i++ ) { |
| 5534 |
$day = sprintf( '%02d', $i ); |
| 5535 |
echo '<option value="' . esc_html( $day ) . '"' . selected( $contracted_day, $day, false ) . '>' . esc_html( $day ) . '</option>'; |
| 5536 |
} |
| 5537 |
echo '</select>'; |
| 5538 |
?> |
| 5539 |
</td> |
| 5540 |
<th><?php esc_html_e( 'Next Withdrawal Date', 'dlseller' ); ?></th> |
| 5541 |
<td> |
| 5542 |
<?php |
| 5543 |
echo '<select id="charged-year">'; |
| 5544 |
echo '<option value="0"' . selected( $charged_year, 0, false ) . '></option>'; |
| 5545 |
echo '<option value="' . esc_html( $this_year ) . '"' . selected( $charged_year, $this_year, false ) . '>' . esc_html( $this_year ) . '</option>'; |
| 5546 |
$next_year = (int) $this_year + 1; |
| 5547 |
echo '<option value="' . esc_html( $next_year ) . '"' . selected( $charged_year, $next_year, false ) . '>' . esc_html( $next_year ) . '</option>'; |
| 5548 |
echo '</select>-<select id="charged-month">'; |
| 5549 |
echo '<option value="0"' . selected( $charged_month, 0, false ) . '></option>'; |
| 5550 |
for ( $i = 1; $i <= 12; $i++ ) { |
| 5551 |
$month = sprintf( '%02d', $i ); |
| 5552 |
echo '<option value="' . esc_html( $month ) . '"' . selected( $charged_month, $month, false ) . '>' . esc_html( $month ) . '</option>'; |
| 5553 |
} |
| 5554 |
echo '</select>-<select id="charged-day">'; |
| 5555 |
echo '<option value="0"' . selected( $charged_day, 0, false ) . '></option>'; |
| 5556 |
for ( $i = 1; $i <= 31; $i++ ) { |
| 5557 |
$day = sprintf( '%02d', $i ); |
| 5558 |
echo '<option value="' . esc_html( $day ) . '"' . selected( $charged_day, $day, false ) . '>' . esc_html( $day ) . '</option>'; |
| 5559 |
} |
| 5560 |
echo '</select>'; |
| 5561 |
?> |
| 5562 |
</td> |
| 5563 |
</tr> |
| 5564 |
<tr> |
| 5565 |
<th><?php esc_html_e( 'Amount on order', 'usces' ); ?></th> |
| 5566 |
<td><?php usces_crform( $continue_data['order_price'], false ); ?></td> |
| 5567 |
<th><?php esc_html_e( 'Transaction amount', 'usces' ); ?></th> |
| 5568 |
<td><input type="text" class="amount" id="price" style="text-align: right;" value="<?php usces_crform( $continue_data['price'], false, false, '', false ); ?>"><?php usces_crcode(); ?></td> |
| 5569 |
</tr> |
| 5570 |
<tr> |
| 5571 |
<th><?php esc_html_e( 'Billing Agreement ID', 'usces' ); ?></th> |
| 5572 |
<?php $ba_id = $this->get_continuation_ba_id( $member_id, $order_id ); ?> |
| 5573 |
<td colspan="3"><?php echo esc_html( $ba_id ); ?></td> |
| 5574 |
</tr> |
| 5575 |
<tr> |
| 5576 |
<th><?php esc_html_e( 'Status', 'dlseller' ); ?></th> |
| 5577 |
<td><select id="dlseller-status"> |
| 5578 |
<?php ob_start(); ?> |
| 5579 |
<?php if ( 'continuation' === $continue_data['status'] ) : ?> |
| 5580 |
<option value="continuation" selected><?php esc_html_e( 'Continuation', 'dlseller' ); ?></option> |
| 5581 |
<option value="cancellation"><?php esc_html_e( 'Stop', 'dlseller' ); ?></option> |
| 5582 |
<?php else : ?> |
| 5583 |
<option value="cancellation" selected><?php esc_html_e( 'Cancellation', 'dlseller' ); ?></option> |
| 5584 |
<option value="continuation"><?php esc_html_e( 'Resumption', 'dlseller' ); ?></option> |
| 5585 |
<?php endif; ?> |
| 5586 |
<?php |
| 5587 |
$dlseller_status_options = ob_get_contents(); |
| 5588 |
ob_end_clean(); |
| 5589 |
$dlseller_status_options = apply_filters( 'usces_filter_continuation_charging_status_options', $dlseller_status_options, $continue_data ); |
| 5590 |
wel_esc_script_e( $dlseller_status_options ); |
| 5591 |
?> |
| 5592 |
</select></td> |
| 5593 |
<td colspan="2"><input id="continuation-update" type="button" class="button button-primary" value="<?php esc_attr_e( 'Update' ); ?>" /></td> |
| 5594 |
</tr> |
| 5595 |
</table> |
| 5596 |
<?php do_action( 'usces_action_continuation_charging_information', $continue_data, $member_id, $order_id ); ?> |
| 5597 |
</td> |
| 5598 |
</tr> |
| 5599 |
</table> |
| 5600 |
</div><!-- searchBox --> |
| 5601 |
</div><!-- tablesearch --> |
| 5602 |
<table id="mainDataTable" class="new-table order-new-table"> |
| 5603 |
<thead> |
| 5604 |
<tr> |
| 5605 |
<th scope="col"> </th> |
| 5606 |
<th scope="col"><?php esc_html_e( 'Processing date', 'usces' ); ?></th> |
| 5607 |
<th scope="col"><?php esc_html_e( 'Trans ID', 'usces' ); ?></th> |
| 5608 |
<th scope="col"><?php esc_html_e( 'Transaction amount', 'usces' ); ?></th> |
| 5609 |
<th scope="col"><?php esc_html_e( 'Process', 'usces' ); ?></th> |
| 5610 |
<th scope="col"> </th> |
| 5611 |
</tr> |
| 5612 |
</thead> |
| 5613 |
<?php |
| 5614 |
foreach ( (array) $log_data as $data ) : |
| 5615 |
$tracking_id = ( isset( $data['tracking_id'] ) ) ? $data['tracking_id'] : ''; |
| 5616 |
$latest_log = $this->get_acting_latest_log( $order_id, $tracking_id, 'ALL' ); |
| 5617 |
if ( $latest_log ) : |
| 5618 |
$acting_status = $this->get_acting_status( $order_id, $tracking_id ); |
| 5619 |
if ( 'COMPLETED' === $latest_log['result'] ) { |
| 5620 |
$class = ' paypal-' . strtolower( $acting_status ); |
| 5621 |
$amount = usces_crform( $this->get_latest_amount( $order_id, $tracking_id ), false, true, 'return', true ); |
| 5622 |
} else { |
| 5623 |
$class = ' paypal-error'; |
| 5624 |
$amount = ''; |
| 5625 |
} |
| 5626 |
$log = usces_unserialize( $latest_log['log'] ); |
| 5627 |
$id = ( isset( $log['id'] ) ) ? $log['id'] : ''; |
| 5628 |
if ( isset( $log['purchase_units'] ) ) { |
| 5629 |
$purchase_units = $log['purchase_units'][0]; |
| 5630 |
if ( isset( $purchase_units['payments'] ) ) { |
| 5631 |
if ( isset( $purchase_units['payments']['captures'] ) ) { |
| 5632 |
$payments = $purchase_units['payments']['captures'][0]; |
| 5633 |
} elseif ( isset( $purchase_units['payments']['authorizations'] ) ) { |
| 5634 |
$payments = $purchase_units['payments']['authorizations'][0]; |
| 5635 |
} elseif ( isset( $purchase_units['payments']['refunds'] ) ) { |
| 5636 |
$payments = $purchase_units['payments']['refunds'][0]; |
| 5637 |
} |
| 5638 |
if ( isset( $payments['id'] ) ) { |
| 5639 |
$id = $payments['id']; |
| 5640 |
} |
| 5641 |
} |
| 5642 |
} |
| 5643 |
?> |
| 5644 |
<tbody> |
| 5645 |
<tr> |
| 5646 |
<td><?php echo esc_html( $num ); ?></td> |
| 5647 |
<td><?php echo esc_html( $data['datetime'] ); ?></td> |
| 5648 |
<td><?php echo esc_html( $id ); ?></td> |
| 5649 |
<td class="amount"><?php echo esc_html( $amount ); ?></td> |
| 5650 |
<td><span id="settlement-status-<?php echo esc_attr( $num ); ?>"><span class="acting-status<?php echo esc_attr( $class ); ?>"><?php echo esc_html__( $acting_status, 'usces' ); ?></span></span></td> |
| 5651 |
<td> |
| 5652 |
<input type="button" class="button settlement-information" data-tracking_id="<?php echo esc_attr( $tracking_id ); ?>" data-num="<?php echo esc_attr( $num ); ?>" value="<?php esc_attr_e( 'Settlement info', 'usces' ); ?>"> |
| 5653 |
</td> |
| 5654 |
</tr> |
| 5655 |
</tbody> |
| 5656 |
<?php |
| 5657 |
$num--; |
| 5658 |
endif; |
| 5659 |
endforeach; |
| 5660 |
?> |
| 5661 |
</table> |
| 5662 |
</div><!--datatable--> |
| 5663 |
<input name="member_id" type="hidden" id="member_id" value="<?php echo esc_attr( $member_id ); ?>" /> |
| 5664 |
<input name="order_id" type="hidden" id="order_id" value="<?php echo esc_attr( $order_id ); ?>" /> |
| 5665 |
<input name="con_id" type="hidden" id="con_id" value="<?php echo esc_attr( $con_id ); ?>" /> |
| 5666 |
<input name="usces_referer" type="hidden" id="usces_referer" value="<?php echo urlencode( $curent_url ); ?>" /> |
| 5667 |
<?php wp_nonce_field( 'order_edit', 'wc_nonce' ); ?> |
| 5668 |
</div><!--usces_admin--> |
| 5669 |
</div><!--wrap--> |
| 5670 |
<?php |
| 5671 |
$order_action = 'edit'; |
| 5672 |
$cart = array(); |
| 5673 |
$action_args = compact( 'order_action', 'order_id', 'cart' ); |
| 5674 |
$this->settlement_dialog( $order_data, $action_args ); |
| 5675 |
include ABSPATH . 'wp-admin/admin-footer.php'; |
| 5676 |
} |
| 5677 |
|
| 5678 |
/** |
| 5679 |
* 自動継続課金処理 |
| 5680 |
* dlseller_action_do_continuation_charging |
| 5681 |
* |
| 5682 |
* @param string $today Today. |
| 5683 |
* @param int $member_id Member ID. |
| 5684 |
* @param int $order_id Order number. |
| 5685 |
* @param array $continue_data Continuation data. |
| 5686 |
*/ |
| 5687 |
public function auto_continuation_charging( $today, $member_id, $order_id, $continue_data ) { |
| 5688 |
global $usces; |
| 5689 |
|
| 5690 |
if ( ! usces_is_membersystem_state() ) { |
| 5691 |
return; |
| 5692 |
} |
| 5693 |
|
| 5694 |
if ( 0 >= $continue_data['price'] ) { |
| 5695 |
return; |
| 5696 |
} |
| 5697 |
|
| 5698 |
$order_data = $usces->get_order_data( $order_id, 'direct' ); |
| 5699 |
if ( ! $order_data || $usces->is_status( 'cancel', $order_data['order_status'] ) ) { |
| 5700 |
return; |
| 5701 |
} |
| 5702 |
|
| 5703 |
$payment = $usces->getPayments( $order_data['order_payment_name'] ); |
| 5704 |
if ( 'acting_paypal_cp' !== $payment['settlement'] || 'acting_paypal_cp' !== $continue_data['acting'] ) { |
| 5705 |
return; |
| 5706 |
} |
| 5707 |
|
| 5708 |
$log_data = $this->get_acting_log( $order_id, 0, 'ALL' ); |
| 5709 |
if ( ! $log_data ) { |
| 5710 |
return; |
| 5711 |
} |
| 5712 |
|
| 5713 |
$bn_code = self::API_BN_CODE_PCP; |
| 5714 |
$ba_id = $this->get_continuation_ba_id( $member_id, $order_id ); |
| 5715 |
$tracking_id = usces_acting_key(); |
| 5716 |
if ( ! empty( $ba_id ) ) { |
| 5717 |
$acting_opts = $this->get_acting_settings(); |
| 5718 |
$cp_intent = ( isset( $acting_opts['autobilling_intent'] ) ) ? $acting_opts['autobilling_intent'] : ''; |
| 5719 |
|
| 5720 |
/* Get Access Token */ |
| 5721 |
$access_token = $this->get_access_token(); |
| 5722 |
|
| 5723 |
$entry = array(); |
| 5724 |
$entry['order']['total_full_price'] = $continue_data['price']; |
| 5725 |
$cart = usces_get_ordercartdata( $order_id ); |
| 5726 |
$shipping = usces_have_shipped( $cart ); |
| 5727 |
if ( $shipping ) { |
| 5728 |
$delivery = wel_safe_unserialize( $order_data['order_delivery'] ); |
| 5729 |
$entry['delivery']['name1'] = $delivery['name1']; |
| 5730 |
$entry['delivery']['name2'] = $delivery['name2']; |
| 5731 |
$entry['delivery']['country'] = $delivery['country']; |
| 5732 |
$entry['delivery']['zipcode'] = $delivery['zipcode']; |
| 5733 |
$entry['delivery']['pref'] = $delivery['pref']; |
| 5734 |
$entry['delivery']['address1'] = $delivery['address1']; |
| 5735 |
$entry['delivery']['address2'] = $delivery['address2']; |
| 5736 |
$entry['delivery']['address3'] = $delivery['address3']; |
| 5737 |
} |
| 5738 |
|
| 5739 |
/* Create order */ |
| 5740 |
$response_order_data = $this->api_create_order( $access_token, $bn_code, $cp_intent, $tracking_id, $entry, $cart ); |
| 5741 |
if ( isset( $response_order_data['id'] ) && isset( $response_order_data['status'] ) && 'CREATED' === $response_order_data['status'] ) { |
| 5742 |
$resource_id = $response_order_data['id']; |
| 5743 |
$correlation_id = ''; |
| 5744 |
$payment_source = array(); |
| 5745 |
$payment_source['token'] = array( |
| 5746 |
'id' => $ba_id, |
| 5747 |
'type' => 'BILLING_AGREEMENT', |
| 5748 |
); |
| 5749 |
dlseller_set_continuation_meta_value( 'resource_' . $tracking_id, $resource_id, $continue_data['con_id'] ); |
| 5750 |
if ( 'CAPTURE' === $cp_intent ) { |
| 5751 |
/* Capture */ |
| 5752 |
$response_data = $this->api_capture_order( $access_token, $bn_code, $tracking_id, $resource_id, $correlation_id, $payment_source ); |
| 5753 |
} elseif ( 'AUTHORIZE' === $cp_intent ) { |
| 5754 |
/* Authorize */ |
| 5755 |
$response_data = $this->api_authorize_order( $access_token, $bn_code, $tracking_id, $resource_id, $correlation_id, $payment_source ); |
| 5756 |
} |
| 5757 |
if ( isset( $response_data['status'] ) ) { |
| 5758 |
$status = $response_data['status']; |
| 5759 |
} elseif ( isset( $response_data['name'] ) ) { |
| 5760 |
$status = $response_data['name']; |
| 5761 |
} else { |
| 5762 |
$status = $cp_intent . ' ERROR'; |
| 5763 |
} |
| 5764 |
$response_data = apply_filters( 'usces_filter_paypal_cp_auto_continuation_charging_log', $response_data, $order_id, $status ); |
| 5765 |
if ( 'COMPLETED' === $status && isset( $response_data['purchase_units'] ) ) { |
| 5766 |
$this->save_acting_log( $response_data, 'paypal_cp', $cp_intent, $status, $continue_data['price'], $order_id, $tracking_id ); |
| 5767 |
// dlseller_set_continuation_meta_value( 'resource_' . $tracking_id, $resource_id, $continue_data['con_id'] ); |
| 5768 |
$purchase_units = $response_data['purchase_units'][0]; |
| 5769 |
if ( isset( $purchase_units['payments']['captures'] ) ) { |
| 5770 |
$payments = $purchase_units['payments']['captures'][0]; |
| 5771 |
} elseif ( isset( $purchase_units['payments']['authorizations'] ) ) { |
| 5772 |
$payments = $purchase_units['payments']['authorizations'][0]; |
| 5773 |
} |
| 5774 |
if ( ! empty( $payments['id'] ) ) { |
| 5775 |
dlseller_set_continuation_meta_value( 'trans_' . $tracking_id, $payments['id'], $continue_data['con_id'] ); /* 取引ID */ |
| 5776 |
} |
| 5777 |
$response_data['acting'] = $this->paymod_id; |
| 5778 |
$this->autobilling_email( $member_id, $order_id, $response_data, $continue_data ); |
| 5779 |
} else { |
| 5780 |
$this->save_acting_log( $response_data, 'paypal_cp', 'ERROR', $status, 0, $order_id, $tracking_id ); |
| 5781 |
$this->save_entry_log( $tracking_id, $continue_data['price'], $cart, $entry ); |
| 5782 |
$log = array( |
| 5783 |
'acting' => $this->paymod_id, |
| 5784 |
'key' => $tracking_id, |
| 5785 |
'result' => $status, |
| 5786 |
'data' => $response_data, |
| 5787 |
); |
| 5788 |
usces_save_order_acting_error( $log ); |
| 5789 |
$this->autobilling_error_email( $member_id, $order_id, $response_data, $response_data ); |
| 5790 |
} |
| 5791 |
do_action( 'usces_action_auto_continuation_charging', $member_id, $order_id, $continue_data, $response_data ); |
| 5792 |
} else { |
| 5793 |
$this->save_entry_log( $tracking_id, $continue_data['price'], $cart, $entry ); |
| 5794 |
if ( isset( $response_order_data['status'] ) ) { |
| 5795 |
$status = $response_order_data['status']; |
| 5796 |
} elseif ( isset( $response_order_data['name'] ) ) { |
| 5797 |
$status = $response_order_data['name']; |
| 5798 |
} else { |
| 5799 |
$status = 'CREATE ORDER ERROR'; |
| 5800 |
} |
| 5801 |
$log = array( |
| 5802 |
'acting' => $this->paymod_id, |
| 5803 |
'key' => $tracking_id, |
| 5804 |
'result' => $status, |
| 5805 |
'data' => $response_order_data, |
| 5806 |
); |
| 5807 |
usces_save_order_acting_error( $log ); |
| 5808 |
$this->save_acting_log( $response_order_data, 'paypal_cp', 'ERROR', $status, 0, $order_id, $tracking_id ); |
| 5809 |
$this->autobilling_error_email( $member_id, $order_id, $response_order_data, $continue_data ); |
| 5810 |
do_action( 'usces_action_auto_continuation_charging', $member_id, $order_id, $continue_data, $response_order_data ); |
| 5811 |
} |
| 5812 |
} else { |
| 5813 |
$this->save_entry_log( $tracking_id, $continue_data['price'], $cart, $entry ); |
| 5814 |
$logdata = array(); |
| 5815 |
$log = array( |
| 5816 |
'acting' => $this->paymod_id, |
| 5817 |
'key' => $member_id, |
| 5818 |
'result' => 'MEMBER ERROR', |
| 5819 |
'data' => $logdata, |
| 5820 |
); |
| 5821 |
usces_save_order_acting_error( $log ); |
| 5822 |
$this->save_acting_log( $logdata, 'paypal_cp', 'ERROR', 'MEMBER ERROR', 0, $order_id, $tracking_id ); |
| 5823 |
$this->autobilling_error_email( $member_id, $order_id, $logdata, $continue_data ); |
| 5824 |
do_action( 'usces_action_auto_continuation_charging', $member_id, $order_id, $continue_data, $logdata ); |
| 5825 |
} |
| 5826 |
} |
| 5827 |
|
| 5828 |
/** |
| 5829 |
* 自動継続課金処理メール(正常) |
| 5830 |
* |
| 5831 |
* @param int $member_id Member ID. |
| 5832 |
* @param int $order_id Order number. |
| 5833 |
* @param array $response_data Response data. |
| 5834 |
* @param array $continue_data Continuation data. |
| 5835 |
*/ |
| 5836 |
public function autobilling_email( $member_id, $order_id, $response_data, $continue_data ) { |
| 5837 |
global $usces; |
| 5838 |
|
| 5839 |
$acting_opts = $this->get_acting_settings(); |
| 5840 |
$order_data = $usces->get_order_data( $order_id, 'direct' ); |
| 5841 |
$mail_body = $this->autobilling_message( $member_id, $order_id, $order_data, $response_data, $continue_data, false ); |
| 5842 |
|
| 5843 |
if ( 'on' === $acting_opts['autobilling_email'] ) { |
| 5844 |
$subject = apply_filters( 'usces_filter_paypal_cp_autobilling_email_subject', __( 'Announcement of automatic continuing charging process', 'usces' ), $member_id, $order_id, $order_data, $response_data, $continue_data ); |
| 5845 |
$member_info = $usces->get_member_info( $member_id ); |
| 5846 |
$name = usces_localized_name( $member_info['mem_name1'], $member_info['mem_name2'], 'return' ); |
| 5847 |
$mail_data = usces_mail_data(); |
| 5848 |
$mail_header = ''; |
| 5849 |
if ( isset( $usces->options['put_customer_name'] ) && 1 === (int) $usces->options['put_customer_name'] ) { |
| 5850 |
$mail_header .= sprintf( __( 'Dear %s', 'usces' ), $name ) . "\r\n\r\n"; |
| 5851 |
} |
| 5852 |
$mail_header .= __( 'We will report automated accounting process was carried out as follows.', 'usces' ) . "\r\n\r\n"; |
| 5853 |
$mail_footer = __( 'If you have any questions, please contact us.', 'usces' ) . "\r\n\r\n" . $mail_data['footer']['thankyou']; |
| 5854 |
$message = apply_filters( 'usces_filter_paypal_cp_autobilling_email_header', $mail_header, $member_id, $order_id, $order_data, $response_data, $continue_data ) . |
| 5855 |
apply_filters( 'usces_filter_paypal_cp_autobilling_email_body', $mail_body, $member_id, $order_id, $order_data, $response_data, $continue_data ) . |
| 5856 |
apply_filters( 'usces_filter_paypal_cp_autobilling_email_footer', $mail_footer, $member_id, $order_id, $order_data, $response_data, $continue_data ); |
| 5857 |
$headers = apply_filters( 'usces_filter_paypal_cp_autobilling_email_headers', '' ); |
| 5858 |
$to_customer = array( |
| 5859 |
'to_name' => sprintf( _x( '%s', 'honorific', 'usces' ), $name ), |
| 5860 |
'to_address' => $member_info['mem_email'], |
| 5861 |
'from_name' => get_option( 'blogname' ), |
| 5862 |
'from_address' => $usces->options['sender_mail'], |
| 5863 |
'reply_name' => get_option( 'blogname' ), |
| 5864 |
'reply_to' => usces_get_first_order_mail(), |
| 5865 |
'return_path' => $usces->options['sender_mail'], |
| 5866 |
'subject' => $subject, |
| 5867 |
'message' => do_shortcode( $message ), |
| 5868 |
'headers' => $headers, |
| 5869 |
); |
| 5870 |
usces_send_mail( $to_customer ); |
| 5871 |
} |
| 5872 |
|
| 5873 |
$ok = ( empty( $this->continuation_charging_mail['OK'] ) ) ? 0 : $this->continuation_charging_mail['OK']; |
| 5874 |
$this->continuation_charging_mail['OK'] = $ok + 1; |
| 5875 |
$this->continuation_charging_mail['mail'][] = $mail_body; |
| 5876 |
} |
| 5877 |
|
| 5878 |
/** |
| 5879 |
* 自動継続課金処理メール(エラー) |
| 5880 |
* |
| 5881 |
* @param int $member_id Member ID. |
| 5882 |
* @param int $order_id Order number. |
| 5883 |
* @param array $response_data Response data. |
| 5884 |
* @param array $continue_data Continuation data. |
| 5885 |
*/ |
| 5886 |
public function autobilling_error_email( $member_id, $order_id, $response_data, $continue_data ) { |
| 5887 |
global $usces; |
| 5888 |
|
| 5889 |
$acting_opts = $this->get_acting_settings(); |
| 5890 |
$order_data = $usces->get_order_data( $order_id, 'direct' ); |
| 5891 |
$mail_body = $this->autobilling_message( $member_id, $order_id, $order_data, $response_data, $continue_data, false ); |
| 5892 |
|
| 5893 |
if ( 'on' === $acting_opts['autobilling_email'] ) { |
| 5894 |
$subject = apply_filters( 'usces_filter_paypal_cp_autobilling_error_email_subject', __( 'Announcement of automatic continuing charging process', 'usces' ), $member_id, $order_id, $order_data, $response_data, $continue_data ); |
| 5895 |
$member_info = $usces->get_member_info( $member_id ); |
| 5896 |
$name = usces_localized_name( $member_info['mem_name1'], $member_info['mem_name2'], 'return' ); |
| 5897 |
$mail_data = usces_mail_data(); |
| 5898 |
$mail_header = ''; |
| 5899 |
if ( isset( $usces->options['put_customer_name'] ) && 1 === (int) $usces->options['put_customer_name'] ) { |
| 5900 |
$mail_header .= sprintf( __( 'Dear %s', 'usces' ), $name ) . "\r\n\r\n"; |
| 5901 |
} |
| 5902 |
$mail_header .= __( 'We will reported that an error occurred in automated accounting process.', 'usces' ) . "\r\n\r\n"; |
| 5903 |
$mail_footer = __( 'If you have any questions, please contact us.', 'usces' ) . "\r\n\r\n" . $mail_data['footer']['thankyou']; |
| 5904 |
$message = apply_filters( 'usces_filter_paypal_cp_autobilling_error_email_header', $mail_header, $member_id, $order_id, $order_data, $response_data, $continue_data ) . |
| 5905 |
apply_filters( 'usces_filter_paypal_cp_autobilling_error_email_body', $mail_body, $member_id, $order_id, $order_data, $response_data, $continue_data ) . |
| 5906 |
apply_filters( 'usces_filter_paypal_cp_autobilling_error_email_footer', $mail_footer, $member_id, $order_id, $order_data, $response_data, $continue_data ); |
| 5907 |
$headers = apply_filters( 'usces_filter_paypal_cp_autobilling_error_email_headers', '' ); |
| 5908 |
$to_customer = array( |
| 5909 |
'to_name' => sprintf( _x( '%s', 'honorific', 'usces' ), $name ), |
| 5910 |
'to_address' => $member_info['mem_email'], |
| 5911 |
'from_name' => get_option( 'blogname' ), |
| 5912 |
'from_address' => $usces->options['sender_mail'], |
| 5913 |
'reply_name' => get_option( 'blogname' ), |
| 5914 |
'reply_to' => usces_get_first_order_mail(), |
| 5915 |
'return_path' => $usces->options['sender_mail'], |
| 5916 |
'subject' => $subject, |
| 5917 |
'message' => do_shortcode( $message ), |
| 5918 |
'headers' => $headers, |
| 5919 |
); |
| 5920 |
usces_send_mail( $to_customer ); |
| 5921 |
} |
| 5922 |
|
| 5923 |
$error = ( empty( $this->continuation_charging_mail['NG'] ) ) ? 0 : $this->continuation_charging_mail['NG']; |
| 5924 |
$this->continuation_charging_mail['NG'] = $error + 1; |
| 5925 |
$this->continuation_charging_mail['mail'][] = $mail_body; |
| 5926 |
} |
| 5927 |
|
| 5928 |
/** |
| 5929 |
* 自動継続課金処理メール本文 |
| 5930 |
* |
| 5931 |
* @param int $member_id Member ID. |
| 5932 |
* @param int $order_id Order number. |
| 5933 |
* @param array $order_data Order data. |
| 5934 |
* @param array $response_data Response data. |
| 5935 |
* @param array $continue_data Continuation data. |
| 5936 |
* @param boolean $html true|false. |
| 5937 |
* @return string |
| 5938 |
*/ |
| 5939 |
public function autobilling_message( $member_id, $order_id, $order_data, $response_data, $continue_data, $html = true ) { |
| 5940 |
global $usces; |
| 5941 |
|
| 5942 |
if ( usces_is_html_mail() && $html ) { |
| 5943 |
$message = $this->autobilling_message_htmlbody( $member_id, $order_id, $order_data, $response_data, $continue_data ); |
| 5944 |
} else { |
| 5945 |
$member_info = $usces->get_member_info( $member_id ); |
| 5946 |
$name = usces_localized_name( $member_info['mem_name1'], $member_info['mem_name2'], 'return' ); |
| 5947 |
$contracted_date = ( isset( $continue_data['contractedday'] ) ) ? $continue_data['contractedday'] : ''; |
| 5948 |
$charged_date = ( isset( $continue_data['chargedday'] ) ) ? $continue_data['chargedday'] : ''; |
| 5949 |
|
| 5950 |
$message = usces_mail_line( 2 ); // -------------------- |
| 5951 |
$message .= __( 'Order ID', 'dlseller' ) . ' : ' . $order_id . "\r\n"; |
| 5952 |
$message .= __( 'Application Date', 'dlseller' ) . ' : ' . $order_data['order_date'] . "\r\n"; |
| 5953 |
$message .= __( 'Member ID', 'dlseller' ) . ' : ' . $member_id . "\r\n"; |
| 5954 |
$message .= __( 'Contractor name', 'dlseller' ) . ' : ' . sprintf( _x( '%s', 'honorific', 'usces' ), $name ) . "\r\n"; |
| 5955 |
|
| 5956 |
$cart = usces_get_ordercartdata( $order_id ); |
| 5957 |
$cart_row = current( $cart ); |
| 5958 |
$item_name = $usces->getCartItemName_byOrder( $cart_row ); |
| 5959 |
$options = ( empty( $cart_row['options'] ) ) ? array() : $cart_row['options']; |
| 5960 |
$message .= __( 'Items', 'usces' ) . ' : ' . $item_name . "\r\n"; |
| 5961 |
if ( is_array( $options ) && 0 < count( $options ) ) { |
| 5962 |
$optstr = ''; |
| 5963 |
foreach ( $options as $key => $value ) { |
| 5964 |
if ( ! empty( $key ) ) { |
| 5965 |
$key = urldecode( $key ); |
| 5966 |
$value = wel_safe_maybe_unserialize( $value ); |
| 5967 |
if ( is_array( $value ) ) { |
| 5968 |
$c = ''; |
| 5969 |
$optstr .= '( ' . $key . ' : '; |
| 5970 |
foreach ( $value as $v ) { |
| 5971 |
$optstr .= $c . rawurldecode( $v ); |
| 5972 |
$c = ', '; |
| 5973 |
} |
| 5974 |
$optstr .= " )\r\n"; |
| 5975 |
} else { |
| 5976 |
$optstr .= '( ' . $key . ' : ' . rawurldecode( $value ) . " )\r\n"; |
| 5977 |
} |
| 5978 |
} |
| 5979 |
} |
| 5980 |
$message .= $optstr; |
| 5981 |
} |
| 5982 |
|
| 5983 |
$message .= __( 'Settlement amount', 'usces' ) . ' : ' . usces_crform( $continue_data['price'], true, false, 'return' ) . "\r\n"; |
| 5984 |
if ( isset( $response_data['reminder'] ) ) { |
| 5985 |
if ( ! empty( $charged_date ) ) { |
| 5986 |
$message .= __( 'Next Withdrawal Date', 'dlseller' ) . ' : ' . $charged_date . "\r\n"; |
| 5987 |
} |
| 5988 |
if ( ! empty( $contracted_date ) ) { |
| 5989 |
$message .= __( 'Renewal Date', 'dlseller' ) . ' : ' . $contracted_date . "\r\n"; |
| 5990 |
} |
| 5991 |
} else { |
| 5992 |
if ( ! empty( $charged_date ) ) { |
| 5993 |
$message .= __( 'Next Withdrawal Date', 'dlseller' ) . ' : ' . $charged_date . "\r\n"; |
| 5994 |
} |
| 5995 |
if ( ! empty( $contracted_date ) ) { |
| 5996 |
$message .= __( 'Renewal Date', 'dlseller' ) . ' : ' . $contracted_date . "\r\n"; |
| 5997 |
} |
| 5998 |
$message .= "\r\n"; |
| 5999 |
if ( isset( $response_data['status'] ) && 'COMPLETED' === $response_data['status'] ) { |
| 6000 |
$message .= __( 'Result', 'usces' ) . ' : ' . __( 'Normal done', 'usces' ) . "\r\n"; |
| 6001 |
} elseif ( isset( $response_data['name'] ) ) { |
| 6002 |
$message .= __( 'Result', 'usces' ) . ' : ' . $response_data['name'] . "\r\n"; |
| 6003 |
} else { |
| 6004 |
$message .= __( 'Result', 'usces' ) . ' : ' . __( 'Error', 'usces' ) . "\r\n"; |
| 6005 |
} |
| 6006 |
} |
| 6007 |
|
| 6008 |
$ba_id = $this->get_continuation_ba_id( $member_id, $order_id ); |
| 6009 |
if ( ! empty( $ba_id ) ) { |
| 6010 |
$message .= "\r\n" . __( 'Billing Agreement ID', 'usces' ) . ' : ' . $ba_id . "\r\n\r\n"; |
| 6011 |
} |
| 6012 |
|
| 6013 |
$message .= usces_mail_line( 2 ) . "\r\n"; // -------------------- |
| 6014 |
} |
| 6015 |
return $message; |
| 6016 |
} |
| 6017 |
|
| 6018 |
/** |
| 6019 |
* Automatic renewal billing process email body html |
| 6020 |
* |
| 6021 |
* @param int $member_id Member ID. |
| 6022 |
* @param int $order_id Order number. |
| 6023 |
* @param array $order_data Order data. |
| 6024 |
* @param array $response_data Response data. |
| 6025 |
* @param array $continue_data Continuation data. |
| 6026 |
* @return string |
| 6027 |
*/ |
| 6028 |
public function autobilling_message_htmlbody( $member_id, $order_id, $order_data, $response_data, $continue_data ) { |
| 6029 |
global $usces; |
| 6030 |
|
| 6031 |
$member_info = $usces->get_member_info( $member_id ); |
| 6032 |
$name = usces_localized_name( $member_info['mem_name1'], $member_info['mem_name2'], 'return' ); |
| 6033 |
$contracted_date = ( isset( $continue_data['contractedday'] ) ) ? $continue_data['contractedday'] : ''; |
| 6034 |
$charged_date = ( isset( $continue_data['chargedday'] ) ) ? $continue_data['chargedday'] : ''; |
| 6035 |
|
| 6036 |
$message = '<table style="font-size: 14px; margin-bottom: 30px; width: 100%; border-collapse: collapse; border: 1px solid #ddd;"><tbody>'; |
| 6037 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6038 |
$message .= __( 'Order ID', 'dlseller' ); |
| 6039 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6040 |
$message .= $order_id; |
| 6041 |
$message .= '</td></tr>'; |
| 6042 |
|
| 6043 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6044 |
$message .= __( 'Application Date', 'dlseller' ); |
| 6045 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6046 |
$message .= $order_data['order_date']; |
| 6047 |
$message .= '</td></tr>'; |
| 6048 |
|
| 6049 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6050 |
$message .= __( 'Member ID', 'dlseller' ); |
| 6051 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6052 |
$message .= $member_id; |
| 6053 |
$message .= '</td></tr>'; |
| 6054 |
|
| 6055 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6056 |
$message .= __( 'Contractor name', 'dlseller' ); |
| 6057 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6058 |
$message .= sprintf( _x( '%s', 'honorific', 'usces' ), $name ); |
| 6059 |
$message .= '</td></tr>'; |
| 6060 |
|
| 6061 |
$cart = usces_get_ordercartdata( $order_id ); |
| 6062 |
$cart_row = current( $cart ); |
| 6063 |
$item_name = $usces->getCartItemName_byOrder( $cart_row ); |
| 6064 |
$options = ( empty( $cart_row['options'] ) ) ? array() : $cart_row['options']; |
| 6065 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6066 |
$message .= __( 'Items', 'usces' ); |
| 6067 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6068 |
$message .= $item_name; |
| 6069 |
if ( is_array( $options ) && 0 < count( $options ) ) { |
| 6070 |
$optstr = ''; |
| 6071 |
foreach ( $options as $key => $value ) { |
| 6072 |
if ( ! empty( $key ) ) { |
| 6073 |
$key = urldecode( $key ); |
| 6074 |
$value = wel_safe_maybe_unserialize( $value ); |
| 6075 |
if ( is_array( $value ) ) { |
| 6076 |
$c = ''; |
| 6077 |
$optstr .= '( ' . $key . ' : '; |
| 6078 |
foreach ( $value as $v ) { |
| 6079 |
$optstr .= $c . rawurldecode( $v ); |
| 6080 |
$c = ', '; |
| 6081 |
} |
| 6082 |
$optstr .= ' )<br>'; |
| 6083 |
} else { |
| 6084 |
$optstr .= '( ' . $key . ' : ' . rawurldecode( $value ) . ' )<br>'; |
| 6085 |
} |
| 6086 |
} |
| 6087 |
} |
| 6088 |
$message .= $optstr; |
| 6089 |
} |
| 6090 |
$message .= '</td></tr>'; |
| 6091 |
|
| 6092 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6093 |
$message .= __( 'Settlement amount', 'usces' ); |
| 6094 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6095 |
$message .= usces_crform( $continue_data['price'], true, false, 'return' ); |
| 6096 |
$message .= '</td></tr>'; |
| 6097 |
if ( isset( $response_data['reminder'] ) ) { |
| 6098 |
if ( ! empty( $charged_date ) ) { |
| 6099 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6100 |
$message .= __( 'Next Withdrawal Date', 'dlseller' ); |
| 6101 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6102 |
$message .= $charged_date; |
| 6103 |
$message .= '</td></tr>'; |
| 6104 |
} |
| 6105 |
if ( ! empty( $contracted_date ) ) { |
| 6106 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6107 |
$message .= __( 'Renewal Date', 'dlseller' ); |
| 6108 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6109 |
$message .= $contracted_date; |
| 6110 |
$message .= '</td></tr>'; |
| 6111 |
} |
| 6112 |
} else { |
| 6113 |
if ( ! empty( $charged_date ) ) { |
| 6114 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6115 |
$message .= __( 'Next Withdrawal Date', 'dlseller' ); |
| 6116 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6117 |
$message .= $charged_date; |
| 6118 |
$message .= '</td></tr>'; |
| 6119 |
} |
| 6120 |
if ( ! empty( $contracted_date ) ) { |
| 6121 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6122 |
$message .= __( 'Renewal Date', 'dlseller' ); |
| 6123 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6124 |
$message .= $contracted_date; |
| 6125 |
$message .= '</td></tr>'; |
| 6126 |
} |
| 6127 |
if ( isset( $response_data['status'] ) && 'COMPLETED' === $response_data['status'] ) { |
| 6128 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6129 |
$message .= __( 'Result', 'usces' ); |
| 6130 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6131 |
$message .= __( 'Normal done', 'usces' ); |
| 6132 |
$message .= '</td></tr>'; |
| 6133 |
} elseif ( isset( $response_data['name'] ) ) { |
| 6134 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6135 |
$message .= __( 'Result', 'usces' ); |
| 6136 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6137 |
$message .= $response_data['name']; |
| 6138 |
$message .= '</td></tr>'; |
| 6139 |
} else { |
| 6140 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6141 |
$message .= __( 'Result', 'usces' ); |
| 6142 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6143 |
$message .= __( 'Error', 'usces' ); |
| 6144 |
$message .= '</td></tr>'; |
| 6145 |
} |
| 6146 |
} |
| 6147 |
|
| 6148 |
$ba_id = $this->get_continuation_ba_id( $member_id, $order_id ); |
| 6149 |
if ( ! empty( $ba_id ) ) { |
| 6150 |
$message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">'; |
| 6151 |
$message .= __( 'Billing Agreement ID', 'usces' ); |
| 6152 |
$message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">'; |
| 6153 |
$message .= $ba_id; |
| 6154 |
$message .= '</td></tr>'; |
| 6155 |
} |
| 6156 |
$message .= '</tbody></table>'; |
| 6157 |
return $message; |
| 6158 |
} |
| 6159 |
|
| 6160 |
/** |
| 6161 |
* 自動継続課金処理 |
| 6162 |
* dlseller_action_do_continuation |
| 6163 |
* |
| 6164 |
* @param string $today Today. |
| 6165 |
* @param array $todays_charging Charged data. |
| 6166 |
*/ |
| 6167 |
public function do_auto_continuation( $today, $todays_charging ) { |
| 6168 |
global $usces; |
| 6169 |
|
| 6170 |
if ( empty( $todays_charging ) ) { |
| 6171 |
return; |
| 6172 |
} |
| 6173 |
|
| 6174 |
$ok = ( empty( $this->continuation_charging_mail['OK'] ) ) ? 0 : $this->continuation_charging_mail['OK']; |
| 6175 |
$error = ( empty( $this->continuation_charging_mail['NG'] ) ) ? 0 : $this->continuation_charging_mail['NG']; |
| 6176 |
$admin_subject = apply_filters( 'usces_filter_paypal_cp_autobilling_email_admin_subject', __( 'Automatic Continuing Charging Process Result', 'usces' ) . ' ' . $today, $today ); |
| 6177 |
$admin_footer = apply_filters( 'usces_filter_paypal_cp_autobilling_email_admin_mail_footer', __( 'For details, please check on the administration panel > Continuous charge member list > Continuous charge member information.', 'usces' ) ); |
| 6178 |
$admin_message = __( 'Report that automated accounting process has been completed.', 'usces' ) . "\r\n\r\n" |
| 6179 |
. __( 'Processing date', 'usces' ) . ' : ' . date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) . "\r\n" |
| 6180 |
. __( 'Normal done', 'usces' ) . ' : ' . $ok . "\r\n" |
| 6181 |
. __( 'Abnormal done', 'usces' ) . ' : ' . $error . "\r\n\r\n"; |
| 6182 |
foreach ( (array) $this->continuation_charging_mail['mail'] as $mail ) { |
| 6183 |
$admin_message .= $mail . "\r\n"; |
| 6184 |
} |
| 6185 |
$admin_message .= $admin_footer . "\r\n"; |
| 6186 |
|
| 6187 |
$to_admin = array( |
| 6188 |
'to_name' => apply_filters( 'usces_filter_bccmail_to_admin_name', 'Shop Admin' ), |
| 6189 |
'to_address' => $usces->options['order_mail'], |
| 6190 |
'from_name' => apply_filters( 'usces_filter_bccmail_from_admin_name', 'Welcart Auto BCC' ), |
| 6191 |
'from_address' => $usces->options['sender_mail'], |
| 6192 |
'reply_name' => get_option( 'blogname' ), |
| 6193 |
'reply_to' => usces_get_first_order_mail(), |
| 6194 |
'return_path' => $usces->options['sender_mail'], |
| 6195 |
'subject' => $admin_subject, |
| 6196 |
'message' => do_shortcode( $admin_message ), |
| 6197 |
); |
| 6198 |
usces_send_mail( $to_admin ); |
| 6199 |
unset( $this->continuation_charging_mail ); |
| 6200 |
} |
| 6201 |
|
| 6202 |
/** |
| 6203 |
* 課金日通知メール |
| 6204 |
* dlseller_filter_reminder_mail_body |
| 6205 |
* |
| 6206 |
* @param string $mail_body Message body. |
| 6207 |
* @param int $order_id Order number. |
| 6208 |
* @param array $continue_data Continuation data. |
| 6209 |
* @return string |
| 6210 |
*/ |
| 6211 |
public function reminder_mail_body( $mail_body, $order_id, $continue_data ) { |
| 6212 |
global $usces; |
| 6213 |
|
| 6214 |
$member_id = $continue_data['member_id']; |
| 6215 |
$order_id = $continue_data['order_id']; |
| 6216 |
$order_data = $usces->get_order_data( $order_id, 'direct' ); |
| 6217 |
$response_data = array( 'reminder' => 'reminder' ); |
| 6218 |
$mail_body = $this->autobilling_message( $member_id, $order_id, $order_data, $response_data, $continue_data ); |
| 6219 |
return $mail_body; |
| 6220 |
} |
| 6221 |
|
| 6222 |
/** |
| 6223 |
* 契約更新日通知メール |
| 6224 |
* dlseller_filter_contract_renewal_mail_body |
| 6225 |
* |
| 6226 |
* @param string $mail_body Message body. |
| 6227 |
* @param int $order_id Order number. |
| 6228 |
* @param array $continue_data Continuation data. |
| 6229 |
* @return string |
| 6230 |
*/ |
| 6231 |
public function contract_renewal_mail_body( $mail_body, $order_id, $continue_data ) { |
| 6232 |
global $usces; |
| 6233 |
|
| 6234 |
$member_id = $continue_data['member_id']; |
| 6235 |
$order_data = $usces->get_order_data( $order_id, 'direct' ); |
| 6236 |
$response_data = array( 'reminder' => 'contract_renewal' ); |
| 6237 |
$mail_body = $this->autobilling_message( $member_id, $order_id, $order_data, $response_data, $continue_data ); |
| 6238 |
return $mail_body; |
| 6239 |
} |
| 6240 |
|
| 6241 |
/** |
| 6242 |
* メール支払方法 |
| 6243 |
* usces_filter_order_confirm_mail_payment |
| 6244 |
* usces_filter_send_order_mail_payment |
| 6245 |
* |
| 6246 |
* @param string $msg_payment Message body. |
| 6247 |
* @param int $order_id Order number. |
| 6248 |
* @param array $payment Payment data. |
| 6249 |
* @param array $cart Cart data. |
| 6250 |
* @return string |
| 6251 |
*/ |
| 6252 |
public function continue_order_mail_payment( $msg_payment, $order_id, $payment, $cart ) { |
| 6253 |
global $usces; |
| 6254 |
|
| 6255 |
$post_id = $cart[0]['post_id']; |
| 6256 |
$charging_type = $usces->getItemChargingType( $post_id ); |
| 6257 |
if ( 'continue' !== $charging_type ) { |
| 6258 |
return $msg_payment; |
| 6259 |
} |
| 6260 |
|
| 6261 |
$acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : ''; |
| 6262 |
if ( 'acting_paypal_cp' !== $acting_flg ) { |
| 6263 |
return $msg_payment; |
| 6264 |
} |
| 6265 |
|
| 6266 |
$member_id = $this->get_member_id( $order_id ); |
| 6267 |
$ba_id = $this->get_continuation_ba_id( $member_id, $order_id ); |
| 6268 |
if ( ! empty( $ba_id ) ) { |
| 6269 |
$msg_payment .= __( 'Billing Agreement ID', 'usces' ) . ' : ' . $ba_id . "\r\n\r\n"; |
| 6270 |
} |
| 6271 |
return $msg_payment; |
| 6272 |
} |
| 6273 |
|
| 6274 |
/** |
| 6275 |
* 継続課金会員データ取得 |
| 6276 |
* |
| 6277 |
* @param int $member_id Member ID. |
| 6278 |
* @param int $order_id Order number. |
| 6279 |
* @return array |
| 6280 |
*/ |
| 6281 |
private function get_continuation_data( $member_id, $order_id ) { |
| 6282 |
global $wpdb; |
| 6283 |
|
| 6284 |
$query = $wpdb->prepare( |
| 6285 |
"SELECT |
| 6286 |
`con_id` AS `con_id`, |
| 6287 |
`con_acting` AS `acting`, |
| 6288 |
`con_order_price` AS `order_price`, |
| 6289 |
`con_price` AS `price`, |
| 6290 |
`con_next_charging` AS `chargedday`, |
| 6291 |
`con_next_contracting` AS `contractedday`, |
| 6292 |
`con_startdate` AS `startdate`, |
| 6293 |
`con_status` AS `status` |
| 6294 |
FROM {$wpdb->prefix}usces_continuation |
| 6295 |
WHERE `con_order_id` = %d AND `con_member_id` = %d", |
| 6296 |
$order_id, |
| 6297 |
$member_id |
| 6298 |
); |
| 6299 |
$data = $wpdb->get_row( $query, ARRAY_A ); |
| 6300 |
return $data; |
| 6301 |
} |
| 6302 |
|
| 6303 |
/** |
| 6304 |
* 継続課金会員データ更新 |
| 6305 |
* |
| 6306 |
* @param int $member_id Member ID. |
| 6307 |
* @param int $order_id Order number. |
| 6308 |
* @param array $data Continuation data. |
| 6309 |
* @param boolean $stop Stop continuous billing. |
| 6310 |
* @return boolean |
| 6311 |
*/ |
| 6312 |
private function update_continuation_data( $member_id, $order_id, $data, $stop = false ) { |
| 6313 |
global $wpdb; |
| 6314 |
|
| 6315 |
if ( $stop ) { |
| 6316 |
$query = $wpdb->prepare( |
| 6317 |
"UPDATE {$wpdb->prefix}usces_continuation SET |
| 6318 |
`con_status` = 'cancellation' |
| 6319 |
WHERE `con_order_id` = %d AND `con_member_id` = %d", |
| 6320 |
$order_id, |
| 6321 |
$member_id |
| 6322 |
); |
| 6323 |
} else { |
| 6324 |
$query = $wpdb->prepare( |
| 6325 |
"UPDATE {$wpdb->prefix}usces_continuation SET |
| 6326 |
`con_price` = %f, |
| 6327 |
`con_next_charging` = %s, |
| 6328 |
`con_next_contracting` = %s, |
| 6329 |
`con_status` = %s |
| 6330 |
WHERE `con_order_id` = %d AND `con_member_id` = %d", |
| 6331 |
$data['price'], |
| 6332 |
$data['chargedday'], |
| 6333 |
$data['contractedday'], |
| 6334 |
$data['status'], |
| 6335 |
$order_id, |
| 6336 |
$member_id |
| 6337 |
); |
| 6338 |
} |
| 6339 |
$res = $wpdb->query( $query ); |
| 6340 |
return $res; |
| 6341 |
} |
| 6342 |
|
| 6343 |
/** |
| 6344 |
* 継続課金 ba_id 保存 |
| 6345 |
* |
| 6346 |
* @param int $member_id Member ID. |
| 6347 |
* @param int $order_id Order number. |
| 6348 |
* @param string $ba_id Billing Agreement ID. |
| 6349 |
*/ |
| 6350 |
private function set_continuation_ba_id( $member_id, $order_id, $ba_id ) { |
| 6351 |
global $usces; |
| 6352 |
|
| 6353 |
$usces->set_member_meta_value( 'paypal_continuation_' . $order_id, $ba_id, $member_id ); |
| 6354 |
} |
| 6355 |
|
| 6356 |
/** |
| 6357 |
* 継続課金 ba_id 取得 |
| 6358 |
* |
| 6359 |
* @param int $member_id Member ID. |
| 6360 |
* @param int $order_id Order number. |
| 6361 |
* @return string |
| 6362 |
*/ |
| 6363 |
private function get_continuation_ba_id( $member_id, $order_id = 0 ) { |
| 6364 |
global $usces, $wpdb; |
| 6365 |
|
| 6366 |
if ( empty( $order_id ) ) { |
| 6367 |
$member_meta_table = usces_get_tablename( 'usces_member_meta' ); |
| 6368 |
$query = $wpdb->prepare( "SELECT COUNT(*) FROM {$member_meta_table} WHERE `member_id` = %d AND `meta_key` LIKE %s", $member_id, 'paypal_continuation_%' ); |
| 6369 |
$ba_id = $wpdb->get_var( $query ); |
| 6370 |
} else { |
| 6371 |
$ba_id = $usces->get_member_meta_value( 'paypal_continuation_' . $order_id, $member_id ); |
| 6372 |
} |
| 6373 |
return $ba_id; |
| 6374 |
} |
| 6375 |
|
| 6376 |
/** |
| 6377 |
* 継続課金決済金額取得 |
| 6378 |
* |
| 6379 |
* @param int $con_id Continuation ID. |
| 6380 |
* @return float |
| 6381 |
*/ |
| 6382 |
private function get_continuation_amount( $con_id ) { |
| 6383 |
global $wpdb; |
| 6384 |
|
| 6385 |
$amount = $wpdb->get_var( $wpdb->prepare( "SELECT `con_order_price` FROM {$wpdb->prefix}usces_continuation WHERE `con_id` = %d", $con_id ) ); |
| 6386 |
return $amount; |
| 6387 |
} |
| 6388 |
|
| 6389 |
/** |
| 6390 |
* 定期購� |
| 6391 |
�データ登録 |
| 6392 |
* wcad_action_reg_regulardata |
| 6393 |
* |
| 6394 |
* @param array $args Compact array( $cart, $entry, $order_id, $member_id, $payments, $charging_type, $results、$reg_id ). |
| 6395 |
*/ |
| 6396 |
public function register_regulardata( $args ) { |
| 6397 |
global $usces; |
| 6398 |
extract( $args ); |
| 6399 |
|
| 6400 |
if ( ! empty( $reg_id ) && ! empty( $member_id ) && ! empty( $results['ba_id'] ) ) { |
| 6401 |
$this->set_regular_ba_id( $member_id, $reg_id, $results['ba_id'] ); |
| 6402 |
} |
| 6403 |
} |
| 6404 |
|
| 6405 |
/** |
| 6406 |
* 発送� |
| 6407 |
�リスト利用可能決済 |
| 6408 |
* wcad_filter_shippinglist_acting |
| 6409 |
* |
| 6410 |
* @param string $acting Payment method. |
| 6411 |
* @return string |
| 6412 |
*/ |
| 6413 |
public function set_shippinglist_acting( $acting ) { |
| 6414 |
$acting = 'acting_paypal_cp'; |
| 6415 |
return $acting; |
| 6416 |
} |
| 6417 |
|
| 6418 |
/** |
| 6419 |
* 管理画面利用可能決済メッセージ |
| 6420 |
* wcad_filter_available_regular_payment_method |
| 6421 |
* |
| 6422 |
* @param array $payment_method Payment method. |
| 6423 |
* @return array |
| 6424 |
*/ |
| 6425 |
public function available_regular_payment_method( $payment_method ) { |
| 6426 |
$payment_method[] = 'acting_paypal_cp'; |
| 6427 |
return $payment_method; |
| 6428 |
} |
| 6429 |
|
| 6430 |
/** |
| 6431 |
* 定期購� |
| 6432 |
�決済処理 |
| 6433 |
* wcad_action_reg_auto_orderdata |
| 6434 |
* |
| 6435 |
* @param array $args Compact array( $cart, $entry, $order_id, $member_id, $payments, $charging_type, $total_amount, $reg_id, $order_date ). |
| 6436 |
*/ |
| 6437 |
public function register_auto_orderdata( $args ) { |
| 6438 |
global $usces; |
| 6439 |
extract( $args ); |
| 6440 |
|
| 6441 |
$acting_flg = $payments['settlement']; |
| 6442 |
if ( 'acting_paypal_cp' !== $payments['settlement'] ) { |
| 6443 |
return; |
| 6444 |
} |
| 6445 |
|
| 6446 |
if ( ! usces_is_membersystem_state() ) { |
| 6447 |
return; |
| 6448 |
} |
| 6449 |
|
| 6450 |
if ( 0 >= $total_amount ) { |
| 6451 |
return; |
| 6452 |
} |
| 6453 |
|
| 6454 |
$bn_code = self::API_BN_CODE_PCP; |
| 6455 |
$ba_id = $this->get_regular_ba_id( $member_id, $reg_id ); |
| 6456 |
$tracking_id = usces_acting_key(); |
| 6457 |
$usces->set_order_meta_value( 'reference_id', $tracking_id, $order_id ); |
| 6458 |
$settltment_errmsg = ''; |
| 6459 |
|
| 6460 |
if ( ! empty( $ba_id ) ) { |
| 6461 |
$acting_opts = $this->get_acting_settings(); |
| 6462 |
$cp_intent = ( isset( $acting_opts['intent'] ) ) ? $acting_opts['intent'] : ''; |
| 6463 |
|
| 6464 |
/* Get Access Token */ |
| 6465 |
$access_token = $this->get_access_token(); |
| 6466 |
|
| 6467 |
$shipping = usces_have_shipped( $cart ); |
| 6468 |
if ( $shipping ) { |
| 6469 |
$regular_data = $this->get_regular_data( $member_id, $reg_id ); |
| 6470 |
$delivery = (array) wel_safe_unserialize( $regular_data['reg_delivery'] ); |
| 6471 |
$entry['delivery']['name1'] = $delivery['name1']; |
| 6472 |
$entry['delivery']['name2'] = $delivery['name2']; |
| 6473 |
$entry['delivery']['country'] = $delivery['country']; |
| 6474 |
$entry['delivery']['zipcode'] = $delivery['zipcode']; |
| 6475 |
$entry['delivery']['pref'] = $delivery['pref']; |
| 6476 |
$entry['delivery']['address1'] = $delivery['address1']; |
| 6477 |
$entry['delivery']['address2'] = $delivery['address2']; |
| 6478 |
$entry['delivery']['address3'] = $delivery['address3']; |
| 6479 |
} |
| 6480 |
$entry['order']['total_full_price'] = usces_crform( $total_amount, false, false, 'return', false ); |
| 6481 |
|
| 6482 |
/* Create order */ |
| 6483 |
$response_order_data = $this->api_create_order( $access_token, $bn_code, $cp_intent, $tracking_id, $entry, $cart ); |
| 6484 |
if ( isset( $response_order_data['id'] ) && isset( $response_order_data['status'] ) && 'CREATED' === $response_order_data['status'] ) { |
| 6485 |
$resource_id = $response_order_data['id']; |
| 6486 |
$correlation_id = ''; |
| 6487 |
$payment_source = array(); |
| 6488 |
$payment_source['token'] = array( |
| 6489 |
'id' => $ba_id, |
| 6490 |
'type' => 'BILLING_AGREEMENT', |
| 6491 |
); |
| 6492 |
if ( 'CAPTURE' === $cp_intent ) { |
| 6493 |
/* Capture */ |
| 6494 |
$response_data = $this->api_capture_order( $access_token, $bn_code, $tracking_id, $resource_id, $correlation_id, $payment_source ); |
| 6495 |
} elseif ( 'AUTHORIZE' === $cp_intent ) { |
| 6496 |
/* Authorize */ |
| 6497 |
$response_data = $this->api_authorize_order( $access_token, $bn_code, $tracking_id, $resource_id, $correlation_id, $payment_source ); |
| 6498 |
} |
| 6499 |
if ( isset( $response_data['status'] ) ) { |
| 6500 |
$status = $response_data['status']; |
| 6501 |
} elseif ( isset( $response_data['name'] ) ) { |
| 6502 |
$status = $response_data['name']; |
| 6503 |
} else { |
| 6504 |
$status = $cp_intent . ' ERROR'; |
| 6505 |
} |
| 6506 |
$response_data = apply_filters( 'usces_filter_paypal_cp_register_auto_orderdata_log', $response_data, $status, $args ); |
| 6507 |
if ( 'COMPLETED' === $status && isset( $response_data['purchase_units'] ) ) { |
| 6508 |
$this->save_acting_log( $response_data, 'paypal_cp', $cp_intent, $status, $total_amount, $order_id, $tracking_id ); |
| 6509 |
$usces->set_order_meta_value( 'resource_id', $resource_id, $order_id ); |
| 6510 |
$purchase_units = $response_data['purchase_units'][0]; |
| 6511 |
if ( isset( $purchase_units['payments']['captures'] ) ) { |
| 6512 |
$payments = $purchase_units['payments']['captures'][0]; |
| 6513 |
} elseif ( isset( $purchase_units['payments']['authorizations'] ) ) { |
| 6514 |
$payments = $purchase_units['payments']['authorizations'][0]; |
| 6515 |
} |
| 6516 |
if ( ! empty( $payments['id'] ) ) { |
| 6517 |
$usces->set_order_meta_value( 'wc_trans_id', $payments['id'], $order_id ); /* 決済ID */ |
| 6518 |
$usces->set_order_meta_value( 'trans_id', $payments['id'], $order_id ); /* 取引ID */ |
| 6519 |
} |
| 6520 |
$response_data['acting'] = $this->paymod_id; |
| 6521 |
$usces->set_order_meta_value( $acting_flg, usces_serialize( $response_data ), $order_id ); |
| 6522 |
} else { |
| 6523 |
$this->save_acting_log( $response_data, 'paypal_cp', 'ERROR', $status, 0, $order_id, $tracking_id ); |
| 6524 |
$this->save_entry_log( $tracking_id, $total_amount, $cart, $entry ); |
| 6525 |
$settltment_errmsg = __( '[Regular purchase] Settlement was not completed.', 'autodelivery' ); |
| 6526 |
$log = array( |
| 6527 |
'acting' => $this->paymod_id, |
| 6528 |
'key' => $tracking_id, |
| 6529 |
'result' => $status, |
| 6530 |
'data' => $response_data, |
| 6531 |
); |
| 6532 |
usces_save_order_acting_error( $log ); |
| 6533 |
} |
| 6534 |
do_action( 'usces_action_register_auto_orderdata', $args, $response_data ); |
| 6535 |
} else { |
| 6536 |
$this->save_entry_log( $tracking_id, $total_amount, $cart, $entry ); |
| 6537 |
$settltment_errmsg = __( '[Regular purchase] Settlement was not completed.', 'autodelivery' ); |
| 6538 |
if ( isset( $response_order_data['status'] ) ) { |
| 6539 |
$status = $response_order_data['status']; |
| 6540 |
} elseif ( isset( $response_order_data['name'] ) ) { |
| 6541 |
$status = $response_order_data['name']; |
| 6542 |
} else { |
| 6543 |
$status = 'CREATE ORDER ERROR'; |
| 6544 |
} |
| 6545 |
$log = array( |
| 6546 |
'acting' => $this->paymod_id, |
| 6547 |
'key' => $tracking_id, |
| 6548 |
'result' => $status, |
| 6549 |
'data' => $response_order_data, |
| 6550 |
); |
| 6551 |
usces_save_order_acting_error( $log ); |
| 6552 |
$this->save_acting_log( $response_order_data, 'paypal_cp', 'ERROR', $status, 0, $order_id, $tracking_id ); |
| 6553 |
do_action( 'usces_action_register_auto_orderdata', $args, $response_order_data ); |
| 6554 |
} |
| 6555 |
} else { |
| 6556 |
$this->save_entry_log( $tracking_id, $total_amount, $cart, $entry ); |
| 6557 |
$settltment_errmsg = __( '[Regular purchase] Member information acquisition error.', 'autodelivery' ); |
| 6558 |
$logdata = array( 'ba_id' => $ba_id ); |
| 6559 |
$log = array( |
| 6560 |
'acting' => $this->paymod_id, |
| 6561 |
'key' => $member_id, |
| 6562 |
'result' => 'MEMBER ERROR', |
| 6563 |
'data' => $logdata, |
| 6564 |
); |
| 6565 |
usces_save_order_acting_error( $log ); |
| 6566 |
$this->save_acting_log( $logdata, 'paypal_cp', 'ERROR', 'MEMBER ERROR', 0, $order_id, $tracking_id ); |
| 6567 |
do_action( 'usces_action_register_auto_orderdata', $args, $log ); |
| 6568 |
} |
| 6569 |
if ( '' !== $settltment_errmsg ) { |
| 6570 |
$settlement = array( |
| 6571 |
'settltment_status' => __( 'Failure', 'autodelivery' ), |
| 6572 |
'settltment_errmsg' => $settltment_errmsg, |
| 6573 |
); |
| 6574 |
$usces->set_order_meta_value( $acting_flg, usces_serialize( $settlement ), $order_id ); |
| 6575 |
wcad_settlement_error_mail( $order_id, $settltment_errmsg ); |
| 6576 |
} |
| 6577 |
} |
| 6578 |
|
| 6579 |
/** |
| 6580 |
* 自動受注決済エラーメールヘッダー |
| 6581 |
* wcad_filter_send_settlement_error_mail_message_head |
| 6582 |
* |
| 6583 |
* @param string $mail_header Message header. |
| 6584 |
* @param array $order_data Order data. |
| 6585 |
* @return string |
| 6586 |
*/ |
| 6587 |
public function settlement_error_mail_message_header( $mail_header, $order_data ) { |
| 6588 |
$payment = usces_get_payments_by_name( $order_data['order_payment_name'] ); |
| 6589 |
$acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : ''; |
| 6590 |
if ( 'acting_paypal_cp' === $acting_flg ) { |
| 6591 |
$mail_header = __( 'Settlement error has occurred in the regular purchase. Please check your PayPal account for any problems.', 'usces' ) . "\r\n\r\n"; |
| 6592 |
} |
| 6593 |
return $mail_header; |
| 6594 |
} |
| 6595 |
|
| 6596 |
/** |
| 6597 |
* 自動受注決済エラーメール本文 |
| 6598 |
* wcad_filter_send_settlement_error_mail_message |
| 6599 |
* |
| 6600 |
* @param string $mail_body Message body. |
| 6601 |
* @param array $order_data Order data. |
| 6602 |
* @param string $errmsg Error message. |
| 6603 |
* @return string |
| 6604 |
*/ |
| 6605 |
public function settlement_error_mail_message( $mail_body, $order_data, $errmsg ) { |
| 6606 |
$payment = usces_get_payments_by_name( $order_data['order_payment_name'] ); |
| 6607 |
$acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : ''; |
| 6608 |
if ( 'acting_paypal_cp' === $acting_flg ) { |
| 6609 |
$name = usces_localized_name( $order_data['order_name1'], $order_data['order_name2'], 'return' ); |
| 6610 |
$order_number = usces_get_deco_order_id( $order_data['ID'] ); |
| 6611 |
if ( usces_is_html_mail() ) { |
| 6612 |
$hook_args = compact( 'order_data', 'name', 'order_number', 'errmsg' ); |
| 6613 |
$mail_body = $this->settlement_error_mail_message_htmlbody( $hook_args ); |
| 6614 |
} else { |
| 6615 |
$mail_body = '--------------------------------' . "\r\n"; |
| 6616 |
$mail_body .= __( 'Member ID', 'usces' ) . ' : ' . $order_data['mem_id'] . "\r\n"; |
| 6617 |
$mail_body .= __( 'Name', 'usces' ) . ' : ' . sprintf( _x( '%s', 'honorific', 'usces' ), $name ) . "\r\n"; |
| 6618 |
$mail_body .= __( 'e-mail adress', 'usces' ) . ' : ' . $order_data['order_email'] . "\r\n"; |
| 6619 |
$mail_body .= __( 'Automatic order number', 'autodelivery' ) . ' : ' . $order_number . "\r\n"; |
| 6620 |
$mail_body .= $errmsg . "\r\n"; |
| 6621 |
$mail_body .= '--------------------------------' . "\r\n\r\n"; |
| 6622 |
$mail_body .= __( 'If you have not requested this email, sorry to trouble you, but please contact us.', 'usces' ) . "\r\n\r\n"; |
| 6623 |
} |
| 6624 |
} |
| 6625 |
return $mail_body; |
| 6626 |
} |
| 6627 |
|
| 6628 |
/** |
| 6629 |
* Generate html for the body of settlement error mail |
| 6630 |
* |
| 6631 |
* @param array $hook_args : compact( 'order_data', 'name', 'order_number', 'errmsg' ). |
| 6632 |
* |
| 6633 |
* @return text : mail body |
| 6634 |
*/ |
| 6635 |
public function settlement_error_mail_message_htmlbody( $hook_args ) { |
| 6636 |
extract( $hook_args ); |
| 6637 |
|
| 6638 |
$mail_body = '<table style="font-size: 14px; margin-bottom: 40px; width: 100%; border-collapse: collapse; border: 1px solid #ddd;">'; |
| 6639 |
$mail_body .= '<caption style="background-color: #111; margin-bottom: 20px; padding: 15px; color: #fff; font-size: 15px; font-weight: 700; text-align: left;">'; |
| 6640 |
$mail_body .= remove_query_arg( 'uscesid', usces_url( 'login', 'return' ) ); |
| 6641 |
$mail_body .= '</caption><tbody>'; |
| 6642 |
$mail_body .= '<tr>'; |
| 6643 |
$mail_body .= '<td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">' . __( 'Member ID', 'usces' ) . '</td>'; |
| 6644 |
$mail_body .= '<td style="padding: 12px; width: 67%; border: 1px solid #ddd;">' . esc_attr( $order_data['mem_id'] ) . '</td>'; |
| 6645 |
$mail_body .= '</tr>'; |
| 6646 |
$mail_body .= '<tr>'; |
| 6647 |
$mail_body .= '<td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">' . __( 'Name', 'usces' ) . '</td>'; |
| 6648 |
$mail_body .= '<td style="padding: 12px; width: 67%; border: 1px solid #ddd;">' . sprintf( _x( '%s', 'honorific', 'usces' ), $name ) . '</td>'; |
| 6649 |
$mail_body .= '</tr>'; |
| 6650 |
$mail_body .= '<tr>'; |
| 6651 |
$mail_body .= '<td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">' . __( 'e-mail adress', 'usces' ) . '</td>'; |
| 6652 |
$mail_body .= '<td style="padding: 12px; width: 67%; border: 1px solid #ddd;">' . esc_attr( $order_data['order_email'] ) . '</td>'; |
| 6653 |
$mail_body .= '</tr>'; |
| 6654 |
$mail_body .= '<tr>'; |
| 6655 |
$mail_body .= '<td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">' . __( 'Automatic order number', 'autodelivery' ) . '</td>'; |
| 6656 |
$mail_body .= '<td style="padding: 12px; width: 67%; border: 1px solid #ddd;">' . esc_attr( $order_number ) . '</td>'; |
| 6657 |
$mail_body .= '</tr>'; |
| 6658 |
if ( ! empty( $errmsg ) ) { |
| 6659 |
$mail_body .= '<tr>'; |
| 6660 |
$mail_body .= '<td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">' . __( 'Settlement error message', 'usces' ) . '</td>'; |
| 6661 |
$mail_body .= '<td style="padding: 12px; width: 67%; border: 1px solid #ddd;">' . esc_html( $errmsg ) . '</td>'; |
| 6662 |
$mail_body .= '</tr>'; |
| 6663 |
} |
| 6664 |
$mail_body .= '</tbody></table>'; |
| 6665 |
|
| 6666 |
$mail_body .= '<table style="font-size:15px; margin-bottom: 10px;" border="0" width="540" cellspacing="0" cellpadding="0" align="center" bgcolor="#ffffff">'; |
| 6667 |
$mail_body .= '<tbody><tr>'; |
| 6668 |
$mail_body .= '<td>' . __( 'If you have not requested this email, sorry to trouble you, but please contact us.', 'usces' ) . '</td>'; |
| 6669 |
$mail_body .= '</tr>'; |
| 6670 |
$mail_body .= '</tbody></table>'; |
| 6671 |
$mail_body .= '<hr style="margin: 50px 0 0; border-style: none; border-top: 3px solid #777;" />'; |
| 6672 |
|
| 6673 |
return $mail_body; |
| 6674 |
} |
| 6675 |
|
| 6676 |
/** |
| 6677 |
* 定期購� |
| 6678 |
�データ編集画面 |
| 6679 |
* wcad_action_regular_information_edit_form |
| 6680 |
* |
| 6681 |
* @param array $regular_order Regular data. |
| 6682 |
*/ |
| 6683 |
public function regular_information_edit_form( $regular_order ) { |
| 6684 |
$payment = usces_get_payments_by_name( $regular_order['reg_payment_name'] ); |
| 6685 |
$acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : ''; |
| 6686 |
if ( 'acting_paypal_cp' !== $acting_flg ) { |
| 6687 |
return; |
| 6688 |
} |
| 6689 |
|
| 6690 |
$ba_id = $this->get_regular_ba_id( $regular_order['reg_mem_id'], $regular_order['reg_id'] ); |
| 6691 |
?> |
| 6692 |
<div class="inside"> |
| 6693 |
<table class="mem_info"> |
| 6694 |
<tr><th class="label"><?php esc_html_e( 'Billing Agreement ID', 'usces' ); ?></th><td class="col1"><?php echo esc_attr( $ba_id ); ?></td></tr> |
| 6695 |
</table> |
| 6696 |
</div> |
| 6697 |
<?php |
| 6698 |
} |
| 6699 |
|
| 6700 |
/** |
| 6701 |
* メール支払方法 |
| 6702 |
* usces_filter_order_confirm_mail_payment |
| 6703 |
* usces_filter_send_order_mail_payment |
| 6704 |
* wcad_filter_order_confirm_mail_payment |
| 6705 |
* |
| 6706 |
* @param string $msg_payment Message body. |
| 6707 |
* @param int $order_id Order number. |
| 6708 |
* @param array $payment Payment data. |
| 6709 |
* @param array $cart Cart data. |
| 6710 |
* @return string |
| 6711 |
*/ |
| 6712 |
public function regular_order_mail_payment( $msg_payment, $order_id, $payment, $cart ) { |
| 6713 |
global $usces; |
| 6714 |
|
| 6715 |
if ( ! wcad_have_regular_order( $cart ) ) { |
| 6716 |
return $msg_payment; |
| 6717 |
} |
| 6718 |
|
| 6719 |
$acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : ''; |
| 6720 |
if ( 'acting_paypal_cp' !== $acting_flg ) { |
| 6721 |
return $msg_payment; |
| 6722 |
} |
| 6723 |
|
| 6724 |
$member_id = $this->get_member_id( $order_id ); |
| 6725 |
$reg_id = $this->get_regular_id( $order_id ); |
| 6726 |
if ( ! empty( $reg_id ) ) { |
| 6727 |
$ba_id = $this->get_regular_ba_id( $member_id, $reg_id ); |
| 6728 |
if ( ! empty( $ba_id ) ) { |
| 6729 |
$msg_payment .= __( 'Billing Agreement ID', 'usces' ) . ' : ' . $ba_id . "\r\n\r\n"; |
| 6730 |
} |
| 6731 |
} |
| 6732 |
return $msg_payment; |
| 6733 |
} |
| 6734 |
|
| 6735 |
/** |
| 6736 |
* 定期購� |
| 6737 |
�ID 取得 |
| 6738 |
* |
| 6739 |
* @param int $order_id Order number. |
| 6740 |
* @return int |
| 6741 |
*/ |
| 6742 |
private function get_regular_id( $order_id ) { |
| 6743 |
global $wpdb, $usces; |
| 6744 |
|
| 6745 |
$query = $wpdb->prepare( "SELECT `reg_id` FROM {$wpdb->prefix}usces_regular WHERE `reg_order_id` = %d ", $order_id ); |
| 6746 |
$reg_id = $wpdb->get_var( $query ); |
| 6747 |
if ( empty( $reg_id ) ) { |
| 6748 |
$reg_id = $usces->get_order_meta_value( 'regular_id', $order_id ); |
| 6749 |
} |
| 6750 |
return $reg_id; |
| 6751 |
} |
| 6752 |
|
| 6753 |
/** |
| 6754 |
* 定期購� |
| 6755 |
�データ取得 |
| 6756 |
* |
| 6757 |
* @param int $member_id Member ID. |
| 6758 |
* @param int $reg_id Regular ID. |
| 6759 |
* @return array |
| 6760 |
*/ |
| 6761 |
private function get_regular_data( $member_id, $reg_id ) { |
| 6762 |
global $wpdb; |
| 6763 |
|
| 6764 |
$query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usces_regular WHERE `reg_id` = %d AND `reg_mem_id` = %d", $reg_id, $member_id ); |
| 6765 |
$data = $wpdb->get_row( $query, ARRAY_A ); |
| 6766 |
return $data; |
| 6767 |
} |
| 6768 |
|
| 6769 |
/** |
| 6770 |
* 定期購� |
| 6771 |
� ba_id 保存 |
| 6772 |
* |
| 6773 |
* @param int $member_id Member ID. |
| 6774 |
* @param int $reg_id Regular ID. |
| 6775 |
* @param string $ba_id Billing Agreement ID. |
| 6776 |
*/ |
| 6777 |
private function set_regular_ba_id( $member_id, $reg_id, $ba_id ) { |
| 6778 |
global $usces; |
| 6779 |
|
| 6780 |
$usces->set_member_meta_value( 'paypal_regular_' . $reg_id, $ba_id, $member_id ); |
| 6781 |
} |
| 6782 |
|
| 6783 |
/** |
| 6784 |
* 定期購� |
| 6785 |
� ba_id 取得 |
| 6786 |
* |
| 6787 |
* @param int $member_id Member ID. |
| 6788 |
* @param int $reg_id Regular ID. |
| 6789 |
* @return string |
| 6790 |
*/ |
| 6791 |
private function get_regular_ba_id( $member_id, $reg_id = 0 ) { |
| 6792 |
global $usces, $wpdb; |
| 6793 |
|
| 6794 |
if ( empty( $reg_id ) ) { |
| 6795 |
$member_meta_table = usces_get_tablename( 'usces_member_meta' ); |
| 6796 |
$query = $wpdb->prepare( "SELECT COUNT(*) FROM {$member_meta_table} WHERE `member_id` = %d AND `meta_key` LIKE %s", $member_id, 'paypal_regular_%' ); |
| 6797 |
$ba_id = $wpdb->get_var( $query ); |
| 6798 |
} else { |
| 6799 |
$ba_id = $usces->get_member_meta_value( 'paypal_regular_' . $reg_id, $member_id ); |
| 6800 |
} |
| 6801 |
return $ba_id; |
| 6802 |
} |
| 6803 |
|
| 6804 |
/** |
| 6805 |
* 定期購� |
| 6806 |
�受注金額取得 |
| 6807 |
* |
| 6808 |
* @param int $order_id Order ID. |
| 6809 |
* @return float |
| 6810 |
*/ |
| 6811 |
private function get_order_amount( $order_id ) { |
| 6812 |
global $wpdb; |
| 6813 |
|
| 6814 |
$amount = $wpdb->get_var( $wpdb->prepare( "SELECT ( `order_item_total_price` - `order_usedpoint` + `order_discount` + `order_shipping_charge` + `order_cod_fee` + `order_tax` ) AS `total_price` FROM {$wpdb->prefix}usces_order WHERE `ID` = %d", $order_id ) ); |
| 6815 |
return $amount; |
| 6816 |
} |
| 6817 |
|
| 6818 |
/** |
| 6819 |
* 会員ID取得 |
| 6820 |
* |
| 6821 |
* @param int $order_id Order number. |
| 6822 |
* @return int |
| 6823 |
*/ |
| 6824 |
private function get_member_id( $order_id ) { |
| 6825 |
global $wpdb; |
| 6826 |
|
| 6827 |
$query = $wpdb->prepare( "SELECT `mem_id` FROM {$wpdb->prefix}usces_order WHERE `ID` = %d", $order_id ); |
| 6828 |
$member_id = $wpdb->get_var( $query ); |
| 6829 |
return $member_id; |
| 6830 |
} |
| 6831 |
|
| 6832 |
/** |
| 6833 |
* 決済ログ保存 |
| 6834 |
* |
| 6835 |
* @param string $log Log data. |
| 6836 |
* @param string $acting Acting type. |
| 6837 |
* @param string $status Status. |
| 6838 |
* @param string $result Result. |
| 6839 |
* @param float $amount Amount. |
| 6840 |
* @param int $order_id Order number. |
| 6841 |
* @param string $tracking_id Tracking ID. |
| 6842 |
* @return array |
| 6843 |
*/ |
| 6844 |
private function save_acting_log( $log, $acting, $status, $result, $amount, $order_id, $tracking_id ) { |
| 6845 |
global $wpdb; |
| 6846 |
|
| 6847 |
$query = $wpdb->prepare( |
| 6848 |
"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 )", |
| 6849 |
current_time( 'mysql' ), |
| 6850 |
usces_serialize( $log ), |
| 6851 |
$acting, |
| 6852 |
$status, |
| 6853 |
$result, |
| 6854 |
$amount, |
| 6855 |
$order_id, |
| 6856 |
$tracking_id |
| 6857 |
); |
| 6858 |
$res = $wpdb->query( $query ); |
| 6859 |
return $res; |
| 6860 |
} |
| 6861 |
|
| 6862 |
/** |
| 6863 |
* 決済ログ取得 |
| 6864 |
* |
| 6865 |
* @param int $order_id Order number. |
| 6866 |
* @param string $tracking_id Tracking ID. |
| 6867 |
* @param string $result Result. |
| 6868 |
* @return array |
| 6869 |
*/ |
| 6870 |
public function get_acting_log( $order_id = 0, $tracking_id = 0, $result = 'COMPLETED' ) { |
| 6871 |
global $wpdb; |
| 6872 |
|
| 6873 |
if ( empty( $order_id ) ) { |
| 6874 |
if ( empty( $tracking_id ) ) { |
| 6875 |
return array(); |
| 6876 |
} |
| 6877 |
if ( 'COMPLETED' === $result ) { |
| 6878 |
$query = $wpdb->prepare( |
| 6879 |
"SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE`tracking_id` = %s AND `result` IN ( 'COMPLETED', 'PENDING' ) ORDER BY `ID` DESC, datetime DESC", |
| 6880 |
$tracking_id |
| 6881 |
); |
| 6882 |
} else { |
| 6883 |
$query = $wpdb->prepare( |
| 6884 |
"SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `tracking_id` = %s ORDER BY `ID` DESC, datetime DESC", |
| 6885 |
$tracking_id |
| 6886 |
); |
| 6887 |
} |
| 6888 |
} else { |
| 6889 |
if ( empty( $tracking_id ) ) { |
| 6890 |
if ( 'COMPLETED' === $result ) { |
| 6891 |
$query = $wpdb->prepare( |
| 6892 |
"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` IN ( 'COMPLETED', 'PENDING' ) ORDER BY `ID` DESC, datetime DESC", |
| 6893 |
$order_id, |
| 6894 |
$order_id |
| 6895 |
); |
| 6896 |
} else { |
| 6897 |
$query = $wpdb->prepare( |
| 6898 |
"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", |
| 6899 |
$order_id, |
| 6900 |
$order_id |
| 6901 |
); |
| 6902 |
} |
| 6903 |
} else { |
| 6904 |
if ( 'COMPLETED' === $result ) { |
| 6905 |
$query = $wpdb->prepare( |
| 6906 |
"SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `order_id` = %d AND `tracking_id` = %s AND `result` IN ( 'COMPLETED', 'PENDING' ) ORDER BY `ID` DESC, datetime DESC", |
| 6907 |
$order_id, |
| 6908 |
$tracking_id |
| 6909 |
); |
| 6910 |
} else { |
| 6911 |
$query = $wpdb->prepare( |
| 6912 |
"SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `order_id` = %d AND `tracking_id` = %s ORDER BY `ID` DESC, datetime DESC", |
| 6913 |
$order_id, |
| 6914 |
$tracking_id |
| 6915 |
); |
| 6916 |
} |
| 6917 |
} |
| 6918 |
} |
| 6919 |
$log_data = $wpdb->get_results( $query, ARRAY_A ); |
| 6920 |
return $log_data; |
| 6921 |
} |
| 6922 |
|
| 6923 |
/** |
| 6924 |
* 自動決済ログ保存 |
| 6925 |
* |
| 6926 |
* @param string $tracking_id Tracking ID. |
| 6927 |
* @param float $amount Amount. |
| 6928 |
* @param array $cart Cart data. |
| 6929 |
* @param array $entry Entry data. |
| 6930 |
* @return array |
| 6931 |
*/ |
| 6932 |
private function save_entry_log( $tracking_id, $amount, $cart, $entry ) { |
| 6933 |
global $wpdb; |
| 6934 |
|
| 6935 |
$log = array( |
| 6936 |
'cart' => $cart, |
| 6937 |
'entry' => $entry, |
| 6938 |
); |
| 6939 |
$query = $wpdb->prepare( |
| 6940 |
"INSERT INTO {$wpdb->prefix}usces_acting_log ( `datetime`, `log`, `acting`, `result`, `amount`, `tracking_id` ) VALUES ( %s, %s, %s, %s, %f, %s )", |
| 6941 |
current_time( 'mysql' ), |
| 6942 |
usces_serialize( $log ), |
| 6943 |
$this->paymod_id, |
| 6944 |
'ENTRY', |
| 6945 |
$amount, |
| 6946 |
$tracking_id |
| 6947 |
); |
| 6948 |
$res = $wpdb->query( $query ); |
| 6949 |
return $res; |
| 6950 |
} |
| 6951 |
|
| 6952 |
/** |
| 6953 |
* 自動決済ログ取得 |
| 6954 |
* |
| 6955 |
* @param string $tracking_id Tracking ID. |
| 6956 |
* @return array |
| 6957 |
*/ |
| 6958 |
public function get_entry_log( $tracking_id ) { |
| 6959 |
global $wpdb; |
| 6960 |
|
| 6961 |
$query = $wpdb->prepare( |
| 6962 |
"SELECT `log` FROM {$wpdb->prefix}usces_acting_log WHERE `acting` = %s AND `result` = %s AND `tracking_id` = %s", |
| 6963 |
$this->paymod_id, |
| 6964 |
'ENTRY', |
| 6965 |
$tracking_id |
| 6966 |
); |
| 6967 |
$log_data = $wpdb->get_var( $query ); |
| 6968 |
$log = ( $log_data ) ? usces_unserialize( $log_data ) : array(); |
| 6969 |
return $log; |
| 6970 |
} |
| 6971 |
|
| 6972 |
/** |
| 6973 |
* 自動決済ログ削除 |
| 6974 |
* |
| 6975 |
* @param string $tracking_id Tracking ID. |
| 6976 |
* @return array |
| 6977 |
*/ |
| 6978 |
public function del_entry_log( $tracking_id ) { |
| 6979 |
global $wpdb; |
| 6980 |
|
| 6981 |
$query = $wpdb->prepare( |
| 6982 |
"DELETE FROM {$wpdb->prefix}usces_acting_log WHERE `acting` = %s AND `result` = %s AND `tracking_id` = %s", |
| 6983 |
$this->paymod_id, |
| 6984 |
'ENTRY', |
| 6985 |
$tracking_id |
| 6986 |
); |
| 6987 |
$res = $wpdb->query( $query ); |
| 6988 |
return $res; |
| 6989 |
} |
| 6990 |
|
| 6991 |
/** |
| 6992 |
* 最新処理取得 |
| 6993 |
* |
| 6994 |
* @param int $order_id Order number. |
| 6995 |
* @param string $tracking_id Tracking ID. |
| 6996 |
* @param string $result Result. |
| 6997 |
* @return array |
| 6998 |
*/ |
| 6999 |
public function get_acting_latest_log( $order_id, $tracking_id, $result = 'COMPLETED' ) { |
| 7000 |
$log_data = $this->get_acting_log( $order_id, $tracking_id, $result ); |
| 7001 |
if ( $log_data ) { |
| 7002 |
$data = current( $log_data ); |
| 7003 |
$latest_log = array( |
| 7004 |
'log' => usces_unserialize( $data['log'] ), |
| 7005 |
'acting' => $data['acting'], |
| 7006 |
'status' => $data['status'], |
| 7007 |
'result' => $data['result'], |
| 7008 |
'amount' => $data['amount'], |
| 7009 |
'order_id' => $data['order_id'], |
| 7010 |
'tracking_id' => $data['tracking_id'], |
| 7011 |
); |
| 7012 |
} else { |
| 7013 |
$latest_log = array(); |
| 7014 |
} |
| 7015 |
return $latest_log; |
| 7016 |
} |
| 7017 |
|
| 7018 |
/** |
| 7019 |
* 最新決済金額取得 |
| 7020 |
* |
| 7021 |
* @param int $order_id Order number. |
| 7022 |
* @param string $tracking_id Tracking ID. |
| 7023 |
* @return int $amount Amount. |
| 7024 |
*/ |
| 7025 |
private function get_latest_amount( $order_id, $tracking_id ) { |
| 7026 |
$amount = 0; |
| 7027 |
$refund = 0; |
| 7028 |
$log_data = $this->get_acting_log( $order_id, $tracking_id ); |
| 7029 |
if ( $log_data ) { |
| 7030 |
foreach ( (array) $log_data as $data ) { |
| 7031 |
if ( 'CAPTURE' === $data['status'] ) { |
| 7032 |
$amount = $data['amount']; |
| 7033 |
} elseif ( 'AUTHORIZE' === $data['status'] ) { |
| 7034 |
if ( 0.0 === (float) $amount ) { |
| 7035 |
$amount = $data['amount']; |
| 7036 |
} |
| 7037 |
} elseif ( 'REFUND' === $data['status'] || 'VOID' === $data['status'] ) { |
| 7038 |
$refund += $data['amount']; /* minus value */ |
| 7039 |
} |
| 7040 |
} |
| 7041 |
} |
| 7042 |
return $amount + $refund; |
| 7043 |
} |
| 7044 |
|
| 7045 |
/** |
| 7046 |
* 決済処理取得 |
| 7047 |
* |
| 7048 |
* @param int $order_id Order number. |
| 7049 |
* @param string $tracking_id Tracking ID. |
| 7050 |
* @return string |
| 7051 |
*/ |
| 7052 |
private function get_acting_status( $order_id, $tracking_id ) { |
| 7053 |
global $wpdb; |
| 7054 |
|
| 7055 |
$acting_status = ''; |
| 7056 |
$latest_log = $this->get_acting_latest_log( $order_id, $tracking_id, 'ALL' ); |
| 7057 |
if ( isset( $latest_log['status'] ) && isset( $latest_log['result'] ) ) { |
| 7058 |
if ( 'COMPLETED' === $latest_log['result'] ) { |
| 7059 |
$amount = $this->get_latest_amount( $order_id, $tracking_id ); |
| 7060 |
if ( 'VOID' === $latest_log['status'] ) { |
| 7061 |
$acting_status = 'VOIDED'; |
| 7062 |
} elseif ( 'REFUND' === $latest_log['status'] && 0 < $amount ) { |
| 7063 |
$acting_status = 'CAPTURE'; |
| 7064 |
} elseif ( 'REFUND' === $latest_log['status'] && 0.0 === (float) $amount ) { |
| 7065 |
$acting_status = 'REFUNDED'; |
| 7066 |
} else { |
| 7067 |
$acting_status = $latest_log['status']; |
| 7068 |
} |
| 7069 |
} else { |
| 7070 |
$acting_status = $latest_log['status']; |
| 7071 |
} |
| 7072 |
} |
| 7073 |
return $acting_status; |
| 7074 |
} |
| 7075 |
|
| 7076 |
/** |
| 7077 |
* 決済履歴 |
| 7078 |
* |
| 7079 |
* @param int $order_id Order number. |
| 7080 |
* @param string $tracking_id Tracking ID. |
| 7081 |
* @return string |
| 7082 |
*/ |
| 7083 |
private function settlement_history( $order_id, $tracking_id ) { |
| 7084 |
$html = ''; |
| 7085 |
$log_data = $this->get_acting_log( $order_id, $tracking_id, 'ALL' ); |
| 7086 |
if ( $log_data ) { |
| 7087 |
$num = count( $log_data ); |
| 7088 |
$html = '<table class="settlement-history"> |
| 7089 |
<thead class="settlement-history-head"> |
| 7090 |
<tr><th></th><th>' . __( 'Processing date', 'usces' ) . '</th><th>' . __( 'Trans ID', 'usces' ) . '</th><th>' . __( 'Process', 'usces' ) . '</th><th>' . __( 'Amount', 'usces' ) . '</th><th>' . __( 'Status', 'usces' ) . '</th></tr> |
| 7091 |
</thead> |
| 7092 |
<tbody class="settlement-history-body">'; |
| 7093 |
foreach ( (array) $log_data as $data ) { |
| 7094 |
$log = usces_unserialize( $data['log'] ); |
| 7095 |
$id = ( isset( $log['id'] ) ) ? $log['id'] : ''; |
| 7096 |
$issue = ''; |
| 7097 |
if ( 'COMPLETED' !== $data['result'] ) { |
| 7098 |
$class = ' error'; |
| 7099 |
$amount = ''; |
| 7100 |
if ( isset( $log['details'][0]['issue'] ) && '' !== $log['details'][0]['issue'] ) { |
| 7101 |
$issue = ' (' . $log['details'][0]['issue'] . ')'; |
| 7102 |
} |
| 7103 |
} else { |
| 7104 |
$class = ''; |
| 7105 |
$amount = ( isset( $data['amount'] ) ) ? usces_crform( $data['amount'], false, true, 'return', true ) : ''; |
| 7106 |
} |
| 7107 |
if ( isset( $log['purchase_units'] ) ) { |
| 7108 |
$purchase_units = $log['purchase_units'][0]; |
| 7109 |
if ( isset( $purchase_units['payments'] ) ) { |
| 7110 |
if ( isset( $purchase_units['payments']['captures'] ) ) { |
| 7111 |
$payments = $purchase_units['payments']['captures'][0]; |
| 7112 |
} elseif ( isset( $purchase_units['payments']['authorizations'] ) ) { |
| 7113 |
$payments = $purchase_units['payments']['authorizations'][0]; |
| 7114 |
} elseif ( isset( $purchase_units['payments']['refunds'] ) ) { |
| 7115 |
$payments = $purchase_units['payments']['refunds'][0]; |
| 7116 |
} |
| 7117 |
if ( isset( $payments['id'] ) ) { |
| 7118 |
$id = $payments['id']; |
| 7119 |
} |
| 7120 |
} |
| 7121 |
} |
| 7122 |
$html .= '<tr> |
| 7123 |
<td class="num">' . $num . '</td> |
| 7124 |
<td class="datetime">' . $data['datetime'] . '</td> |
| 7125 |
<td class="transactionid">' . $id . '</td> |
| 7126 |
<td class="status">' . $data['status'] . '</td> |
| 7127 |
<td class="amount">' . $amount . '</td> |
| 7128 |
<td class="result' . $class . '">' . $data['result'] . $issue . '</td> |
| 7129 |
</tr>'; |
| 7130 |
$num--; |
| 7131 |
} |
| 7132 |
$html .= '</tbody> |
| 7133 |
</table>'; |
| 7134 |
} |
| 7135 |
return $html; |
| 7136 |
} |
| 7137 |
|
| 7138 |
/** |
| 7139 |
* 受注データ支払方法取得 |
| 7140 |
* |
| 7141 |
* @param int $order_id Order number. |
| 7142 |
* @return string |
| 7143 |
*/ |
| 7144 |
private function get_order_acting_flg( $order_id ) { |
| 7145 |
global $wpdb; |
| 7146 |
|
| 7147 |
$query = $wpdb->prepare( "SELECT `order_payment_name` FROM {$wpdb->prefix}usces_order WHERE `ID` = %d", $order_id ); |
| 7148 |
$order_payment_name = $wpdb->get_var( $query ); |
| 7149 |
$payment = usces_get_payments_by_name( $order_payment_name ); |
| 7150 |
$acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : ''; |
| 7151 |
return $acting_flg; |
| 7152 |
} |
| 7153 |
|
| 7154 |
/** |
| 7155 |
* 決済オプション取得 |
| 7156 |
* |
| 7157 |
* @return array |
| 7158 |
*/ |
| 7159 |
public function get_acting_settings() { |
| 7160 |
global $usces; |
| 7161 |
|
| 7162 |
$acting_settings = ( isset( $usces->options['acting_settings'][ $this->paymod_id ] ) ) ? $usces->options['acting_settings'][ $this->paymod_id ] : array(); |
| 7163 |
return $acting_settings; |
| 7164 |
} |
| 7165 |
|
| 7166 |
/** |
| 7167 |
* Date validity check. |
| 7168 |
* |
| 7169 |
* @param string $date Date to check. |
| 7170 |
* @return boolean |
| 7171 |
*/ |
| 7172 |
private function isdate( $date ) { |
| 7173 |
if ( empty( $date ) ) { |
| 7174 |
return false; |
| 7175 |
} |
| 7176 |
try { |
| 7177 |
new DateTime( $date ); |
| 7178 |
list( $year, $month, $day ) = explode( '-', $date ); |
| 7179 |
$res = checkdate( (int) $month, (int) $day, (int) $year ); |
| 7180 |
return $res; |
| 7181 |
} catch ( Exception $e ) { |
| 7182 |
return false; |
| 7183 |
} |
| 7184 |
} |
| 7185 |
|
| 7186 |
/** |
| 7187 |
* Get PayPal locale. |
| 7188 |
* |
| 7189 |
* @return string |
| 7190 |
*/ |
| 7191 |
private function get_locale() { |
| 7192 |
global $usces; |
| 7193 |
|
| 7194 |
$front_lang = ( isset( $usces->options['system']['front_lang'] ) && ! empty( $usces->options['system']['front_lang'] ) ) ? $usces->options['system']['front_lang'] : usces_get_local_language(); |
| 7195 |
switch ( $front_lang ) { |
| 7196 |
case 'en': |
| 7197 |
$locale = 'en_US'; |
| 7198 |
break; |
| 7199 |
case 'ja': |
| 7200 |
$locale = 'ja_JP'; |
| 7201 |
break; |
| 7202 |
case 'th': |
| 7203 |
$locale = 'th_TH'; |
| 7204 |
break; |
| 7205 |
default: |
| 7206 |
$locale = get_locale(); |
| 7207 |
} |
| 7208 |
return $locale; |
| 7209 |
} |
| 7210 |
|
| 7211 |
/** |
| 7212 |
* Check prefix. |
| 7213 |
* |
| 7214 |
* @param string $prefix Prefix. |
| 7215 |
* @return bool |
| 7216 |
*/ |
| 7217 |
private function check_prefix( $prefix ) { |
| 7218 |
if ( 0 === strlen( $prefix ) ) { |
| 7219 |
return true; |
| 7220 |
} |
| 7221 |
$check = false; |
| 7222 |
if ( 1 > strlen( $prefix ) || 4 < strlen( $prefix ) ) { |
| 7223 |
return $check; |
| 7224 |
} |
| 7225 |
if ( preg_match( '/[A-Z0-9]/', $prefix ) ) { |
| 7226 |
$check = true; |
| 7227 |
} |
| 7228 |
return $check; |
| 7229 |
} |
| 7230 |
} |
| 7231 |
|