paymod_id = 'paidy'; $this->pay_method = array( 'acting_paidy', ); $this->acting_name = 'ペイディ'; $this->acting_formal_name = 'あと払い(ペイディ)'; $this->acting_company_url = 'https://paidy.com/'; $this->initialize_data(); if ( is_admin() ) { add_action( 'admin_print_footer_scripts', array( $this, 'admin_scripts' ) ); add_action( 'usces_action_admin_settlement_update', array( $this, 'settlement_update' ) ); add_action( 'usces_action_settlement_tab_title', array( $this, 'settlement_tab_title' ) ); add_action( 'usces_action_settlement_tab_body', array( $this, 'settlement_tab_body' ) ); add_action( 'usces_filter_add_payment_method', array( $this, 'add_payment_method' ) ); add_action( 'usces_filter_up_payment_method', array( $this, 'up_payment_method' ) ); } if ( $this->is_validity_acting() ) { add_action( 'init', array( $this, 'acting_transaction' ) ); add_filter( 'usces_filter_is_complete_settlement', array( $this, 'is_complete_settlement' ), 10, 3 ); if ( is_admin() ) { add_action( 'usces_action_admin_ajax', array( $this, 'admin_ajax' ) ); add_filter( 'usces_filter_orderlist_detail_value', array( $this, 'orderlist_settlement_status' ), 10, 4 ); add_action( 'usces_action_order_edit_form_status_block_middle', array( $this, 'settlement_status' ), 10, 3 ); add_action( 'usces_action_order_edit_form_settle_info', array( $this, 'settlement_information' ), 10, 2 ); add_action( 'usces_action_endof_order_edit_form', array( $this, 'settlement_dialog' ), 10, 2 ); add_filter( 'usces_filter_settle_info_field_meta_keys', array( $this, 'settlement_info_field_meta_keys' ) ); add_filter( 'usces_filter_settle_info_field_keys', array( $this, 'settlement_info_field_keys' ), 10, 2 ); add_filter( 'usces_filter_settle_info_field_value', array( $this, 'settlement_info_field_value' ), 10, 3 ); add_filter( 'usces_filter_get_link_key', array( $this, 'get_link_key' ), 10, 2 ); add_action( 'usces_action_revival_order_data', array( $this, 'revival_orderdata' ), 10, 3 ); } else { add_action( 'wp_print_footer_scripts', array( $this, 'footer_scripts' ), 9 ); add_filter( 'usces_filter_confirm_inform', array( $this, 'confirm_inform' ), 10, 5 ); add_action( 'usces_action_acting_processing', array( $this, 'acting_processing' ), 10, 2 ); add_filter( 'usces_filter_check_acting_return_results', array( $this, 'acting_return' ) ); add_filter( 'usces_filter_check_acting_return_duplicate', array( $this, 'check_acting_return_duplicate' ), 10, 2 ); add_action( 'usces_action_reg_orderdata', array( $this, 'register_orderdata' ) ); add_filter( 'usces_filter_get_error_settlement', array( $this, 'error_page_message' ) ); } } } /** * Return an instance of this class. */ public static function get_instance() { if ( is_null( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Initialize. */ public function initialize_data() { $options = get_option( 'usces', array() ); $options['acting_settings']['paidy']['activate'] = ( isset( $options['acting_settings']['paidy']['activate'] ) ) ? $options['acting_settings']['paidy']['activate'] : 'off'; $options['acting_settings']['paidy']['paidy_activate'] = ( isset( $options['acting_settings']['paidy']['paidy_activate'] ) ) ? $options['acting_settings']['paidy']['paidy_activate'] : 'off'; if ( false !== strpos( $options['acting_settings']['paidy']['public_key'], '_test_' ) ) { $options['acting_settings']['paidy']['environment'] = 'test'; $options['acting_settings']['paidy']['public_key'] = ( ! empty( $options['acting_settings']['paidy']['public_key'] ) ) ? $options['acting_settings']['paidy']['public_key'] : ''; $options['acting_settings']['paidy']['secret_key'] = ( ! empty( $options['acting_settings']['paidy']['secret_key'] ) ) ? $options['acting_settings']['paidy']['secret_key'] : ''; $options['acting_settings']['paidy']['public_key_test'] = ( ! empty( $options['acting_settings']['paidy']['public_key'] ) ) ? $options['acting_settings']['paidy']['public_key'] : ''; $options['acting_settings']['paidy']['secret_key_test'] = ( ! empty( $options['acting_settings']['paidy']['secret_key'] ) ) ? $options['acting_settings']['paidy']['secret_key'] : ''; } else { $options['acting_settings']['paidy']['environment'] = ( isset( $options['acting_settings']['paidy']['environment'] ) ) ? $options['acting_settings']['paidy']['environment'] : 'live'; $options['acting_settings']['paidy']['public_key'] = ( isset( $options['acting_settings']['paidy']['public_key'] ) ) ? $options['acting_settings']['paidy']['public_key'] : ''; $options['acting_settings']['paidy']['secret_key'] = ( isset( $options['acting_settings']['paidy']['secret_key'] ) ) ? $options['acting_settings']['paidy']['secret_key'] : ''; $options['acting_settings']['paidy']['public_key_test'] = ( isset( $options['acting_settings']['paidy']['public_key_test'] ) ) ? $options['acting_settings']['paidy']['public_key_test'] : ''; $options['acting_settings']['paidy']['secret_key_test'] = ( isset( $options['acting_settings']['paidy']['secret_key_test'] ) ) ? $options['acting_settings']['paidy']['secret_key_test'] : ''; } update_option( 'usces', $options ); $available_settlement = get_option( 'usces_available_settlement', array() ); if ( ! in_array( $this->paymod_id, $available_settlement, true ) ) { $available_settlement[ $this->paymod_id ] = $this->acting_name; update_option( 'usces_available_settlement', $available_settlement ); } $this->unavailable_method = array( 'acting_paygent_paidy' ); } /** * 決済有効判定 * 支払方法で使用している場合に true * * @param string $type Module type. * @return boolean */ public function is_validity_acting( $type = '' ) { $options = get_option( 'usces', array() ); if ( empty( $options['acting_settings']['paidy'] ) ) { return false; } $payment_method = usces_get_system_option( 'usces_payment_method', 'sort' ); $method = false; switch ( $type ) { case 'paidy': foreach ( $payment_method as $payment ) { if ( 'acting_paidy' === $payment['settlement'] && 'activate' === $payment['use'] ) { $method = true; break; } } if ( $method && $this->is_activate_paidy() ) { return true; } else { return false; } break; default: if ( isset( $options['acting_settings']['paidy']['activate'] ) && 'on' === $options['acting_settings']['paidy']['activate'] ) { return true; } else { return false; } } } /** * ペイディ決済有効判定 * * @return boolean */ public function is_activate_paidy() { $options = get_option( 'usces', array() ); if ( ( isset( $options['acting_settings']['paidy']['activate'] ) && 'on' === $options['acting_settings']['paidy']['activate'] ) && ( isset( $options['acting_settings']['paidy']['paidy_activate'] ) && 'on' === $options['acting_settings']['paidy']['paidy_activate'] ) ) { $res = true; } else { $res = false; } return $res; } /** * 管理画面スクリプト * admin_print_footer_scripts */ public function admin_scripts() { $admin_page = filter_input( INPUT_GET, 'page' ); switch ( $admin_page ) : /* クレジット決済設定画面 */ case 'usces_settlement': $settlement_selected = get_option( 'usces_settlement_selected', array() ); if ( in_array( $this->paymod_id, (array) $settlement_selected, true ) ) : $options = get_option( 'usces', array() ); $paidy_activate = ( isset( $options['acting_settings']['paidy']['paidy_activate'] ) ) ? $options['acting_settings']['paidy']['paidy_activate'] : 'off'; ?> get_order_acting_flg( $order_id ); } } if ( in_array( $acting_flg, $this->pay_method, true ) ) : ?> paymod_id ) { return; } $this->error_mes = ''; $payment_method = usces_get_system_option( 'usces_payment_method', 'settlement' ); $options = get_option( 'usces', array() ); $post_data = wp_unslash( $_POST ); unset( $options['acting_settings']['paidy'] ); $options['acting_settings']['paidy']['paidy_activate'] = ( isset( $post_data['paidy_activate'] ) ) ? $post_data['paidy_activate'] : 'off'; $options['acting_settings']['paidy']['environment'] = ( isset( $post_data['environment'] ) ) ? $post_data['environment'] : 'live'; $options['acting_settings']['paidy']['public_key'] = ( isset( $post_data['public_key'] ) ) ? $post_data['public_key'] : ''; $options['acting_settings']['paidy']['secret_key'] = ( isset( $post_data['secret_key'] ) ) ? $post_data['secret_key'] : ''; $options['acting_settings']['paidy']['public_key_test'] = ( isset( $post_data['public_key_test'] ) ) ? $post_data['public_key_test'] : ''; $options['acting_settings']['paidy']['secret_key_test'] = ( isset( $post_data['secret_key_test'] ) ) ? $post_data['secret_key_test'] : ''; if ( 'on' === $options['acting_settings']['paidy']['paidy_activate'] ) { if ( 'live' === $options['acting_settings']['paidy']['environment'] ) { if ( WCUtils::is_blank( $options['acting_settings']['paidy']['public_key'] ) ) { $this->error_mes .= '※本番用パブリックキーを入力してください
'; } if ( WCUtils::is_blank( $options['acting_settings']['paidy']['secret_key'] ) ) { $this->error_mes .= '※本番用シークレットキーを入力してください
'; } } else { if ( WCUtils::is_blank( $options['acting_settings']['paidy']['public_key_test'] ) ) { $this->error_mes .= '※テスト用パブリックキーを入力してください
'; } if ( WCUtils::is_blank( $options['acting_settings']['paidy']['secret_key_test'] ) ) { $this->error_mes .= '※テスト用シークレットキーを入力してください
'; } } } if ( '' === $this->error_mes ) { $usces->action_status = 'success'; $usces->action_message = __( 'Options are updated.', 'usces' ); $toactive = array(); if ( 'on' === $options['acting_settings']['paidy']['paidy_activate'] ) { $usces->payment_structure['acting_paidy'] = 'Paidy'; foreach ( $payment_method as $settlement => $payment ) { if ( 'acting_paidy' === $settlement && 'activate' !== $payment['use'] ) { $toactive[] = $payment['name']; } } } else { unset( $usces->payment_structure['acting_paidy'] ); } if ( 'on' === $options['acting_settings']['paidy']['paidy_activate'] ) { $options['acting_settings']['paidy']['activate'] = 'on'; usces_admin_orderlist_show_wc_trans_id(); if ( 0 < count( $toactive ) ) { $usces->action_message .= __( 'Please update the payment method to "Activate". General Setting > Payment Methods', 'usces' ); } } else { $options['acting_settings']['paidy']['activate'] = 'off'; unset( $usces->payment_structure['acting_paidy'] ); } $deactivate = array(); foreach ( $payment_method as $settlement => $payment ) { if ( ! array_key_exists( $settlement, $usces->payment_structure ) ) { if ( 'deactivate' !== $payment['use'] ) { $payment['use'] = 'deactivate'; $deactivate[] = $payment['name']; usces_update_system_option( 'usces_payment_method', $payment['id'], $payment ); } } } if ( 0 < count( $deactivate ) ) { $deactivate_message = sprintf( __( '"Deactivate" %s of payment method.', 'usces' ), implode( ',', $deactivate ) ); $usces->action_message .= $deactivate_message; } } else { $usces->action_status = 'error'; $usces->action_message = __( 'Data have deficiency.', 'usces' ); $options['acting_settings']['paidy']['activate'] = 'off'; unset( $usces->payment_structure['acting_paidy'] ); $deactivate = array(); foreach ( $payment_method as $settlement => $payment ) { if ( in_array( $settlement, $this->pay_method, true ) ) { if ( 'deactivate' !== $payment['use'] ) { $payment['use'] = 'deactivate'; $deactivate[] = $payment['name']; usces_update_system_option( 'usces_payment_method', $payment['id'], $payment ); } } } if ( 0 < count( $deactivate ) ) { $deactivate_message = sprintf( __( '"Deactivate" %s of payment method.', 'usces' ), implode( ',', $deactivate ) ); $usces->action_message .= $deactivate_message . __( 'Please complete the setup and update the payment method to "Activate".', 'usces' ); } } ksort( $usces->payment_structure ); update_option( 'usces', $options ); update_option( 'usces_payment_structure', $usces->payment_structure ); } /** * クレジット決済設定画面タブ * usces_action_settlement_tab_title */ public function settlement_tab_title() { $settlement_selected = get_option( 'usces_settlement_selected', array() ); if ( in_array( $this->paymod_id, $settlement_selected, true ) ) { echo '
  • ' . esc_html( $this->acting_name ) . '
  • '; } } /** * クレジット決済設定画面フォーム * usces_action_settlement_tab_body */ public function settlement_tab_body() { $settlement_selected = get_option( 'usces_settlement_selected', array() ); if ( in_array( $this->paymod_id, $settlement_selected, true ) ) : $options = get_option( 'usces', array() ); $activate = ( isset( $options['acting_settings']['paidy']['activate'] ) && 'on' === $options['acting_settings']['paidy']['activate'] ) ? true : false; $paidy_activate = ( isset( $options['acting_settings']['paidy']['paidy_activate'] ) && ( 'on' === $options['acting_settings']['paidy']['paidy_activate'] ) ) ? 'on' : 'off'; $environment = ( isset( $options['acting_settings']['paidy']['environment'] ) ) ? $options['acting_settings']['paidy']['environment'] : 'live'; ?>
    acting_name ); ?>
    paymod_id ) : if ( '' !== $this->error_mes ) : ?>
    error_mes ); ?>
    十分にテストを行ってから運用してください。
    acting_name ); ?>
    動作環境
    本番用パブリックキー
    ペイディ加盟店管理画面の設定より本番用の「パブリックキー」を取得してください。(半角英数字)
    本番用シークレットキー
    ペイディ加盟店管理画面の設定より本番用の「シークレットキー」を取得してください。(半角英数字)
    テスト用パブリックキー
    ペイディ加盟店管理画面の設定よりテスト用の「パブリックキー」を取得してください。(半角英数字)
    テスト用シークレットキー
    ペイディ加盟店管理画面の設定よりテスト用の「シークレットキー」を取得してください。(半角英数字)

    ペイディとは

    クレジットカードが不要なため、クレジットカードを持っていない若年層や、セキュリティが不安でクレジットカードをなるべく使いたくないユーザーも、安心してお買い物を楽しむことができる決済です。

    ペイディの詳細はこちら 》

    【ご利用までの流れ】
    お申し込み前に「特定商取引法に基づく表示」と「プライバシーポリシー(個人情報の第三者提供含む)」ページのご準備をお願いいたします。

    1. 加盟店申請:ダッシュボードのペイディ決済らくらく設定、またはペイディWebサイトからお申し込みください。
    2. 加盟店審査:お申し込みから最大10営業日で、審査結果メールがPaidy合同会社より届きます。添付されている条件通知書で、「契約日」と「経済条件」をご確認ください。
    3. 利用開始 :
      1. ペイディ決済らくらく設定から申し込んだ場合、ダッシュボードに表示されるボタンによりご利用開始が可能です。
      2. ペイディWebサイトから申し込んだ場合、WelcartでAPIキーの設定が完了したら、ご利用開始となります。

    APIキーの確認方法は、ペイディ導入ガイドの Paidy APIキー をご確認ください。

    【資料】
    操作方法などについては下記をご覧ください。
    ペイディ導入ガイド
    ペイディ加盟店管理画面マニュアル
    加盟店FAQ

    acting_formal_name ) { $unique = false; } elseif ( $pm['name'] === $newvalue['name'] ) { $unique = false; } } if ( $unique ) { $newvalue['name'] = $this->acting_formal_name; } $newvalue['explanation'] = ''; } return $newvalue; } /** * 支払方法変更 * usces_filter_up_payment_method * * @param array $value Payment method data. * @return array */ public function up_payment_method( $value ) { if ( USCES_JP && 'acting_paidy' === $value['settlement'] ) { $value['name'] = $this->acting_formal_name; } return $value; } /** * 結果通知処理 * usces_after_cart_instant */ public function acting_transaction() { global $usces; $post_json = file_get_contents( 'php://input' ); $post_data = json_decode( $post_json, true ); if ( isset( $post_data['payment_id'] ) && isset( $post_data['status'] ) && isset( $post_data['order_ref'] ) ) { if ( 'authorize_success' === $post_data['status'] ) { $order_id = usces_get_order_id_by_trans_id( $post_data['order_ref'] ); if ( empty( $order_id ) ) { // $response_data = $this->api_close( $post_data['payment_id'] ); $response_data = $this->api_retrieve( $post_data['payment_id'] ); if ( isset( $response_data['status'] ) && 'authorized' === $response_data['status'] ) { if ( ! isset( $response_data['acting'] ) ) { $response_data['acting'] = 'paidy'; } $res = $usces->order_processing( $response_data ); } } } header( 'HTTP/1.0 200 OK' ); die(); } } /** * ポイント即時付与 * usces_filter_is_complete_settlement * * @param boolean $complete Complete the payment. * @param string $payment_name Payment name. * @param string $status Payment status. * @return boolean */ public function is_complete_settlement( $complete, $payment_name, $status ) { $payment = usces_get_payments_by_name( $payment_name ); if ( isset( $payment['settlement'] ) && 'acting_paidy' === $payment['settlement'] ) { $complete = true; } return $complete; } /** * 管理画面決済処理 * usces_action_admin_ajax */ public function admin_ajax() { global $usces; $mode = filter_input( INPUT_POST, 'mode' ); $data = array(); switch ( $mode ) { /* 参照 */ case 'retrieve_paidy': check_admin_referer( 'order_edit', 'wc_nonce' ); $order_id = filter_input( INPUT_POST, 'order_id' ); $trans_id = filter_input( INPUT_POST, 'trans_id' ); if ( empty( $order_id ) || empty( $trans_id ) ) { $data['status'] = 'retrieve_error'; wp_send_json( $data ); break; } $result = ''; $latest_log = $this->get_acting_latest_log( $order_id, $trans_id ); $payment_id = ( isset( $latest_log['payment_id'] ) ) ? $latest_log['payment_id'] : ''; $response_data = $this->api_retrieve( $payment_id, true ); if ( isset( $response_data['status'] ) ) { $status = $response_data['status']; $amount = ( isset( $response_data['final_amount'] ) ) ? $response_data['final_amount'] : $response_data['amount']; if ( ! empty( $response_data['capture_id'] ) && 0 < $amount ) { $status = 'capture'; } $class = ' paidy-' . $status; $status_name = $this->get_status_name( $status ); $result .= '
    ' . $status_name . '
    '; switch ( $status ) { case 'authorized': $result .= ''; $result .= ''; $result .= ''; $result .= '
    ' . __( 'Settlement amount', 'usces' ) . '' . __( usces_crcode( 'return' ), 'usces' ) . '
    '; $result .= '
    '; $result .= ''; $result .= ''; $result .= '
    '; break; case 'capture': $result .= ''; $result .= ''; $result .= ''; $result .= '
    ' . __( 'Settlement amount', 'usces' ) . '' . __( usces_crcode( 'return' ), 'usces' ) . '
    '; $result .= '
    '; $result .= ''; $result .= '
    '; break; case 'closed': $result .= ''; $result .= ''; $result .= ''; $result .= '
    ' . __( 'Settlement amount', 'usces' ) . '' . __( usces_crcode( 'return' ), 'usces' ) . '
    '; break; } } $result .= $this->settlement_history( $order_id, $trans_id ); $data['result'] = $result; wp_send_json( $data ); break; /* クローズ */ case 'close_paidy': check_admin_referer( 'order_edit', 'wc_nonce' ); $order_id = filter_input( INPUT_POST, 'order_id' ); $trans_id = filter_input( INPUT_POST, 'trans_id' ); if ( empty( $order_id ) || empty( $trans_id ) ) { $data['status'] = 'retrieve_error'; wp_send_json( $data ); break; } $result = ''; $status = 'closed'; $acting_status = ''; $latest_log = $this->get_acting_latest_log( $order_id, $trans_id ); $payment_id = ( isset( $latest_log['payment_id'] ) ) ? $latest_log['payment_id'] : ''; $response_data = $this->api_close( $payment_id ); if ( isset( $response_data['status'] ) && ! isset( $response_data['code'] ) ) { $this->save_acting_log( $response_data, 'paidy', $status, 'OK', $order_id, $trans_id ); $class = ' paidy-' . $status; $status_name = $this->get_status_name( $status ); $result .= '
    ' . $status_name . '
    '; $acting_status = '' . $status_name . ''; $result .= ''; $result .= ''; $result .= ''; $result .= '
    ' . __( 'Settlement amount', 'usces' ) . '' . __( usces_crcode( 'return' ), 'usces' ) . '
    '; } else { $status = 'closed_error'; $this->save_acting_log( $response_data, 'paidy', $status, 'NG', $order_id, $trans_id ); $status_name = $this->get_status_name( $status ); $result .= '
    ' . $status_name . '
    '; $amount = (int) $latest_log['amount']; switch ( $latest_log['status'] ) { case 'authorized': $result .= ''; $result .= ''; $result .= ''; $result .= '
    ' . __( 'Settlement amount', 'usces' ) . '' . __( usces_crcode( 'return' ), 'usces' ) . '
    '; $result .= '
    '; $result .= ''; $result .= ''; $result .= '
    '; break; case 'capture': $result .= ''; $result .= ''; $result .= ''; $result .= '
    ' . __( 'Settlement amount', 'usces' ) . '' . __( usces_crcode( 'return' ), 'usces' ) . '
    '; $result .= '
    '; $result .= ''; $result .= '
    '; break; } } $result .= $this->settlement_history( $order_id, $trans_id ); $data['result'] = $result; $data['acting_status'] = $acting_status; wp_send_json( $data ); break; /* キャプチャー(売上確定) */ case 'capture_paidy': check_admin_referer( 'order_edit', 'wc_nonce' ); $order_id = filter_input( INPUT_POST, 'order_id' ); $trans_id = filter_input( INPUT_POST, 'trans_id' ); if ( empty( $order_id ) || empty( $trans_id ) ) { $data['status'] = 'retrieve_error'; wp_send_json( $data ); break; } $result = ''; $status = 'capture'; $acting_status = ''; $latest_log = $this->get_acting_latest_log( $order_id, $trans_id ); $payment_id = ( isset( $latest_log['payment_id'] ) ) ? $latest_log['payment_id'] : ''; $response_data = $this->api_capture( $payment_id ); if ( isset( $response_data['status'] ) && ! isset( $response_data['code'] ) ) { $this->save_acting_log( $response_data, 'paidy', $status, 'OK', $order_id, $trans_id ); $class = ' paidy-' . $status; $status_name = $this->get_status_name( $status ); $result .= '
    ' . $status_name . '
    '; $acting_status = '' . $status_name . ''; $amount = (int) $latest_log['amount']; $result .= ''; $result .= ''; $result .= ''; $result .= '
    ' . __( 'Settlement amount', 'usces' ) . '' . __( usces_crcode( 'return' ), 'usces' ) . '
    '; $result .= '
    '; $result .= ''; $result .= '
    '; } else { $status = 'capture_error'; $this->save_acting_log( $response_data, 'paidy', $status, 'NG', $order_id, $trans_id ); $status_name = $this->get_status_name( $status ); $amount = (int) $latest_log['amount']; $result .= '
    ' . $status_name . '
    '; $result .= ''; $result .= ''; $result .= ''; $result .= '
    ' . __( 'Settlement amount', 'usces' ) . '' . __( usces_crcode( 'return' ), 'usces' ) . '
    '; $result .= '
    '; $result .= ''; $result .= ''; $result .= '
    '; } $result .= $this->settlement_history( $order_id, $trans_id ); $data['result'] = $result; $data['acting_status'] = $acting_status; wp_send_json( $data ); break; /* リファンド(返金) */ case 'refund_paidy': check_admin_referer( 'order_edit', 'wc_nonce' ); $order_id = filter_input( INPUT_POST, 'order_id' ); $trans_id = filter_input( INPUT_POST, 'trans_id' ); $amount = filter_input( INPUT_POST, 'amount' ); if ( empty( $order_id ) || empty( $trans_id ) ) { $data['status'] = 'retrieve_error'; wp_send_json( $data ); break; } $result = ''; $status = 'refund'; $acting_status = ''; $latest_log = $this->get_acting_latest_log( $order_id, $trans_id ); $payment_id = ( isset( $latest_log['payment_id'] ) ) ? $latest_log['payment_id'] : ''; $retrieve_data = $this->api_retrieve( $payment_id, true ); if ( isset( $retrieve_data['status'] ) && 'closed' === $retrieve_data['status'] && ! empty( $retrieve_data['capture_id'] ) && ! empty( $retrieve_data['final_amount'] ) ) { $response_data = $this->api_refund( $payment_id, $retrieve_data['capture_id'], $amount ); if ( isset( $response_data['status'] ) && ! isset( $response_data['code'] ) ) { $this->save_acting_log( $response_data, 'paidy', $status, 'OK', $order_id, $trans_id, $amount ); $final_amount = (int) $retrieve_data['final_amount'] - $amount; if ( 0 === $final_amount ) { $status = 'closed'; $this->save_acting_log( $response_data, 'paidy', $status, 'OK', $order_id, $trans_id ); } else { $status = 'capture'; } $class = ' paidy-' . $status; $status_name = $this->get_status_name( $status ); $result .= '
    ' . $status_name . '
    '; $acting_status = '' . $status_name . ''; } else { $status = 'refund_error'; $this->save_acting_log( $response_data, 'paidy', $status, 'NG', $order_id, $trans_id ); $status_name = $this->get_status_name( $status ); $result .= '
    ' . $status_name . '
    '; $final_amount = (int) $latest_log['amount']; } switch ( $status ) { case 'closed': $result .= ''; $result .= ''; $result .= ''; $result .= '
    ' . __( 'Settlement amount', 'usces' ) . '' . __( usces_crcode( 'return' ), 'usces' ) . '
    '; break; default: $result .= ''; $result .= ''; $result .= ''; $result .= '
    ' . __( 'Settlement amount', 'usces' ) . '' . __( usces_crcode( 'return' ), 'usces' ) . '
    '; $result .= '
    '; $result .= ''; $result .= '
    '; } } $result .= $this->settlement_history( $order_id, $trans_id ); $data['result'] = $result; $data['acting_status'] = $acting_status; wp_send_json( $data ); break; } } /** * 決済履歴 * * @param int $order_id Order number. * @param string $trans_id Transaction ID. * @return string */ private function settlement_history( $order_id, $trans_id ) { $history = ''; $log_data = $this->get_acting_log( $order_id, $trans_id, 'ALL' ); if ( $log_data ) { $num = count( $log_data ); $history = ''; $history .= ''; $history .= ''; $history .= ''; $history .= ''; foreach ( (array) $log_data as $data ) { $log = usces_unserialize( $data['log'] ); $payment_id = ( isset( $log['id'] ) ) ? $log['id'] : ''; $status_name = ( isset( $data['status'] ) ) ? $this->get_status_name( $data['status'] ) : ''; $err_code = ''; $class = ''; if ( 'OK' === $data['result'] && 0 < $data['amount'] ) { $amount = usces_crform( $data['amount'], false, true, 'return', true ); } else { $amount = ''; } if ( 'OK' !== $data['result'] ) { $err_code = ( isset( $log['code'] ) ) ? $log['code'] : ''; $class = ' error'; } $history .= ''; $history .= ''; $history .= ''; $history .= ''; $history .= ''; $history .= ''; $history .= ''; $history .= ''; $num--; } $history .= ''; $history .= '
    ' . __( 'Processing date', 'usces' ) . '決済ID' . __( 'Status', 'usces' ) . '' . __( 'Amount', 'usces' ) . '' . __( 'Result', 'usces' ) . '
    ' . $num . '' . $data['datetime'] . '' . $payment_id . '' . $status_name . '' . $amount . '' . $err_code . '
    '; } return $history; } /** * 決済状況 * usces_filter_orderlist_detail_value * * @param string $detail HTML. * @param string $value Settlement info key. * @param string $key Settlement info value. * @param int $order_id Order number. * @return array */ public function orderlist_settlement_status( $detail, $value, $key, $order_id ) { if ( 'wc_trans_id' !== $key || empty( $value ) ) { return $detail; } $acting_flg = $this->get_order_acting_flg( $order_id ); if ( 'acting_paidy' === $acting_flg ) { $trans_id = $this->get_trans_id( $order_id ); $payment_status = $this->get_payment_status( $order_id, $trans_id ); if ( ! empty( $payment_status ) ) { $class = ' paidy-' . $this->get_status( $payment_status ); $status_name = $this->get_status_name( $payment_status ); if ( ! empty( $status_name ) ) { $detail = '' . esc_html( $value ) . '' . esc_html( $status_name ) . ''; } } } return $detail; } /** * 受注編集画面【ステータス】 * usces_action_order_edit_form_status_block_middle * * @param array $data Order data. * @param array $cscs_meta Custom field data. * @param array $action_args Compact array( 'order_action', 'order_id', 'cart' ). */ public function settlement_status( $data, $cscs_meta, $action_args ) { extract( $action_args ); if ( 'new' !== $order_action && ! empty( $order_id ) ) { $payment = usces_get_payments_by_name( $data['order_payment_name'] ); $acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : ''; if ( 'acting_paidy' === $acting_flg ) { $trans_id = $this->get_trans_id( $order_id ); $payment_status = $this->get_payment_status( $order_id, $trans_id ); if ( ! empty( $payment_status ) ) { $class = ' paidy-' . $this->get_status( $payment_status ); $status_name = $this->get_status_name( $payment_status ); if ( ! empty( $status_name ) ) { echo ' ' . esc_html__( 'Settlement status', 'usces' ) . ' ' . esc_html( $status_name ) . ' '; } } } } } /** * 受注編集画面【支払情報】 * usces_action_order_edit_form_settle_info * * @param array $data Order data. * @param array $action_args Compact array( 'order_action', 'order_id', 'cart' ). */ public function settlement_information( $data, $action_args ) { global $usces; extract( $action_args ); if ( 'new' !== $order_action && ! empty( $order_id ) ) { $payment = usces_get_payments_by_name( $data['order_payment_name'] ); if ( isset( $payment['settlement'] ) && 'acting_paidy' === $payment['settlement'] ) { $trans_id = $this->get_trans_id( $order_id ); $acting_data = usces_unserialize( $usces->get_order_meta_value( $payment['settlement'], $order_id ) ); if ( ! empty( $trans_id ) && isset( $acting_data['id'] ) ) { echo ''; } } } } /** * 決済情報ダイアログ * usces_action_endof_order_edit_form * * @param array $data Order data. * @param array $action_args Compact array( 'order_action', 'order_id', 'cart' ). */ public function settlement_dialog( $data, $action_args ) { extract( $action_args ); if ( 'new' !== $order_action && ! empty( $order_id ) ) : $payment = usces_get_payments_by_name( $data['order_payment_name'] ); if ( isset( $payment['settlement'] ) && 'acting_paidy' === $payment['settlement'] ) : ?>
    acting_name; } return $value; } /** * 決済リンクキー * usces_filter_get_link_key * * @param string $linkkey Settlement link key. * @param array $results Response data. * @return string */ public function get_link_key( $linkkey, $results ) { if ( isset( $results['trans_id'] ) ) { $linkkey = $results['trans_id']; } elseif ( isset( $results['trading_id'] ) ) { $linkkey = $results['trading_id']; } return $linkkey; } /** * 受注データ復旧処理 * usces_action_revival_order_data * * @param int $order_id Order number. * @param string $log_key Link key. * @param string $acting_flg Payment type. */ public function revival_orderdata( $order_id, $log_key, $acting_flg ) { global $usces; if ( 'acting_paidy' === $acting_flg ) { $usces->set_order_meta_value( 'trans_id', $log_key, $order_id ); $usces->set_order_meta_value( 'wc_trans_id', $log_key, $order_id ); $data = array( 'trans_id' => $log_key, ); $usces->set_order_meta_value( $acting_flg, usces_serialize( $data ), $order_id ); } } /** * 内容確認ページ [注文する] ボタン * usces_filter_confirm_inform * * @param string $form Purchase post form. * @param array $payments Payment data. * @param string $acting_flg Payment type. * @param string $rand Welcart transaction key. * @param string $purchase_disabled Disable purchase button. * @return string */ public function confirm_inform( $form, $payments, $acting_flg, $rand, $purchase_disabled ) { global $usces; if ( 'acting_paidy' !== $acting_flg ) { return $form; } $entry = $usces->cart->get_entry(); $cart = $usces->cart->get_cart(); if ( ! $entry || ! $cart ) { return $form; } if ( ! $entry['order']['total_full_price'] ) { return $form; } usces_save_order_acting_data( $rand ); $form = '
    ' . apply_filters( 'usces_filter_confirm_before_backbutton', '', $payments, $acting_flg, $rand ) . '
    '; return $form; } /** * 決済処理 * usces_action_acting_processing * * @param string $acting_flg Payment type. * @param array $post_query Post data. */ public function acting_processing( $acting_flg, $post_query ) { global $usces; if ( 'acting_paidy' !== $acting_flg ) { return; } $entry = $usces->cart->get_entry(); $cart = $usces->cart->get_cart(); if ( ! $entry || ! $cart ) { wp_redirect( USCES_CART_URL ); exit(); } parse_str( $post_query, $post_data ); if ( isset( $post_data['_nonce'] ) && ! wp_verify_nonce( $post_data['_nonce'], $acting_flg ) ) { wp_redirect( USCES_CART_URL ); exit(); } if ( isset( $post_data['paidy_id'] ) && isset( $post_data['paidy_created_at'] ) && isset( $post_data['paidy_status'] ) && 'authorized' === $post_data['paidy_status'] ) { $acting = substr( $acting_flg, 7 ); $trans_id = ( isset( $post_data['trans_id'] ) ) ? $post_data['trans_id'] : ''; $response_data = $this->api_retrieve( $post_data['paidy_id'] ); if ( isset( $response_data['status'] ) && 'authorized' === $response_data['status'] ) { $res = $usces->order_processing( $response_data ); if ( 'ordercompletion' === $res ) { wp_redirect( add_query_arg( array( 'acting' => $acting, 'acting_return' => 1, 'result' => 1, '_nonce' => $post_data['_nonce'], ), USCES_CART_URL ) ); } else { $log = array( 'acting' => $acting, 'key' => $trans_id, 'result' => 'ORDER DATA REGISTERED ERROR', 'data' => $response_data, ); usces_save_order_acting_error( $log ); wp_redirect( add_query_arg( array( 'acting' => $acting, 'acting_return' => 0, 'result' => 0, ), USCES_CART_URL ) ); } } else { $log = array( 'acting' => $acting, 'key' => $trans_id, 'result' => 'PAIDY AUTHORIZE ERROR', 'data' => $response_data, ); usces_save_order_acting_error( $log ); wp_redirect( add_query_arg( array( 'acting' => $acting, 'acting_return' => 0, 'result' => 0, ), USCES_CART_URL ) ); } exit(); } elseif ( isset( $post_data['paidy_id'] ) && isset( $post_data['paidy_created_at'] ) && isset( $post_data['paidy_status'] ) && 'rejected' === $post_data['paidy_status'] ) { $acting = substr( $acting_flg, 7 ); $trans_id = ( isset( $post_data['trans_id'] ) ) ? $post_data['trans_id'] : ''; $log = array( 'acting' => $acting, 'key' => $trans_id, 'result' => 'PAIDY REJECTED', 'data' => $post_data, ); usces_save_order_acting_error( $log ); wp_redirect( add_query_arg( array( 'acting' => $acting, 'acting_return' => 0, 'result' => 0, ), USCES_CART_URL ) ); exit(); } } /** * 決済完了ページ制御 * usces_filter_check_acting_return_results * * @param array $results Result data. * @return array */ public function acting_return( $results ) { $acting = filter_input( INPUT_GET, 'acting' ); if ( 'paidy' === $acting ) { $results = wp_unslash( $_GET ); $results[0] = filter_input( INPUT_GET, 'acting_return' ); $results['reg_order'] = false; } return $results; } /** * 重複オーダー禁止処理 * usces_filter_check_acting_return_duplicate * * @param string $trans_id Transaction ID. * @param array $results Result data. * @return string */ public function check_acting_return_duplicate( $trans_id, $results ) { if ( isset( $_POST['paidy_id'] ) || ( isset( $results['acting'] ) && 'paidy' === $results['acting'] ) ) { if ( isset( $_POST['trans_id'] ) ) { $trans_id = filter_input( INPUT_POST, 'trans_id' ); } elseif ( isset( $results['order']['order_ref'] ) ) { $trans_id = $results['order']['order_ref']; } } return $trans_id; } /** * 受注データ登録 * Called by usces_reg_orderdata() and usces_new_orderdata(). * usces_action_reg_orderdata * * @param array $args Compact array( $cart, $entry, $order_id, $member_id, $payments, $charging_type, $results ). */ public function register_orderdata( $args ) { global $usces; extract( $args ); $acting_flg = ( isset( $payments['settlement'] ) ) ? $payments['settlement'] : ''; if ( 'acting_paidy' !== $acting_flg ) { return; } if ( ! $entry['order']['total_full_price'] ) { return; } $trans_id = ''; if ( isset( $results['order']['order_ref'] ) ) { $trans_id = $results['order']['order_ref']; } elseif ( isset( $results['order_ref'] ) ) { $trans_id = $results['order_ref']; } if ( ! empty( $trans_id ) ) { if ( ! isset( $results['acting'] ) ) { $results['acting'] = 'paidy'; } $usces->set_order_meta_value( $acting_flg, usces_serialize( $results ), $order_id ); $usces->set_order_meta_value( 'trans_id', $trans_id, $order_id ); $usces->set_order_meta_value( 'wc_trans_id', $trans_id, $order_id ); $this->save_acting_log( $results, 'paidy', $results['status'], 'OK', $order_id, $trans_id ); } } /** * 決済エラーメッセージ * usces_filter_get_error_settlement * * @param string $form Payment error message. * @return string */ public function error_page_message( $form ) { $acting = ( isset( $_REQUEST['acting'] ) ) ? wp_unslash( $_REQUEST['acting'] ) : ''; if ( 'paidy' === $acting ) { $form .= '
    他の支払方法を選ぶ 》
    '; } return $form; } /** * Front scripts. * wp_print_footer_scripts */ public function footer_scripts() { global $usces; if ( $this->is_validity_acting( 'paidy' ) ) : /* 内容確認ページ */ if ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) && 'confirm' === $usces->page ) : $entry = $usces->cart->get_entry(); $cart = $usces->cart->get_cart(); if ( empty( $entry['order']['total_full_price'] ) ) { return; } $payment = usces_get_payments_by_name( $entry['order']['payment_name'] ); if ( empty( $payment['settlement'] ) || 'acting_paidy' !== $payment['settlement'] ) { return; } $continue = ( defined( 'WCEX_DLSELLER' ) ) ? usces_have_continue_charge( $cart ) : false; $regular = ( defined( 'WCEX_AUTO_DELIVERY' ) ) ? usces_have_regular_order() : false; if ( $continue || $regular ) { return; } $acting_opts = $this->get_acting_settings(); if ( usces_is_login() ) { $member = $usces->get_member(); $age = ceil( ( strtotime( date_i18n( 'Y-m-d H:i:s' ) ) - strtotime( $member['registered'] ) ) / ( 60 * 60 * 24 ) ); $member_data = $this->get_buyer_data( $member['ID'] ); $buyer_data = '"user_id": "' . $member['ID'] . '",' . "\n"; $buyer_data .= "\t\t\t" . '"age": ' . $age . ',' . "\n"; $buyer_data .= "\t\t\t" . '"ltv": ' . $member_data['ltv'] . ',' . "\n"; $buyer_data .= "\t\t\t" . '"order_count": ' . $member_data['order_count'] . ',' . "\n"; $buyer_data .= "\t\t\t" . '"last_order_amount": ' . $member_data['last_order_amount'] . ',' . "\n"; $buyer_data .= "\t\t\t" . '"last_order_at": ' . $member_data['last_order_at'] . ',' . "\n"; $number_of_points = '"number_of_points": "' . $member['point'] . '"' . "\n"; } else { $buyer_data = '"age": null,' . "\n"; $buyer_data .= "\t\t\t" . '"ltv": null,' . "\n"; $buyer_data .= "\t\t\t" . '"order_count": null,' . "\n"; $buyer_data .= "\t\t\t" . '"last_order_amount": null,' . "\n"; $buyer_data .= "\t\t\t" . '"last_order_at": null,' . "\n"; $number_of_points = ''; } $amount = usces_crform( $entry['order']['total_full_price'], false, false, 'return', false ); // if ( isset( $acting_opts['environment'] ) && 'live' === $acting_opts['environment'] ) { $email = trim( $entry['customer']['mailaddress1'] ); if ( ! empty( $entry['customer']['tel'] ) ) { $phone = '"phone": "' . str_replace( '-', '', mb_convert_kana( $entry['customer']['tel'], 'a', 'UTF-8' ) ) . '"' . "\n"; } else { $phone = ''; } // } else { // $email = 'successful.payment@paidy.com'; // $phone = '"phone": "08000000001"' . "\n"; // } $name1 = $entry['customer']['name1'] . ' ' . $entry['customer']['name2']; if ( ! empty( $entry['customer']['name3'] ) ) { $name2 = '"name2": "' . $entry['customer']['name3'] . ' ' . $entry['customer']['name4'] . '",' . "\n"; } else { $name2 = ''; } $line1 = ''; $line2 = ''; $city = ''; $state = ''; $zip = ''; $additional_shipping_addresses = ''; $billing_address = ''; if ( usces_is_login() && defined( 'WCEX_MSA' ) && isset( $entry['delivery']['delivery_flag'] ) && 2 === (int) $entry['delivery']['delivery_flag'] ) { $msacart = $usces->msacart->get_cart(); $count_msa = ( is_array( $msacart ) ) ? count( $msacart ) : 0; if ( 0 < $count_msa ) { krsort( $msacart ); $idx_msa = 0; foreach ( $msacart as $group_id => $group ) { $delivery = $group['delivery']; $destination_info = msa_get_destination( $usces->current_member['id'], $delivery['destination_id'] ); if ( 7 === strlen( trim( $destination_info['msa_zip'] ) ) ) { $msa_zip = substr( trim( $destination_info['msa_zip'] ), 0, 3 ) . '-' . substr( trim( $destination_info['msa_zip'] ), 3 ); } else { $msa_zip = trim( $destination_info['msa_zip'] ); } if ( 0 === $idx_msa ) { $line1 = trim( $destination_info['msa_address3'] ); $line2 = trim( $destination_info['msa_address2'] ); $city = trim( $destination_info['msa_address1'] ); $state = trim( $destination_info['msa_pref'] ); $zip = $msa_zip; } elseif ( 1 === $idx_msa ) { $additional_shipping_addresses .= '"additional_shipping_addresses": [{' . "\n"; $additional_shipping_addresses .= "\t\t\t\t" . '"line1": "' . trim( $destination_info['msa_address3'] ) . '",' . "\n"; $additional_shipping_addresses .= "\t\t\t\t" . '"line2": "' . trim( $destination_info['msa_address2'] ) . '",' . "\n"; $additional_shipping_addresses .= "\t\t\t\t" . '"city": "' . trim( $destination_info['msa_address1'] ) . '",' . "\n"; $additional_shipping_addresses .= "\t\t\t\t" . '"state": "' . trim( $destination_info['msa_pref'] ) . '",' . "\n"; $additional_shipping_addresses .= "\t\t\t\t" . '"zip": "' . $msa_zip . '"' . "\n"; $additional_shipping_addresses .= "\t\t\t" . '}'; } else { $additional_shipping_addresses .= ',' . "\n\t\t\t" . '{' . "\n"; $additional_shipping_addresses .= "\t\t\t\t" . '"line1": "' . trim( $destination_info['msa_address3'] ) . '",' . "\n"; $additional_shipping_addresses .= "\t\t\t\t" . '"line2": "' . trim( $destination_info['msa_address2'] ) . '",' . "\n"; $additional_shipping_addresses .= "\t\t\t\t" . '"city": "' . trim( $destination_info['msa_address1'] ) . '",' . "\n"; $additional_shipping_addresses .= "\t\t\t\t" . '"state": "' . trim( $destination_info['msa_pref'] ) . '",' . "\n"; $additional_shipping_addresses .= "\t\t\t\t" . '"zip": "' . $msa_zip . '"' . "\n"; $additional_shipping_addresses .= "\t\t\t" . '}'; } $idx_msa++; } $additional_shipping_addresses .= '],' . "\n"; } } else { $line1 = trim( $entry['delivery']['address3'] ); $line2 = trim( $entry['delivery']['address2'] ); $city = trim( $entry['delivery']['address1'] ); $state = trim( $entry['delivery']['pref'] ); if ( 7 === strlen( trim( $entry['delivery']['zipcode'] ) ) ) { $zip = substr( trim( $entry['delivery']['zipcode'] ), 0, 3 ) . '-' . substr( trim( $entry['delivery']['zipcode'] ), 3 ); } else { $zip = trim( $entry['delivery']['zipcode'] ); } if ( isset( $entry['delivery']['delivery_flag'] ) && 1 === (int) $entry['delivery']['delivery_flag'] ) { $customer_line1 = trim( $entry['customer']['address3'] ); $customer_line2 = trim( $entry['customer']['address2'] ); $customer_city = trim( $entry['customer']['address1'] ); $customer_state = trim( $entry['customer']['pref'] ); if ( 7 === strlen( trim( $entry['customer']['zipcode'] ) ) ) { $customer_zip = substr( trim( $entry['customer']['zipcode'] ), 0, 3 ) . '-' . substr( trim( $entry['customer']['zipcode'] ), 3 ); } else { $customer_zip = trim( $entry['customer']['zipcode'] ); } if ( $line1 !== $customer_line1 || $line2 !== $customer_line2 || $city !== $customer_city || $state !== $customer_state || $zip !== $customer_zip ) { $billing_address .= ',"delivery_locn_type": "not_primary_home",' . "\n"; $billing_address .= "\t\t\t" . '"billing_address": {' . "\n"; $billing_address .= "\t\t\t\t" . '"line1": "' . $customer_line1 . '",' . "\n"; $billing_address .= "\t\t\t\t" . '"line2": "' . $customer_line2 . '",' . "\n"; $billing_address .= "\t\t\t\t" . '"city": "' . $customer_city . '",' . "\n"; $billing_address .= "\t\t\t\t" . '"state": "' . $customer_state . '",' . "\n"; $billing_address .= "\t\t\t\t" . '"zip": "' . $customer_zip . '"' . "\n"; $billing_address .= "\t\t\t" . '}' . "\n"; } } elseif ( ! isset( $entry['delivery']['delivery_flag'] ) || 0 === (int) $entry['delivery']['delivery_flag'] ) { $billing_address .= ',"delivery_locn_type": "home",' . "\n"; } } $items = ''; foreach ( $cart as $cart_row ) { $items .= "\n\t\t\t\t" . '{' . "\n"; $items .= "\t\t\t\t\t" . '"id": ' . wp_json_encode( (string) $usces->getItemCode( $cart_row['post_id'] ) ) . ',' . "\n"; $items .= "\t\t\t\t\t" . '"quantity": ' . $cart_row['quantity'] . ',' . "\n"; $items .= "\t\t\t\t\t" . '"title": ' . wp_json_encode( (string) $usces->getItemName( $cart_row['post_id'] ) ) . ',' . "\n"; $items .= "\t\t\t\t\t" . '"unit_price": ' . $cart_row['price'] . "\n"; $items .= "\t\t\t\t" . '},'; } if ( isset( $entry['order']['discount'] ) && 0 !== $entry['order']['discount'] ) { $items .= "\n\t\t\t\t" . '{' . "\n"; $items .= "\t\t\t\t\t" . '"quantity": 1,' . "\n"; $items .= "\t\t\t\t\t" . '"title": "' . apply_filters( 'usces_confirm_discount_label', __( 'Campaign discount', 'usces' ) ) . '",' . "\n"; $items .= "\t\t\t\t\t" . '"unit_price": ' . $entry['order']['discount'] . "\n"; $items .= "\t\t\t\t" . '},'; } if ( usces_is_member_system() && usces_is_member_system_point() && ! empty( $entry['order']['usedpoint'] ) ) { $items .= "\n\t\t\t\t" . '{' . "\n"; $items .= "\t\t\t\t\t" . '"quantity": 1,' . "\n"; $items .= "\t\t\t\t\t" . '"title": "' . __( 'Used points', 'usces' ) . '",' . "\n"; $items .= "\t\t\t\t\t" . '"unit_price": ' . ( $entry['order']['usedpoint'] * -1 ) . "\n"; $items .= "\t\t\t\t" . '},'; } if ( ! empty( $entry['order']['cod_fee'] ) ) { $items .= "\n\t\t\t\t" . '{' . "\n"; $items .= "\t\t\t\t\t" . '"quantity": 1,' . "\n"; $items .= "\t\t\t\t\t" . '"title": "' . apply_filters( 'usces_filter_paidy_fee_label', 'ペイディ手数料' ) . '",' . "\n"; $items .= "\t\t\t\t\t" . '"unit_price": ' . $entry['order']['cod_fee'] . "\n"; $items .= "\t\t\t\t" . '},'; } $items = rtrim( $items, ',' ) . "\n"; if ( 0 !== $entry['order']['shipping_charge'] ) { $shipping = $entry['order']['shipping_charge']; } else { $shipping = '0'; } if ( isset( $entry['order']['tax'] ) && 'exclude' === usces_get_tax_mode() ) { $tax = $entry['order']['tax'] . "\n"; } else { $tax = '0' . "\n"; } ?> prepare( "SELECT * FROM {$wpdb->prefix}usces_order WHERE `mem_id` = %d ORDER BY `order_date` DESC", $member_id ); $results = $wpdb->get_results( $query, ARRAY_A ); if ( 0 < count( $results ) ) { foreach ( $results as $order ) { if ( false === strpos( $order['order_status'], 'cancel' ) && false === strpos( $order['order_status'], 'estimate' ) ) { $payment = usces_get_payments_by_name( $order['order_payment_name'] ); if ( isset( $payment['settlement'] ) && 'acting_paidy' !== $payment['settlement'] ) { $total_price = $order['order_item_total_price'] - $order['order_usedpoint'] + $order['order_discount'] + $order['order_shipping_charge'] + $order['order_cod_fee'] + $order['order_tax']; if ( 0 === $order_count ) { $last_order_amount = $total_price; $last_order_at = ceil( ( strtotime( date_i18n( 'Y-m-d H:i:s' ) ) - strtotime( $order['order_date'] ) ) / ( 60 * 60 * 24 ) ); } $ltv += $total_price; $order_count++; } } } } $member_data = array( 'ID' => $member_id, 'ltv' => $ltv, 'order_count' => $order_count, 'last_order_amount' => $last_order_amount, 'last_order_at' => $last_order_at, ); return $member_data; } /** * 決済オプション取得 * * @return array */ protected function get_acting_settings() { $options = get_option( 'usces', array() ); $acting_settings = array(); if ( isset( $options['acting_settings']['paidy'] ) ) { $environment = ( ! empty( $options['acting_settings']['paidy']['environment'] ) ) ? $options['acting_settings']['paidy']['environment'] : 'live'; $acting_settings['api_url'] = 'https://api.paidy.com/payments/'; $acting_settings['apps_url'] = 'https://apps.paidy.com/'; if ( 'live' === $environment ) { $acting_settings['send_url'] = 'https://link.paidy.co.jp/v/u/request'; $acting_settings['token_url'] = 'https://token.paidy.co.jp/js/PaygentToken.js'; $acting_settings['public_key'] = ( ! empty( $options['acting_settings']['paidy']['public_key'] ) ) ? $options['acting_settings']['paidy']['public_key'] : ''; $acting_settings['secret_key'] = ( ! empty( $options['acting_settings']['paidy']['secret_key'] ) ) ? $options['acting_settings']['paidy']['secret_key'] : ''; } else { $acting_settings['send_url'] = 'https://sandbox.paidy.co.jp/v/u/request'; $acting_settings['token_url'] = 'https://sandbox.paidy.co.jp/js/PaygentToken.js'; $acting_settings['public_key'] = ( ! empty( $options['acting_settings']['paidy']['public_key_test'] ) ) ? $options['acting_settings']['paidy']['public_key_test'] : ''; $acting_settings['secret_key'] = ( ! empty( $options['acting_settings']['paidy']['secret_key_test'] ) ) ? $options['acting_settings']['paidy']['secret_key_test'] : ''; } } return $acting_settings; } /** * 受注ID 取得 * * @param string $trans_id Transaction ID. * @return int */ protected function get_order_id( $trans_id ) { global $wpdb; $query = $wpdb->prepare( "SELECT `order_id` FROM {$wpdb->prefix}usces_order_meta WHERE `meta_key` = %s AND `meta_value` = %s", 'trans_id', $trans_id ); $order_id = $wpdb->get_var( $query ); return $order_id; } /** * 取引ID 取得 * * @param int $order_id Order number. * @return string */ protected function get_trans_id( $order_id ) { global $usces; $trans_id = $usces->get_order_meta_value( 'trans_id', $order_id ); if ( empty( $trans_id ) ) { $trans_id = $usces->get_order_meta_value( 'trading_id', $order_id ); } return $trans_id; } /** * 受注ステータス取得 * * @param int $order_id Order number. * @return string */ protected function get_order_status( $order_id ) { global $wpdb; $query = $wpdb->prepare( "SELECT LOCATE( 'receipted', `order_status` ) FROM {$wpdb->prefix}usces_order WHERE `ID` = %d", $order_id ); $order_status = $wpdb->get_var( $query ); return $order_status; } /** * 受注データ支払方法取得 * * @param int $order_id Order number. * @return string */ protected function get_order_acting_flg( $order_id ) { global $wpdb; $query = $wpdb->prepare( "SELECT `order_payment_name` FROM {$wpdb->prefix}usces_order WHERE `ID` = %d", $order_id ); $order_payment_name = $wpdb->get_var( $query ); $payment = usces_get_payments_by_name( $order_payment_name ); $acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : ''; return $acting_flg; } /** * 決済ログ取得 * * @param int $order_id Order number. * @param string $trans_id Transaction ID. * @param string $result Result. * @return array */ public function get_acting_log( $order_id = 0, $trans_id = 0, $result = 'OK' ) { global $wpdb; if ( empty( $order_id ) ) { if ( empty( $trans_id ) ) { return array(); } if ( 'OK' === $result ) { $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `tracking_id` = %s AND `result` = %s ORDER BY `ID` DESC, `datetime` DESC", $trans_id, 'OK' ); } else { $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `tracking_id` = %s ORDER BY `ID` DESC, `datetime` DESC", $trans_id ); } } else { if ( empty( $trans_id ) ) { if ( 'OK' === $result ) { $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `datetime` IN( SELECT MAX( `datetime` ) FROM {$wpdb->prefix}usces_acting_log WHERE `order_id` = %d GROUP BY `tracking_id` ) AND `order_id` = %d AND `result` = %s ORDER BY `ID` DESC, `datetime` DESC", $order_id, $order_id, 'OK' ); } else { $query = $wpdb->prepare( "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", $order_id, $order_id ); } } else { if ( 'OK' === $result ) { $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `order_id` = %d AND `tracking_id` = %s AND `result` = %s ORDER BY `ID` DESC, `datetime` DESC", $order_id, $trans_id, 'OK' ); } else { $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `order_id` = %d AND `tracking_id` = %s ORDER BY `ID` DESC, `datetime` DESC", $order_id, $trans_id ); } } } $log_data = $wpdb->get_results( $query, ARRAY_A ); return $log_data; } /** * 決済ログ出力 * * @param string $log Log data. * @param string $acting Acting type. * @param string $status Status. * @param string $result Result. * @param int $order_id Order number. * @param string $trans_id Transaction ID. * @param float $amount Amount. * @return array */ private function save_acting_log( $log, $acting, $status, $result, $order_id, $trans_id, $amount = 0 ) { global $wpdb; if ( 'OK' === $result ) { if ( empty( $amount ) && isset( $log['amount'] ) ) { $amount = $log['amount']; } } else { $amount = 0; } if ( 'authorized' === $status && ! empty( $log['created_at'] ) ) { $datetime = date_i18n( 'Y-m-d H:i:s', strtotime( $log['created_at'] . ' +9hour' ) ); } else { $datetime = date_i18n( 'Y-m-d H:i:s' ); } $query = $wpdb->prepare( "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 )", $datetime, usces_serialize( $log ), $acting, $status, $result, $amount, $order_id, $trans_id ); $res = $wpdb->query( $query ); return $res; } /** * 最新処理取得 * * @param int $order_id Order number. * @param string $trans_id Transaction ID. * @param string $result Result. * @return array */ public function get_acting_latest_log( $order_id, $trans_id, $result = 'OK' ) { $log_data = $this->get_acting_log( $order_id, $trans_id, $result ); if ( $log_data ) { $data = current( $log_data ); $log = usces_unserialize( $data['log'] ); $payment_id = ( isset( $log['id'] ) ) ? $log['id'] : ''; $latest_log = array( 'log' => $log, 'acting' => $data['acting'], 'status' => $data['status'], 'result' => $data['result'], 'amount' => $data['amount'], 'order_id' => $data['order_id'], 'trans_id' => $data['tracking_id'], 'payment_id' => $payment_id, ); } else { $latest_log = array(); } return $latest_log; } /** * 決済ステータス取得 * * @param int $order_id Order number. * @param string $trans_id Transaction ID. * @return string */ private function get_payment_status( $order_id, $trans_id ) { global $wpdb; $payment_status = ''; $latest_log = $this->get_acting_latest_log( $order_id, $trans_id, 'ALL' ); if ( isset( $latest_log['status'] ) ) { $refund = strpos( $latest_log['status'], 'refund' ); if ( false !== $refund ) { $payment_status = 'capture'; } else { $payment_status = $latest_log['status']; } } return $payment_status; } /** * 処理区分名称取得 * * @param string $payment_status Payment status code. * @return string */ private function get_status_name( $payment_status ) { $status_name = ''; switch ( $payment_status ) { case 'retrieve_error': $status_name = 'RETRIEVE ERROR'; break; case 'authorized_error': $status_name = 'AUTHORIZED ERROR'; break; case 'closed_error': $status_name = 'CLOSED ERROR'; break; case 'capture_error': $status_name = 'CAPTURE ERROR'; break; case 'refund_error': $status_name = 'REFUND ERROR'; break; default: $status_name = strtoupper( $payment_status ); } return $status_name; } /** * 処理区分取得 * * @param string $payment_status Payment status code. * @return string */ private function get_status( $payment_status ) { $status = ''; switch ( $payment_status ) { case 'retrieve_error': $status = 'retrieve-error'; break; case 'authorized_error': $status = 'authorized-error'; break; case 'closed_error': $status = 'closed-error'; break; case 'capture_error': $status = 'capture-error'; break; case 'refund_error': $status = 'refund-error'; break; default: $status = $payment_status; } return $status; } /** * Retrieve API. * * @param string $payment_id Payment ID. * @param bool $history All history retrieval. * @return array */ public function api_retrieve( $payment_id, $history = false ) { $acting_opts = $this->get_acting_settings(); $api_url = $acting_opts['api_url'] . $payment_id; $params = array( 'method' => 'GET', 'headers' => array( 'Content-Type' => 'application/json;charset=utf-8', 'Authorization' => 'Bearer ' . $acting_opts['secret_key'], 'Paidy-Version' => '2018-04-10', ), ); $response = wp_remote_get( $api_url, $params ); if ( is_wp_error( $response ) ) { $response_data = array(); } else { $response_data = json_decode( wp_remote_retrieve_body( $response ), true ); if ( $history ) { $amount = $response_data['amount']; $capture_id = ''; if ( isset( $response_data['captures'] ) ) { $captures = $response_data['captures']; foreach ( (array) $captures as $capture ) { if ( isset( $capture['id'] ) ) { $capture_id = $capture['id']; } } $response_data['capture_id'] = $capture_id; } if ( isset( $response_data['refunds'] ) ) { $refunds = $response_data['refunds']; foreach ( (array) $refunds as $refund ) { if ( isset( $refund['amount'] ) ) { $amount -= (int) $refund['amount']; } } } if ( 'closed' === $response_data['status'] && empty( $capture_id ) ) { $amount = 0; } $response_data['final_amount'] = $amount; } } return $response_data; } /** * Captures API. * * @param string $payment_id Payment ID. * @return array */ public function api_capture( $payment_id ) { $acting_opts = $this->get_acting_settings(); $api_url = $acting_opts['api_url'] . $payment_id . '/captures'; $body = array( 'metadata' => array( 'Platform' => 'Welcart' ), ); $params = array( 'method' => 'POST', 'headers' => array( 'Content-Type' => 'application/json;charset=utf-8', 'Authorization' => 'Bearer ' . $acting_opts['secret_key'], 'Paidy-Version' => '2018-04-10', ), 'body' => wp_json_encode( $body ), ); $response = wp_remote_post( $api_url, $params ); if ( is_wp_error( $response ) ) { $response_data = array(); } else { $response_data = json_decode( wp_remote_retrieve_body( $response ), true ); } return $response_data; } /** * Refunds API. * * @param string $payment_id Payment ID. * @param string $capture_id Capture ID. * @param float $amount 返金金額. * @return array */ public function api_refund( $payment_id, $capture_id, $amount = 0 ) { $acting_opts = $this->get_acting_settings(); $api_url = $acting_opts['api_url'] . $payment_id . '/refunds'; $body = array( 'metadata' => array( 'Platform' => 'Welcart' ), 'capture_id' => $capture_id, ); if ( ! empty( $amount ) ) { $body['amount'] = $amount; } $params = array( 'method' => 'POST', 'headers' => array( 'Content-Type' => 'application/json;charset=utf-8', 'Authorization' => 'Bearer ' . $acting_opts['secret_key'], 'Paidy-Version' => '2018-04-10', ), 'body' => wp_json_encode( $body ), ); $response = wp_remote_post( $api_url, $params ); if ( is_wp_error( $response ) ) { $response_data = array(); } else { if ( isset( $response_data['response']['code'] ) && '2' === substr( $response['response']['code'], 0, 1 ) ) { $response_data = json_decode( wp_remote_retrieve_body( $response ), true ); } else { $response_data = json_decode( wp_remote_retrieve_body( $response ), true ); } } return $response_data; } /** * Close API. * * @param string $payment_id Payment ID. * @return array */ public function api_close( $payment_id ) { $acting_opts = $this->get_acting_settings(); $api_url = $acting_opts['api_url'] . $payment_id . '/close'; $body = array( 'metadata' => array( 'Platform' => 'Welcart' ), ); $params = array( 'method' => 'POST', 'headers' => array( 'Content-Type' => 'application/json;charset=utf-8', 'Authorization' => 'Bearer ' . $acting_opts['secret_key'], 'Paidy-Version' => '2018-04-10', ), 'body' => wp_json_encode( $body ), ); $response = wp_remote_get( $api_url, $params ); if ( is_wp_error( $response ) ) { $response_data = array(); } else { $response_data = json_decode( wp_remote_retrieve_body( $response ), true ); } return $response_data; } }