PluginProbe
Welcart e-Commerce / 2.12.4
Welcart e-Commerce v2.12.4
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / classes / paymentSBPS.class.php

paymentSBPS.class.php in Welcart e-Commerce 2.12.4, at classes/paymentSBPS.class.php

5,320 lines 250.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * SBペイメントサービス
4 *
5 * @package Welcart
6 * @author Collne Inc.
7 * @version 1.0.0
8 * @since 1.9.16
9 */
10 class SBPS_SETTLEMENT extends SBPS_MAIN {
11
12 /**
13 * Instance of this class.
14 *
15 * @var object
16 */
17 protected static $instance = null;
18
19 /**
20 * 自動継続課金処理結果メール
21 *
22 * @var array
23 */
24 protected $continuation_charging_mail;
25
26 /**
27 * Construct.
28 */
29 public function __construct() {
30
31 $this->acting_name = 'SBPS';
32 $this->acting_formal_name = 'SBペイメントサービス';
33
34 $this->acting_card = 'sbps_card';
35 $this->acting_conv = 'sbps_conv';
36 $this->acting_payeasy = 'sbps_payeasy';
37 $this->acting_wallet = 'sbps_wallet';
38 $this->acting_mobile = 'sbps_mobile';
39 $this->acting_paypay = 'sbps_paypay';
40
41 $this->acting_flg_card = 'acting_sbps_card';
42 $this->acting_flg_conv = 'acting_sbps_conv';
43 $this->acting_flg_payeasy = 'acting_sbps_payeasy';
44 $this->acting_flg_wallet = 'acting_sbps_wallet';
45 $this->acting_flg_mobile = 'acting_sbps_mobile';
46 $this->acting_flg_paypay = 'acting_sbps_paypay';
47
48 $this->pay_method = array(
49 'acting_sbps_card',
50 'acting_sbps_conv',
51 'acting_sbps_payeasy',
52 'acting_sbps_wallet',
53 'acting_sbps_mobile',
54 'acting_sbps_paypay',
55 );
56
57 parent::__construct( 'sbps' );
58
59 if ( $this->is_activate_card() || $this->is_activate_paypay() ) {
60 add_action( 'usces_after_cart_instant', array( $this, 'acting_notice' ) );
61 if ( is_admin() ) {
62 add_action( 'usces_action_admin_ajax', array( $this, 'admin_ajax' ) );
63 add_filter( 'usces_filter_orderlist_detail_value', array( $this, 'orderlist_settlement_status' ), 10, 4 );
64 add_action( 'usces_action_order_edit_form_status_block_middle', array( $this, 'settlement_status' ), 10, 3 );
65 add_action( 'usces_action_order_edit_form_settle_info', array( $this, 'settlement_information' ), 10, 2 );
66 add_action( 'usces_action_endof_order_edit_form', array( $this, 'settlement_dialog' ), 10, 2 );
67 }
68 }
69
70 if ( $this->is_validity_acting( 'card' ) ) {
71 add_filter( 'usces_filter_delete_member_check', array( $this, 'delete_member_check' ), 10, 2 );
72 add_filter( 'usces_filter_delete_member_check_front', array( $this, 'delete_member_check' ), 10, 2 );
73 add_filter( 'usces_filter_delivery_secure_form_howpay', array( $this, 'delivery_secure_form_howpay' ) );
74 add_filter( 'usces_filter_template_redirect', array( $this, 'member_update_settlement' ), 1 );
75 add_action( 'usces_action_member_submenu_list', array( $this, 'e_update_settlement' ) );
76 add_filter( 'usces_filter_member_submenu_list', array( $this, 'update_settlement' ), 10, 2 );
77
78 /* WCEX DL Seller */
79 if ( defined( 'WCEX_DLSELLER' ) ) {
80 add_filter( 'usces_filter_the_continue_payment_method', array( $this, 'continuation_payment_method' ) );
81 add_filter( 'dlseller_filter_first_charging', array( $this, 'first_charging_date' ), 9, 5 );
82 add_filter( 'dlseller_filter_the_payment_method_restriction', array( $this, 'payment_method_restriction' ), 10, 2 );
83 add_filter( 'dlseller_filter_continue_member_list_condition', array( $this, 'continue_member_list_condition' ), 10, 4 );
84 add_action( 'dlseller_action_continue_member_list_page', array( $this, 'continue_member_list_page' ) );
85 add_action( 'dlseller_action_do_continuation_charging', array( $this, 'auto_continuation_charging' ), 10, 4 );
86 add_action( 'dlseller_action_do_continuation', array( $this, 'do_auto_continuation' ), 10, 2 );
87 add_filter( 'dlseller_filter_reminder_mail_body', array( $this, 'reminder_mail_body' ), 10, 3 );
88 add_filter( 'dlseller_filter_contract_renewal_mail_body', array( $this, 'contract_renewal_mail_body' ), 10, 3 );
89 }
90
91 /* WCEX Auto Delivery */
92 if ( defined( 'WCEX_AUTO_DELIVERY' ) ) {
93 add_filter( 'wcad_filter_shippinglist_acting', array( $this, 'set_shippinglist_acting' ) );
94 add_filter( 'wcad_filter_available_regular_payment_method', array( $this, 'available_regular_payment_method' ) );
95 add_filter( 'wcad_filter_the_payment_method_restriction', array( $this, 'payment_method_restriction' ), 10, 2 );
96 add_action( 'wcad_action_reg_auto_orderdata', array( $this, 'register_auto_orderdata' ) );
97 }
98 }
99
100 $this->initialize_data();
101 }
102
103 /**
104 * Return an instance of this class.
105 */
106 public static function get_instance() {
107 if ( is_null( self::$instance ) ) {
108 self::$instance = new self();
109 }
110 return self::$instance;
111 }
112
113 /**
114 * Initialize
115 */
116 public function initialize_data() {
117 $options = get_option( 'usces', array() );
118
119 $options['acting_settings']['sbps']['merchant_id'] = ( isset( $options['acting_settings']['sbps']['merchant_id'] ) ) ? $options['acting_settings']['sbps']['merchant_id'] : '';
120 $options['acting_settings']['sbps']['service_id'] = ( isset( $options['acting_settings']['sbps']['service_id'] ) ) ? $options['acting_settings']['sbps']['service_id'] : '';
121 $options['acting_settings']['sbps']['hash_key'] = ( isset( $options['acting_settings']['sbps']['hash_key'] ) ) ? $options['acting_settings']['sbps']['hash_key'] : '';
122 $options['acting_settings']['sbps']['ope'] = ( isset( $options['acting_settings']['sbps']['ope'] ) ) ? $options['acting_settings']['sbps']['ope'] : '';
123 $options['acting_settings']['sbps']['send_url'] = ( isset( $options['acting_settings']['sbps']['send_url'] ) ) ? $options['acting_settings']['sbps']['send_url'] : '';
124 $options['acting_settings']['sbps']['send_url_check'] = ( isset( $options['acting_settings']['sbps']['send_url_check'] ) ) ? $options['acting_settings']['sbps']['send_url_check'] : '';
125 $options['acting_settings']['sbps']['send_url_test'] = ( isset( $options['acting_settings']['sbps']['send_url_test'] ) ) ? $options['acting_settings']['sbps']['send_url_test'] : '';
126 $options['acting_settings']['sbps']['cust_url'] = ( ! empty( $options['acting_settings']['sbps']['cust_url'] ) ) ? $options['acting_settings']['sbps']['cust_url'] : 'https://fep.sps-system.com/f04/FepPayInfoReceive.do';
127 $options['acting_settings']['sbps']['cust_url_test'] = ( ! empty( $options['acting_settings']['sbps']['cust_url_test'] ) ) ? $options['acting_settings']['sbps']['cust_url_test'] : 'https://stbfep.sps-system.com/f04/FepPayInfoReceive.do';
128 $options['acting_settings']['sbps']['card_activate'] = ( isset( $options['acting_settings']['sbps']['card_activate'] ) ) ? $options['acting_settings']['sbps']['card_activate'] : 'off';
129 $options['acting_settings']['sbps']['3d_secure'] = ( isset( $options['acting_settings']['sbps']['3d_secure'] ) ) ? $options['acting_settings']['sbps']['3d_secure'] : 'off';
130 $options['acting_settings']['sbps']['cust_manage'] = ( isset( $options['acting_settings']['sbps']['cust_manage'] ) ) ? $options['acting_settings']['sbps']['cust_manage'] : 'off';
131 $options['acting_settings']['sbps']['sales'] = ( isset( $options['acting_settings']['sbps']['sales'] ) ) ? $options['acting_settings']['sbps']['sales'] : 'manual';
132 $options['acting_settings']['sbps']['sales_dlseller'] = ( isset( $options['acting_settings']['sbps']['sales_dlseller'] ) ) ? $options['acting_settings']['sbps']['sales_dlseller'] : 'manual';
133 $options['acting_settings']['sbps']['auto_settlement_mail'] = ( isset( $options['acting_settings']['sbps']['auto_settlement_mail'] ) ) ? $options['acting_settings']['sbps']['auto_settlement_mail'] : 'off';
134 $options['acting_settings']['sbps']['3des_key'] = ( isset( $options['acting_settings']['sbps']['3des_key'] ) ) ? $options['acting_settings']['sbps']['3des_key'] : '';
135 $options['acting_settings']['sbps']['3desinit_key'] = ( isset( $options['acting_settings']['sbps']['3desinit_key'] ) ) ? $options['acting_settings']['sbps']['3desinit_key'] : '';
136 $options['acting_settings']['sbps']['basic_id'] = ( isset( $options['acting_settings']['sbps']['basic_id'] ) ) ? $options['acting_settings']['sbps']['basic_id'] : '';
137 $options['acting_settings']['sbps']['basic_password'] = ( isset( $options['acting_settings']['sbps']['basic_password'] ) ) ? $options['acting_settings']['sbps']['basic_password'] : '';
138 $options['acting_settings']['sbps']['conv_activate'] = ( isset( $options['acting_settings']['sbps']['conv_activate'] ) ) ? $options['acting_settings']['sbps']['conv_activate'] : 'off';
139 $options['acting_settings']['sbps']['conv_limit'] = ( isset( $options['acting_settings']['sbps']['conv_limit'] ) ) ? $options['acting_settings']['sbps']['conv_limit'] : '';
140 $options['acting_settings']['sbps']['payeasy_activate'] = ( isset( $options['acting_settings']['sbps']['payeasy_activate'] ) ) ? $options['acting_settings']['sbps']['payeasy_activate'] : 'off';
141 $options['acting_settings']['sbps']['wallet_yahoowallet'] = ( isset( $options['acting_settings']['sbps']['wallet_yahoowallet'] ) ) ? $options['acting_settings']['sbps']['wallet_yahoowallet'] : 'off';
142 $options['acting_settings']['sbps']['wallet_rakuten'] = ( isset( $options['acting_settings']['sbps']['wallet_rakuten'] ) ) ? $options['acting_settings']['sbps']['wallet_rakuten'] : 'off';
143 $options['acting_settings']['sbps']['wallet_rakutenv2'] = ( isset( $options['acting_settings']['sbps']['wallet_rakutenv2'] ) ) ? $options['acting_settings']['sbps']['wallet_rakutenv2'] : 'off';
144 $options['acting_settings']['sbps']['wallet_paypal'] = ( isset( $options['acting_settings']['sbps']['wallet_paypal'] ) ) ? $options['acting_settings']['sbps']['wallet_paypal'] : 'off';
145 $options['acting_settings']['sbps']['wallet_netmile'] = 'off';
146 $options['acting_settings']['sbps']['wallet_alipay'] = ( isset( $options['acting_settings']['sbps']['wallet_alipay'] ) ) ? $options['acting_settings']['sbps']['wallet_alipay'] : 'off';
147 $options['acting_settings']['sbps']['wallet_activate'] = ( isset( $options['acting_settings']['sbps']['wallet_activate'] ) ) ? $options['acting_settings']['sbps']['wallet_activate'] : 'off';
148 $options['acting_settings']['sbps']['mobile_docomo'] = ( isset( $options['acting_settings']['sbps']['mobile_docomo'] ) ) ? $options['acting_settings']['sbps']['mobile_docomo'] : 'off';
149 $options['acting_settings']['sbps']['mobile_auone'] = ( isset( $options['acting_settings']['sbps']['mobile_auone'] ) ) ? $options['acting_settings']['sbps']['mobile_auone'] : 'off';
150 $options['acting_settings']['sbps']['mobile_mysoftbank'] = 'off';
151 $options['acting_settings']['sbps']['mobile_softbank2'] = ( isset( $options['acting_settings']['sbps']['mobile_softbank2'] ) ) ? $options['acting_settings']['sbps']['mobile_softbank2'] : 'off';
152 $options['acting_settings']['sbps']['mobile_activate'] = ( isset( $options['acting_settings']['sbps']['mobile_activate'] ) ) ? $options['acting_settings']['sbps']['mobile_activate'] : 'off';
153 $options['acting_settings']['sbps']['paypay_activate'] = ( isset( $options['acting_settings']['sbps']['paypay_activate'] ) ) ? $options['acting_settings']['sbps']['paypay_activate'] : 'off';
154 $options['acting_settings']['sbps']['paypay_sales'] = ( isset( $options['acting_settings']['sbps']['paypay_sales'] ) ) ? $options['acting_settings']['sbps']['paypay_sales'] : 'manual';
155 update_option( 'usces', $options );
156
157 $available_settlement = get_option( 'usces_available_settlement', array() );
158 if ( ! in_array( 'sbps', $available_settlement ) ) {
159 $available_settlement['sbps'] = $this->acting_formal_name;
160 update_option( 'usces_available_settlement', $available_settlement );
161 }
162
163 $noreceipt_status = get_option( 'usces_noreceipt_status', array() );
164 if ( ! in_array( 'acting_sbps_conv', $noreceipt_status ) || ! in_array( 'acting_sbps_payeasy', $noreceipt_status ) ) {
165 $noreceipt_status[] = 'acting_sbps_conv';
166 $noreceipt_status[] = 'acting_sbps_payeasy';
167 update_option( 'usces_noreceipt_status', $noreceipt_status );
168 }
169
170 $this->unavailable_method = array( 'acting_dsk_card', 'acting_dsk_conv', 'acting_dsk_payeasy' );
171 }
172
173 /**
174 * Admin script.
175 * admin_print_footer_scripts
176 */
177 public function admin_scripts() {
178 global $usces;
179
180 $admin_page = ( isset( $_GET['page'] ) ) ? wp_unslash( $_GET['page'] ) : '';
181 switch ( $admin_page ) :
182 case 'usces_settlement':
183 $settlement_selected = get_option( 'usces_settlement_selected', array() );
184 if ( in_array( $this->paymod_id, (array) $settlement_selected ) ) :
185 $acting_opts = $this->get_acting_settings();
186 ?>
187 <script type="text/javascript">
188 jQuery( document ).ready( function( $ ) {
189 var sbps_card_activate = "<?php echo esc_js( $acting_opts['card_activate'] ); ?>";
190 var conv_activate = "<?php echo esc_js( $acting_opts['conv_activate'] ); ?>";
191 var sbps_paypay_activate = "<?php echo esc_js( $acting_opts['paypay_activate'] ); ?>";
192 if ( "token" == sbps_card_activate ) {
193 $( ".card_link_sbps" ).css( "display", "none" );
194 $( ".card_link_token_sbps" ).css( "display", "" );
195 $( ".card_token_sbps" ).css( "display", "" );
196 } else if ( "on" == sbps_card_activate ) {
197 $( ".card_link_sbps" ).css( "display", "" );
198 $( ".card_link_token_sbps" ).css( "display", "" );
199 $( ".card_token_sbps" ).css( "display", "none" );
200 } else {
201 $( ".card_link_sbps" ).css( "display", "none" );
202 $( ".card_link_token_sbps" ).css( "display", "none" );
203 $( ".card_token_sbps" ).css( "display", "none" );
204 }
205
206 $( document ).on( "change", ".card_activate_sbps", function() {
207 if ( "token" == $( this ).val() ) {
208 $( ".card_link_sbps" ).css( "display", "none" );
209 $( ".card_link_token_sbps" ).css( "display", "" );
210 $( ".card_token_sbps" ).css( "display", "" );
211 } else if ( "on" == $( this ).val() ) {
212 $( ".card_link_sbps" ).css( "display", "" );
213 $( ".card_link_token_sbps" ).css( "display", "" );
214 $( ".card_token_sbps" ).css( "display", "none" );
215 } else {
216 $( ".card_link_sbps" ).css( "display", "none" );
217 $( ".card_link_token_sbps" ).css( "display", "none" );
218 $( ".card_token_sbps" ).css( "display", "none" );
219 }
220 });
221
222 if ( "on" == conv_activate ) {
223 $( ".conv_sbps" ).css( "display", "" );
224 } else {
225 $( ".conv_sbps" ).css( "display", "none" );
226 }
227
228 $( document ).on( "change", ".conv_activate_sbps", function() {
229 if( "on" == $( this ).val() ) {
230 $( ".conv_sbps" ).css( "display", "" );
231 } else {
232 $( ".conv_sbps" ).css( "display", "none" );
233 }
234 });
235
236 if ( "on" == sbps_paypay_activate ) {
237 $( ".paypay_sbps" ).css( "display", "" );
238 } else {
239 $( ".paypay_sbps" ).css( "display", "none" );
240 }
241
242 $( document ).on( "change", ".paypay_activate_sbps", function() {
243 if ( "on" == $( this ).val() ) {
244 $( ".paypay_sbps" ).css( "display", "" );
245 } else {
246 $( ".paypay_sbps" ).css( "display", "none" );
247 }
248 });
249 });
250 </script>
251 <?php
252 endif;
253 break;
254
255 case 'usces_orderlist':
256 case 'usces_continue':
257 $acting_flg = '';
258 $dialog_title = '';
259 $order_id = '';
260 $order_data = array();
261
262 $order_action = ( isset( $_GET['order_action'] ) ) ? wp_unslash( $_GET['order_action'] ) : '';
263 $continue_action = ( isset( $_GET['continue_action'] ) ) ? wp_unslash( $_GET['continue_action'] ) : '';
264
265 /* 受注編集画面・継続課金会員詳細画面 */
266 if ( ( 'usces_orderlist' === $admin_page && ( 'edit' === $order_action || 'editpost' === $order_action || 'newpost' === $order_action ) ) ||
267 ( 'usces_continue' === $admin_page && 'settlement_sbps_card' === $continue_action ) ) {
268 $order_id = ( isset( $_REQUEST['order_id'] ) ) ? wp_unslash( $_REQUEST['order_id'] ) : '';
269 if ( ! empty( $order_id ) ) {
270 $order_data = $usces->get_order_data( $order_id, 'direct' );
271 $payment = usces_get_payments_by_name( $order_data['order_payment_name'] );
272 if ( isset( $payment['settlement'] ) ) {
273 $acting_flg = $payment['settlement'];
274 }
275 if ( isset( $payment['name'] ) ) {
276 $dialog_title = $payment['name'];
277 }
278 }
279 }
280 $args = compact( 'order_id', 'acting_flg', 'admin_page', 'order_data' );
281
282 if ( 'acting_sbps_card' === $acting_flg || 'acting_sbps_paypay' === $acting_flg ) :
283 $acting_opts = $this->get_acting_settings();
284 ?>
285 <script type="text/javascript">
286 jQuery( document ).ready( function( $ ) {
287 adminOrderEdit = {
288 <?php
289 /* クレジットカード */
290 if ( 'acting_sbps_card' === $acting_flg ) :
291 ?>
292 getSettlementInfoCard : function() {
293 $( "#settlement-response" ).html( "" );
294 $( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' );
295 var mode = ( "" != $( "#error" ).val() ) ? "error_sbps_card" : "get_sbps_card";
296 $.ajax({
297 url: ajaxurl,
298 type: "POST",
299 cache: false,
300 dataType: 'json',
301 data: {
302 action: "usces_admin_ajax",
303 mode: mode,
304 order_id: $( "#order_id" ).val(),
305 tracking_id: $( "#tracking_id" ).val(),
306 member_id: $( "#member_id" ).val(),
307 wc_nonce: $( "#wc_nonce" ).val()
308 }
309 }).done( function( retVal, dataType ) {
310 $( "#settlement-response" ).html( retVal.result );
311 if ( $( "#refund-settlement" ).length ) {
312 $( "#refund-settlement" ).prop( "disabled", true );
313 }
314 $( "#settlement-response-loading" ).html( "" );
315 }).fail( function( jqXHR, textStatus, errorThrown ) {
316 console.log( textStatus );
317 console.log( jqXHR.status );
318 console.log( errorThrown.message );
319 $( "#settlement-response-loading" ).html( "" );
320 });
321 return false;
322 },
323 manualSettlementCard : function( amount, trans_id ) {
324 $( "#settlement-response" ).html( "" );
325 $( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' );
326 $.ajax({
327 url: ajaxurl,
328 type: "POST",
329 cache: false,
330 dataType: 'json',
331 data: {
332 action: "usces_admin_ajax",
333 mode: "manual_sbps_card",
334 order_id: $( "#order_id" ).val(),
335 order_num: $( "#order_num" ).val(),
336 member_id: $( "#member_id" ).val(),
337 amount: amount,
338 trans_id: trans_id,
339 wc_nonce: $( "#wc_nonce" ).val()
340 }
341 }).done( function( retVal, dataType ) {
342 $( "#settlement-response" ).html( retVal.result );
343 if ( "OK" == retVal.status && 0 < retVal.acting_status.length ) {
344 $( "#settlement-status" ).html( retVal.acting_status );
345 if ( undefined != $( "#settlement-status-"+$( "#order_num" ).val() ) ) {
346 $( "#settlement-status-"+$( "#order_num" ).val() ).html( retVal.acting_status );
347 }
348 if ( undefined != $( "#settlement-amount-"+$( "#order_num" ).val() ) ) {
349 $( "#settlement-amount-"+$( "#order_num" ).val() ).html( amount );
350 }
351 }
352 if ( $( "#refund-settlement" ).length ) {
353 $( "#refund-settlement" ).prop( "disabled", true );
354 }
355 if ( 0 < retVal.tracking_id.length ) {
356 $( "#tracking_id" ).val( retVal.tracking_id );
357 if ( undefined != $( "#settlement-tracking_id-"+$( "#order_num" ).val() ) ) {
358 $( "#settlement-tracking_id-"+$( "#order_num" ).val() ).html( retVal.tracking_id );
359 }
360 if ( undefined != $( "#settlement-information-"+trans_id ) ) {
361 $( "#settlement-information-"+trans_id ).attr( "data-tracking_id", retVal.tracking_id );
362 $( "#settlement-information-"+trans_id ).attr( "id", "settlement-information-"+retVal.tracking_id );
363 }
364 }
365 $( "#settlement-response-loading" ).html( "" );
366 }).fail( function( jqXHR, textStatus, errorThrown ) {
367 console.log( textStatus );
368 console.log( jqXHR.status );
369 console.log( errorThrown.message );
370 $( "#settlement-response-loading" ).html( "" );
371 });
372 return false;
373 },
374 salesSettlementCard : function( amount ) {
375 $( "#settlement-response" ).html( "" );
376 $( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' );
377 $.ajax({
378 url: ajaxurl,
379 type: "POST",
380 cache: false,
381 dataType: 'json',
382 data: {
383 action: "usces_admin_ajax",
384 mode: "sales_sbps_card",
385 order_id: $( "#order_id" ).val(),
386 tracking_id: $( "#tracking_id" ).val(),
387 member_id: $( "#member_id" ).val(),
388 amount: amount,
389 wc_nonce: $( "#wc_nonce" ).val()
390 }
391 }).done( function( retVal, dataType ) {
392 $( "#settlement-response" ).html( retVal.result );
393 if ( "OK" == retVal.status && 0 < retVal.acting_status.length ) {
394 $( "#settlement-status" ).html( retVal.acting_status );
395 if ( undefined != $( "#settlement-status-"+$( "#order_num" ).val() ) ) {
396 $( "#settlement-status-"+$( "#order_num" ).val() ).html( retVal.acting_status );
397 }
398 }
399 if ( $( "#refund-settlement" ).length ) {
400 $( "#refund-settlement" ).prop( "disabled", true );
401 }
402 $( "#settlement-response-loading" ).html( "" );
403 }).fail( function( jqXHR, textStatus, errorThrown ) {
404 console.log( textStatus );
405 console.log( jqXHR.status );
406 console.log( errorThrown.message );
407 $( "#settlement-response-loading" ).html( "" );
408 });
409 return false;
410 },
411 cancelSettlementCard : function() {
412 $( "#settlement-response" ).html( "" );
413 $( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' );
414 $.ajax({
415 url: ajaxurl,
416 type: "POST",
417 cache: false,
418 dataType: 'json',
419 data: {
420 action: "usces_admin_ajax",
421 mode: "cancel_sbps_card",
422 order_id: $( "#order_id" ).val(),
423 tracking_id: $( "#tracking_id" ).val(),
424 member_id: $( "#member_id" ).val(),
425 wc_nonce: $( "#wc_nonce" ).val()
426 }
427 }).done( function( retVal, dataType ) {
428 $( "#settlement-response" ).html( retVal.result );
429 if ( "OK" == retVal.status && 0 < retVal.acting_status.length ) {
430 $( "#settlement-status" ).html( retVal.acting_status );
431 if ( undefined != $( "#settlement-status-"+$( "#order_num" ).val() ) ) {
432 $( "#settlement-status-"+$( "#order_num" ).val() ).html( retVal.acting_status );
433 }
434 }
435 if ( $( "#refund-settlement" ).length ) {
436 $( "#refund-settlement" ).prop( "disabled", true );
437 }
438 $( "#settlement-response-loading" ).html( "" );
439 }).fail( function( jqXHR, textStatus, errorThrown ) {
440 console.log( textStatus );
441 console.log( jqXHR.status );
442 console.log( errorThrown.message );
443 $( "#settlement-response-loading" ).html( "" );
444 });
445 return false;
446 },
447 refundSettlementCard : function( amount ) {
448 $( "#settlement-response" ).html( "" );
449 $( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' );
450 $.ajax({
451 url: ajaxurl,
452 type: "POST",
453 cache: false,
454 dataType: 'json',
455 data: {
456 action: "usces_admin_ajax",
457 mode: "refund_sbps_card",
458 order_id: $( "#order_id" ).val(),
459 tracking_id: $( "#tracking_id" ).val(),
460 member_id: $( "#member_id" ).val(),
461 amount: amount,
462 wc_nonce: $( "#wc_nonce" ).val()
463 }
464 }).done( function( retVal, dataType ) {
465 $( "#settlement-response" ).html( retVal.result );
466 if ( "OK" == retVal.status && 0 < retVal.acting_status.length ) {
467 $( "#settlement-status" ).html( retVal.acting_status );
468 if ( undefined != $( "#settlement-status-"+$( "#order_num" ).val() ) ) {
469 $( "#settlement-status-"+$( "#order_num" ).val() ).html( retVal.acting_status );
470 }
471 }
472 if ( $( "#refund-settlement" ).length ) {
473 $( "#refund-settlement" ).prop( "disabled", true );
474 }
475 $( "#settlement-response-loading" ).html( "" );
476 }).fail( function( jqXHR, textStatus, errorThrown ) {
477 console.log( textStatus );
478 console.log( jqXHR.status );
479 console.log( errorThrown.message );
480 $( "#settlement-response-loading" ).html( "" );
481 });
482 return false;
483 },
484 <?php
485 /* PayPay */
486 elseif ( 'acting_sbps_paypay' === $acting_flg ) :
487 ?>
488 getSettlementInfoPayPay : function() {
489 $( "#settlement-response" ).html( "" );
490 $( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' );
491 var mode = ( "" != $( "#error" ).val() ) ? "error_sbps_paypay" : "get_sbps_paypay";
492 $.ajax({
493 url: ajaxurl,
494 type: "POST",
495 cache: false,
496 dataType: 'json',
497 data: {
498 action: "usces_admin_ajax",
499 mode: mode,
500 order_id: $( "#order_id" ).val(),
501 tracking_id: $( "#tracking_id" ).val(),
502 member_id: $( "#member_id" ).val(),
503 wc_nonce: $( "#wc_nonce" ).val()
504 }
505 }).done( function( retVal, dataType ) {
506 $( "#settlement-response" ).html( retVal.result );
507 if ( $( "#refund-settlement" ).length ) {
508 $( "#refund-settlement" ).prop( "disabled", true );
509 }
510 if ( $( "#increase-settlement" ).length ) {
511 $( "#increase-settlement" ).prop( "disabled", true );
512 }
513 $( "#settlement-response-loading" ).html( "" );
514 }).fail( function( jqXHR, textStatus, errorThrown ) {
515 console.log( textStatus );
516 console.log( jqXHR.status );
517 console.log( errorThrown.message );
518 $( "#settlement-response-loading" ).html( "" );
519 });
520 return false;
521 },
522 <?php
523 /* 指定売上 */
524 if ( 'manual' === $acting_opts['paypay_sales'] ) :
525 ?>
526 salesSettlementPayPay : function( amount ) {
527 $( "#settlement-response" ).html( "" );
528 $( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' );
529 $.ajax({
530 url: ajaxurl,
531 type: "POST",
532 cache: false,
533 dataType: 'json',
534 data: {
535 action: "usces_admin_ajax",
536 mode: "sales_sbps_paypay",
537 order_id: $( "#order_id" ).val(),
538 tracking_id: $( "#tracking_id" ).val(),
539 member_id: $( "#member_id" ).val(),
540 amount: amount,
541 wc_nonce: $( "#wc_nonce" ).val()
542 }
543 }).done( function( retVal, dataType ) {
544 $( "#settlement-response" ).html( retVal.result );
545 if ( "OK" == retVal.status && 0 < retVal.acting_status.length ) {
546 $( "#settlement-status" ).html( retVal.acting_status );
547 }
548 if ( $( "#refund-settlement" ).length ) {
549 $( "#refund-settlement" ).prop( "disabled", true );
550 }
551 if ( $( "#increase-settlement" ).length ) {
552 $( "#increase-settlement" ).prop( "disabled", true );
553 }
554 $( "#settlement-response-loading" ).html( "" );
555 }).fail( function( jqXHR, textStatus, errorThrown ) {
556 console.log( textStatus );
557 console.log( jqXHR.status );
558 console.log( errorThrown.message );
559 $( "#settlement-response-loading" ).html( "" );
560 });
561 return false;
562 },
563 <?php
564 endif;
565 ?>
566 cancelSettlementPayPay : function() {
567 $( "#settlement-response" ).html( "" );
568 $( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' );
569 $.ajax({
570 url: ajaxurl,
571 type: "POST",
572 cache: false,
573 dataType: 'json',
574 data: {
575 action: "usces_admin_ajax",
576 mode: "cancel_sbps_paypay",
577 order_id: $( "#order_id" ).val(),
578 tracking_id: $( "#tracking_id" ).val(),
579 member_id: $( "#member_id" ).val(),
580 wc_nonce: $( "#wc_nonce" ).val()
581 }
582 }).done( function( retVal, dataType ) {
583 $( "#settlement-response" ).html( retVal.result );
584 if ( "OK" == retVal.status && 0 < retVal.acting_status.length ) {
585 $( "#settlement-status" ).html( retVal.acting_status );
586 }
587 if ( $( "#refund-settlement" ).length ) {
588 $( "#refund-settlement" ).prop( "disabled", true );
589 }
590 if ( $( "#increase-settlement" ).length ) {
591 $( "#increase-settlement" ).prop( "disabled", true );
592 }
593 $( "#settlement-response-loading" ).html( "" );
594 }).fail( function( jqXHR, textStatus, errorThrown ) {
595 console.log( textStatus );
596 console.log( jqXHR.status );
597 console.log( errorThrown.message );
598 $( "#settlement-response-loading" ).html( "" );
599 });
600 return false;
601 },
602 refundSettlementPayPay : function( amount ) {
603 $( "#settlement-response" ).html( "" );
604 $( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' );
605 $.ajax({
606 url: ajaxurl,
607 type: "POST",
608 cache: false,
609 dataType: 'json',
610 data: {
611 action: "usces_admin_ajax",
612 mode: "refund_sbps_paypay",
613 order_id: $( "#order_id" ).val(),
614 tracking_id: $( "#tracking_id" ).val(),
615 member_id: $( "#member_id" ).val(),
616 amount: amount,
617 wc_nonce: $( "#wc_nonce" ).val()
618 }
619 }).done( function( retVal, dataType ) {
620 $( "#settlement-response" ).html( retVal.result );
621 if ( "OK" == retVal.status && 0 < retVal.acting_status.length ) {
622 $( "#settlement-status" ).html( retVal.acting_status );
623 }
624 if ( $( "#refund-settlement" ).length ) {
625 $( "#refund-settlement" ).prop( "disabled", true );
626 }
627 if ( $( "#increase-settlement" ).length ) {
628 $( "#increase-settlement" ).prop( "disabled", true );
629 }
630 $( "#settlement-response-loading" ).html( "" );
631 }).fail( function( jqXHR, textStatus, errorThrown ) {
632 console.log( textStatus );
633 console.log( jqXHR.status );
634 console.log( errorThrown.message );
635 $( "#settlement-response-loading" ).html( "" );
636 });
637 return false;
638 },
639 increaseSettlementPayPay : function( amount ) {
640 $( "#settlement-response" ).html( "" );
641 $( "#settlement-response-loading" ).html( '<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading.gif" />' );
642 $.ajax({
643 url: ajaxurl,
644 type: "POST",
645 cache: false,
646 dataType: 'json',
647 data: {
648 action: "usces_admin_ajax",
649 mode: "increase_sbps_paypay",
650 order_id: $( "#order_id" ).val(),
651 tracking_id: $( "#tracking_id" ).val(),
652 member_id: $( "#member_id" ).val(),
653 amount: amount,
654 wc_nonce: $( "#wc_nonce" ).val()
655 }
656 }).done( function( retVal, dataType ) {
657 $( "#settlement-response" ).html( retVal.result );
658 if ( ( "OK" == retVal.status || "AC" == retVal.status ) && 0 < retVal.acting_status.length ) {
659 $( "#settlement-status" ).html( retVal.acting_status );
660 }
661 if ( $( "#refund-settlement" ).length ) {
662 $( "#refund-settlement" ).prop( "disabled", true );
663 }
664 if ( $( "#increase-settlement" ).length ) {
665 $( "#increase-settlement" ).prop( "disabled", true );
666 }
667 $( "#settlement-response-loading" ).html( "" );
668 }).fail( function( jqXHR, textStatus, errorThrown ) {
669 console.log( textStatus );
670 console.log( jqXHR.status );
671 console.log( errorThrown.message );
672 $( "#settlement-response-loading" ).html( "" );
673 });
674 return false;
675 },
676 <?php
677 endif;
678 ?>
679 };
680
681 $( "#settlement_dialog" ).dialog({
682 bgiframe: true,
683 autoOpen: false,
684 height: "auto",
685 width: 800,
686 resizable: true,
687 modal: true,
688 buttons: {
689 "<?php esc_html_e( 'Close' ); ?>": function() {
690 $( this ).dialog( "close" );
691 }
692 },
693 open: function() {
694 <?php
695 if ( 'acting_sbps_card' === $acting_flg ) :
696 ?>
697 adminOrderEdit.getSettlementInfoCard();
698 <?php
699 elseif ( 'acting_sbps_paypay' === $acting_flg ) :
700 ?>
701 adminOrderEdit.getSettlementInfoPayPay();
702 <?php
703 endif;
704 ?>
705 },
706 close: function() {
707 <?php do_action( 'usces_action_sbps_settlement_dialog_close', $args ); ?>
708 }
709 });
710
711 $( document ).on( "click", ".settlement-information", function() {
712 var tracking_id = $( this ).attr( "data-tracking_id" );
713 var order_num = $( this ).attr( "data-num" );
714 $( "#tracking_id" ).val( tracking_id );
715 $( "#order_num" ).val( order_num );
716 $( "#settlement_dialog" ).dialog( "option", "title", "<?php echo esc_js( $dialog_title ); ?>" );
717 $( "#settlement_dialog" ).dialog( "open" );
718 });
719
720 <?php
721 if ( 'acting_sbps_card' === $acting_flg ) :
722 ?>
723 $( document ).on( "click", "#manual-settlement", function() {
724 var amount_change = parseInt( $( "#amount_change" ).val() ) || 0;
725 var trans_id = $( this ).attr( "data-trans_id" );
726 if ( 0 >= amount_change ) {
727 alert( "金額が不正です。" );
728 return;
729 }
730 if ( ! confirm( amount_change + "円の与信処理を実行します。よろしいですか?" ) ) {
731 return;
732 }
733 adminOrderEdit.manualSettlementCard( amount_change, trans_id );
734 });
735
736 $( document ).on( "click", "#sales-settlement", function() {
737 var amount_original = parseInt( $( "#amount_original" ).val() ) || 0;
738 var amount_change = parseInt( $( "#amount_change" ).val() ) || 0;
739 if ( 0 >= amount_change ) {
740 alert( "金額が不正です。" );
741 return;
742 }
743 if ( amount_change > amount_original ) {
744 alert( "与信金額を�
745 える金額は売上計上できません。" );
746 return;
747 }
748 if ( amount_change < amount_original ) {
749 if ( ! confirm( amount_change + "円に減額して売上処理を実行します。よろしいですか?" ) ) {
750 return;
751 }
752 } else if ( ! confirm( "<?php esc_html_e( 'Are you sure you want to execute sales accounting processing?', 'usces' ); ?>" ) ) {
753 return;
754 }
755 adminOrderEdit.salesSettlementCard( amount_change );
756 });
757
758 $( document ).on( "click", "#cancel-settlement", function() {
759 if ( ! confirm( "<?php esc_html_e( 'Are you sure you want to cancellation processing?', 'usces' ); ?>" ) ) {
760 return;
761 }
762 adminOrderEdit.cancelSettlementCard();
763 });
764
765 $( document ).on( "click", "#refund-settlement", function() {
766 var amount_original = parseInt( $( "#amount_original" ).val() ) || 0;
767 var amount_change = parseInt( $( "#amount_change" ).val() ) || 0;
768 if ( amount_change == amount_original ) {
769 return;
770 }
771 if ( amount_change > amount_original ) {
772 alert( "売上金額を�
773 える金額は返金できません。" );
774 return;
775 }
776 if ( 0 == amount_change ) {
777 if ( ! confirm( "<?php esc_html_e( 'Are you sure you want to cancellation processing?', 'usces' ); ?>" ) ) {
778 return;
779 }
780 adminOrderEdit.cancelSettlementCard( amount_original );
781 } else {
782 var amount = amount_original - amount_change;
783 if ( ! confirm( amount + "円の返金処理を実行します。よろしいですか?" ) ) {
784 return;
785 }
786 adminOrderEdit.refundSettlementCard( amount );
787 }
788 });
789 <?php
790 elseif ( 'acting_sbps_paypay' === $acting_flg ) :
791 if ( 'manual' === $acting_opts['paypay_sales'] ) :
792 ?>
793 $( document ).on( "click", "#sales-settlement", function() {
794 var amount_original = parseInt( $( "#amount_original" ).val() ) || 0;
795 var amount_change = parseInt( $( "#amount_change" ).val() ) || 0;
796 if ( amount_change > amount_original ) {
797 alert( "与信金額を�
798 える金額は売上計上できません。" );
799 return;
800 }
801 if ( amount_change < amount_original ) {
802 if ( ! confirm( amount_change + "円に減額して売上処理を実行します。よろしいですか?" ) ) {
803 return;
804 }
805 } else if ( ! confirm( "<?php esc_html_e( 'Are you sure you want to execute sales accounting processing?', 'usces' ); ?>" ) ) {
806 return;
807 }
808 adminOrderEdit.salesSettlementPayPay( amount_change );
809 });
810 <?php
811 endif;
812 ?>
813
814 $( document ).on( "click", "#cancel-settlement", function() {
815 if ( ! confirm( "<?php esc_html_e( 'Are you sure you want to cancellation processing?', 'usces' ); ?>" ) ) {
816 return;
817 }
818 adminOrderEdit.cancelSettlementPayPay();
819 });
820
821 $( document ).on( "click", "#refund-settlement", function() {
822 var amount_original = parseInt( $( "#amount_original" ).val() ) || 0;
823 var amount_change = parseInt( $( "#amount_change" ).val() ) || 0;
824 if ( amount_change == amount_original ) {
825 return;
826 }
827 if ( amount_change > amount_original ) {
828 alert( "返金できません。" );
829 return;
830 }
831 if ( 0 == amount_change ) {
832 if ( ! confirm( "<?php esc_html_e( 'Are you sure you want to cancellation processing?', 'usces' ); ?>" ) ) {
833 return;
834 }
835 adminOrderEdit.cancelSettlementPayPay( amount_original );
836 } else {
837 var amount = amount_original - amount_change;
838 if ( ! confirm( amount + "円の返金処理を実行します。よろしいですか?" ) ) {
839 return;
840 }
841 adminOrderEdit.refundSettlementPayPay( amount );
842 }
843 });
844
845 $( document ).on( "click", "#increase-settlement", function() {
846 var amount_original = parseInt( $( "#amount_original" ).val() ) || 0;
847 var amount_change = parseInt( $( "#amount_change" ).val() ) || 0;
848 if ( amount_change == amount_original ) {
849 return;
850 }
851 if ( amount_change < amount_original ) {
852 alert( "増額できません。" );
853 return;
854 }
855 var amount = amount_change - amount_original;
856 if ( ! confirm( amount + "円の増額売上処理を実行します。よろしいですか?" ) ) {
857 return;
858 }
859 var amount = $( "#amount_change" ).val();
860 adminOrderEdit.increaseSettlementPayPay( amount_change );
861 });
862 <?php
863 endif;
864 ?>
865
866 $( document ).on( "keydown", "#amount_change", function( e ) {
867 var halfVal = $( this ).val().replace( /[-]/g,
868 function( tmpStr ) {
869 return String.fromCharCode( tmpStr.charCodeAt(0) - 0xFEE0 );
870 }
871 );
872 $( this ).val( halfVal.replace( /[^0-9]/g, '' ) );
873 });
874
875 $( document ).on( "keyup", "#amount_change", function() {
876 this.value = this.value.replace( /[^0-9]+/i, '' );
877 this.value = Number( this.value ) || 0;
878 var amount_original = Number( $( "#amount_original" ).val() ) || 0;
879 if ( this.value > amount_original ) {
880 $( "#refund-settlement" ).prop( "disabled", true );
881 <?php
882 if ( 'acting_sbps_paypay' === $acting_flg ) :
883 ?>
884 $( "#increase-settlement" ).prop( "disabled", false );
885 <?php
886 endif;
887 ?>
888 } else if ( this.value < amount_original ) {
889 $( "#refund-settlement" ).prop( "disabled", false );
890 <?php
891 if ( 'acting_sbps_paypay' === $acting_flg ) :
892 ?>
893 $( "#increase-settlement" ).prop( "disabled", true );
894 <?php
895 endif;
896 ?>
897 } else {
898 $( "#refund-settlement" ).prop( "disabled", true );
899 <?php
900 if ( 'acting_sbps_paypay' === $acting_flg ) :
901 ?>
902 $( "#increase-settlement" ).prop( "disabled", true );
903 <?php
904 endif;
905 ?>
906 }
907 });
908
909 $( document ).on( "blur", "#amount_change", function() {
910 this.value = this.value.replace( /[^0-9]+/i, '' );
911 });
912 <?php if ( 'usces_continue' === $admin_page ) : ?>
913 adminContinuation = {
914 update : function() {
915 $.ajax({
916 url: ajaxurl,
917 type: "POST",
918 cache: false,
919 dataType: 'json',
920 data: {
921 action: "usces_admin_ajax",
922 mode: "continuation_update",
923 member_id: $( "#member_id" ).val(),
924 order_id: $( "#order_id" ).val(),
925 contracted_year: $( "#contracted-year option:selected" ).val(),
926 contracted_month: $( "#contracted-month option:selected" ).val(),
927 contracted_day: $( "#contracted-day option:selected" ).val(),
928 charged_year: $( "#charged-year option:selected" ).val(),
929 charged_month: $( "#charged-month option:selected" ).val(),
930 charged_day: $( "#charged-day option:selected" ).val(),
931 price: $( "#price" ).val(),
932 status: $( "#dlseller-status" ).val(),
933 wc_nonce: $( "#wc_nonce" ).val()
934 }
935 }).done( function( retVal, dataType ) {
936 if ( "OK" == retVal.status ) {
937 adminOperation.setActionStatus( "success", "<?php esc_html_e( 'The update was completed.', 'usces' ); ?>" );
938 } else {
939 var message = ( retVal.message != "" ) ? retVal.message : "<?php esc_html_e( 'failure in update', 'usces' ); ?>";
940 adminOperation.setActionStatus( "error", message );
941 }
942 }).fail( function( jqXHR, textStatus, errorThrown ) {
943 console.log( textStatus );
944 console.log( jqXHR.status );
945 console.log( errorThrown.message );
946 adminOperation.setActionStatus( "error", "<?php esc_html_e( 'failure in update', 'usces' ); ?>" );
947 });
948 return false;
949 }
950 };
951
952 $( document ).on( "click", "#continuation-update", function() {
953 var status = $( "#dlseller-status option:selected" ).val();
954 if ( "continuation" == status ) {
955 var year = $( "#charged-year option:selected" ).val();
956 var month = $( "#charged-month option:selected" ).val();
957 var day = $( "#charged-day option:selected" ).val();
958 if ( 0 == year || 0 == month || 0 == day ) {
959 alert( "<?php esc_html_e( 'Data have deficiency.', 'usces' ); ?>" );
960 $( "#charged-year" ).focus();
961 return;
962 }
963 if ( "" == $( "#price" ).val() || 0 == parseFloat( $( "#price" ).val() ) ) {
964 alert( "<?php printf( __( 'Input the %s', 'usces' ), __( 'Amount', 'dlseller' ) ); ?>" );
965 $( "#price" ).focus();
966 return;
967 }
968 }
969 if ( ! confirm( "<?php esc_html_e( 'Are you sure you want to update the settings?', 'usces' ); ?>" ) ) {
970 return;
971 }
972 adminContinuation.update();
973 });
974 <?php endif; ?>
975 });
976 </script>
977 <?php
978 endif;
979 break;
980 endswitch;
981 }
982
983 /**
984 * 決済オプション登録・更新
985 * usces_action_admin_settlement_update
986 */
987 public function settlement_update() {
988 global $usces;
989
990 if ( 'sbps' !== wp_unslash( $_POST['acting'] ) ) {
991 return;
992 }
993
994 $this->error_mes = '';
995 $options = get_option( 'usces', array() );
996 $payment_method = usces_get_system_option( 'usces_payment_method', 'settlement' );
997 $post_data = wp_unslash( $_POST );
998
999 unset( $options['acting_settings']['sbps'] );
1000 $options['acting_settings']['sbps']['merchant_id'] = ( isset( $post_data['merchant_id'] ) ) ? trim( $post_data['merchant_id'] ) : '';
1001 $options['acting_settings']['sbps']['service_id'] = ( isset( $post_data['service_id'] ) ) ? trim( $post_data['service_id'] ) : '';
1002 $options['acting_settings']['sbps']['hash_key'] = ( isset( $post_data['hash_key'] ) ) ? trim( $post_data['hash_key'] ) : '';
1003 $options['acting_settings']['sbps']['ope'] = ( isset( $post_data['ope'] ) ) ? $post_data['ope'] : '';
1004 $options['acting_settings']['sbps']['card_activate'] = ( isset( $post_data['card_activate'] ) ) ? $post_data['card_activate'] : 'off';
1005 $options['acting_settings']['sbps']['3d_secure'] = ( isset( $post_data['3d_secure'] ) ) ? $post_data['3d_secure'] : 'off';
1006 $options['acting_settings']['sbps']['cust_manage'] = ( isset( $post_data['cust_manage'] ) ) ? $post_data['cust_manage'] : 'off';
1007 $options['acting_settings']['sbps']['sales'] = ( isset( $post_data['sales'] ) ) ? $post_data['sales'] : 'manual';
1008 $options['acting_settings']['sbps']['sales_dlseller'] = ( isset( $post_data['sales_dlseller'] ) ) ? $post_data['sales_dlseller'] : 'manual';
1009 $options['acting_settings']['sbps']['auto_settlement_mail'] = ( isset( $post_data['auto_settlement_mail'] ) ) ? $post_data['auto_settlement_mail'] : 'off';
1010 $options['acting_settings']['sbps']['3des_key'] = ( isset( $post_data['3des_key'] ) ) ? trim( $post_data['3des_key'] ) : '';
1011 $options['acting_settings']['sbps']['3desinit_key'] = ( isset( $post_data['3desinit_key'] ) ) ? trim( $post_data['3desinit_key'] ) : '';
1012 $options['acting_settings']['sbps']['basic_id'] = ( isset( $post_data['basic_id'] ) ) ? trim( $post_data['basic_id'] ) : '';
1013 $options['acting_settings']['sbps']['basic_password'] = ( isset( $post_data['basic_password'] ) ) ? trim( $post_data['basic_password'] ) : '';
1014 $options['acting_settings']['sbps']['conv_activate'] = ( isset( $post_data['conv_activate'] ) ) ? $post_data['conv_activate'] : 'off';
1015 $options['acting_settings']['sbps']['conv_limit'] = ( isset( $post_data['conv_limit'] ) ) ? $post_data['conv_limit'] : '';
1016 $options['acting_settings']['sbps']['payeasy_activate'] = ( isset( $post_data['payeasy_activate'] ) ) ? $post_data['payeasy_activate'] : 'off';
1017 $options['acting_settings']['sbps']['wallet_yahoowallet'] = ( isset( $post_data['wallet_yahoowallet'] ) ) ? $post_data['wallet_yahoowallet'] : 'off';
1018 $options['acting_settings']['sbps']['wallet_rakuten'] = ( isset( $post_data['wallet_rakuten'] ) ) ? $post_data['wallet_rakuten'] : 'off';
1019 $options['acting_settings']['sbps']['wallet_rakutenv2'] = ( isset( $post_data['wallet_rakutenv2'] ) ) ? $post_data['wallet_rakutenv2'] : 'off';
1020 $options['acting_settings']['sbps']['wallet_paypal'] = ( isset( $post_data['wallet_paypal'] ) ) ? $post_data['wallet_paypal'] : 'off';
1021 $options['acting_settings']['sbps']['wallet_netmile'] = 'off';
1022 $options['acting_settings']['sbps']['wallet_alipay'] = ( isset( $post_data['wallet_alipay'] ) ) ? $post_data['wallet_alipay'] : 'off';
1023 $options['acting_settings']['sbps']['wallet_activate'] = ( isset( $post_data['wallet_activate'] ) ) ? $post_data['wallet_activate'] : 'off';
1024 $options['acting_settings']['sbps']['mobile_docomo'] = ( isset( $post_data['mobile_docomo'] ) ) ? $post_data['mobile_docomo'] : 'off';
1025 $options['acting_settings']['sbps']['mobile_auone'] = ( isset( $post_data['mobile_auone'] ) ) ? $post_data['mobile_auone'] : 'off';
1026 $options['acting_settings']['sbps']['mobile_mysoftbank'] = 'off';
1027 $options['acting_settings']['sbps']['mobile_softbank2'] = ( isset( $post_data['mobile_softbank2'] ) ) ? $post_data['mobile_softbank2'] : 'off';
1028 $options['acting_settings']['sbps']['mobile_activate'] = ( isset( $post_data['mobile_activate'] ) ) ? $post_data['mobile_activate'] : 'off';
1029 $options['acting_settings']['sbps']['paypay_activate'] = ( isset( $post_data['paypay_activate'] ) ) ? $post_data['paypay_activate'] : 'off';
1030 $options['acting_settings']['sbps']['paypay_sales'] = ( isset( $post_data['paypay_sales'] ) ) ? $post_data['paypay_sales'] : 'manual';
1031
1032 if ( ( 'on' === $options['acting_settings']['sbps']['card_activate'] || 'token' === $options['acting_settings']['sbps']['card_activate'] ) ||
1033 'on' === $options['acting_settings']['sbps']['conv_activate'] ||
1034 'on' === $options['acting_settings']['sbps']['payeasy_activate'] ||
1035 'on' === $options['acting_settings']['sbps']['wallet_activate'] ||
1036 'on' === $options['acting_settings']['sbps']['mobile_activate'] ||
1037 'on' === $options['acting_settings']['sbps']['paypay_activate'] ) {
1038 $unavailable_activate = false;
1039 foreach ( $payment_method as $settlement => $payment ) {
1040 if ( in_array( $settlement, $this->unavailable_method ) && 'activate' === $payment['use'] ) {
1041 $unavailable_activate = true;
1042 break;
1043 }
1044 }
1045 if ( $unavailable_activate ) {
1046 $this->error_mes .= __( '* Settlement that can not be used together is activated.', 'usces' ) . '<br />';
1047 } else {
1048 if ( WCUtils::is_blank( $post_data['merchant_id'] ) ) {
1049 $this->error_mes .= '※マーチャントID を�
1050 �力してください<br />';
1051 }
1052 if ( WCUtils::is_blank( $post_data['service_id'] ) ) {
1053 $this->error_mes .= '※サービスID を�
1054 �力してください<br />';
1055 }
1056 if ( WCUtils::is_blank( $post_data['hash_key'] ) ) {
1057 $this->error_mes .= '※ハッシュキーを�
1058 �力してください<br />';
1059 }
1060 if ( ( 'on' === $options['acting_settings']['sbps']['card_activate'] || 'token' === $options['acting_settings']['sbps']['card_activate'] ) ||
1061 'on' === $options['acting_settings']['sbps']['paypay_activate'] ) {
1062 if ( WCUtils::is_blank( $post_data['3des_key'] ) ) {
1063 $this->error_mes .= '※3DES 暗号化キーを�
1064 �力してください<br />';
1065 }
1066 if ( WCUtils::is_blank( $post_data['3desinit_key'] ) ) {
1067 $this->error_mes .= '※3DES 初期化キーを�
1068 �力してください<br />';
1069 }
1070 }
1071 if ( 'token' === $options['acting_settings']['sbps']['card_activate'] ) {
1072 if ( WCUtils::is_blank( $post_data['basic_id'] ) ) {
1073 $this->error_mes .= '※Basic認証ID を�
1074 �力してください<br />';
1075 }
1076 if ( WCUtils::is_blank( $post_data['basic_password'] ) ) {
1077 $this->error_mes .= '※Basic認証 Password を�
1078 �力してください<br />';
1079 }
1080 }
1081 }
1082 }
1083
1084 if ( 'on' === $options['acting_settings']['sbps']['wallet_rakuten'] && 'on' === $options['acting_settings']['sbps']['wallet_rakutenv2'] ) {
1085 $this->error_mes .= '※楽天ペイと楽天ペイV2の併用はできません。楽天ペイV2をご利用ください。<br />';
1086 }
1087
1088 if ( '' === $this->error_mes ) {
1089 $usces->action_status = 'success';
1090 $usces->action_message = __( 'Options are updated.', 'usces' );
1091 $toactive = array();
1092 if ( 'on' === $options['acting_settings']['sbps']['card_activate'] || 'token' === $options['acting_settings']['sbps']['card_activate'] ) {
1093 $usces->payment_structure[ $this->acting_flg_card ] = 'カード決済(SBPS)';
1094 foreach ( $payment_method as $settlement => $payment ) {
1095 if ( $this->acting_flg_card === $settlement && 'deactivate' === $payment['use'] ) {
1096 $toactive[] = $payment['name'];
1097 }
1098 }
1099 } else {
1100 unset( $usces->payment_structure[ $this->acting_flg_card ] );
1101 }
1102 if ( 'on' === $options['acting_settings']['sbps']['conv_activate'] ) {
1103 $usces->payment_structure[ $this->acting_flg_conv ] = 'コンビニ決済(SBPS)';
1104 foreach ( $payment_method as $settlement => $payment ) {
1105 if ( $this->acting_flg_conv === $settlement && 'deactivate' === $payment['use'] ) {
1106 $toactive[] = $payment['name'];
1107 }
1108 }
1109 } else {
1110 unset( $usces->payment_structure[ $this->acting_flg_conv ] );
1111 }
1112 if ( 'on' === $options['acting_settings']['sbps']['payeasy_activate'] ) {
1113 $usces->payment_structure[ $this->acting_flg_payeasy ] = 'ペイジー決済(SBPS)';
1114 foreach ( $payment_method as $settlement => $payment ) {
1115 if ( $this->acting_flg_payeasy === $settlement && 'deactivate' === $payment['use'] ) {
1116 $toactive[] = $payment['name'];
1117 }
1118 }
1119 } else {
1120 unset( $usces->payment_structure[ $this->acting_flg_payeasy ] );
1121 }
1122 if ( 'on' === $options['acting_settings']['sbps']['wallet_yahoowallet'] ||
1123 'on' === $options['acting_settings']['sbps']['wallet_rakuten'] ||
1124 'on' === $options['acting_settings']['sbps']['wallet_rakutenv2'] ||
1125 'on' === $options['acting_settings']['sbps']['wallet_paypal'] ||
1126 'on' === $options['acting_settings']['sbps']['wallet_alipay'] ) {
1127 $options['acting_settings']['sbps']['wallet_activate'] = 'on';
1128 } else {
1129 $options['acting_settings']['sbps']['wallet_activate'] = 'off';
1130 }
1131 if ( 'on' === $options['acting_settings']['sbps']['wallet_activate'] ) {
1132 $usces->payment_structure[ $this->acting_flg_wallet ] = 'ウォレット決済(SBPS)';
1133 foreach ( $payment_method as $settlement => $payment ) {
1134 if ( $this->acting_flg_wallet === $settlement && 'deactivate' === $payment['use'] ) {
1135 $toactive[] = $payment['name'];
1136 }
1137 }
1138 } else {
1139 unset( $usces->payment_structure[ $this->acting_flg_wallet ] );
1140 }
1141 if ( 'on' === $options['acting_settings']['sbps']['mobile_docomo'] ||
1142 'on' === $options['acting_settings']['sbps']['mobile_auone'] ||
1143 'on' === $options['acting_settings']['sbps']['mobile_softbank2'] ) {
1144 $options['acting_settings']['sbps']['mobile_activate'] = 'on';
1145 } else {
1146 $options['acting_settings']['sbps']['mobile_activate'] = 'off';
1147 }
1148 if ( 'on' === $options['acting_settings']['sbps']['mobile_activate'] ) {
1149 $usces->payment_structure[ $this->acting_flg_mobile ] = 'キャリア決済(SBPS)';
1150 foreach ( $payment_method as $settlement => $payment ) {
1151 if ( $this->acting_flg_mobile === $settlement && 'deactivate' === $payment['use'] ) {
1152 $toactive[] = $payment['name'];
1153 }
1154 }
1155 } else {
1156 unset( $usces->payment_structure[ $this->acting_flg_mobile ] );
1157 }
1158 if ( 'on' === $options['acting_settings']['sbps']['paypay_activate'] ) {
1159 $usces->payment_structure[ $this->acting_flg_paypay ] = 'PayPay オンライン決済(SBPS)';
1160 foreach ( $payment_method as $settlement => $payment ) {
1161 if ( $this->acting_flg_paypay === $settlement && 'deactivate' === $payment['use'] ) {
1162 $toactive[] = $payment['name'];
1163 }
1164 }
1165 } else {
1166 unset( $usces->payment_structure[ $this->acting_flg_paypay ] );
1167 }
1168 if ( ( 'on' === $options['acting_settings']['sbps']['card_activate'] || 'token' === $options['acting_settings']['sbps']['card_activate'] ) ||
1169 'on' === $options['acting_settings']['sbps']['conv_activate'] ||
1170 'on' === $options['acting_settings']['sbps']['payeasy_activate'] ||
1171 'on' === $options['acting_settings']['sbps']['wallet_activate'] ||
1172 'on' === $options['acting_settings']['sbps']['mobile_activate'] ||
1173 'on' === $options['acting_settings']['sbps']['paypay_activate'] ) {
1174 $options['acting_settings']['sbps']['activate'] = 'on';
1175 $options['acting_settings']['sbps']['send_url'] = 'https://fep.sps-system.com/f01/FepBuyInfoReceive.do';
1176 $options['acting_settings']['sbps']['send_url_check'] = 'https://stbfep.sps-system.com/Extra/BuyRequestAction.do';
1177 $options['acting_settings']['sbps']['send_url_test'] = 'https://stbfep.sps-system.com/f01/FepBuyInfoReceive.do';
1178 $options['acting_settings']['sbps']['token_url'] = 'https://token.sps-system.com/sbpstoken/com_sbps_system_token.js';
1179 $options['acting_settings']['sbps']['token_url_test'] = 'https://stbtoken.sps-system.com/sbpstoken/com_sbps_system_token.js';
1180 $options['acting_settings']['sbps']['api_url'] = 'https://api.sps-system.com/api/xmlapi.do';
1181 $options['acting_settings']['sbps']['api_url_test'] = 'https://stbfep.sps-system.com/api/xmlapi.do';
1182 $options['acting_settings']['sbps']['cust_url'] = 'https://fep.sps-system.com/f04/FepPayInfoReceive.do';
1183 $options['acting_settings']['sbps']['cust_url_test'] = 'https://stbfep.sps-system.com/f04/FepPayInfoReceive.do';
1184 usces_admin_orderlist_show_wc_trans_id();
1185 if ( 0 < count( $toactive ) ) {
1186 $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' );
1187 }
1188 } else {
1189 $options['acting_settings']['sbps']['activate'] = 'off';
1190 unset( $usces->payment_structure[ $this->acting_flg_card ] );
1191 unset( $usces->payment_structure[ $this->acting_flg_conv ] );
1192 unset( $usces->payment_structure[ $this->acting_flg_payeasy ] );
1193 unset( $usces->payment_structure[ $this->acting_flg_wallet ] );
1194 unset( $usces->payment_structure[ $this->acting_flg_mobile ] );
1195 unset( $usces->payment_structure[ $this->acting_flg_paypay ] );
1196 }
1197 $deactivate = array();
1198 foreach ( $payment_method as $settlement => $payment ) {
1199 if ( ! array_key_exists( $settlement, $usces->payment_structure ) ) {
1200 if ( 'deactivate' !== $payment['use'] ) {
1201 $payment['use'] = 'deactivate';
1202 $deactivate[] = $payment['name'];
1203 usces_update_system_option( 'usces_payment_method', $payment['id'], $payment );
1204 }
1205 }
1206 }
1207 if ( 0 < count( $deactivate ) ) {
1208 $deactivate_message = sprintf( __( '"Deactivate" %s of payment method.', 'usces' ), implode( ',', $deactivate ) );
1209 $usces->action_message .= $deactivate_message;
1210 }
1211 } else {
1212 $usces->action_status = 'error';
1213 $usces->action_message = __( 'Data have deficiency.', 'usces' );
1214 $options['acting_settings']['sbps']['activate'] = 'off';
1215 unset( $usces->payment_structure[ $this->acting_flg_card ] );
1216 unset( $usces->payment_structure[ $this->acting_flg_conv ] );
1217 unset( $usces->payment_structure[ $this->acting_flg_payeasy ] );
1218 unset( $usces->payment_structure[ $this->acting_flg_wallet ] );
1219 unset( $usces->payment_structure[ $this->acting_flg_mobile ] );
1220 unset( $usces->payment_structure[ $this->acting_flg_paypay ] );
1221 $deactivate = array();
1222 foreach ( $payment_method as $settlement => $payment ) {
1223 if ( in_array( $settlement, $this->pay_method ) ) {
1224 if ( 'deactivate' !== $payment['use'] ) {
1225 $payment['use'] = 'deactivate';
1226 $deactivate[] = $payment['name'];
1227 usces_update_system_option( 'usces_payment_method', $payment['id'], $payment );
1228 }
1229 }
1230 }
1231 if ( 0 < count( $deactivate ) ) {
1232 $deactivate_message = sprintf( __( '"Deactivate" %s of payment method.', 'usces' ), implode( ',', $deactivate ) );
1233 $usces->action_message .= $deactivate_message . __( 'Please complete the setup and update the payment method to "Activate".', 'usces' );
1234 }
1235 }
1236 ksort( $usces->payment_structure );
1237 update_option( 'usces', $options );
1238 update_option( 'usces_payment_structure', $usces->payment_structure );
1239 }
1240
1241 /**
1242 * クレジット決済設定画面フォーム
1243 * usces_action_settlement_tab_body
1244 */
1245 public function settlement_tab_body() {
1246
1247 $settlement_selected = get_option( 'usces_settlement_selected', array() );
1248 if ( in_array( 'sbps', (array) $settlement_selected ) ) :
1249 $acting_opts = $this->get_acting_settings();
1250 $merchant_id = isset( $acting_opts['merchant_id'] ) ? $acting_opts['merchant_id'] : '';
1251 $service_id = isset( $acting_opts['service_id'] ) ? $acting_opts['service_id'] : '';
1252 $hash_key = isset( $acting_opts['hash_key'] ) ? $acting_opts['hash_key'] : '';
1253 $threedes_key = isset( $acting_opts['3des_key'] ) ? $acting_opts['3des_key'] : '';
1254 $threedesinit_key = isset( $acting_opts['3desinit_key'] ) ? $acting_opts['3desinit_key'] : '';
1255 $basic_id = isset( $acting_opts['basic_id'] ) ? $acting_opts['basic_id'] : '';
1256 $basic_password = isset( $acting_opts['basic_password'] ) ? $acting_opts['basic_password'] : '';
1257 ?>
1258 <div id="uscestabs_sbps">
1259 <div class="settlement_service"><span class="service_title"><?php echo esc_html( $this->acting_formal_name ); ?></span></div>
1260 <?php
1261 if ( isset( $_POST['acting'] ) && 'sbps' === wp_unslash( $_POST['acting'] ) ) :
1262 if ( '' !== $this->error_mes ) :
1263 ?>
1264 <div class="error_message"><?php wel_esc_script_e( $this->error_mes ); ?></div>
1265 <?php
1266 elseif ( isset( $acting_opts['activate'] ) && 'on' === $acting_opts['activate'] ) :
1267 ?>
1268 <div class="message"><?php esc_html_e( 'Test thoroughly before use.', 'usces' ); ?></div>
1269 <?php
1270 endif;
1271 endif;
1272 ?>
1273 <form action="" method="post" name="sbps_form" id="sbps_form">
1274 <table class="settle_table">
1275 <tr>
1276 <th><a class="explanation-label" id="label_ex_merchant_id_sbps">マーチャントID</a></th>
1277 <td><input name="merchant_id" type="text" id="merchant_id_sbps" value="<?php echo esc_attr( $merchant_id ); ?>" class="regular-text" maxlength="5" /></td>
1278 </tr>
1279 <tr id="ex_merchant_id_sbps" class="explanation"><td colspan="2">契約時にSBペイメントサービスから発行されるマーチャントID(半角数字)</td></tr>
1280 <tr>
1281 <th><a class="explanation-label" id="label_ex_service_id_sbps">サービスID</a></th>
1282 <td><input name="service_id" type="text" id="service_id_sbps" value="<?php echo esc_attr( $service_id ); ?>" class="regular-text" maxlength="3" /></td>
1283 </tr>
1284 <tr id="ex_service_id_sbps" class="explanation"><td colspan="2">契約時にSBペイメントサービスから発行されるサービスID(半角数字)</td></tr>
1285 <tr>
1286 <th><a class="explanation-label" id="label_ex_hash_key_sbps">ハッシュキー</a></th>
1287 <td><input name="hash_key" type="text" id="hash_key_sbps" value="<?php echo esc_attr( $hash_key ); ?>" class="regular-text" maxlength="40" /></td>
1288 </tr>
1289 <tr id="ex_hash_key_sbps" class="explanation"><td colspan="2">契約時にSBペイメントサービスから発行されるハッシュキー(半角英数)</td></tr>
1290 <tr>
1291 <th><a class="explanation-label" id="label_ex_3des_key_sbps">3DES<br />暗号化キー</a></th>
1292 <td><input name="3des_key" type="text" id="3des_key_sbps" value="<?php echo esc_attr( $threedes_key ); ?>" class="regular-text" maxlength="40" /></td>
1293 </tr>
1294 <tr id="ex_3des_key_sbps" class="explanation"><td colspan="2">契約時にSBペイメントサービスから発行される 3DES 暗号化キー(半角英数)</td></tr>
1295 <tr>
1296 <th><a class="explanation-label" id="label_ex_3desinit_key_sbps">3DES<br />初期化キー</a></th>
1297 <td><input name="3desinit_key" type="text" id="3desinit_key_sbps" value="<?php echo esc_attr( $threedesinit_key ); ?>" class="regular-text" maxlength="40" /></td>
1298 </tr>
1299 <tr id="ex_3desinit_key_sbps" class="explanation"><td colspan="2">契約時にSBペイメントサービスから発行される 3DES 初期化キー(半角英数)</td></tr>
1300 <tr>
1301 <th><a class="explanation-label" id="label_ex_ope_sbps"><?php esc_html_e( 'Operation Environment', 'usces' ); ?></a></th>
1302 <td><label><input name="ope" type="radio" id="ope_sbps_1" value="check"<?php checked( $acting_opts['ope'], 'check' ); ?> /><span>接続支援サイト</span></label><br />
1303 <label><input name="ope" type="radio" id="ope_sbps_2" value="test"<?php checked( $acting_opts['ope'], 'test' ); ?> /><span>テスト環境</span></label><br />
1304 <label><input name="ope" type="radio" id="ope_sbps_3" value="public"<?php checked( $acting_opts['ope'], 'public' ); ?> /><span>本番環境</span></label>
1305 </td>
1306 </tr>
1307 <tr id="ex_ope_sbps" class="explanation"><td colspan="2"><?php esc_html_e( 'Switch the operating environment.', 'usces' ); ?></td></tr>
1308 </table>
1309 <table class="settle_table">
1310 <tr>
1311 <th>クレジットカード決済</th>
1312 <td><label><input name="card_activate" type="radio" class="card_activate_sbps" id="card_activate_sbps_1" value="on"<?php checked( $acting_opts['card_activate'], 'on' ); ?> /><span>リンク型で利用する</span></label><br />
1313 <label><input name="card_activate" type="radio" class="card_activate_sbps" id="card_activate_sbps_2" value="token"<?php checked( $acting_opts['card_activate'], 'token' ); ?> /><span>API 型で利用する</span></label><br />
1314 <label><input name="card_activate" type="radio" class="card_activate_sbps" id="card_activate_sbps_0" value="off"<?php checked( $acting_opts['card_activate'], 'off' ); ?> /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1315 </td>
1316 </tr>
1317 <tr class="card_token_sbps">
1318 <th><a class="explanation-label" id="label_ex_cust_manage_sbps">クレジットカード�
1319 報保存</a></th>
1320 <td><label><input name="cust_manage" type="radio" id="cust_manage_sbps_1" value="on"<?php checked( $acting_opts['cust_manage'], 'on' ); ?> /><span>保存する</span></label><br />
1321 <label><input name="cust_manage" type="radio" id="cust_manage_sbps_2" value="choice"<?php checked( $acting_opts['cust_manage'], 'choice' ); ?> /><span>会員が選択して保存する</span></label><br />
1322 <label><input name="cust_manage" type="radio" id="cust_manage_sbps_0" value="off"<?php checked( $acting_opts['cust_manage'], 'off' ); ?> /><span>保存しない</span></label>
1323 </td>
1324 </tr>
1325 <?php
1326 $cust_manage_msg = '';
1327 if ( defined( 'WCEX_DLSELLER' ) ) {
1328 $cust_manage_msg = '自動継続課金をご利用の場合は「保存する」を選択してください。';
1329 } elseif ( defined( 'WCEX_AUTO_DELIVERY' ) ) {
1330 $cust_manage_msg = '定期購�
1331 �をご利用の場合は「保存する」を選択してください。';
1332 }
1333 ?>
1334 <tr id="ex_cust_manage_sbps" class="explanation card_token_sbps"><td colspan="2">クレジットカード�
1335 報お預かりサービスを利用して、会員のカード�
1336 報をSBペイメントサービスに保存します。保存する場合は、基本設定の「会員システム」を「利用する」に設定してください。<?php echo esc_html( $cust_manage_msg ); ?></td></tr>
1337 <tr class="card_link_token_sbps">
1338 <th><a class="explanation-label" id="label_ex_sales_sbps">売上方式</a></th>
1339 <td><label><input name="sales" type="radio" id="sales_sbps_manual" value="manual"<?php checked( $acting_opts['sales'], 'manual' ); ?> /><span>指定売上(仮売上)</span></label><br />
1340 <label><input name="sales" type="radio" id="sales_sbps_auto" value="auto"<?php checked( $acting_opts['sales'], 'auto' ); ?> /><span>自動売上(実売上)</span></label>
1341 </td>
1342 </tr>
1343 <tr id="ex_sales_sbps" class="explanation card_link_token_sbps"><td colspan="2">「指定売上」の場合は、決済時には与信のみ行い、Welcart の管理画面から手動で売上処理を行います。「自動売上」の場合は、決済時に即時売上計上されます。</td></tr>
1344 <?php if ( defined( 'WCEX_DLSELLER' ) ) : ?>
1345 <tr class="card_link_token_sbps">
1346 <th><a class="explanation-label" id="label_ex_sales_dlseller_sbps">自動継続課金売上方式</a></th>
1347 <td><label><input name="sales_dlseller" type="radio" id="sales_dlseller_sbps_manual" value="manual"<?php checked( $acting_opts['sales_dlseller'], 'manual' ); ?> /><span>指定売上(仮売上)</span></label><br />
1348 <label><input name="sales_dlseller" type="radio" id="sales_dlseller_sbps_auto" value="auto"<?php checked( $acting_opts['sales_dlseller'], 'auto' ); ?> /><span>自動売上(実売上)</span></label>
1349 </td>
1350 </tr>
1351 <tr id="ex_sales_dlseller_sbps" class="explanation card_link_token_sbps"><td colspan="2">自動継続課金(要 WCEX DLSeller)時の売上方式。</td></tr>
1352 <tr class="card_link_token_sbps">
1353 <th><a class="explanation-label" id="label_ex_auto_settlement_mail_sbps"><?php esc_html_e( 'Automatic Continuing Charging Completion Mail', 'usces' ); /* 自動継続課金完了メール */ ?></a></th>
1354 <td><label><input name="auto_settlement_mail" type="radio" id="auto_settlement_mail_sbps_1" value="on"<?php checked( $acting_opts['auto_settlement_mail'], 'on' ); ?> /><span><?php esc_html_e( 'Send', 'usces' ); ?></span></label><br />
1355 <label><input name="auto_settlement_mail" type="radio" id="auto_settlement_mail_sbps_0" value="off"<?php checked( $acting_opts['auto_settlement_mail'], 'off' ); ?> /><span><?php esc_html_e( "Don't send", 'usces' ); ?></span></label>
1356 </td>
1357 </tr>
1358 <tr id="ex_auto_settlement_mail_sbps" class="explanation card_link_token_sbps"><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>
1359 <?php endif; ?>
1360 <tr>
1361 <th><a class="explanation-label" id="label_ex_basic_id_sbps">Basic認証ID</a></th>
1362 <td><input name="basic_id" type="text" id="basic_id_sbps" value="<?php echo esc_attr( $basic_id ); ?>" class="regular-text" maxlength="40" /></td>
1363 </tr>
1364 <tr id="ex_basic_id_sbps" class="explanation"><td colspan="2">契約時にSBペイメントサービスから発行される Basic認証ID(半角数字)</td></tr>
1365 <tr>
1366 <th><a class="explanation-label" id="label_ex_basic_password_sbps">Basic認証Password</a></th>
1367 <td><input name="basic_password" type="text" id="basic_password_sbps" value="<?php echo esc_attr( $basic_password ); ?>" class="regular-text" maxlength="40" /></td>
1368 </tr>
1369 <tr id="ex_basic_password_sbps" class="explanation"><td colspan="2">契約時にSBペイメントサービスから発行される Basic認証 Password(半角英数)</td></tr>
1370 <tr class="card_link_sbps">
1371 <th>3Dセキュア</th>
1372 <td><label><input name="3d_secure" type="radio" id="threed_secure_sbps_1" value="on"<?php checked( $acting_opts['3d_secure'], 'on' ); ?> /><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br />
1373 <label><input name="3d_secure" type="radio" id="threed_secure_sbps_2" value="off"<?php checked( $acting_opts['3d_secure'], 'off' ); ?> /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1374 </td>
1375 </tr>
1376 </table>
1377 <table class="settle_table">
1378 <tr>
1379 <th>コンビニ決済</th>
1380 <td><label><input name="conv_activate" type="radio" class="conv_activate_sbps" id="conv_activate_sbps_1" value="on"<?php checked( $acting_opts['conv_activate'], 'on' ); ?> /><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br />
1381 <label><input name="conv_activate" type="radio" class="conv_activate_sbps" id="conv_activate_sbps_2" value="off"<?php checked( $acting_opts['conv_activate'], 'off' ); ?> /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1382 </td>
1383 </tr>
1384 <tr class="conv_sbps">
1385 <th><a class="explanation-label" id="label_ex_conv_limit_sbps"><?php esc_html_e( 'Payment due days', 'usces' ); ?></a></th>
1386 <td><input name="conv_limit" type="text" id="conv_limit" value="<?php echo esc_attr( $acting_opts['conv_limit'] ); ?>" class="small-text" /><?php esc_html_e( 'days', 'usces' ); ?>(1~59)</td>
1387 </tr>
1388 <tr id="ex_conv_limit_sbps" class="explanation"><td colspan="2">未設定の場合は申込時に設定した既定値となります。ここでの変更は、申込時に設定した既定値以�
1389 の指定が可能(既定値が14日の場合、13日まで)となります。既定値が不明な場合はSBペイメントサービスにお問い合わせください。</td></tr>
1390 </table>
1391 <table class="settle_table">
1392 <tr>
1393 <th>Pay-easy(ペイジー)決済</th>
1394 <td><label><input name="payeasy_activate" type="radio" id="payeasy_activate_sbps_1" value="on"<?php checked( $acting_opts['payeasy_activate'], 'on' ); ?> /><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br />
1395 <label><input name="payeasy_activate" type="radio" id="payeasy_activate_sbps_2" value="off"<?php checked( $acting_opts['payeasy_activate'], 'off' ); ?> /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1396 </td>
1397 </tr>
1398 </table>
1399 <table class="settle_table">
1400 <tr>
1401 <th>Yahoo! ウォレット決済</th>
1402 <td><label><input name="wallet_yahoowallet" type="radio" id="wallet_yahoowallet_sbps_1" value="on"<?php checked( $acting_opts['wallet_yahoowallet'], 'on' ); ?> /><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br />
1403 <label><input name="wallet_yahoowallet" type="radio" id="wallet_yahoowallet_sbps_2" value="off"<?php checked( $acting_opts['wallet_yahoowallet'], 'off' ); ?> /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1404 </td>
1405 </tr>
1406 <tr>
1407 <th><a class="explanation-label" id="label_ex_wallet_rakuten_sbps">楽天ペイ(オンライン決済)</a></th>
1408 <?php if ( 'on' === $acting_opts['wallet_rakuten'] ) : ?>
1409 <td><label><input name="wallet_rakuten" type="radio" id="wallet_rakuten_sbps_1" value="on"<?php checked( $acting_opts['wallet_rakuten'], 'on' ); ?> /><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br />
1410 <label><input name="wallet_rakuten" type="radio" id="wallet_rakuten_sbps_2" value="off"<?php checked( $acting_opts['wallet_rakuten'], 'off' ); ?> /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1411 </td>
1412 <?php else : ?>
1413 <td><label><input name="wallet_rakuten" type="radio" id="wallet_rakuten_sbps_1" value="on" disabled="disabled" /><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br />
1414 <label><input name="wallet_rakuten" type="radio" id="wallet_rakuten_sbps_2" value="off" checked="checked" /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1415 </td>
1416 <?php endif; ?>
1417 </tr>
1418 <tr id="ex_wallet_rakuten_sbps" class="explanation"><td colspan="2">楽天ペイの新規ご契約は終了しました。楽天ペイV2をご利用ください。</td></tr>
1419 <tr>
1420 <th>楽天ペイV2(オンライン決済)</th>
1421 <td><label><input name="wallet_rakutenv2" type="radio" id="wallet_rakutenv2_sbps_1" value="on"<?php checked( $acting_opts['wallet_rakutenv2'], 'on' ); ?> /><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br />
1422 <label><input name="wallet_rakutenv2" type="radio" id="wallet_rakutenv2_sbps_2" value="off"<?php checked( $acting_opts['wallet_rakutenv2'], 'off' ); ?> /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1423 </td>
1424 </tr>
1425 <tr>
1426 <th>PayPal 決済</th>
1427 <td><label><input name="wallet_paypal" type="radio" id="wallet_paypal_sbps_1" value="on"<?php checked( $acting_opts['wallet_paypal'], 'on' ); ?> /><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br />
1428 <label><input name="wallet_paypal" type="radio" id="wallet_paypal_sbps_2" value="off"<?php checked( $acting_opts['wallet_paypal'], 'off' ); ?> /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1429 </td>
1430 </tr>
1431 <tr>
1432 <th>Alipay 国際決済</th>
1433 <td><label><input name="wallet_alipay" type="radio" id="wallet_alipay_sbps_1" value="on"<?php checked( $acting_opts['wallet_alipay'], 'on' ); ?> /><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br />
1434 <label><input name="wallet_alipay" type="radio" id="wallet_alipay_sbps_2" value="off"<?php checked( $acting_opts['wallet_alipay'], 'off' ); ?> /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1435 </td>
1436 </tr>
1437 </table>
1438 <table class="settle_table">
1439 <tr>
1440 <th>d払い</th>
1441 <td><label><input name="mobile_docomo" type="radio" id="mobile_docomo_sbps_1" value="on"<?php checked( $acting_opts['mobile_docomo'], 'on' ); ?> /><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br />
1442 <label><input name="mobile_docomo" type="radio" id="mobile_docomo_sbps_2" value="off"<?php checked( $acting_opts['mobile_docomo'], 'off' ); ?> /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1443 </td>
1444 </tr>
1445 <tr>
1446 <th>au PAY</th>
1447 <td><label><input name="mobile_auone" type="radio" id="mobile_auone_sbps_1" value="on"<?php checked( $acting_opts['mobile_auone'], 'on' ); ?> /><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br />
1448 <label><input name="mobile_auone" type="radio" id="mobile_auone_sbps_2" value="off"<?php checked( $acting_opts['mobile_auone'], 'off' ); ?> /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1449 </td>
1450 </tr>
1451 <tr>
1452 <th>ソフトバンク<br />まとめて支払い</th>
1453 <td><label><input name="mobile_softbank2" type="radio" id="mobile_softbank2_sbps_1" value="on"<?php checked( $acting_opts['mobile_softbank2'], 'on' ); ?> /><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br />
1454 <label><input name="mobile_softbank2" type="radio" id="mobile_softbank2_sbps_2" value="off"<?php checked( $acting_opts['mobile_softbank2'], 'off' ); ?> /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1455 </td>
1456 </tr>
1457 </table>
1458 <table class="settle_table">
1459 <tr>
1460 <th>PayPay オンライン決済</th>
1461 <td><label><input name="paypay_activate" type="radio" class="paypay_activate_sbps" id="paypay_activate_sbps_1" value="on"<?php checked( $acting_opts['paypay_activate'], 'on' ); ?> /><span><?php esc_html_e( 'Use', 'usces' ); ?></span></label><br />
1462 <label><input name="paypay_activate" type="radio" class="paypay_activate_sbps" id="paypay_activate_sbps_2" value="off"<?php checked( $acting_opts['paypay_activate'], 'off' ); ?> /><span><?php esc_html_e( 'Do not Use', 'usces' ); ?></span></label>
1463 </td>
1464 </tr>
1465 <tr class="paypay_sbps">
1466 <th><a class="explanation-label" id="label_ex_paypay_sales_sbps">売上方式</a></th>
1467 <td><label><input name="paypay_sales" type="radio" id="paypay_sales_sbps_manual" value="manual"<?php checked( $acting_opts['paypay_sales'], 'manual' ); ?> /><span>指定売上(仮売上)</span></label><br />
1468 <label><input name="paypay_sales" type="radio" id="paypay_sales_sbps_auto" value="auto"<?php checked( $acting_opts['paypay_sales'], 'auto' ); ?> /><span>自動売上(実売上)</span></label>
1469 </td>
1470 </tr>
1471 <tr id="ex_paypay_sales_sbps" class="explanation paypay_sbps"><td colspan="2">「指定売上」の場合は、決済時には与信のみ行い、Welcart の管理画面から手動で売上処理を行います。「自動売上」の場合は、決済時に即時売上計上されます。</td></tr>
1472 </table>
1473 <input name="acting" type="hidden" value="sbps" />
1474 <input name="usces_option_update" type="submit" class="button button-primary" value="SBペイメントサービスの設定を更新する" />
1475 <?php
1476 wp_nonce_field( 'admin_settlement', 'wc_nonce' );
1477 ?>
1478 </form>
1479 <div class="settle_exp">
1480 <p><strong>SBペイメントサービス</strong></p>
1481 <a href="https://www.sbpayment.jp/service/partner/welcart/lp01/" target="_blank">SBペイメントサービスの詳細はこちら </a>
1482 <p>クレジットカード決済では、「API型(トークン決済方式)」と「リンク型」が選択できます。</p>
1483 <p>「API型」は、決済会社のページへは遷移せず、Welcart のページのみで決済まで完結します。デザインの統一性が保て、スムーズなチェックアウトが可能です。ただし、カード番号を扱いますので専用SSLが�
1484 須となります。�
1485 �力されたカード番号はSBペイメントサービスのシステムに送信されますので、Welcart に保存することはありません。<br />
1486 「リンク型」は、決済会社のページへ遷移してカード�
1487 報を�
1488 �力します。<br />
1489 クレジットカード決済以外の決済サービスでは、�
1490 �て「リンク型」になります。</p>
1491 <p>PayPay オンライン決済で「自動売上」を利用したい場合は、「Basic 認証ID」「Basic 認証 Password」の設定が�
1492 要です。</p>
1493 <p>尚、本番環境では、正規SSL証明書のみでのSSL通信となりますのでご注意ください。</p>
1494 <?php
1495 $wcex = '';
1496 if ( defined( 'WCEX_DLSELLER' ) ) {
1497 $wcex = '、WCEX DLSeller での自動継続課金';
1498 } elseif ( defined( 'WCEX_AUTO_DELIVERY' ) ) {
1499 $wcex = '、WCEX Auto Delivery での定期購�
1500 �';
1501 }
1502 ?>
1503 <p>※Welcart v1.9.34 以前からご利用で、「リンク型」から「API型」へ変更される場合は、SBペイメントサービスへの申請が�
1504 要となります。また、管理画面連携機能<?php echo esc_html( $wcex ); ?>を利用したい場合は、「3DES 暗号化キー」「3DES 初期化キー」「Basic 認証ID」「Basic 認証 Password」の設定が�
1505 要です。<br />
1506 各設定値がご不明な場合は、SBペイメントサービスにお問い合わせください。</p>
1507 <p>※クレジットカード決済およびPayPay オンライン決済で売上方式を「自動売上」にしていても、決済ステータスが「売上確定」にならなかったり、決済履歴にエラーが表示されている場合は、SBペイメントサービスの加盟店管理画面で売上方式が「自動売上」になっている可能性があります。SBペイメントサービスの売上方式を「指定売上」に変更してください。<br />
1508 設定方法がご不明な場合は、SBペイメントサービスにお問い合わせください。</p>
1509 </div>
1510 </div><!-- uscestabs_sbps -->
1511 <?php
1512 endif;
1513 }
1514
1515 /**
1516 * 通知処理
1517 * usces_after_cart_instant
1518 */
1519 public function acting_notice() {
1520 global $usces;
1521
1522 if ( isset( $_SERVER['REMOTE_ADDR'] ) && '61.215.213.47' === $_SERVER['REMOTE_ADDR'] ) {
1523 $post_data = file_get_contents( 'php://input' );
1524 $request_data = $this->xml2assoc( $post_data, $this->acting_paypay );
1525 if ( isset( $request_data['@attributes']['id'] ) && isset( $request_data['merchant_id'] ) && isset( $request_data['service_id'] ) && isset( $request_data['sps_transaction_id'] ) && isset( $request_data['tracking_id'] ) && isset( $request_data['pay_option_manage'] ) ) {
1526 $acting_opts = $this->get_acting_settings();
1527 if ( $acting_opts['merchant_id'] === $request_data['merchant_id'] && $acting_opts['service_id'] === $request_data['service_id'] ) {
1528 $latest_log = $this->get_acting_latest_log( 0, $request_data['tracking_id'] );
1529 if ( $latest_log && isset( $latest_log['status'] ) && 'pending' === $latest_log['status'] && isset( $latest_log['order_id'] ) ) {
1530 $attributes_id = $request_data['@attributes']['id'];
1531 if ( 'NT01-00110-311' === $attributes_id ) {
1532 $status = 'increase';
1533 } elseif ( 'NT01-00112-311' === $attributes_id ) {
1534 $status = 'expired';
1535 $request_data['amount'] = $latest_log['amount'];
1536 } else {
1537 $status = 'error';
1538 }
1539 $this->save_acting_log( $request_data, $this->acting_paypay, $status, 'OK', $latest_log['order_id'], $request_data['tracking_id'] );
1540 }
1541 die( 'OK,' );
1542 }
1543 }
1544 }
1545 }
1546
1547 /**
1548 * 管理画面決済処理
1549 * usces_action_admin_ajax
1550 */
1551 public function admin_ajax() {
1552 global $usces;
1553
1554 $mode = wp_unslash( $_POST['mode'] );
1555 $data = array();
1556
1557 switch ( $mode ) {
1558 /* クレジットカード参�
1559 � */
1560 case 'get_sbps_card':
1561 check_admin_referer( 'order_edit', 'wc_nonce' );
1562 $order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : '';
1563 $tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : '';
1564 $member_id = ( isset( $_POST['member_id'] ) ) ? wp_unslash( $_POST['member_id'] ) : '';
1565 if ( empty( $order_id ) || empty( $tracking_id ) ) {
1566 $data['status'] = 'NG';
1567 wp_send_json( $data );
1568 break;
1569 }
1570
1571 $res = '';
1572 $status = '';
1573 $reference_settlement = $this->get_settlement_status( 'sbps_card', $order_id, $tracking_id );
1574 if ( ( isset( $reference_settlement['res_result'] ) && 'OK' === $reference_settlement['res_result'] ) && ( isset( $reference_settlement['res_status'] ) && 0 === (int) $reference_settlement['res_status'] ) ) {
1575 $result = 'OK';
1576 $payment_status = $reference_settlement['res_pay_method_info']['payment_status'];
1577 switch ( $payment_status ) {
1578 case 1:/* 与信済 */
1579 $status = 'manual';
1580 break;
1581 case 2:/* 売上済 */
1582 $status = 'sales';
1583 break;
1584 case 3:/* 与信取消済 */
1585 $status = 'cancel';
1586 break;
1587 case 4:/* 返金済 */
1588 $status = 'cancel';
1589 break;
1590 default:
1591 $status = 'error';
1592 }
1593
1594 $latest_log = $this->get_acting_latest_log( $order_id, $tracking_id );
1595 if ( $status !== $latest_log['status'] ) {
1596 if ( 'cancel' === $status && 'refund' === $latest_log['status'] ) {
1597 $status = 'refund';
1598 }
1599 }
1600
1601 $class = ' card-' . $status;
1602 $status_name = $this->get_status_name( $status );
1603 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
1604 if ( 'error' !== $status ) {
1605 $amount = ( 'cancel' === $status ) ? 0 : $this->get_sales_amount( $order_id, $tracking_id );
1606 if ( 'cancel' === $status || 'refund' === $status ) {
1607 $res .= '<table class="sbps-settlement-admin-table">
1608 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
1609 <td><input type="tel" class="settlement-amount" value="' . intval( $amount ) . '" disabled="disabled" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>
1610 </tr></table>';
1611 } else {
1612 $res .= '<table class="sbps-settlement-admin-table">
1613 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
1614 <td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $amount ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $amount ) . '" /></td>
1615 </tr></table>';
1616 $res .= '<div class="sbps-settlement-admin-button">';
1617 if ( 'manual' === $status ) {
1618 $res .= '<input id="sales-settlement" type="button" class="button" value="売上確定" />';
1619 }
1620 $res .= '<input id="cancel-settlement" type="button" class="button" value="取消" />';
1621 if ( 'manual' !== $status ) {
1622 $res .= '<input id="refund-settlement" type="button" class="button" value="部分返金" />';
1623 }
1624 $res .= '</div>';
1625 }
1626 } else {
1627 $status = 'error';
1628 $status_name = $this->get_status_name( $status );
1629 $res .= '<div class="sbps-settlement-admin card-error">' . $status_name . '</div>';
1630 }
1631 } else {
1632 $result = 'NG';
1633 $latest_log = $this->get_acting_latest_log( $order_id, 0, 'ALL' );
1634 if ( 'NG' === $latest_log['result'] && 10 === strlen( $tracking_id ) ) {
1635 $cust_ref = $this->api_customer_reference( $member_id );
1636 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) {
1637 $amount = 0;
1638 $res .= '<table class="sbps-settlement-admin-table">
1639 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
1640 <td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $amount ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>
1641 </tr></table>';
1642 $res .= '<div class="sbps-settlement-admin-button">';
1643 $res .= '<input id="manual-settlement" type="button" class="button" data-trans_id="' . $tracking_id . '" value="与信済" />';
1644 $res .= '</div>';
1645 } else {
1646 $status = 'error';
1647 $status_name = $this->get_status_name( $status );
1648 $res .= '<div class="sbps-settlement-admin card-error">' . $status_name . '</div>';
1649 }
1650 } else {
1651 $status = 'error';
1652 $status_name = $this->get_status_name( $status );
1653 $res .= '<div class="sbps-settlement-admin card-error">' . $status_name . '</div>';
1654 }
1655 }
1656 $res .= $this->settlement_history( $order_id, $tracking_id );
1657 $data['status'] = $result;
1658 $data['result'] = $res;
1659 wp_send_json( $data );
1660 break;
1661
1662 /* クレジットカード与信済 */
1663 case 'manual_sbps_card':
1664 check_admin_referer( 'order_edit', 'wc_nonce' );
1665 $order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : '';
1666 $order_num = ( isset( $_POST['order_num'] ) ) ? (int) wp_unslash( $_POST['order_num'] ) : 0;
1667 $member_id = ( isset( $_POST['member_id'] ) ) ? wp_unslash( $_POST['member_id'] ) : '';
1668 $amount = ( isset( $_POST['amount'] ) ) ? wp_unslash( $_POST['amount'] ) : 0;
1669 $trans_id = ( isset( $_POST['trans_id'] ) ) ? wp_unslash( $_POST['trans_id'] ) : '';
1670 if ( empty( $order_id ) || empty( $member_id ) || empty( $amount ) || empty( $amount ) ) {
1671 $data['status'] = 'NG';
1672 wp_send_json( $data );
1673 break;
1674 }
1675
1676 $res = '';
1677 $acting_status = '';
1678 $acting_flg = 'acting_sbps_card';
1679 $tracking_id = '';
1680
1681 $acting_opts = $this->get_acting_settings();
1682 $rand = $trans_id;
1683 $cust_code = $member_id;
1684 $cust_ref = $this->api_customer_reference( $cust_code );
1685 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) {
1686 $cart = usces_get_ordercartdata( $order_id );
1687 $cart_row = current( $cart );
1688 $item_id = mb_convert_kana( $usces->getItemCode( $cart_row['post_id'] ), 'a', 'UTF-8' );
1689 $item_name = $usces->getCartItemName_byOrder( $cart_row );
1690 if ( 1 < count( $cart ) ) {
1691 $item_name .= ' ' . __( 'Others', 'usces' );
1692 }
1693 if ( 36 < mb_strlen( $item_name, 'UTF-8' ) ) {
1694 $item_name = mb_substr( $item_name, 0, 30, 'UTF-8' ) . '...';
1695 }
1696 $item_name = trim( mb_convert_encoding( $item_name, 'SJIS', 'UTF-8' ) );
1697 $free1 = $acting_flg;
1698 $order_rowno = '1';
1699 $encrypted_flg = '1';
1700 $request_date = wp_date( 'YmdHis' );
1701 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $cust_code . $rand . $item_id . $item_name . $amount . $free1 . $order_rowno . $encrypted_flg . $request_date . $acting_opts['hash_key'];
1702 $sps_hashcode = sha1( $sps_hashcode );
1703 $connection = $this->get_connection();
1704
1705 /* 決済要求 */
1706 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
1707 <sps-api-request id="ST01-00131-101">
1708 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
1709 <service_id>' . $acting_opts['service_id'] . '</service_id>
1710 <cust_code>' . $cust_code . '</cust_code>
1711 <order_id>' . $rand . '</order_id>
1712 <item_id>' . $item_id . '</item_id>
1713 <item_name>' . base64_encode( $item_name ) . '</item_name>
1714 <amount>' . $amount . '</amount>
1715 <free1>' . base64_encode( $free1 ) . '</free1>
1716 <order_rowno>' . $order_rowno . '</order_rowno>
1717 <encrypted_flg>' . $encrypted_flg . '</encrypted_flg>
1718 <request_date>' . $request_date . '</request_date>
1719 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
1720 </sps-api-request>';
1721 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
1722 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_card, $encrypted_flg );
1723 if ( isset( $response_settlement['res_result'] ) && 'OK' === $response_settlement['res_result'] ) {
1724 $sps_transaction_id = $response_settlement['res_sps_transaction_id'];
1725 $tracking_id = $response_settlement['res_tracking_id'];
1726 $request_date = wp_date( 'YmdHis' );
1727 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $sps_transaction_id . $tracking_id . $request_date . $acting_opts['hash_key'];
1728 $sps_hashcode = sha1( $sps_hashcode );
1729
1730 /* 確定要求 */
1731 $request_credit = '<?xml version="1.0" encoding="Shift_JIS"?>
1732 <sps-api-request id="ST02-00101-101">
1733 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
1734 <service_id>' . $acting_opts['service_id'] . '</service_id>
1735 <sps_transaction_id>' . $sps_transaction_id . '</sps_transaction_id>
1736 <tracking_id>' . $tracking_id . '</tracking_id>
1737 <processing_datetime></processing_datetime>
1738 <request_date>' . $request_date . '</request_date>
1739 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
1740 </sps-api-request>';
1741 $xml_credit = $this->get_xml_response( $connection['api_url'], $request_credit );
1742 $response_credit = $this->xml2assoc( $xml_credit, $this->acting_card );
1743 $response_credit = apply_filters( 'usces_filter_sbps_card_manual_log', $response_credit, $order_id );
1744 if ( isset( $response_credit['res_result'] ) ) {
1745 $status = 'manual';
1746 $result = $response_credit['res_result'];
1747 if ( 'OK' === $result ) {
1748 if ( ! isset( $response_credit['amount'] ) ) {
1749 $response_credit['amount'] = $amount;
1750 }
1751 if ( 1 < (int) $order_num ) {
1752 $this->update_acting_log( $this->acting_card, $order_id, $tracking_id, $trans_id );
1753 $this->save_acting_log( $response_credit, $this->acting_card, $status, $result, $order_id, $tracking_id );
1754 } else {
1755 $this->save_acting_log( $response_credit, $this->acting_card, $status, $result, $order_id, $tracking_id );
1756 $usces->set_order_meta_value( 'res_tracking_id', $tracking_id, $order_id );
1757 $usces->set_order_meta_value( 'wc_trans_id', $tracking_id, $order_id );
1758 if ( ! isset( $response_credit['acting'] ) ) {
1759 $response_credit['acting'] = $this->acting_card;
1760 }
1761 $usces->set_order_meta_value( $acting_flg, usces_serialize( $response_credit ), $order_id );
1762 }
1763
1764 $class = ' card-' . $status;
1765 $status_name = $this->get_status_name( $status );
1766 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
1767 $acting_status = '<span class="acting-status' . $class . '">' . $status_name . '</span>';
1768 $res .= '<table class="sbps-settlement-admin-table">
1769 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
1770 <td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $amount ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $amount ) . '" /></td>
1771 </tr></table>';
1772 $res .= '<div class="sbps-settlement-admin-button">';
1773 $res .= '<input id="sales-settlement" type="button" class="button" value="売上確定" />';
1774 if ( ! $this->is_status( array( 'cancel', 'refund' ), $order_id, $tracking_id ) ) {
1775 $res .= '<input id="cancel-settlement" type="button" class="button" value="取消" />';
1776 }
1777 $res .= '</div>';
1778 } else {
1779 $usces->set_order_meta_value( 'trans_id', $rand, $order_id );
1780 $this->save_acting_log( $response_credit, $this->acting_card, $status, $response_credit['res_result'], $order_id, $tracking_id );
1781 $status = $response_credit['res_result'];
1782 $class = ' card-' . $status;
1783 $status_name = $this->get_status_name( $status );
1784 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
1785 }
1786 } else {
1787 $result = 'NG';
1788 $status = 'error';
1789 $status_name = $this->get_status_name( $status );
1790 $res .= '<div class="sbps-settlement-admin card-error">' . $status_name . '</div>';
1791 }
1792 } else {
1793 $result = 'NG';
1794 $status = 'error';
1795 $status_name = $this->get_status_name( $status );
1796 $res .= '<div class="sbps-settlement-admin card-error">' . $status_name . '</div>';
1797 }
1798 } else {
1799 $result = 'NG';
1800 $status = 'error';
1801 $status_name = $this->get_status_name( $status );
1802 $res .= '<div class="sbps-settlement-admin card-error">' . $status_name . '</div>';
1803 }
1804 $res .= $this->settlement_history( $order_id, $tracking_id );
1805 $data['status'] = $result;
1806 $data['result'] = $res;
1807 $data['acting_status'] = $acting_status;
1808 $data['tracking_id'] = $tracking_id;
1809 wp_send_json( $data );
1810 break;
1811
1812 /* クレジットカード売上確定 */
1813 case 'sales_sbps_card':
1814 check_admin_referer( 'order_edit', 'wc_nonce' );
1815 $order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : '';
1816 $tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : '';
1817 $amount = ( isset( $_POST['amount'] ) ) ? wp_unslash( $_POST['amount'] ) : 0;
1818 if ( empty( $order_id ) || empty( $tracking_id ) || empty( $amount ) ) {
1819 $data['status'] = 'NG';
1820 wp_send_json( $data );
1821 break;
1822 }
1823
1824 $res = '';
1825 $acting_status = '';
1826 $acting_opts = $this->get_acting_settings();
1827 $connection = $this->get_connection();
1828 $request_date = wp_date( 'YmdHis' );
1829 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $tracking_id . $request_date . $amount . $request_date . $acting_opts['hash_key'];
1830 $sps_hashcode = sha1( $sps_hashcode );
1831
1832 /* 売上要求 */
1833 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
1834 <sps-api-request id="ST02-00201-101">
1835 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
1836 <service_id>' . $acting_opts['service_id'] . '</service_id>
1837 <tracking_id>' . $tracking_id . '</tracking_id>
1838 <processing_datetime>' . $request_date . '</processing_datetime>
1839 <pay_option_manage>
1840 <amount>' . $amount . '</amount>
1841 </pay_option_manage>
1842 <request_date>' . $request_date . '</request_date>
1843 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
1844 </sps-api-request>';
1845 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
1846 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_card );
1847 $response_settlement = apply_filters( 'usces_filter_sbps_card_sales_log', $response_settlement, $order_id );
1848 if ( isset( $response_settlement['res_result'] ) ) {
1849 $status = 'sales';
1850 $result = $response_settlement['res_result'];
1851 if ( 'OK' === $result ) {
1852 if ( ! isset( $response_settlement['amount'] ) ) {
1853 $response_settlement['amount'] = $amount;
1854 }
1855 $this->save_acting_log( $response_settlement, $this->acting_card, $status, $result, $order_id, $tracking_id );
1856 $class = ' card-' . $status;
1857 $status_name = $this->get_status_name( $status );
1858 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
1859 $acting_status = '<span class="acting-status' . $class . '">' . $status_name . '</span>';
1860 } else {
1861 $latest_log = $this->get_acting_latest_log( $order_id, $tracking_id );
1862 if ( ! isset( $response_settlement['amount'] ) ) {
1863 if ( isset( $latest_log['amount'] ) ) {
1864 $response_settlement['amount'] = $latest_log['amount'];
1865 }
1866 }
1867 $this->save_acting_log( $response_settlement, $this->acting_card, $status, $result, $order_id, $tracking_id );
1868 $status = $latest_log['status'];
1869 $class = ' card-' . $status;
1870 $status_name = $this->get_status_name( $status );
1871 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
1872 $amount = $latest_log['amount'];
1873 }
1874 $res .= '<table class="sbps-settlement-admin-table">
1875 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
1876 <td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $amount ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $amount ) . '" /></td>
1877 </tr></table>';
1878 $res .= '<div class="sbps-settlement-admin-button">';
1879 if ( 'manual' === $status ) {
1880 $res .= '<input id="sales-settlement" type="button" class="button" value="売上確定" />';
1881 }
1882 if ( ! $this->is_status( array( 'cancel', 'refund' ), $order_id, $tracking_id ) ) {
1883 $res .= '<input id="cancel-settlement" type="button" class="button" value="取消" />';
1884 if ( 'manual' !== $status ) {
1885 $res .= '<input id="refund-settlement" type="button" class="button" value="部分返金" />';
1886 }
1887 }
1888 $res .= '</div>';
1889 } else {
1890 $result = 'NG';
1891 $status = 'error';
1892 $status_name = $this->get_status_name( $status );
1893 $res .= '<div class="sbps-settlement-admin card-error">' . $status_name . '</div>';
1894 }
1895 $res .= $this->settlement_history( $order_id, $tracking_id );
1896 $data['status'] = $result;
1897 $data['result'] = $res;
1898 $data['acting_status'] = $acting_status;
1899 wp_send_json( $data );
1900 break;
1901
1902 /* クレジットカード取消 */
1903 case 'cancel_sbps_card':
1904 check_admin_referer( 'order_edit', 'wc_nonce' );
1905 $order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : '';
1906 $tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : '';
1907 if ( empty( $order_id ) || empty( $tracking_id ) ) {
1908 $data['status'] = 'NG';
1909 wp_send_json( $data );
1910 break;
1911 }
1912
1913 $res = '';
1914 $acting_status = '';
1915 $acting_opts = $this->get_acting_settings();
1916 $connection = $this->get_connection();
1917 $request_date = wp_date( 'YmdHis' );
1918 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $tracking_id . $request_date . $request_date . $acting_opts['hash_key'];
1919 $sps_hashcode = sha1( $sps_hashcode );
1920
1921 /* 取消返金要求 */
1922 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
1923 <sps-api-request id="ST02-00303-101">
1924 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
1925 <service_id>' . $acting_opts['service_id'] . '</service_id>
1926 <tracking_id>' . $tracking_id . '</tracking_id>
1927 <processing_datetime>' . $request_date . '</processing_datetime>
1928 <request_date>' . $request_date . '</request_date>
1929 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
1930 </sps-api-request>';
1931 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
1932 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_card );
1933 $response_settlement = apply_filters( 'usces_filter_sbps_card_cancel_log', $response_settlement, $order_id );
1934 if ( isset( $response_settlement['res_result'] ) ) {
1935 $status = 'cancel';
1936 $result = $response_settlement['res_result'];
1937 if ( 'OK' === $result ) {
1938 $response_settlement['amount'] = 0;
1939 $this->save_acting_log( $response_settlement, $this->acting_card, $status, $result, $order_id, $tracking_id );
1940 $class = ' card-' . $status;
1941 $status_name = $this->get_status_name( $status );
1942 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
1943 $res .= '<table class="sbps-settlement-admin-table">
1944 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
1945 <td><input type="tel" class="settlement-amount" value="0" disabled="disabled" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>
1946 </tr></table>';
1947 $acting_status = '<span class="acting-status' . $class . '">' . $status_name . '</span>';
1948 } else {
1949 $latest_log = $this->get_acting_latest_log( $order_id, $tracking_id );
1950 if ( ! isset( $response_settlement['amount'] ) ) {
1951 if ( isset( $latest_log['amount'] ) ) {
1952 $response_settlement['amount'] = $latest_log['amount'];
1953 }
1954 }
1955 $this->save_acting_log( $response_settlement, $this->acting_card, $status, $result, $order_id, $tracking_id );
1956 $status = $latest_log['status'];
1957 $class = ' card-' . $status;
1958 $status_name = $this->get_status_name( $status );
1959 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
1960 $res .= '<table class="sbps-settlement-admin-table">
1961 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
1962 <td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $latest_log['amount'] ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $latest_log['amount'] ) . '" /></td>
1963 </tr></table>';
1964 $res .= '<div class="sbps-settlement-admin-button">';
1965 if ( 'manual' === $status ) {
1966 $res .= '<input id="sales-settlement" type="button" class="button" value="売上確定" />';
1967 }
1968 if ( ! $this->is_status( array( 'cancel', 'refund' ), $order_id, $tracking_id ) ) {
1969 $res .= '<input id="cancel-settlement" type="button" class="button" value="取消" />';
1970 if ( 'manual' !== $status ) {
1971 $res .= '<input id="refund-settlement" type="button" class="button" value="部分返金" />';
1972 }
1973 }
1974 $res .= '</div>';
1975 }
1976 } else {
1977 $result = 'NG';
1978 }
1979 $res .= $this->settlement_history( $order_id, $tracking_id );
1980 $data['status'] = $result;
1981 $data['result'] = $res;
1982 $data['acting_status'] = $acting_status;
1983 wp_send_json( $data );
1984 break;
1985
1986 /* クレジットカード部分返金 */
1987 case 'refund_sbps_card':
1988 check_admin_referer( 'order_edit', 'wc_nonce' );
1989 $order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : '';
1990 $tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : '';
1991 $amount = ( isset( $_POST['amount'] ) ) ? wp_unslash( $_POST['amount'] ) : 0;
1992 if ( empty( $order_id ) || empty( $tracking_id ) || empty( $amount ) ) {
1993 $data['status'] = 'NG';
1994 wp_send_json( $data );
1995 break;
1996 }
1997
1998 $res = '';
1999 $acting_status = '';
2000 $acting_opts = $this->get_acting_settings();
2001 $connection = $this->get_connection();
2002 $request_date = wp_date( 'YmdHis' );
2003 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $tracking_id . $request_date . $amount . $request_date . $acting_opts['hash_key'];
2004 $sps_hashcode = sha1( $sps_hashcode );
2005
2006 /* 部分返金要求 */
2007 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
2008 <sps-api-request id="ST02-00307-101">
2009 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
2010 <service_id>' . $acting_opts['service_id'] . '</service_id>
2011 <tracking_id>' . $tracking_id . '</tracking_id>
2012 <processing_datetime>' . $request_date . '</processing_datetime>
2013 <pay_option_manage>
2014 <amount>' . $amount . '</amount>
2015 </pay_option_manage>
2016 <request_date>' . $request_date . '</request_date>
2017 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
2018 </sps-api-request>';
2019 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
2020 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_card );
2021 $response_settlement = apply_filters( 'usces_filter_sbps_card_refund_log', $response_settlement, $order_id );
2022 if ( isset( $response_settlement['res_result'] ) ) {
2023 $status = 'refund';
2024 $result = $response_settlement['res_result'];
2025 if ( 'OK' === $result ) {
2026 $response_settlement['amount'] = $amount * -1;
2027 $this->save_acting_log( $response_settlement, $this->acting_card, $status, $result, $order_id, $tracking_id );
2028 $class = ' card-' . $status;
2029 $status_name = $this->get_status_name( $status );
2030 $sales_amount = $this->get_sales_amount( $order_id, $tracking_id );
2031 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
2032 $res .= '<table class="sbps-settlement-admin-table">
2033 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
2034 <td><input type="tel" class="settlement-amount" value="' . intval( $sales_amount ) . '" disabled="disabled" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>
2035 </tr></table>';
2036 $acting_status = '<span class="acting-status' . $class . '">' . $status_name . '</span>';
2037 } else {
2038 $latest_log = $this->get_acting_latest_log( $order_id, $tracking_id );
2039 if ( ! isset( $response_settlement['amount'] ) ) {
2040 if ( isset( $latest_log['amount'] ) ) {
2041 $response_settlement['amount'] = $latest_log['amount'];
2042 }
2043 }
2044 $this->save_acting_log( $response_settlement, $this->acting_card, $status, $result, $order_id, $tracking_id );
2045 $status = $latest_log['status'];
2046 $class = ' card-' . $status;
2047 $status_name = $this->get_status_name( $status );
2048 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
2049 $res .= '<table class="sbps-settlement-admin-table">
2050 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
2051 <td><input type="tel" value="' . $latest_log['amount'] . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>
2052 </tr></table>';
2053 $res .= '<div class="sbps-settlement-admin-button">';
2054 if ( ! $this->is_status( array( 'cancel', 'refund' ), $order_id, $tracking_id ) ) {
2055 $res .= '<input id="cancel-settlement" type="button" class="button" value="取消" />';
2056 $res .= '<input id="refund-settlement" type="button" class="button" value="部分返金" />';
2057 }
2058 $res .= '</div>';
2059 }
2060 } else {
2061 $result = 'NG';
2062 }
2063 $res .= $this->settlement_history( $order_id, $tracking_id );
2064 $data['status'] = $result;
2065 $data['result'] = $res;
2066 $data['acting_status'] = $acting_status;
2067 wp_send_json( $data );
2068 break;
2069
2070 /* クレジットカード決済エラー */
2071 case 'error_sbps_card':
2072 break;
2073
2074 /* 継続課金�
2075 報更新 */
2076 case 'continuation_update':
2077 check_admin_referer( 'order_edit', 'wc_nonce' );
2078 $order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : '';
2079 $member_id = ( isset( $_POST['member_id'] ) ) ? wp_unslash( $_POST['member_id'] ) : '';
2080 $contracted_year = ( isset( $_POST['contracted_year'] ) ) ? wp_unslash( $_POST['contracted_year'] ) : '';
2081 $contracted_month = ( isset( $_POST['contracted_month'] ) ) ? wp_unslash( $_POST['contracted_month'] ) : '';
2082 $contracted_day = ( isset( $_POST['contracted_day'] ) ) ? wp_unslash( $_POST['contracted_day'] ) : '';
2083 $charged_year = ( isset( $_POST['charged_year'] ) ) ? wp_unslash( $_POST['charged_year'] ) : '';
2084 $charged_month = ( isset( $_POST['charged_month'] ) ) ? wp_unslash( $_POST['charged_month'] ) : '';
2085 $charged_day = ( isset( $_POST['charged_day'] ) ) ? wp_unslash( $_POST['charged_day'] ) : '';
2086 $price = ( isset( $_POST['price'] ) ) ? wp_unslash( $_POST['price'] ) : 0;
2087 $status = ( isset( $_POST['status'] ) ) ? wp_unslash( $_POST['status'] ) : '';
2088
2089 $continue_data = $this->get_continuation_data( $member_id, $order_id );
2090 if ( ! $continue_data ) {
2091 $data['status'] = 'NG';
2092 wp_send_json( $data );
2093 break;
2094 }
2095
2096 /* 継続中→停止 */
2097 if ( 'continuation' === $continue_data['status'] && 'cancellation' === $status ) {
2098 $this->update_continuation_data( $member_id, $order_id, $continue_data, true );
2099 } else {
2100 if ( ! empty( $contracted_year ) && ! empty( $contracted_month ) && ! empty( $contracted_day ) ) {
2101 $contracted_date = ( empty( $continue_data['contractedday'] ) ) ? dlseller_next_contracting( $order_id ) : $continue_data['contractedday'];
2102 if ( $contracted_date ) {
2103 $new_contracted_date = $contracted_year . '-' . $contracted_month . '-' . $contracted_day;
2104 if ( ! $this->isdate( $new_contracted_date ) ) {
2105 $data['status'] = 'NG';
2106 $data['message'] = __( 'Next contract renewal date is incorrect.', 'dlseller' );
2107 wp_send_json( $data );
2108 }
2109 }
2110 } else {
2111 $new_contracted_date = '';
2112 }
2113 $new_charged_date = $charged_year . '-' . $charged_month . '-' . $charged_day;
2114 if ( ! $this->isdate( $new_charged_date ) ) {
2115 $data['status'] = 'NG';
2116 $data['message'] = __( 'Next settlement date is incorrect.', 'dlseller' );
2117 wp_send_json( $data );
2118 }
2119 $tomorrow = date_i18n( 'Y-m-d', strtotime( '+1 day' ) );
2120 if ( $new_charged_date < $tomorrow ) {
2121 $data['status'] = 'NG';
2122 $data['message'] = sprintf( __( 'The next settlement date must be after %s.', 'dlseller' ), $tomorrow );
2123 wp_send_json( $data );
2124 }
2125 $continue_data['contractedday'] = $new_contracted_date;
2126 $continue_data['chargedday'] = $new_charged_date;
2127 $continue_data['price'] = usces_crform( $price, false, false, 'return', false );
2128 $continue_data['status'] = $status;
2129 $this->update_continuation_data( $member_id, $order_id, $continue_data );
2130 }
2131 $data['status'] = 'OK';
2132 wp_send_json( $data );
2133 break;
2134
2135 /* PayPay参�
2136 � */
2137 case 'get_sbps_paypay':
2138 check_admin_referer( 'order_edit', 'wc_nonce' );
2139 $order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : '';
2140 $tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : '';
2141 if ( empty( $order_id ) || empty( $tracking_id ) ) {
2142 $data['status'] = 'NG';
2143 wp_send_json( $data );
2144 break;
2145 }
2146
2147 $res = '';
2148 $status = '';
2149 $reference_settlement = $this->get_settlement_status( 'sbps_paypay', $order_id, $tracking_id );
2150 if ( ( isset( $reference_settlement['res_result'] ) && 'OK' === $reference_settlement['res_result'] ) && ( isset( $reference_settlement['res_status'] ) && 0 === (int) $reference_settlement['res_status'] ) ) {
2151 $result = 'OK';
2152 $payment_status = $reference_settlement['res_pay_method_info']['payment_status'];
2153 switch ( $payment_status ) {
2154 case 1:/* 与信済 */
2155 $status = 'manual';
2156 break;
2157 case 0:/* 処理中 */
2158 case 2:/* 売上処理中 */
2159 $status = 'pending';
2160 break;
2161 case 3:/* �
2162 �金済(売上済) */
2163 $status = 'sales';
2164 break;
2165 case 4:/* 与信取消済 */
2166 case 5:/* 返金済 */
2167 $status = 'cancel';
2168 break;
2169 case 9:/* 処理エラー */
2170 $status = 'error';
2171 break;
2172 }
2173
2174 $latest_log = $this->get_acting_latest_log( $order_id, $tracking_id );
2175 if ( $status !== $latest_log['status'] ) {
2176 if ( 'cancel' === $status && 'refund' === $latest_log['status'] ) {
2177 $status = 'refund';
2178 }
2179 }
2180
2181 $class = ' paypay-' . $status;
2182 $status_name = $this->get_status_name( $status );
2183 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
2184 if ( 'pending' !== $status && 'error' !== $status ) {
2185 $amount = ( 'cancel' === $status ) ? 0 : $this->get_sales_amount( $order_id, $tracking_id );
2186 if ( 'cancel' === $status || 'refund' === $status ) {
2187 $res .= '<table class="sbps-settlement-admin-table">
2188 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
2189 <td><input type="tel" class="settlement-amount" value="' . intval( $amount ) . '" disabled="disabled" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>
2190 </tr></table>';
2191 } else {
2192 $res .= '<table class="sbps-settlement-admin-table">
2193 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
2194 <td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $amount ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $amount ) . '" /></td>
2195 </tr></table>';
2196 $res .= '<div class="sbps-settlement-admin-button">';
2197 if ( 'manual' === $status ) {
2198 $res .= '<input id="sales-settlement" type="button" class="button" value="売上確定" />';
2199 }
2200 $res .= '<input id="cancel-settlement" type="button" class="button" value="取消" />';
2201 if ( 'manual' !== $status ) {
2202 $res .= '<input id="refund-settlement" type="button" class="button" value="部分返金" />';
2203 }
2204 if ( ! $this->is_status( array( 'auto', 'sales', 'increase' ), $order_id, $tracking_id ) ) {
2205 $res .= '<input id="increase-settlement" type="button" class="button" value="増額売上" />';
2206 }
2207 $res .= '</div>';
2208 }
2209 } else {
2210 if ( 'pending' !== $status ) {
2211 $status = 'error';
2212 $status_name = $this->get_status_name( $status );
2213 $res .= '<div class="sbps-settlement-admin paypay-error">' . $status_name . '</div>';
2214 }
2215 }
2216 } else {
2217 $result = 'NG';
2218 $status = 'error';
2219 $status_name = $this->get_status_name( $status );
2220 $res .= '<div class="sbps-settlement-admin paypay-error">' . $status_name . '</div>';
2221 }
2222 $res .= $this->settlement_history( $order_id, $tracking_id );
2223 $data['status'] = $result;
2224 $data['result'] = $res;
2225 wp_send_json( $data );
2226 break;
2227
2228 /* PayPay売上確定 */
2229 case 'sales_sbps_paypay':
2230 check_admin_referer( 'order_edit', 'wc_nonce' );
2231 $order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : '';
2232 $tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : '';
2233 $amount = ( isset( $_POST['amount'] ) ) ? wp_unslash( $_POST['amount'] ) : 0;
2234 if ( empty( $order_id ) || empty( $tracking_id ) || empty( $amount ) ) {
2235 $data['status'] = 'NG';
2236 wp_send_json( $data );
2237 break;
2238 }
2239
2240 $res = '';
2241 $acting_status = '';
2242 $acting_opts = $this->get_acting_settings();
2243 $connection = $this->get_connection();
2244 $request_date = wp_date( 'YmdHis' );
2245 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $tracking_id . $amount . $request_date . $acting_opts['hash_key'];
2246 $sps_hashcode = sha1( $sps_hashcode );
2247
2248 /* 売上要求 */
2249 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
2250 <sps-api-request id="ST02-00201-311">
2251 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
2252 <service_id>' . $acting_opts['service_id'] . '</service_id>
2253 <tracking_id>' . $tracking_id . '</tracking_id>
2254 <pay_option_manage>
2255 <amount>' . $amount . '</amount>
2256 </pay_option_manage>
2257 <request_date>' . $request_date . '</request_date>
2258 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
2259 </sps-api-request>';
2260 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
2261 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_paypay );
2262 $response_settlement = apply_filters( 'usces_filter_sbps_paypay_sales_log', $response_settlement, $order_id );
2263 if ( isset( $response_settlement['res_result'] ) ) {
2264 $status = 'sales';
2265 $result = $response_settlement['res_result'];
2266 if ( 'OK' === $result ) {
2267 if ( ! isset( $response_settlement['amount'] ) ) {
2268 $response_settlement['amount'] = $amount;
2269 }
2270 $this->save_acting_log( $response_settlement, $this->acting_paypay, $status, $result, $order_id, $tracking_id );
2271 $class = ' paypay-' . $status;
2272 $status_name = $this->get_status_name( $status );
2273 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
2274 $acting_status = '<span class="acting-status' . $class . '">' . $status_name . '</span>';
2275 } else {
2276 $latest_log = $this->get_acting_latest_log( $order_id, $tracking_id );
2277 if ( ! isset( $response_settlement['amount'] ) ) {
2278 if ( isset( $latest_log['amount'] ) ) {
2279 $response_settlement['amount'] = $latest_log['amount'];
2280 }
2281 }
2282 $this->save_acting_log( $response_settlement, $this->acting_paypay, $status, $result, $order_id, $tracking_id );
2283 $status = $latest_log['status'];
2284 $class = ' paypay-' . $status;
2285 $status_name = $this->get_status_name( $status );
2286 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
2287 $amount = $latest_log['amount'];
2288 }
2289 $res .= '<table class="sbps-settlement-admin-table">
2290 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
2291 <td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $amount ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $amount ) . '" /></td>
2292 </tr></table>';
2293 $res .= '<div class="sbps-settlement-admin-button">';
2294 if ( 'manual' === $status ) {
2295 $res .= '<input id="sales-settlement" type="button" class="button" value="売上確定" />';
2296 }
2297 if ( ! $this->is_status( array( 'cancel', 'refund' ), $order_id, $tracking_id ) ) {
2298 $res .= '<input id="cancel-settlement" type="button" class="button" value="取消" />';
2299 if ( 'manual' !== $status ) {
2300 $res .= '<input id="refund-settlement" type="button" class="button" value="部分返金" />';
2301 }
2302 if ( ! $this->is_status( array( 'auto', 'sales', 'increase' ), $order_id, $tracking_id ) ) {
2303 $res .= '<input id="increase-settlement" type="button" class="button" value="増額売上" />';
2304 }
2305 }
2306 $res .= '</div>';
2307 } else {
2308 $result = 'NG';
2309 $status = 'error';
2310 $status_name = $this->get_status_name( $status );
2311 $res .= '<div class="sbps-settlement-admin card-error">' . $status_name . '</div>';
2312 }
2313 $res .= $this->settlement_history( $order_id, $tracking_id );
2314 $data['status'] = $result;
2315 $data['result'] = $res;
2316 $data['acting_status'] = $acting_status;
2317 wp_send_json( $data );
2318 break;
2319
2320 /* PayPay取消 */
2321 case 'cancel_sbps_paypay':
2322 check_admin_referer( 'order_edit', 'wc_nonce' );
2323 $order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : '';
2324 $tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : '';
2325 if ( empty( $order_id ) || empty( $tracking_id ) ) {
2326 $data['status'] = 'NG';
2327 wp_send_json( $data );
2328 break;
2329 }
2330
2331 $res = '';
2332 $acting_status = '';
2333 $acting_opts = $this->get_acting_settings();
2334 $connection = $this->get_connection();
2335 $encrypted_flg = '1';
2336 $request_date = wp_date( 'YmdHis' );
2337 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $tracking_id . $encrypted_flg . $request_date . $acting_opts['hash_key'];
2338 $sps_hashcode = sha1( $sps_hashcode );
2339
2340 /* 取消返金要求 */
2341 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
2342 <sps-api-request id="ST02-00303-311">
2343 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
2344 <service_id>' . $acting_opts['service_id'] . '</service_id>
2345 <tracking_id>' . $tracking_id . '</tracking_id>
2346 <encrypted_flg>' . $encrypted_flg . '</encrypted_flg>
2347 <request_date>' . $request_date . '</request_date>
2348 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
2349 </sps-api-request>';
2350 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
2351 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_paypay, $encrypted_flg );
2352 $response_settlement = apply_filters( 'usces_filter_sbps_paypay_cancel_log', $response_settlement, $order_id );
2353 if ( isset( $response_settlement['res_result'] ) ) {
2354 $status = 'cancel';
2355 $result = $response_settlement['res_result'];
2356 if ( 'OK' === $result ) {
2357 $response_settlement['amount'] = 0;
2358 $this->save_acting_log( $response_settlement, $this->acting_paypay, $status, $result, $order_id, $tracking_id );
2359 $class = ' paypay-' . $status;
2360 $status_name = $this->get_status_name( $status );
2361 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
2362 $acting_status = '<span class="acting-status' . $class . '">' . $status_name . '</span>';
2363 $res .= '<table class="sbps-settlement-admin-table">
2364 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
2365 <td><input type="tel" class="settlement-amount" value="0" disabled="disabled" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>
2366 </tr></table>';
2367 $acting_status = '<span class="acting-status' . $class . '">' . $status_name . '</span>';
2368 } else {
2369 $latest_log = $this->get_acting_latest_log( $order_id, $tracking_id );
2370 if ( ! isset( $response_settlement['amount'] ) ) {
2371 if ( isset( $latest_log['amount'] ) ) {
2372 $response_settlement['amount'] = $latest_log['amount'];
2373 }
2374 }
2375 $this->save_acting_log( $response_settlement, $this->acting_paypay, $status, $result, $order_id, $tracking_id );
2376 $status = $latest_log['status'];
2377 $class = ' paypay-' . $status;
2378 $status_name = $this->get_status_name( $status );
2379 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
2380 $res .= '<table class="sbps-settlement-admin-table">
2381 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
2382 <td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $latest_log['amount'] ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $latest_log['amount'] ) . '" /></td>
2383 </tr></table>';
2384 $res .= '<div class="sbps-settlement-admin-button">';
2385 if ( 'manual' === $status ) {
2386 $res .= '<input id="sales-settlement" type="button" class="button" value="売上確定" />';
2387 }
2388 if ( ! $this->is_status( array( 'cancel', 'refund' ), $order_id, $tracking_id ) ) {
2389 $res .= '<input id="cancel-settlement" type="button" class="button" value="取消" />';
2390 if ( 'manual' !== $status ) {
2391 $res .= '<input id="refund-settlement" type="button" class="button" value="部分返金" />';
2392 }
2393 if ( ! $this->is_status( array( 'auto', 'sales', 'increase' ), $order_id, $tracking_id ) ) {
2394 $res .= '<input id="increase-settlement" type="button" class="button" value="増額売上" />';
2395 }
2396 }
2397 $res .= '</div>';
2398 }
2399 } else {
2400 $result = 'NG';
2401 }
2402 $res .= $this->settlement_history( $order_id, $tracking_id );
2403 $data['status'] = $result;
2404 $data['result'] = $res;
2405 $data['acting_status'] = $acting_status;
2406 wp_send_json( $data );
2407 break;
2408
2409 /* PayPay返金 */
2410 case 'refund_sbps_paypay':
2411 check_admin_referer( 'order_edit', 'wc_nonce' );
2412 $order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : '';
2413 $tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : '';
2414 $amount = ( isset( $_POST['amount'] ) ) ? wp_unslash( $_POST['amount'] ) : 0;
2415 if ( empty( $order_id ) || empty( $tracking_id ) || empty( $amount ) ) {
2416 $data['status'] = 'NG';
2417 wp_send_json( $data );
2418 break;
2419 }
2420
2421 $res = '';
2422 $acting_status = '';
2423 $acting_opts = $this->get_acting_settings();
2424 $connection = $this->get_connection();
2425 $request_date = wp_date( 'YmdHis' );
2426 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $tracking_id . $amount . $request_date . $acting_opts['hash_key'];
2427 $sps_hashcode = sha1( $sps_hashcode );
2428
2429 /* 返金要求 */
2430 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
2431 <sps-api-request id="ST02-00306-311">
2432 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
2433 <service_id>' . $acting_opts['service_id'] . '</service_id>
2434 <tracking_id>' . $tracking_id . '</tracking_id>
2435 <pay_option_manage>
2436 <amount>' . $amount . '</amount>
2437 </pay_option_manage>
2438 <request_date>' . $request_date . '</request_date>
2439 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
2440 </sps-api-request>';
2441 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
2442 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_paypay );
2443 $response_settlement = apply_filters( 'usces_filter_sbps_paypay_refund_log', $response_settlement, $order_id );
2444 if ( isset( $response_settlement['res_result'] ) ) {
2445 $status = 'refund';
2446 $result = $response_settlement['res_result'];
2447 if ( 'OK' === $result ) {
2448 $response_settlement['amount'] = $amount * -1;
2449 $this->save_acting_log( $response_settlement, $this->acting_paypay, $status, $result, $order_id, $tracking_id );
2450 $class = ' paypay-' . $status;
2451 $status_name = $this->get_status_name( $status );
2452 $sales_amount = $this->get_sales_amount( $order_id, $tracking_id );
2453 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
2454 $res .= '<table class="sbps-settlement-admin-table">
2455 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
2456 <td><input type="tel" class="settlement-amount" value="' . intval( $sales_amount ) . '" disabled="disabled" />' . __( usces_crcode( 'return' ), 'usces' ) . '</td>
2457 </tr></table>';
2458 $acting_status = '<span class="acting-status' . $class . '">' . $status_name . '</span>';
2459 } else {
2460 $latest_log = $this->get_acting_latest_log( $order_id, $tracking_id );
2461 if ( ! isset( $response_settlement['amount'] ) ) {
2462 if ( isset( $latest_log['amount'] ) ) {
2463 $response_settlement['amount'] = $latest_log['amount'];
2464 }
2465 }
2466 $this->save_acting_log( $response_settlement, $this->acting_paypay, $status, $result, $order_id, $tracking_id );
2467 $status = $latest_log['status'];
2468 $class = ' paypay-' . $status;
2469 $status_name = $this->get_status_name( $status );
2470 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
2471 $res .= '<table class="sbps-settlement-admin-table">
2472 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
2473 <td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $latest_log['amount'] ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $latest_log['amount'] ) . '" /></td>
2474 </tr></table>';
2475 $res .= '<div class="sbps-settlement-admin-button">';
2476 if ( ! $this->is_status( array( 'cancel', 'refund' ), $order_id, $tracking_id ) ) {
2477 $res .= '<input id="cancel-settlement" type="button" class="button" value="取消" />';
2478 if ( 'manual' !== $status ) {
2479 $res .= '<input id="refund-settlement" type="button" class="button" value="部分返金" />';
2480 }
2481 if ( ! $this->is_status( array( 'auto', 'sales', 'increase' ), $order_id, $tracking_id ) ) {
2482 $res .= '<input id="increase-settlement" type="button" class="button" value="増額売上" />';
2483 }
2484 }
2485 $res .= '</div>';
2486 }
2487 } else {
2488 $result = 'NG';
2489 }
2490 $res .= $this->settlement_history( $order_id, $tracking_id );
2491 $data['status'] = $result;
2492 $data['result'] = $res;
2493 $data['acting_status'] = $acting_status;
2494 wp_send_json( $data );
2495 break;
2496
2497 /* PayPay増額売上 */
2498 case 'increase_sbps_paypay':
2499 check_admin_referer( 'order_edit', 'wc_nonce' );
2500 $order_id = ( isset( $_POST['order_id'] ) ) ? wp_unslash( $_POST['order_id'] ) : '';
2501 $tracking_id = ( isset( $_POST['tracking_id'] ) ) ? wp_unslash( $_POST['tracking_id'] ) : '';
2502 $amount = ( isset( $_POST['amount'] ) ) ? wp_unslash( $_POST['amount'] ) : 0;
2503 if ( empty( $order_id ) || empty( $tracking_id ) || empty( $amount ) ) {
2504 $data['status'] = 'NG';
2505 wp_send_json( $data );
2506 break;
2507 }
2508
2509 $res = '';
2510 $acting_status = '';
2511 $acting_opts = $this->get_acting_settings();
2512 $connection = $this->get_connection();
2513 $request_date = wp_date( 'YmdHis' );
2514 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $tracking_id . $amount . $request_date . $acting_opts['hash_key'];
2515 $sps_hashcode = sha1( $sps_hashcode );
2516
2517 /* 売上要求 */
2518 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
2519 <sps-api-request id="ST02-00201-311">
2520 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
2521 <service_id>' . $acting_opts['service_id'] . '</service_id>
2522 <tracking_id>' . $tracking_id . '</tracking_id>
2523 <pay_option_manage>
2524 <amount>' . $amount . '</amount>
2525 </pay_option_manage>
2526 <request_date>' . $request_date . '</request_date>
2527 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
2528 </sps-api-request>';
2529 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
2530 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_paypay );
2531 $response_settlement = apply_filters( 'usces_filter_sbps_paypay_increase_log', $response_settlement, $order_id );
2532 if ( isset( $response_settlement['res_result'] ) ) {
2533 $result = $response_settlement['res_result'];
2534 if ( 'OK' === $result ) {
2535 if ( ! isset( $response_settlement['amount'] ) ) {
2536 $response_settlement['amount'] = $amount;
2537 }
2538 $status = 'increase';
2539 $this->save_acting_log( $response_settlement, $this->acting_paypay, $status, $result, $order_id, $tracking_id );
2540 $class = ' paypay-' . $status;
2541 $status_name = $this->get_status_name( $status );
2542 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
2543 $res .= '<table class="sbps-settlement-admin-table">
2544 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
2545 <td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $amount ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $amount ) . '" /></td>
2546 </tr></table>';
2547 $res .= '<div class="sbps-settlement-admin-button">';
2548 $res .= '<input id="sales-settlement" type="button" class="button" value="売上確定" />';
2549 $res .= '<input id="cancel-settlement" type="button" class="button" value="取消" />';
2550 $res .= '</div>';
2551 $acting_status = '<span class="acting-status' . $class . '">' . $status_name . '</span>';
2552 } elseif ( 'AC' === $result ) {
2553 $status = 'pending';
2554 if ( ! isset( $response_settlement['amount'] ) ) {
2555 $response_settlement['amount'] = $amount;
2556 }
2557 $this->save_acting_log( $response_settlement, $this->acting_paypay, $status, $result, $order_id, $tracking_id );
2558 $class = ' paypay-' . $status;
2559 $status_name = $this->get_status_name( $status );
2560 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
2561 $acting_status = '<span class="acting-status' . $class . '">' . $status_name . '</span>';
2562 } else {
2563 if ( ! isset( $response_settlement['amount'] ) ) {
2564 $response_settlement['amount'] = $amount;
2565 }
2566 $this->save_acting_log( $response_settlement, $this->acting_paypay, 'pending', $result, $order_id, $tracking_id );
2567 $latest_log = $this->get_acting_latest_log( $order_id, $tracking_id );
2568 $status = $latest_log['status'];
2569 $class = ' paypay-' . $status;
2570 $status_name = $this->get_status_name( $status );
2571 $res .= '<div class="sbps-settlement-admin' . $class . '">' . $status_name . '</div>';
2572 $res .= '<table class="sbps-settlement-admin-table">
2573 <tr><th>' . __( 'Settlement amount', 'usces' ) . '</th>
2574 <td><input type="tel" class="settlement-amount" id="amount_change" value="' . intval( $latest_log['amount'] ) . '" />' . __( usces_crcode( 'return' ), 'usces' ) . '<input type="hidden" id="amount_original" value="' . intval( $latest_log['amount'] ) . '" /></td>
2575 </tr></table>';
2576 $res .= '<div class="sbps-settlement-admin-button">';
2577 if ( 'manual' === $status ) {
2578 $res .= '<input id="sales-settlement" type="button" class="button" value="売上確定" />';
2579 }
2580 if ( ! $this->is_status( array( 'cancel', 'refund' ), $order_id, $tracking_id ) ) {
2581 $res .= '<input id="cancel-settlement" type="button" class="button" value="取消" />';
2582 if ( 'manual' !== $status ) {
2583 $res .= '<input id="refund-settlement" type="button" class="button" value="部分返金" />';
2584 }
2585 if ( ! $this->is_status( array( 'auto', 'sales', 'increase' ), $order_id, $tracking_id ) ) {
2586 $res .= '<input id="increase-settlement" type="button" class="button" value="増額売上" />';
2587 }
2588 }
2589 $res .= '</div>';
2590 }
2591 } else {
2592 $result = 'NG';
2593 }
2594 $res .= $this->settlement_history( $order_id, $tracking_id );
2595 $data['status'] = $result;
2596 $data['result'] = $res;
2597 $data['acting_status'] = $acting_status;
2598 wp_send_json( $data );
2599 break;
2600 }
2601 }
2602
2603 /**
2604 * 受注編集画面に表示する決済�
2605 報の値整形
2606 * usces_filter_settle_info_field_value
2607 *
2608 * @param string $value Settlement information value.
2609 * @param string $key Settlement information key.
2610 * @param string $acting Acting type.
2611 * @return string
2612 */
2613 public function settlement_info_field_value( $value, $key, $acting ) {
2614 if ( ! in_array( 'acting_' . $acting, $this->pay_method ) ) {
2615 return $value;
2616 }
2617 $value = parent::settlement_info_field_value( $value, $key, $acting );
2618
2619 return $value;
2620 }
2621
2622 /**
2623 * 決済状況
2624 * usces_filter_orderlist_detail_value
2625 *
2626 * @param string $detail HTML.
2627 * @param string $value Settlement info key.
2628 * @param string $key Settlement info value.
2629 * @param int $order_id Order number.
2630 * @return array
2631 */
2632 public function orderlist_settlement_status( $detail, $value, $key, $order_id ) {
2633 global $usces;
2634
2635 if ( 'wc_trans_id' !== $key || empty( $value ) ) {
2636 return $detail;
2637 }
2638
2639 $order_data = $usces->get_order_data( $order_id, 'direct' );
2640 $payment = usces_get_payments_by_name( $order_data['order_payment_name'] );
2641 $acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : '';
2642 if ( 'acting_sbps_card' === $acting_flg || 'acting_sbps_paypay' === $acting_flg ) {
2643 $tracking_id = $usces->get_order_meta_value( 'res_tracking_id', $order_id );
2644 if ( 'acting_sbps_card' === $acting_flg && defined( 'WCEX_AUTO_DELIVERY' ) && empty( $tracking_id ) ) {
2645 $trans_id = $usces->get_order_meta_value( 'trans_id', $order_id );
2646 $regular_id = $usces->get_order_meta_value( 'regular_id', $order_id );
2647 if ( ! empty( $regular_id ) && empty( $trans_id ) ) {
2648 $acting_status = 'error';
2649 } else {
2650 $latest_log = $this->get_acting_latest_log( $order_id, 0, 'ALL' );
2651 if ( isset( $latest_log['result'] ) && 'OK' !== $latest_log['result'] ) {
2652 $cust_ref = $this->api_customer_reference( $order_data['mem_id'] );
2653 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) {
2654 } else {
2655 $acting_status = 'error';
2656 }
2657 }
2658 }
2659 } else {
2660 $acting_status = $this->get_acting_status( $order_id, $tracking_id );
2661 }
2662 if ( ! empty( $acting_status ) ) {
2663 $status_name = '';
2664 $class = '';
2665 switch ( $acting_flg ) {
2666 case 'acting_sbps_card':
2667 $class = ' card-' . $acting_status;
2668 $status_name = $this->get_status_name( $acting_status );
2669 break;
2670 case 'acting_sbps_paypay':
2671 $class = ' paypay-' . $acting_status;
2672 $status_name = $this->get_status_name( $acting_status );
2673 break;
2674 }
2675 $detail = '<td>' . $value . '<span class="acting-status' . $class . '">' . $status_name . '</span></td>';
2676 }
2677 }
2678 return $detail;
2679 }
2680
2681 /**
2682 * 受注編集画面【ステータス】
2683 * usces_action_order_edit_form_status_block_middle
2684 *
2685 * @param array $data Order data.
2686 * @param array $cscs_meta Custom field data.
2687 * @param string $action_args {
2688 * The array of Order related data.
2689 * @type string $order_action Order action mode.
2690 * @type int $order_id Order ID.
2691 * @type array $cart Cart data.
2692 * }
2693 */
2694 public function settlement_status( $data, $cscs_meta, $action_args ) {
2695 global $usces;
2696 extract( $action_args );
2697
2698 if ( 'new' !== $order_action && ! empty( $order_id ) ) {
2699 $payment = usces_get_payments_by_name( $data['order_payment_name'] );
2700 $acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : '';
2701 if ( 'acting_sbps_card' === $acting_flg || 'acting_sbps_paypay' === $acting_flg ) {
2702 $tracking_id = $usces->get_order_meta_value( 'res_tracking_id', $order_id );
2703 if ( 'acting_sbps_card' === $acting_flg && defined( 'WCEX_AUTO_DELIVERY' ) && empty( $tracking_id ) ) {
2704 $trans_id = $usces->get_order_meta_value( 'trans_id', $order_id );
2705 $regular_id = $usces->get_order_meta_value( 'regular_id', $order_id );
2706 if ( ! empty( $regular_id ) && empty( $trans_id ) ) {
2707 $acting_status = 'error';
2708 } else {
2709 $latest_log = $this->get_acting_latest_log( $order_id, 0, 'ALL' );
2710 if ( isset( $latest_log['result'] ) && 'OK' !== $latest_log['result'] ) {
2711 $cust_ref = $this->api_customer_reference( $data['mem_id'] );
2712 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) {
2713 } else {
2714 $acting_status = 'error';
2715 }
2716 }
2717 }
2718 } else {
2719 $acting_status = $this->get_acting_status( $order_id, $tracking_id );
2720 }
2721 if ( ! empty( $acting_status ) ) {
2722 $status_name = '';
2723 $class = '';
2724 switch ( $acting_flg ) {
2725 case 'acting_sbps_card':
2726 $class = ' card-' . $acting_status;
2727 $status_name = $this->get_status_name( $acting_status );
2728 break;
2729 case 'acting_sbps_paypay':
2730 $class = ' paypay-' . $acting_status;
2731 $status_name = $this->get_status_name( $acting_status );
2732 break;
2733 }
2734 if ( ! empty( $status_name ) ) {
2735 echo '
2736 <tr>
2737 <td class="label status">' . esc_html__( 'Settlement status', 'usces' ) . '</td>
2738 <td class="col1 status"><span id="settlement-status"><span class="acting-status' . esc_attr( $class ) . '">' . esc_html( $status_name ) . '</span></span></td>
2739 </tr>';
2740 }
2741 }
2742 }
2743 }
2744 }
2745
2746 /**
2747 * 受注編集画面【支払�
2748 報】
2749 * usces_action_order_edit_form_settle_info
2750 *
2751 * @param array $data Order data.
2752 * @param string $action_args {
2753 * The array of Order related data.
2754 * @type string $order_action Order action mode.
2755 * @type int $order_id Order ID.
2756 * @type array $cart Cart data.
2757 * }
2758 */
2759 public function settlement_information( $data, $action_args ) {
2760 global $usces;
2761 extract( $action_args );
2762
2763 if ( 'new' !== $order_action && ! empty( $order_id ) ) {
2764 $payment = usces_get_payments_by_name( $data['order_payment_name'] );
2765 if ( 'acting_sbps_card' === $payment['settlement'] || 'acting_sbps_paypay' === $payment['settlement'] ) {
2766 $tracking_id = $usces->get_order_meta_value( 'res_tracking_id', $order_id );
2767 if ( empty( $tracking_id ) ) {
2768 $acting_data = usces_unserialize( $usces->get_order_meta_value( $payment['settlement'], $order_id ) );
2769 $tracking_id = ( isset( $acting_data['res_tracking_id'] ) ) ? $acting_data['res_tracking_id'] : '';
2770 }
2771 if ( 'acting_sbps_card' === $payment['settlement'] && empty( $tracking_id ) ) {
2772 $tracking_id = $usces->get_order_meta_value( 'trans_id', $order_id );
2773 }
2774 if ( ! empty( $tracking_id ) ) {
2775 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' ) . '">';
2776 }
2777 }
2778 }
2779 }
2780
2781 /**
2782 * 決済�
2783 報ダイアログ
2784 * usces_action_endof_order_edit_form
2785 *
2786 * @param array $data Order data.
2787 * @param string $action_args {
2788 * The array of Order related data.
2789 * @type string $order_action Order action mode.
2790 * @type int $order_id Order ID.
2791 * @type array $cart Cart data.
2792 * }
2793 */
2794 public function settlement_dialog( $data, $action_args ) {
2795 global $usces;
2796 extract( $action_args );
2797
2798 if ( 'new' !== $order_action && ! empty( $order_id ) ) :
2799 $payment = usces_get_payments_by_name( $data['order_payment_name'] );
2800 if ( in_array( $payment['settlement'], $this->pay_method ) ) :
2801 ?>
2802 <div id="settlement_dialog" title="">
2803 <div id="settlement-response-loading"></div>
2804 <fieldset>
2805 <div id="settlement-response"></div>
2806 <input type="hidden" id="order_num">
2807 <input type="hidden" id="tracking_id">
2808 <input type="hidden" id="acting" value="<?php echo esc_attr( $payment['settlement'] ); ?>">
2809 <input type="hidden" id="error">
2810 </fieldset>
2811 </div>
2812 <?php
2813 endif;
2814 endif;
2815 }
2816
2817 /**
2818 * 受注データ登録
2819 * Call from usces_reg_orderdata() and usces_new_orderdata().
2820 * usces_action_reg_orderdata
2821 *
2822 * @param string $args {
2823 * The array of Order related data.
2824 * @type array $cart Cart data.
2825 * @type array $entry Entry data.
2826 * @type int $order_id Order ID.
2827 * @type int $member_id Member ID.
2828 * @type array $payments Payment data.
2829 * @type int $charging_type Charging type.
2830 * @type array $results Results data.
2831 * }
2832 */
2833 public function register_orderdata( $args ) {
2834 global $usces;
2835 extract( $args );
2836
2837 $acting_flg = $payments['settlement'];
2838 if ( ! in_array( $acting_flg, $this->pay_method ) ) {
2839 return;
2840 }
2841 if ( ! $entry['order']['total_full_price'] ) {
2842 return;
2843 }
2844
2845 parent::register_orderdata( $args );
2846
2847 if ( 'acting_sbps_card' === $acting_flg || 'acting_sbps_paypay' === $acting_flg ) {
2848 $acting_opts = $this->get_acting_settings();
2849 $acting = substr( $acting_flg, 7 );
2850 if ( 'acting_sbps_card' === $acting_flg ) {
2851 if ( 'on' === $acting_opts['card_activate'] && 'auto' === $acting_opts['sales'] ) {
2852 $status = 'manual';
2853 } elseif ( 'token' === $acting_opts['card_activate'] && 'auto' === $acting_opts['sales'] ) {
2854 $status = 'sales';
2855 } else {
2856 $status = $acting_opts['sales'];
2857 }
2858 } elseif ( 'acting_sbps_paypay' === $acting_flg ) {
2859 if ( 'auto' === $acting_opts['paypay_sales'] ) {
2860 $status = 'manual';
2861 } else {
2862 $status = $acting_opts['paypay_sales'];
2863 }
2864 }
2865 $result = ( isset( $results['res_result'] ) ) ? $results['res_result'] : '';
2866 $tracking_id = ( isset( $results['res_tracking_id'] ) ) ? $results['res_tracking_id'] : '';
2867 if ( ! isset( $results['amount'] ) ) {
2868 $results['amount'] = usces_crform( $entry['order']['total_full_price'], false, false, 'return', false );
2869 }
2870 $results = apply_filters( 'usces_filter_' . $acting . '_register_orderdata_log', $results, $args );
2871 $this->save_acting_log( $results, $acting, $status, $result, $order_id, $tracking_id );
2872
2873 if ( 'acting_sbps_card' === $acting_flg ) {
2874 if ( 'on' === $acting_opts['card_activate'] && 'auto' === $acting_opts['sales'] ) {
2875 $connection = $this->get_connection();
2876 $process_date = wp_date( 'Ymd' ) . '000000';
2877 $request_date = wp_date( 'YmdHis' );
2878 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $tracking_id . $process_date . $request_date . $acting_opts['hash_key'];
2879 $sps_hashcode = sha1( $sps_hashcode );
2880
2881 /* 売上要求(自動売上) */
2882 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
2883 <sps-api-request id="ST02-00201-101">
2884 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
2885 <service_id>' . $acting_opts['service_id'] . '</service_id>
2886 <tracking_id>' . $tracking_id . '</tracking_id>
2887 <processing_datetime>' . $process_date . '</processing_datetime>
2888 <request_date>' . $request_date . '</request_date>
2889 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
2890 </sps-api-request>';
2891 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
2892 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_card );
2893 if ( isset( $response_settlement['res_result'] ) ) {
2894 if ( ! isset( $response_settlement['amount'] ) ) {
2895 $response_settlement['amount'] = usces_crform( $entry['order']['total_full_price'], false, false, 'return', false );
2896 }
2897 $response_settlement = apply_filters( 'usces_filter_' . $acting . '_register_orderdata_log', $response_settlement, $args );
2898 $this->save_acting_log( $response_settlement, $this->acting_card, 'sales', $response_settlement['res_result'], $order_id, $tracking_id );
2899 }
2900 }
2901 } elseif ( 'acting_sbps_paypay' === $acting_flg ) {
2902 if ( 'auto' === $acting_opts['paypay_sales'] ) {
2903 $connection = $this->get_connection();
2904 $request_date = wp_date( 'YmdHis' );
2905 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $tracking_id . $request_date . $acting_opts['hash_key'];
2906 $sps_hashcode = sha1( $sps_hashcode );
2907
2908 /* 売上要求(自動売上) */
2909 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
2910 <sps-api-request id="ST02-00201-311">
2911 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
2912 <service_id>' . $acting_opts['service_id'] . '</service_id>
2913 <tracking_id>' . $tracking_id . '</tracking_id>
2914 <request_date>' . $request_date . '</request_date>
2915 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
2916 </sps-api-request>';
2917 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
2918 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_paypay );
2919 if ( isset( $response_settlement['res_result'] ) ) {
2920 if ( ! isset( $response_settlement['amount'] ) ) {
2921 $response_settlement['amount'] = usces_crform( $entry['order']['total_full_price'], false, false, 'return', false );
2922 }
2923 $response_settlement = apply_filters( 'usces_filter_' . $acting . '_register_orderdata_log', $response_settlement, $args );
2924 $this->save_acting_log( $response_settlement, $this->acting_paypay, 'sales', $response_settlement['res_result'], $order_id, $tracking_id );
2925 }
2926 }
2927 }
2928 }
2929 }
2930
2931 /**
2932 * 決済ログ取得
2933 *
2934 * @param int $order_id Order number.
2935 * @param string $tracking_id Tracking ID.
2936 * @param string $result Result.
2937 * @return array
2938 */
2939 public function get_acting_log( $order_id = 0, $tracking_id = 0, $result = 'OK' ) {
2940 global $wpdb;
2941
2942 if ( empty( $order_id ) ) {
2943 if ( 'OK' === $result ) {
2944 $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `tracking_id` = %s AND `result` IN ( 'OK', 'AC' ) ORDER BY `ID` DESC, `datetime` DESC",
2945 $tracking_id
2946 );
2947 } else {
2948 $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `tracking_id` = %s ORDER BY `ID` DESC, `datetime` DESC",
2949 $tracking_id
2950 );
2951 }
2952 } else {
2953 if ( empty( $tracking_id ) ) {
2954 if ( 'OK' === $result ) {
2955 $query = $wpdb->prepare(
2956 "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 ( 'OK', 'AC' ) ORDER BY `ID` DESC, `datetime` DESC",
2957 $order_id,
2958 $order_id
2959 );
2960 } else {
2961 $query = $wpdb->prepare(
2962 "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",
2963 $order_id,
2964 $order_id
2965 );
2966 }
2967 } else {
2968 if ( 'OK' === $result ) {
2969 $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `order_id` = %d AND `tracking_id` = %s AND `result` IN ( 'OK', 'AC' ) ORDER BY `ID` DESC, `datetime` DESC",
2970 $order_id,
2971 $tracking_id
2972 );
2973 } else {
2974 $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `order_id` = %d AND `tracking_id` = %s ORDER BY `ID` DESC, `datetime` DESC",
2975 $order_id,
2976 $tracking_id
2977 );
2978 }
2979 }
2980 }
2981 $log_data = $wpdb->get_results( $query, ARRAY_A );
2982 return $log_data;
2983 }
2984
2985 /**
2986 * 決済ログ出力
2987 *
2988 * @param string $log Log data.
2989 * @param string $acting Acting type.
2990 * @param string $status Status.
2991 * @param string $result Result.
2992 * @param int $order_id Order number.
2993 * @param string $tracking_id Tracking ID.
2994 * @return array
2995 */
2996 private function save_acting_log( $log, $acting, $status, $result, $order_id, $tracking_id ) {
2997 global $wpdb;
2998
2999 if ( isset( $log['amount'] ) ) {
3000 $amount = $log['amount'];
3001 } elseif ( isset( $log['pay_option_manage']['amount'] ) ) {
3002 $amount = $log['pay_option_manage']['amount'];
3003 } elseif ( isset( $log['pay_option_manage']['rec_amount'] ) ) {
3004 $amount = $log['pay_option_manage']['rec_amount'];
3005 } else {
3006 $amount = 0;
3007 }
3008 $query = $wpdb->prepare(
3009 "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 )",
3010 current_time( 'mysql' ),
3011 usces_serialize( $log ),
3012 $acting,
3013 $status,
3014 $result,
3015 $amount,
3016 $order_id,
3017 $tracking_id
3018 );
3019 $res = $wpdb->query( $query );
3020 return $res;
3021 }
3022
3023 /**
3024 * 最新処理取得
3025 *
3026 * @param int $order_id Order number.
3027 * @param string $tracking_id Tracking ID.
3028 * @param string $result Result.
3029 * @return array
3030 */
3031 public function get_acting_latest_log( $order_id, $tracking_id, $result = 'OK' ) {
3032 $latest_log = array();
3033 $log_data = $this->get_acting_log( $order_id, $tracking_id, $result );
3034 if ( $log_data ) {
3035 $data = current( $log_data );
3036 $latest_log['acting'] = $data['acting'];
3037 $latest_log['status'] = $data['status'];
3038 $latest_log['result'] = $data['result'];
3039 $latest_log['log'] = usces_unserialize( $data['log'] );
3040 $latest_log['amount'] = $data['amount'];
3041 $latest_log['order_id'] = $data['order_id'];
3042 }
3043 return $latest_log;
3044 }
3045
3046 /**
3047 * 最新決済金額取得
3048 *
3049 * @param int $order_id Order number.
3050 * @param string $tracking_id Tracking ID.
3051 * @return int $amount Sales amount.
3052 */
3053 private function get_sales_amount( $order_id, $tracking_id ) {
3054 $sales_amount = 0;
3055 $log_data = $this->get_acting_log( $order_id, $tracking_id );
3056 if ( $log_data ) {
3057 $amount = 0;
3058 $refund = 0;
3059 foreach ( (array) $log_data as $data ) {
3060 if ( 'refund' === $data['status'] ) {
3061 $refund = $data['amount'];
3062 } else {
3063 if ( $amount < $data['amount'] ) {
3064 $amount = $data['amount'];
3065 }
3066 if ( 'sales' === $data['status'] ) {
3067 $sales_amount = $data['amount'];
3068 }
3069 }
3070 }
3071 if ( 0 === (int) $sales_amount ) {
3072 $sales_amount = $amount;
3073 }
3074 if ( 0 !== (int) $refund ) {
3075 $sales_amount += $refund;
3076 }
3077 }
3078 return $sales_amount;
3079 }
3080
3081 /**
3082 * 決済処理取得
3083 *
3084 * @param int $order_id Order number.
3085 * @param string $tracking_id Tracking ID.
3086 * @return string
3087 */
3088 private function get_acting_status( $order_id, $tracking_id ) {
3089 global $wpdb;
3090
3091 $acting_status = '';
3092 $latest_log = $this->get_acting_latest_log( $order_id, $tracking_id );
3093 if ( isset( $latest_log['status'] ) ) {
3094 $acting_status = $latest_log['status'];
3095 }
3096 return $acting_status;
3097 }
3098
3099 /**
3100 * ステータスチェック
3101 *
3102 * @param array $status Status code.
3103 * @param int $order_id Order number.
3104 * @param string $tracking_id Tracking ID.
3105 * @return boolean
3106 */
3107 private function is_status( $status, $order_id, $tracking_id ) {
3108 $exist = false;
3109 $log_data = $this->get_acting_log( $order_id, $tracking_id );
3110 if ( $log_data ) {
3111 foreach ( (array) $log_data as $data ) {
3112 if ( in_array( $data['status'], $status ) ) {
3113 $exist = true;
3114 break;
3115 }
3116 }
3117 }
3118 return $exist;
3119 }
3120
3121 /**
3122 * 決済履歴
3123 *
3124 * @param int $order_id Order number.
3125 * @param string $tracking_id Tracking ID.
3126 * @return string
3127 */
3128 private function settlement_history( $order_id, $tracking_id ) {
3129 $html = '';
3130 $log_data = $this->get_acting_log( $order_id, $tracking_id, 'ALL' );
3131 if ( $log_data ) {
3132 $num = count( $log_data );
3133 $html = '<table class="settlement-history">
3134 <thead class="settlement-history-head">
3135 <tr><th></th><th>' . __( 'Processing date', 'usces' ) . '</th><th>' . __( 'Sequence number', 'usces' ) . '</th><th>' . __( 'Processing classification', 'usces' ) . '</th><th>' . __( 'Amount', 'usces' ) . '</th><th>' . __( 'Result', 'usces' ) . '</th></tr>
3136 </thead>
3137 <tbody class="settlement-history-body">';
3138 foreach ( (array) $log_data as $data ) {
3139 $log = usces_unserialize( $data['log'] );
3140 if ( 'NG' === $data['result'] ) {
3141 $err_code = ( isset( $log['res_err_code'] ) ) ? '<br>' . $log['res_err_code'] : '';
3142 $class = ' error';
3143 } else {
3144 $err_code = '';
3145 $class = '';
3146 }
3147 if ( isset( $log['res_sps_transaction_id'] ) ) {
3148 $transactionid = $log['res_sps_transaction_id'];
3149 } elseif ( isset( $log['sps_transaction_id'] ) ) {
3150 $transactionid = $log['sps_transaction_id'];
3151 } else {
3152 $transactionid = '';
3153 }
3154 $status_name = ( isset( $data['status'] ) ) ? $this->get_status_name( $data['status'] ) : '';
3155 $amount = ( isset( $log['amount'] ) ) ? usces_crform( $log['amount'], false, true, 'return', true ) : '';
3156 $html .= '<tr>
3157 <td class="num">' . $num . '</td>
3158 <td class="datetime">' . $data['datetime'] . '</td>
3159 <td class="transactionid">' . $transactionid . '</td>
3160 <td class="status">' . $status_name . '</td>
3161 <td class="amount">' . $amount . '</td>
3162 <td class="result' . $class . '">' . $data['result'] . $err_code . '</td>
3163 </tr>';
3164 $num--;
3165 }
3166 $html .= '</tbody>
3167 </table>';
3168 }
3169 return $html;
3170 }
3171
3172 /**
3173 * 処理区分名称取得
3174 *
3175 * @param string $status Status code.
3176 * @return string
3177 */
3178 private function get_status_name( $status ) {
3179 $status_name = '';
3180 switch ( $status ) {
3181 case 'manual':/* 指定売上時 */
3182 $status_name = _x( 'Authorized', 'SBPS payment status', 'usces' );
3183 break;
3184 case 'auto':/* 自動売上時 */
3185 $status_name = _x( 'Auto-captured', 'SBPS payment status', 'usces' );
3186 break;
3187 case 'sales':/* 管理画面からの売上要求実行時 */
3188 $status_name = _x( 'Captured', 'SBPS payment status', 'usces' );
3189 break;
3190 case 'refund':/* 管理画面からの部分返金処理実行時 */
3191 $status_name = _x( 'Partial refund', 'SBPS payment status', 'usces' );
3192 break;
3193 case 'increase':/* 増額売上確定通知受信時 */
3194 $status_name = _x( 'Increased capture finalized', 'SBPS payment status', 'usces' );
3195 break;
3196 case 'pending':/* 管理画面からの増額売上実行後 */
3197 $status_name = _x( 'Increased capture processing', 'SBPS payment status', 'usces' );
3198 break;
3199 case 'expired':/* 増額売上期限切れ */
3200 $status_name = _x( 'Increased capture expired', 'SBPS payment status', 'usces' );
3201 break;
3202 case 'cancel':/* 取消 */
3203 $status_name = _x( 'Canceled', 'SBPS payment status', 'usces' );
3204 break;
3205 case 'error':
3206 $status_name = _x( 'Payment processing unavailable', 'SBPS payment status', 'usces' );
3207 break;
3208 default:
3209 $status_name = $status;
3210 }
3211 return $status_name;
3212 }
3213
3214 /**
3215 * 決済結果参�
3216
3217 *
3218 * @param string $acting Acting type.
3219 * @param int $order_id Order number.
3220 * @param string $tracking_id Tracking ID.
3221 * @return array
3222 */
3223 private function get_settlement_status( $acting, $order_id, $tracking_id ) {
3224 $acting_opts = $this->get_acting_settings();
3225 if ( empty( $acting_opts['3des_key'] ) || empty( $acting_opts['3desinit_key'] ) ) {
3226 return array( 'res_result' => 'NG' );
3227 }
3228 $connection = $this->get_connection();
3229 $encrypted_flg = '1';
3230 $request_date = wp_date( 'YmdHis' );
3231 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $tracking_id . $encrypted_flg . $request_date . $acting_opts['hash_key'];
3232 $sps_hashcode = sha1( $sps_hashcode );
3233 switch ( $acting ) {
3234 case 'sbps_card':
3235 $api_id = 'MG01-00101-101';
3236 break;
3237 case 'sbps_paypay':
3238 $api_id = 'MG01-00101-311';
3239 break;
3240 default:
3241 $api_id = '';
3242 }
3243
3244 $response_settlement = array();
3245 if ( $api_id ) {
3246 /* 決済結果参�
3247 �要求 */
3248 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
3249 <sps-api-request id="' . $api_id . '">
3250 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
3251 <service_id>' . $acting_opts['service_id'] . '</service_id>
3252 <tracking_id>' . $tracking_id . '</tracking_id>
3253 <encrypted_flg>' . $encrypted_flg . '</encrypted_flg>
3254 <request_date>' . $request_date . '</request_date>
3255 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
3256 </sps-api-request>';
3257 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
3258 $response_settlement = $this->xml2assoc( $xml_settlement, $acting, $encrypted_flg );
3259 }
3260 return $response_settlement;
3261 }
3262
3263 /**
3264 * 受注データ支払方法取得
3265 *
3266 * @param int $order_id Order number.
3267 * @return string
3268 */
3269 private function get_order_acting_flg( $order_id ) {
3270 global $wpdb;
3271
3272 $query = $wpdb->prepare( "SELECT `order_payment_name` FROM {$wpdb->prefix}usces_order WHERE `ID` = %d", $order_id );
3273 $order_payment_name = $wpdb->get_var( $query );
3274 $payment = usces_get_payments_by_name( $order_payment_name );
3275 $acting_flg = ( isset( $payment['settlement'] ) ) ? $payment['settlement'] : '';
3276 return $acting_flg;
3277 }
3278
3279 /**
3280 * 会員データ削除チェック
3281 * usces_filter_delete_member_check
3282 *
3283 * @param boolean $del Deletable.
3284 * @param int $member_id Member ID.
3285 * @return boolean
3286 */
3287 public function delete_member_check( $del, $member_id ) {
3288 $cust_ref = $this->api_customer_reference( $member_id );
3289 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) {
3290 if ( usces_have_member_continue_order( $member_id ) || usces_have_member_regular_order( $member_id ) ) {
3291 $del = false;
3292 }
3293 }
3294 return $del;
3295 }
3296
3297 /**
3298 * フロントスクリプト
3299 * wp_enqueue_scripts
3300 */
3301 public function enqueue_scripts() {
3302 global $usces;
3303
3304 /* 発送・支払方法ページ、クレジットカード�
3305 報更新ページ */
3306 if ( ! is_admin() && $this->is_validity_acting( 'card' ) ) :
3307 $usces_page = ( isset( $_GET['usces_page'] ) ) ? wp_unslash( $_GET['usces_page'] ) : '';
3308 if ( ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) && 'delivery' === $usces->page ) ||
3309 ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) && ( 'member_register_settlement' === $usces_page || 'member_update_settlement' === $usces_page ) ) ) :
3310 $acting_opts = $this->get_acting_settings();
3311 if ( isset( $acting_opts['card_activate'] ) ) :
3312 $connection = $this->get_connection();
3313 ?>
3314 <script type="text/javascript" src="<?php echo esc_url( $connection['token_url'] ); ?>"></script>
3315 <?php
3316 endif;
3317 endif;
3318 endif;
3319 }
3320
3321 /**
3322 * フロントスクリプト
3323 * wp_print_footer_scripts
3324 */
3325 public function footer_scripts() {
3326 global $usces;
3327
3328 if ( ! $this->is_validity_acting( 'card' ) ) {
3329 return;
3330 }
3331
3332 parent::footer_scripts();
3333
3334 /* マイページ */
3335 if ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) :
3336
3337 /* クレジットカード�
3338 報更新ページ */
3339 $usces_page = ( isset( $_GET['usces_page'] ) ) ? wp_unslash( $_GET['usces_page'] ) : '';
3340 if ( 'member_register_settlement' === $usces_page || 'member_update_settlement' === $usces_page ) :
3341 $acting_opts = $this->get_acting_settings();
3342 wp_register_style( 'sbps-token-style', USCES_FRONT_PLUGIN_URL . '/css/sbps_token.css' );
3343 wp_enqueue_style( 'sbps-token-style' );
3344 wp_register_script( 'usces_member_sbps', USCES_FRONT_PLUGIN_URL . '/js/member_sbps.js', array( 'jquery' ), USCES_VERSION, true );
3345 $sbps_params = array();
3346 $sbps_params['sbps_merchantId'] = $acting_opts['merchant_id'];
3347 $sbps_params['sbps_serviceId'] = $acting_opts['service_id'];
3348 $sbps_params['message'] = array(
3349 'error_token' => __( 'Credit card information is not appropriate.', 'usces' ),
3350 'error_card_number' => __( 'Credit card information is not appropriate.', 'usces' ),
3351 'error_card_expym' => __( 'Credit card information is not appropriate.', 'usces' ),
3352 'error_card_seccd' => __( 'Credit card information is not appropriate.', 'usces' ),
3353 'confirm_deletion' => __( 'Are you sure delete credit card registration?', 'usces' ),
3354 );
3355 wp_localize_script( 'usces_member_sbps', 'sbps_params', $sbps_params );
3356 wp_enqueue_script( 'usces_member_sbps' );
3357 print_google_recaptcha_response( wp_unslash( $_GET['usces_page'] ), 'member-card-info', 'member_update_settlement' );
3358 else :
3359 $member = $usces->get_member();
3360 if ( usces_have_member_continue_order( $member['ID'] ) || usces_have_member_regular_order( $member['ID'] ) ) :
3361 ?>
3362 <script type="text/javascript">
3363 jQuery( document ).ready( function( $ ) {
3364 $( "input[name='deletemember']" ).css( "display", "none" );
3365 });
3366 </script>
3367 <?php
3368 endif;
3369 endif;
3370 endif;
3371 }
3372
3373 /**
3374 * 支払回数
3375 * usces_filter_delivery_secure_form_howpay
3376 *
3377 * @param string $html HTML.
3378 * @return string
3379 */
3380 public function delivery_secure_form_howpay( $html ) {
3381 $usces_page = ( isset( $_GET['usces_page'] ) ) ? wp_unslash( $_GET['usces_page'] ) : '';
3382 if ( 'member_register_settlement' === $usces_page || 'member_update_settlement' === $usces_page ) {
3383 $html = '';
3384 }
3385 return $html;
3386 }
3387
3388 /**
3389 * クレジットカード登録・変更ページ表示
3390 * usces_filter_template_redirect
3391 */
3392 public function member_update_settlement() {
3393 global $usces;
3394
3395 if ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
3396 if ( ! usces_is_membersystem_state() || ! usces_is_login() ) {
3397 return;
3398 }
3399
3400 $acting_opts = $this->get_acting_settings();
3401 if ( 'off' === $acting_opts['cust_manage'] || 'on' === $acting_opts['card_activate'] ) {
3402 return;
3403 }
3404
3405 $usces_page = ( isset( $_REQUEST['usces_page'] ) ) ? wp_unslash( $_REQUEST['usces_page'] ) : '';
3406 if ( 'member_update_settlement' === $usces_page ) {
3407 add_filter( 'usces_filter_states_form_js', array( $this, 'states_form_js' ) );
3408 $usces->page = 'member_update_settlement';
3409 $this->member_update_settlement_form();
3410 exit();
3411
3412 } elseif ( 'member_register_settlement' === $usces_page ) {
3413 add_filter( 'usces_filter_states_form_js', array( $this, 'states_form_js' ) );
3414 $usces->page = 'member_register_settlement';
3415 $this->member_update_settlement_form();
3416 exit();
3417 }
3418 }
3419 return false;
3420 }
3421
3422 /**
3423 * クレジットカード登録・変更ページ表示
3424 * usces_filter_states_form_js
3425 *
3426 * @param string $js Scripts.
3427 * @return string
3428 */
3429 public function states_form_js( $js ) {
3430 return '';
3431 }
3432
3433 /**
3434 * クレジットカード登録・変更ページリンク
3435 * usces_action_member_submenu_list
3436 */
3437 public function e_update_settlement() {
3438 global $usces;
3439
3440 $member = $usces->get_member();
3441 $html = $this->update_settlement( '', $member );
3442 echo $html; // no escape.
3443 }
3444
3445 /**
3446 * クレジットカード登録・変更ページリンク
3447 * usces_filter_member_submenu_list
3448 *
3449 * @param string $html Submenu area of the member page.
3450 * @param array $member Member information.
3451 * @return string
3452 */
3453 public function update_settlement( $html, $member ) {
3454 global $usces;
3455
3456 $acting_opts = $this->get_acting_settings();
3457 if ( 'on' === $acting_opts['cust_manage'] || 'choice' === $acting_opts['cust_manage'] ) {
3458 $cust_ref = $this->api_customer_reference( $member['ID'] );
3459 if ( 'on' === $acting_opts['card_activate'] ) {
3460 $connection = $this->get_connection();
3461 $pay_method = ( 'on' === $acting_opts['3d_secure'] ) ? 'credit3d2' : 'credit';
3462 $cust_code = $member['ID'];
3463 $success_url = USCES_MEMBER_URL . $usces->delim . 'acting=' . $this->acting_card;
3464 $cancel_url = USCES_MEMBER_URL . $usces->delim . 'acting=' . $this->acting_card;
3465 $error_url = USCES_MEMBER_URL . $usces->delim . 'acting=' . $this->acting_card;
3466 $pagecon_url = USCES_MEMBER_URL;
3467 $free1 = $this->acting_flg_card;
3468 $free_csv = '';
3469 $request_date = wp_date( 'YmdHis' );
3470 $limit_second = '600';
3471 $sps_hashcode = $pay_method . $acting_opts['merchant_id'] . $acting_opts['service_id'] . $cust_code . $success_url . $cancel_url . $error_url . $pagecon_url . $free1 . $free_csv . $request_date . $limit_second . $acting_opts['hash_key'];
3472 $sps_hashcode = sha1( $sps_hashcode );
3473 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) {
3474 $html = '<li class="settlement-update"><a href="#" onclick="redirect_form.submit(); return false;">' . __( 'Change the credit card is here >>', 'usces' ) . '</a></li>';
3475 } else {
3476 $html = '<li class="settlement-register"><a href="#" onclick="redirect_form.submit(); return false;">' . __( 'Credit card registration is here >>', 'usces' ) . '</a></li>';
3477 }
3478 $html .= '<form id="redirect_form" name="redirect_form" action="' . $connection['cust_url'] . '" method="post" accept-charset="Shift_JIS">
3479 <input type="hidden" name="pay_method" value="' . $pay_method . '" />
3480 <input type="hidden" name="merchant_id" value="' . $acting_opts['merchant_id'] . '" />
3481 <input type="hidden" name="service_id" value="' . $acting_opts['service_id'] . '" />
3482 <input type="hidden" name="cust_code" value="' . $cust_code . '" />
3483 <input type="hidden" name="success_url" value="' . $success_url . '" />
3484 <input type="hidden" name="cancel_url" value="' . $cancel_url . '" />
3485 <input type="hidden" name="error_url" value="' . $error_url . '" />
3486 <input type="hidden" name="pagecon_url" value="' . $pagecon_url . '" />
3487 <input type="hidden" name="free1" value="' . $free1 . '" />
3488 <input type="hidden" name="free_csv" value="' . $free_csv . '" />
3489 <input type="hidden" name="request_date" value="' . $request_date . '" />
3490 <input type="hidden" name="limit_second" value="' . $limit_second . '" />
3491 <input type="hidden" name="sps_hashcode" value="' . $sps_hashcode . '" />
3492 <input type="hidden" name="dummy" value="&#65533;" />
3493 </form>';
3494 } else {
3495 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) {
3496 $update_settlement_url = add_query_arg(
3497 array(
3498 'usces_page' => 'member_update_settlement',
3499 're-enter' => 1,
3500 ),
3501 USCES_MEMBER_URL
3502 );
3503 $html .= '<li class="settlement-update gotoedit"><a href="' . $update_settlement_url . '">' . __( 'Change the credit card is here >>', 'usces' ) . '</a></li>';
3504 } else {
3505 $register_settlement_url = add_query_arg(
3506 array(
3507 'usces_page' => 'member_register_settlement',
3508 're-enter' => 1,
3509 ),
3510 USCES_MEMBER_URL
3511 );
3512 $html .= '<li class="settlement-register gotoedit"><a href="' . $register_settlement_url . '">' . __( 'Credit card registration is here >>', 'usces' ) . '</a></li>';
3513 }
3514 }
3515 }
3516 return $html;
3517 }
3518
3519 /**
3520 * クレジットカード登録・変更ページ
3521 */
3522 public function member_update_settlement_form() {
3523 global $usces;
3524
3525 $member = $usces->get_member();
3526 $acting_opts = $this->get_acting_settings();
3527
3528 $script = '';
3529 $done_message = '';
3530 $html = '';
3531 $update_settlement_url = add_query_arg(
3532 array(
3533 'usces_page' => $usces->page,
3534 'settlement' => 1,
3535 're-enter' => 1,
3536 ),
3537 USCES_MEMBER_URL
3538 );
3539 $register = ( 'member_register_settlement' === $usces->page ) ? true : false;
3540
3541 $err_code = '';
3542
3543 $cust_code = $member['ID'];
3544 $cardlast4 = '';
3545 $expyy = '';
3546 $expmm = '';
3547
3548 if ( 'on' === $acting_opts['cust_manage'] || 'choice' === $acting_opts['cust_manage'] ) {
3549 $update = ( isset( $_POST['update'] ) ) ? wp_unslash( $_POST['update'] ) : '';
3550 if ( 'register' === $update ) {
3551 check_admin_referer( 'member_update_settlement', 'wc_nonce' );
3552 $verify_action = wel_verify_update_settlement( $member['ID'] );
3553 if ( ! $verify_action ) {
3554 $usces->error_message .= '<p>' . __( 'Update has been locked. Please contact the store administrator.', 'usces' ) . '</p>';
3555 } else {
3556 $connection = $this->get_connection();
3557 $sps_cust_info_return_flg = '1';
3558 $token = sanitize_text_field( wp_unslash( $_POST['token'] ) );
3559 $token_key = sanitize_text_field( wp_unslash( $_POST['tokenKey'] ) );
3560 $cardbrand_return_flg = '0';
3561 $encrypted_flg = '1';
3562 $request_date = wp_date( 'YmdHis' );
3563 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $cust_code . $sps_cust_info_return_flg . $token . $token_key . $cardbrand_return_flg . $encrypted_flg . $request_date . $acting_opts['hash_key'];
3564 $sps_hashcode = sha1( $sps_hashcode );
3565
3566 /* クレジットカード�
3567 報登録要求 */
3568 $request_cust_reg = '<?xml version="1.0" encoding="Shift_JIS"?>
3569 <sps-api-request id="MG02-00131-101">
3570 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
3571 <service_id>' . $acting_opts['service_id'] . '</service_id>
3572 <cust_code>' . $cust_code . '</cust_code>
3573 <sps_cust_info_return_flg>' . $sps_cust_info_return_flg . '</sps_cust_info_return_flg>
3574 <pay_option_manage>
3575 <token>' . $token . '</token>
3576 <token_key>' . $token_key . '</token_key>
3577 <cardbrand_return_flg>' . $cardbrand_return_flg . '</cardbrand_return_flg>
3578 </pay_option_manage>
3579 <encrypted_flg>' . $encrypted_flg . '</encrypted_flg>
3580 <request_date>' . $request_date . '</request_date>
3581 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
3582 </sps-api-request>';
3583 $xml_cust_reg = $this->get_xml_response( $connection['api_url'], $request_cust_reg );
3584 $response_cust_reg = $this->xml2assoc( $xml_cust_reg, $this->acting_card, $encrypted_flg );
3585 if ( isset( $response_cust_reg['res_result'] ) && 'OK' === $response_cust_reg['res_result'] ) {
3586 $done_message = __( 'Successfully registered.', 'usces' );
3587 $register = false;
3588 } else {
3589 if ( isset( $response_cust_reg['res_err_code'] ) ) {
3590 $err_code = ' : ' . $response_cust_reg['res_err_code'];
3591 }
3592 $done_message = __( 'Registration failed.', 'usces' ) . $err_code;
3593 }
3594 }
3595 } elseif ( 'update' === $update ) {
3596 check_admin_referer( 'member_update_settlement', 'wc_nonce' );
3597 $verify_action = wel_verify_update_settlement( $member['ID'] );
3598 if ( ! $verify_action ) {
3599 $usces->error_message .= '<p>' . __( 'Update has been locked. Please contact the store administrator.', 'usces' ) . '</p>';
3600 } else {
3601 $connection = $this->get_connection();
3602 $sps_cust_info_return_flg = '1';
3603 $token = sanitize_text_field( wp_unslash( $_POST['token'] ) );
3604 $token_key = sanitize_text_field( wp_unslash( $_POST['tokenKey'] ) );
3605 $cardbrand_return_flg = '0';
3606 $encrypted_flg = '1';
3607 $request_date = wp_date( 'YmdHis' );
3608 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $cust_code . $sps_cust_info_return_flg . $token . $token_key . $cardbrand_return_flg . $encrypted_flg . $request_date . $acting_opts['hash_key'];
3609 $sps_hashcode = sha1( $sps_hashcode );
3610
3611 /* クレジットカード�
3612 報更新要求 */
3613 $request_cust_upd = '<?xml version="1.0" encoding="Shift_JIS"?>
3614 <sps-api-request id="MG02-00132-101">
3615 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
3616 <service_id>' . $acting_opts['service_id'] . '</service_id>
3617 <cust_code>' . $cust_code . '</cust_code>
3618 <sps_cust_info_return_flg>' . $sps_cust_info_return_flg . '</sps_cust_info_return_flg>
3619 <pay_option_manage>
3620 <token>' . $token . '</token>
3621 <token_key>' . $token_key . '</token_key>
3622 <cardbrand_return_flg>' . $cardbrand_return_flg . '</cardbrand_return_flg>
3623 </pay_option_manage>
3624 <encrypted_flg>' . $encrypted_flg . '</encrypted_flg>
3625 <request_date>' . $request_date . '</request_date>
3626 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
3627 </sps-api-request>';
3628 $xml_cust_upd = $this->get_xml_response( $connection['api_url'], $request_cust_upd );
3629 $response_cust_upd = $this->xml2assoc( $xml_cust_upd, $this->acting_card, $encrypted_flg );
3630 if ( isset( $response_cust_upd['res_result'] ) && 'OK' === $response_cust_upd['res_result'] ) {
3631 $this->send_update_settlement_mail();
3632 $done_message = __( 'Successfully updated.', 'usces' );
3633 } else {
3634 if ( isset( $response_cust_upd['res_err_code'] ) ) {
3635 $err_code = ' : ' . $response_cust_upd['res_err_code'];
3636 }
3637 $done_message = __( 'Update failed.', 'usces' ) . $err_code;
3638 }
3639 }
3640 } elseif ( 'delete' === $update ) {
3641 check_admin_referer( 'member_update_settlement', 'wc_nonce' );
3642 $connection = $this->get_connection();
3643 $sps_cust_info_return_flg = '1';
3644 $request_date = wp_date( 'YmdHis' );
3645 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $cust_code . $sps_cust_info_return_flg . $request_date . $acting_opts['hash_key'];
3646 $sps_hashcode = sha1( $sps_hashcode );
3647
3648 /* クレジットカード�
3649 報削除要求 */
3650 $request_cust_del = '<?xml version="1.0" encoding="Shift_JIS"?>
3651 <sps-api-request id="MG02-00103-101">
3652 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
3653 <service_id>' . $acting_opts['service_id'] . '</service_id>
3654 <cust_code>' . $cust_code . '</cust_code>
3655 <sps_cust_info_return_flg>' . $sps_cust_info_return_flg . '</sps_cust_info_return_flg>
3656 <request_date>' . $request_date . '</request_date>
3657 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
3658 </sps-api-request>';
3659 $xml_cust_del = $this->get_xml_response( $connection['api_url'], $request_cust_del );
3660 $response_cust_del = $this->xml2assoc( $xml_cust_del, $this->acting_card );
3661 if ( isset( $response_cust_del['res_result'] ) && 'OK' === $response_cust_del['res_result'] ) {
3662 $done_message = __( 'Successfully deleted.', 'usces' );
3663 $register = true;
3664 } else {
3665 if ( isset( $response_cust_del['res_err_code'] ) ) {
3666 $err_code = ' : ' . $response_cust_del['res_err_code'];
3667 }
3668 $done_message = __( 'Deletion failed.', 'usces' ) . $err_code;
3669 }
3670 }
3671
3672 $cust_ref = $this->api_customer_reference( $cust_code );
3673 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) {
3674 $cardlast4 = substr( $cust_ref['cc_number'], -4 );
3675 $expyy = substr( $cust_ref['cc_expiration'], 0, 4 );
3676 $expmm = substr( $cust_ref['cc_expiration'], 4, 2 );
3677 }
3678 $html .= '<input name="acting" type="hidden" value="' . $this->paymod_id . '" />
3679 <table class="customer_form" id="' . $this->paymod_id . '">';
3680 if ( ! empty( $cardlast4 ) ) {
3681 $html .= '
3682 <tr>
3683 <th scope="row">' . __( 'The last four digits of your card number', 'usces' ) . '</th>
3684 <td colspan="2"><p>' . $cardlast4 . '</p></td>
3685 </tr>';
3686 }
3687 $cardno_attention = apply_filters( 'usces_filter_cardno_attention', __( '(Single-byte numbers only)', 'usces' ) . '<div class="attention">' . __( '* Please do not enter symbols or letters other than numbers such as space (blank), hyphen (-) between numbers.', 'usces' ) . '</div>' );
3688 $html .= '
3689 <tr>
3690 <th scope="row">' . __( 'card number', 'usces' ) . '</th>
3691 <td colspan="2"><input class="cc_number" id="cc_number" type="tel" maxlength="16" value="" />' . $cardno_attention . '</td>
3692 </tr>';
3693 $html .= '
3694 <tr>
3695 <th scope="row">' . __( 'Card expiration', 'usces' ) . '</th>
3696 <td colspan="2">
3697 <select class="cc_expmm" id="cc_expmm">
3698 <option value=""' . ( empty( $expmm ) ? ' selected="selected"' : '' ) . '>--</option>';
3699 for ( $i = 1; $i <= 12; $i++ ) {
3700 $html .= '
3701 <option value="' . sprintf( '%02d', $i ) . '"' . ( ( $i == (int) $expmm ) ? ' selected="selected"' : '' ) . '>' . sprintf( '%2d', $i ) . '</option>';
3702 }
3703 $html .= '
3704 </select>' . __( 'month', 'usces' ) . '&nbsp;
3705 <select class="cc_expyy" id="cc_expyy">
3706 <option value=""' . ( empty( $expyy ) ? ' selected="selected"' : '' ) . '>----</option>';
3707 for ( $i = 0; $i < 15; $i++ ) {
3708 $year = wp_date( 'Y' ) + $i;
3709 $selected = ( $year == $expyy ) ? ' selected="selected"' : '';
3710 $html .= '
3711 <option value="' . $year . '"' . $selected . '>' . $year . '</option>';
3712 }
3713 $html .= '
3714 </select>' . __( 'year', 'usces' ) . '
3715 </td>
3716 </tr>';
3717 $seccd_attention = apply_filters( 'usces_filter_seccd_attention', __( '(Single-byte numbers only)', 'usces' ) );
3718 $html .= '
3719 <tr>
3720 <th scope="row">' . __( 'security code', 'usces' ) . '</th>
3721 <td colspan="2"><input class="cc_seccd" id="cc_seccd" type="tel" maxlength="4" value="" />' . $seccd_attention . '</td>
3722 </tr>';
3723 $html .= '
3724 </table>';
3725 }
3726
3727 if ( '' !== $done_message ) {
3728 $script .= '
3729 <script type="text/javascript">
3730 jQuery.event.add( window, "load", function() {
3731 alert( "' . $done_message . '" );
3732 });
3733 </script>';
3734 }
3735 $error_message = apply_filters( 'usces_filter_member_update_settlement_error_message', $usces->error_message );
3736
3737 ob_start();
3738 get_header();
3739
3740 if ( '' !== $script ) {
3741 echo $script; // no escape due to script.
3742 }
3743 ?>
3744 <div id="content" class="two-column">
3745 <div class="catbox">
3746 <?php
3747 if ( have_posts() ) :
3748 usces_remove_filter();
3749 ?>
3750 <div class="post" id="wc_member_update_settlement">
3751 <?php if ( $register ) : ?>
3752 <h1 class="member_page_title"><?php esc_html_e( 'Credit card registration', 'usces' ); ?></h1>
3753 <?php else : ?>
3754 <h1 class="member_page_title"><?php esc_html_e( 'Credit card update', 'usces' ); ?></h1>
3755 <?php endif; ?>
3756 <div class="entry">
3757 <div id="memberpages">
3758 <div class="whitebox">
3759 <div id="memberinfo">
3760 <div class="header_explanation"></div>
3761 <div class="error_message"><?php wel_esc_script_e( $error_message ); ?></div>
3762 <form id="member-card-info" name="member_update_settlement" action="<?php echo esc_url( $update_settlement_url ); ?>" method="post" onKeyDown="if(event.keyCode == 13) {return false;}">
3763 <?php wel_esc_script_e( $html ); ?>
3764 <div class="send">
3765 <input type="hidden" name="update" value="" />
3766 <input type="hidden" name="token" id="token" value="" />
3767 <input type="hidden" name="tokenKey" id="tokenKey" value="" />
3768 <?php if ( $register ) : ?>
3769 <input type="button" id="card-register" class="card-update" data-update_mode="register" value="<?php esc_attr_e( 'Register', 'usces' ); ?>" />
3770 <?php else : ?>
3771 <input type="button" id="card-update" class="card-update" data-update_mode="update" value="<?php esc_attr_e( 'Update', 'usces' ); ?>" />
3772 <?php if ( ! usces_have_member_continue_order( $member['ID'] ) && ! usces_have_member_regular_order( $member['ID'] ) ) : ?>
3773 <input type="button" id="card-delete" class="card-delete" data-update_mode="delete" value="<?php esc_attr_e( 'Delete', 'usces' ); ?>" />
3774 <?php endif; ?>
3775 <?php endif; ?>
3776 <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 ); ?>'" />
3777 <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() ); ?>'" />
3778 </div>
3779 <?php wp_nonce_field( 'member_update_settlement', 'wc_nonce' ); ?>
3780 </form>
3781 <div class="footer_explanation"></div>
3782 </div><!-- end of memberinfo -->
3783 </div><!-- end of whitebox -->
3784 </div><!-- end of memberpages -->
3785 </div><!-- end of entry -->
3786 </div><!-- end of post -->
3787 <?php else : ?>
3788 <p><?php esc_html_e( 'Sorry, no posts matched your criteria.', 'usces' ); ?></p>
3789 <?php endif; ?>
3790 </div><!-- end of catbox -->
3791 </div><!-- end of content -->
3792 <?php
3793 $sidebar = apply_filters( 'usces_filter_member_update_settlement_page_sidebar', 'cartmember' );
3794 if ( ! empty( $sidebar ) ) {
3795 get_sidebar( $sidebar );
3796 }
3797 get_footer();
3798 $contents = ob_get_contents();
3799 ob_end_clean();
3800
3801 echo $contents; // no escape.
3802 }
3803
3804 /**
3805 * クレジットカード変更メール
3806 */
3807 public function send_update_settlement_mail() {
3808 global $usces;
3809
3810 $member = $usces->get_member();
3811 // $mail_data = $usces->options['mail_data'];
3812
3813 $subject = apply_filters( 'usces_filter_send_update_settlement_mail_subject', __( 'Confirmation of credit card update', 'usces' ), $member );
3814 $mail_header = __( 'Your credit card information has been updated on the membership page.', 'usces' ) . "\r\n\r\n";
3815 // $mail_footer = $mail_data['footer']['thankyou'];
3816 $mail_footer = get_option( 'blogname' ) . "\r\n";
3817 $name = usces_localized_name( $member['name1'], $member['name2'], 'return' );
3818
3819 $message = '--------------------------------' . "\r\n";
3820 $message .= __( 'Member ID', 'usces' ) . ' : ' . $member['ID'] . "\r\n";
3821 $message .= __( 'Name', 'usces' ) . ' : ' . sprintf( _x( '%s', 'honorific', 'usces' ), $name ) . "\r\n";
3822 $message .= __( 'e-mail adress', 'usces' ) . ' : ' . $member['mailaddress1'] . "\r\n";
3823 $message .= '--------------------------------' . "\r\n\r\n";
3824 $message .= __( 'If you have not requested this email, sorry to trouble you, but please contact us.', 'usces' ) . "\r\n\r\n";
3825 $message = apply_filters( 'usces_filter_send_update_settlement_mail_message', $message, $member );
3826 $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";
3827 $message = sprintf( __( 'Dear %s', 'usces' ), $name ) . "\r\n\r\n" . $message;
3828
3829 $send_para = array(
3830 'to_name' => sprintf( _x( '%s', 'honorific', 'usces' ), $name ),
3831 'to_address' => $member['mailaddress1'],
3832 'from_name' => get_option( 'blogname' ),
3833 'from_address' => $usces->options['sender_mail'],
3834 'reply_name' => get_option( 'blogname' ),
3835 'reply_to' => usces_get_first_order_mail(),
3836 'return_path' => $usces->options['sender_mail'],
3837 'subject' => $subject,
3838 'message' => do_shortcode( $message ),
3839 );
3840 usces_send_mail( $send_para );
3841
3842 $admin_message = $mail_header;
3843 $admin_message .= '--------------------------------' . "\r\n";
3844 $admin_message .= __( 'Member ID', 'usces' ) . ' : ' . $member['ID'] . "\r\n";
3845 $admin_message .= __( 'Name', 'usces' ) . ' : ' . sprintf( _x( '%s', 'honorific', 'usces' ), $name ) . "\r\n";
3846 $admin_message .= __( 'e-mail adress', 'usces' ) . ' : ' . $member['mailaddress1'] . "\r\n";
3847 $admin_message .= '--------------------------------' . "\r\n\r\n";
3848 if ( usces_have_member_continue_order( $member['ID'] ) ) {
3849 $admin_message .= $this->message_continue_order( $member['ID'] );
3850 }
3851 if ( usces_have_member_regular_order( $member['ID'] ) ) {
3852 $admin_message .= $this->message_regular_order( $member['ID'] );
3853 }
3854 $admin_message .=
3855 "\r\n----------------------------------------------------\r\n" .
3856 'REMOTE_ADDR : ' . $_SERVER['REMOTE_ADDR'] .
3857 "\r\n----------------------------------------------------\r\n";
3858
3859 $admin_para = array(
3860 'to_name' => apply_filters( 'usces_filter_bccmail_to_admin_name', 'Shop Admin' ),
3861 'to_address' => $usces->options['order_mail'],
3862 'from_name' => apply_filters( 'usces_filter_bccmail_from_admin_name', 'Welcart Auto BCC' ),
3863 'from_address' => $usces->options['sender_mail'],
3864 'reply_name' => get_option( 'blogname' ),
3865 'reply_to' => usces_get_first_order_mail(),
3866 'return_path' => $usces->options['sender_mail'],
3867 'subject' => $subject . '( ' . sprintf( _x( '%s', 'honorific', 'usces' ), $name ) . ' )',
3868 'message' => do_shortcode( $admin_message ),
3869 );
3870 usces_send_mail( $admin_para );
3871 }
3872
3873 /**
3874 * 契約中の自動継続課金�
3875
3876 *
3877 * @param int $member_id Member ID.
3878 */
3879 public function message_continue_order( $member_id ) {
3880 global $usces, $wpdb;
3881 $message = '';
3882
3883 $continuation_table = $wpdb->prefix . 'usces_continuation';
3884 $query = $wpdb->prepare( "SELECT * FROM {$continuation_table} WHERE `con_member_id` = %d AND `con_acting` = %s AND `con_status` = 'continuation'", $member_id, 'acting_sbps_card' );
3885 $continue_order = $wpdb->get_results( $query, ARRAY_A );
3886 if ( 0 < count( $continue_order ) ) {
3887 $message .= '--------------------------------' . "\r\n";
3888 $message .= __( 'Auto-continuation charging Information under Contract with a credit card', 'usces' ) . "\r\n";
3889 foreach ( $continue_order as $continue_data ) {
3890 $con_id = $continue_data['con_id'];
3891 $con_order_id = $continue_data['con_order_id'];
3892 $message .= __( 'Order number', 'usces' ) . ' : ' . $con_order_id;
3893 $latest_log = $this->get_acting_latest_log( $con_order_id, 0, 'ALL' );
3894 if ( ! empty( $latest_log ) ) {
3895 $next_charging = ( empty( $continue_data['con_next_contracting'] ) ) ? dlseller_next_charging( $con_order_id ) : $continue_data['con_next_contracting'];
3896 $message .= ' ( ' . __( 'Next Withdrawal Date', 'dlseller' ) . ' : ' . wp_date( __( 'Y/m/d' ), strtotime( $next_charging ) );
3897 if ( 0 < (int) $continue_data['con_interval'] ) {
3898 $next_contracting = ( empty( $continue_data['con_next_contracting'] ) ) ? dlseller_next_contracting( $con_order_id ) : $continue_data['con_next_contracting'];
3899 $message .= ', ' . __( 'Renewal Date', 'dlseller' ) . ' : ' . wp_date( __( 'Y/m/d' ), strtotime( $next_contracting ) );
3900 }
3901 $message .= ' )';
3902 if ( 'NG' === $latest_log['result'] ) {
3903 $message .= ' ' . __( 'Condition', 'dlseller' ) . ' : ' . __( 'Settlement error', 'usces' );
3904 if ( ! empty( $latest_log['tracking_id'] ) ) {
3905 $message .= ' ( ' . __( 'Transaction ID', 'usces' ) . ' : ' . $latest_log['tracking_id'] . ' )';
3906 }
3907 }
3908 }
3909 $message .= "\r\n";
3910 }
3911 $message .= '--------------------------------' . "\r\n\r\n";
3912 }
3913 return $message;
3914 }
3915
3916 /**
3917 * 契約中の定期購�
3918 ��
3919
3920 *
3921 * @param int $member_id Member ID.
3922 */
3923 public function message_regular_order( $member_id ) {
3924 global $usces, $wpdb;
3925 $message = '';
3926
3927 $regular_table_name = $wpdb->prefix . 'usces_regular';
3928 $regular_detail_table_name = $wpdb->prefix . 'usces_regular_detail';
3929 $order_table_name = $wpdb->prefix . 'usces_order';
3930 $order_meta_table_name = $wpdb->prefix . 'usces_order_meta';
3931
3932 $query = $wpdb->prepare( "SELECT r.reg_id, r.reg_payment_name, d.regdet_schedule_date FROM {$regular_detail_table_name} AS `d` RIGHT JOIN {$regular_table_name} AS `r` ON r.reg_id = d.reg_id WHERE r.reg_mem_id = %d AND d.regdet_condition = 'continuation' GROUP BY r.reg_id", $member_id );
3933 $regular_order = $wpdb->get_results( $query, ARRAY_A );
3934 if ( 0 < count( $regular_order ) ) {
3935 foreach ( $regular_order as $regular_data ) {
3936 $payment = $usces->getPayments( $regular_data['reg_payment_name'] );
3937 if ( 'acting_sbps_card' != $payment['settlement'] ) {
3938 continue;
3939 }
3940 $reg_id = $regular_data['reg_id'];
3941 $message .= __( 'Regular ID', 'autodelivery' ) . ' : ' . $reg_id;
3942 $query = $wpdb->prepare(
3943 "SELECT o.ID AS `order_id`, meta.meta_value AS `deco_id`, DATE_FORMAT( order_date, %s ) AS `date`
3944 FROM {$order_table_name} AS `o`
3945 LEFT JOIN {$order_meta_table_name} AS `meta` ON o.ID = meta.order_id AND meta.meta_key = 'dec_order_id'
3946 LEFT JOIN {$regular_table_name} ON o.ID = reg_order_id
3947 WHERE reg_id = %d
3948 UNION ALL
3949 SELECT o1.ID AS `order_id`, meta1.meta_value AS `deco_id`, DATE_FORMAT( order_date, %s ) AS `date`
3950 FROM {$order_table_name} AS `o1`
3951 LEFT JOIN {$order_meta_table_name} AS `meta1` ON o1.ID = meta1.order_id AND meta1.meta_key = 'dec_order_id'
3952 LEFT JOIN {$order_meta_table_name} AS `meta2` ON o1.ID = meta2.order_id AND meta2.meta_key = 'regular_id'
3953 WHERE meta2.meta_value = %d
3954 ORDER BY order_id DESC, date DESC",
3955 '%Y-%m-%d', $reg_id, '%Y-%m-%d', $reg_id
3956 );
3957 $regular_order_data = $wpdb->get_results( $query, ARRAY_A );
3958 if ( 0 < count( $regular_order_data ) ) {
3959 $reg_order_id = $regular_order_data[0]['order_id'];
3960 $latest_log = $this->get_acting_latest_log( $reg_order_id, 0, 'ALL' );
3961 if ( ! empty( $latest_log ) && 'OK' === $latest_log['result'] ) {
3962 if ( $this->isdate( $regular_data['regdet_schedule_date'] ) ) {
3963 $message .= ' ( ' . __( 'Scheduled order date', 'autodelivery' ) . ' : ' . wp_date( __( 'Y/m/d' ), strtotime( $regular_data['regdet_schedule_date'] ) ) . ' )';
3964 }
3965 } else {
3966 $message .= ' ' . __( 'Condition', 'autodelivery' ) . ' : ' . __( 'Settlement error', 'usces' );
3967 $tracking_id = $usces->get_order_meta_value( 'res_tracking_id', $reg_order_id );
3968 if ( $tracking_id ) {
3969 $message .= ' ( ' . __( 'Transaction ID', 'usces' ) . ' : ' . $tracking_id . ' )';
3970 }
3971 }
3972 $message .= "\r\n";
3973 }
3974 }
3975 if ( '' != $message ) {
3976 $message = '--------------------------------' . "\r\n"
3977 . __( 'Subscription Information under Contract with a credit card', 'usces' ) . "\r\n"
3978 . $message
3979 . '--------------------------------' . "\r\n\r\n";
3980 }
3981 }
3982 return $message;
3983 }
3984
3985 /**
3986 * 日付チェック
3987 *
3988 * @param object $date DateTime.
3989 * @return boolean
3990 */
3991 private function isdate( $date ) {
3992 if ( empty( $date ) ) {
3993 return false;
3994 }
3995 try {
3996 new DateTime( $date );
3997 list( $year, $month, $day ) = explode( '-', $date );
3998 $res = checkdate( (int) $month, (int) $day, (int) $year );
3999 return $res;
4000 } catch ( Exception $e ) {
4001 return false;
4002 }
4003 }
4004
4005 /**
4006 * 利用可能な支払方法(継続課金・定期購�
4007 �)
4008 * dlseller_filter_the_payment_method_restriction
4009 * wcad_filter_the_payment_method_restriction
4010 *
4011 * @param array $payments_restriction Payment method.
4012 * @param string $value Input value.
4013 * @return array
4014 */
4015 public function payment_method_restriction( $payments_restriction, $value ) {
4016 if ( ( usces_have_regular_order() || usces_have_continue_charge() ) && usces_is_login() ) {
4017 $sbps_card = false;
4018 foreach ( (array) $payments_restriction as $key => $payment ) {
4019 if ( 'acting_sbps_card' === $payment['settlement'] ) {
4020 $sbps_card = true;
4021 }
4022 }
4023 if ( ! $sbps_card ) {
4024 $payments = usces_get_system_option( 'usces_payment_method', 'settlement' );
4025 $payments_restriction[] = $payments['acting_sbps_card'];
4026 }
4027 $sort = array();
4028 foreach ( (array) $payments_restriction as $key => $payment ) {
4029 $sort[ $key ] = $payment['sort'];
4030 }
4031 array_multisort( $sort, SORT_ASC, $payments_restriction );
4032 }
4033 return $payments_restriction;
4034 }
4035
4036 /**
4037 * 利用可能な支払方法
4038 * usces_filter_the_continue_payment_method
4039 *
4040 * @param array $payment_method Payment method.
4041 * @return array
4042 */
4043 public function continuation_payment_method( $payment_method ) {
4044 if ( ! array_key_exists( 'acting_sbps_card', $payment_method ) ) {
4045 $payment_method[] = 'acting_sbps_card';
4046 }
4047 return $payment_method;
4048 }
4049
4050 /**
4051 * 「初回引落し日」
4052 * dlseller_filter_first_charging
4053 *
4054 * @param object $time Datetime.
4055 * @param int $post_id Post ID.
4056 * @param array $usces_item Item data.
4057 * @param int $order_id Order number.
4058 * @param array $continue_data Continuation data.
4059 * @return object
4060 */
4061 public function first_charging_date( $time, $post_id, $usces_item, $order_id, $continue_data ) {
4062 if ( 99 === (int) $usces_item['item_chargingday'] ) {
4063 if ( empty( $order_id ) ) {
4064 $today = wp_date( 'Y-m-d' );
4065 list( $year, $month, $day ) = explode( '-', $today );
4066 $time = mktime( 0, 0, 0, (int) $month, (int) $day, (int) $year );
4067 }
4068 }
4069 return $time;
4070 }
4071
4072 /**
4073 * 継続課金会員リスト「契約」
4074 * dlseller_filter_continue_member_list_continue_status
4075 *
4076 * @param string $status Continuation status.
4077 * @param int $member_id Member ID.
4078 * @param int $order_id Order number.
4079 * @param array $meta_data Continuation data.
4080 * @return string
4081 */
4082 public function continue_member_list_continue_status( $status, $member_id, $order_id, $meta_data ) {
4083 return $status;
4084 }
4085
4086 /**
4087 * 継続課金会員リスト「状�
4088 �」
4089 * dlseller_filter_continue_member_list_condition
4090 *
4091 * @param string $condition Continuation condition.
4092 * @param int $member_id Member ID.
4093 * @param int $order_id Order number.
4094 * @param array $continue_data Continuation data.
4095 * @return string
4096 */
4097 public function continue_member_list_condition( $condition, $member_id, $order_id, $continue_data ) {
4098 global $usces;
4099
4100 if ( isset( $continue_data['acting'] ) && 'acting_sbps_card' === $continue_data['acting'] ) {
4101 $url = admin_url( 'admin.php?page=usces_continue&continue_action=settlement_sbps_card&member_id=' . esc_attr( $member_id ) . '&order_id=' . esc_attr( $order_id ) );
4102 $condition = '<a href="' . $url . '">' . __( 'Detail', 'usces' ) . '</a>';
4103 if ( 'continuation' === $continue_data['status'] ) {
4104 $latest_log = $this->get_acting_latest_log( $order_id, 0, 'ALL' );
4105 if ( 'NG' === $latest_log['result'] ) {
4106 $condition .= '<div class="acting-status sbps-error">' . __( 'Settlement error', 'usces' ) . '</div>';
4107 }
4108 }
4109 }
4110 return $condition;
4111 }
4112
4113 /**
4114 * 継続課金会員決済状況ページ表示
4115 * dlseller_action_continue_member_list_page
4116 *
4117 * @param string $continue_action Continuation action.
4118 */
4119 public function continue_member_list_page( $continue_action ) {
4120 if ( 'settlement_sbps_card' == $continue_action ) {
4121 $member_id = ( isset( $_GET['member_id'] ) ) ? wp_unslash( $_GET['member_id'] ) : '';
4122 $order_id = ( isset( $_GET['order_id'] ) ) ? wp_unslash( $_GET['order_id'] ) : '';
4123 if ( ! empty( $member_id ) && ! empty( $order_id ) ) {
4124 $this->continue_member_settlement_info_page( $member_id, $order_id );
4125 exit();
4126 }
4127 }
4128 }
4129
4130 /**
4131 * 継続課金会員決済状況ページ
4132 *
4133 * @param int $member_id Member ID.
4134 * @param int $order_id Order number.
4135 */
4136 public function continue_member_settlement_info_page( $member_id, $order_id ) {
4137 global $usces;
4138
4139 $order_data = $usces->get_order_data( $order_id, 'direct' );
4140 if ( ! $order_data ) {
4141 return;
4142 }
4143
4144 $payment = $usces->getPayments( $order_data['order_payment_name'] );
4145 if ( 'acting_sbps_card' !== $payment['settlement'] ) {
4146 return;
4147 }
4148
4149 $continue_data = $this->get_continuation_data( $member_id, $order_id );
4150 $con_id = $continue_data['con_id'];
4151 $curent_url = $_SERVER['REQUEST_URI'];
4152 $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>';
4153
4154 $member_info = $usces->get_member_info( $member_id );
4155 $name = usces_localized_name( $member_info['mem_name1'], $member_info['mem_name2'], 'return' );
4156
4157 $contracted_date = ( empty( $continue_data['contractedday'] ) ) ? dlseller_next_contracting( $order_id ) : $continue_data['contractedday'];
4158 if ( ! empty( $contracted_date ) ) {
4159 list( $contracted_year, $contracted_month, $contracted_day ) = explode( '-', $contracted_date );
4160 } else {
4161 $contracted_year = 0;
4162 $contracted_month = 0;
4163 $contracted_day = 0;
4164 }
4165 $charged_date = ( empty( $continue_data['chargedday'] ) ) ? dlseller_next_charging( $order_id ) : $continue_data['chargedday'];
4166 if ( ! empty( $charged_date ) ) {
4167 list( $charged_year, $charged_month, $charged_day ) = explode( '-', $charged_date );
4168 } else {
4169 $charged_year = 0;
4170 $charged_month = 0;
4171 $charged_day = 0;
4172 }
4173 $year = substr( wp_date( 'Y' ), 0, 4 );
4174
4175 $log_data = $this->get_acting_log( $order_id, 0, 'ALL' );
4176 $num = ( $log_data ) ? count( $log_data ) : 1;
4177 ?>
4178 <div class="wrap">
4179 <div class="usces_admin">
4180 <h1>Welcart Management <?php esc_html_e( 'Continuation charging member information', 'dlseller' ); ?></h1>
4181 <p class="version_info">Version <?php echo esc_html( WCEX_DLSELLER_VERSION ); ?></p>
4182 <?php usces_admin_action_status(); ?>
4183 <div class="edit_pagenav"><?php wel_esc_script_e( $navibutton ); ?></div>
4184 <div id="datatable">
4185 <div id="tablesearch" class="usces_tablesearch">
4186 <div id="searchBox" style="display:block">
4187 <table class="search_table">
4188 <tr>
4189 <td class="label"><?php esc_html_e( 'Continuation charging information', 'dlseller' ); ?></td>
4190 <td>
4191 <table class="order_info">
4192 <tr>
4193 <th><?php esc_html_e( 'Member ID', 'dlseller' ); ?></th>
4194 <td><?php echo esc_html( $member_id ); ?></td>
4195 <th><?php esc_html_e( 'Contractor name', 'dlseller' ); ?></th>
4196 <td><?php echo esc_html( $name ); ?></td>
4197 </tr>
4198 <tr>
4199 <th><?php esc_html_e( 'Order ID', 'dlseller' ); ?></th>
4200 <td><?php echo esc_html( $order_id ); ?></td>
4201 <th><?php esc_html_e( 'Application Date', 'dlseller' ); ?></th>
4202 <td><?php echo esc_html( $order_data['order_date'] ); ?></td>
4203 </tr>
4204 <tr>
4205 <th><?php esc_html_e( 'Renewal Date', 'dlseller' ); ?></th>
4206 <td>
4207 <select id="contracted-year">
4208 <option value="0"<?php selected( (int) $contracted_year, 0 ); ?>></option>
4209 <?php for ( $i = 0; $i <= 10; $i++ ) : ?>
4210 <option value="<?php echo esc_attr( $year + $i ); ?>"<?php selected( (int) $contracted_year, ( (int) $year + $i ) ); ?>><?php echo esc_html( (int) $year + $i ); ?></option>
4211 <?php endfor; ?>
4212 </select>-<select id="contracted-month">
4213 <option value="0"<?php selected( (int) $contracted_month, 0 ); ?>></option>
4214 <?php for ( $i = 1; $i <= 12; $i++ ) : ?>
4215 <option value="<?php printf( '%02d', $i ); ?>"<?php selected( (int) $contracted_month, $i ); ?>><?php printf( '%2d', $i ); ?></option>
4216 <?php endfor; ?>
4217 </select>-<select id="contracted-day">
4218 <option value="0"<?php selected( $contracted_day, 0 ); ?>></option>
4219 <?php for ( $i = 1; $i <= 31; $i++ ) : ?>
4220 <option value="<?php printf( '%02d', $i ); ?>"<?php selected( (int) $contracted_day, $i ); ?>><?php printf( '%2d', $i ); ?></option>
4221 <?php endfor; ?>
4222 </select>
4223 </td>
4224 <th><?php esc_html_e( 'Next Withdrawal Date', 'dlseller' ); ?></th>
4225 <td>
4226 <select id="charged-year">
4227 <option value="0"<?php selected( (int) $charged_year, 0 ); ?>></option>
4228 <option value="<?php echo esc_attr( $year ); ?>"<?php selected( (int) $charged_year, (int) $year ); ?>><?php echo esc_html( $year ); ?></option>
4229 <option value="<?php echo esc_attr( $year + 1 ); ?>"<?php selected( (int) $charged_year, ( (int) $year + 1 ) ); ?>><?php echo esc_html( (int) $year + 1 ); ?></option>
4230 </select>-<select id="charged-month">
4231 <option value="0"<?php selected( (int) $charged_month, 0 ); ?>></option>
4232 <?php for ( $i = 1; $i <= 12; $i++ ) : ?>
4233 <option value="<?php printf( '%02d', $i ); ?>"<?php selected( (int) $charged_month, $i ); ?>><?php printf( '%2d', $i ); ?></option>
4234 <?php endfor; ?>
4235 </select>-<select id="charged-day">
4236 <option value="0"<?php selected( $charged_day, 0 ); ?>></option>
4237 <?php for ( $i = 1; $i <= 31; $i++ ) : ?>
4238 <option value="<?php printf( '%02d', $i ); ?>"<?php selected( (int) $charged_day, $i ); ?>><?php printf( '%2d', $i ); ?></option>
4239 <?php endfor; ?>
4240 </select>
4241 </td>
4242 </tr>
4243 <tr>
4244 <th><?php esc_html_e( 'Amount on order', 'usces' ); ?></th>
4245 <td><?php usces_crform( $continue_data['order_price'], false ); ?></td>
4246 <th><?php esc_html_e( 'Transaction amount', 'usces' ); ?></th>
4247 <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>
4248 </tr>
4249 <tr>
4250 <th><?php esc_html_e( 'Status', 'dlseller' ); ?></th>
4251 <td><select id="dlseller-status">
4252 <?php ob_start(); ?>
4253 <?php if ( 'continuation' === $continue_data['status'] ) : ?>
4254 <option value="continuation" selected="selected"><?php esc_html_e( 'Continuation', 'dlseller' ); ?></option>
4255 <option value="cancellation"><?php esc_html_e( 'Stop', 'dlseller' ); ?></option>
4256 <?php else : ?>
4257 <option value="cancellation" selected="selected"><?php esc_html_e( 'Cancellation', 'dlseller' ); ?></option>
4258 <option value="continuation"><?php esc_html_e( 'Resumption', 'dlseller' ); ?></option>
4259 <?php endif; ?>
4260 <?php
4261 $dlseller_status_options = ob_get_contents();
4262 ob_end_clean();
4263 $dlseller_status_options = apply_filters( 'usces_filter_continuation_charging_status_options', $dlseller_status_options, $continue_data );
4264 wel_esc_script_e( $dlseller_status_options );
4265 ?>
4266 </select></td>
4267 <td colspan="2"><input id="continuation-update" type="button" class="button button-primary" value="<?php esc_attr_e( 'Update' ); ?>" /></td>
4268 </tr>
4269 </table>
4270 <?php do_action( 'usces_action_continuation_charging_information', $continue_data, $member_id, $order_id ); ?>
4271 </td>
4272 </tr>
4273 </table>
4274 </div><!-- searchBox -->
4275 </div><!-- tablesearch -->
4276 <table id="mainDataTable" class="new-table order-new-table">
4277 <thead>
4278 <tr>
4279 <th scope="col">&nbsp;</th>
4280 <th scope="col"><?php esc_html_e( 'Processing date', 'usces' ); ?></th>
4281 <th scope="col"><?php esc_html_e( 'Transaction ID', 'usces' ); ?></th>
4282 <th scope="col"><?php esc_html_e( 'Settlement amount', 'usces' ); ?></th>
4283 <th scope="col"><?php esc_html_e( 'Processing classification', 'usces' ); ?></th>
4284 <th scope="col">&nbsp;</th>
4285 </tr>
4286 </thead>
4287 <?php
4288 foreach ( (array) $log_data as $data ) :
4289 $tracking_id = ( isset( $data['tracking_id'] ) ) ? $data['tracking_id'] : '';
4290 $latest_log = $this->get_acting_latest_log( $order_id, $tracking_id, 'ALL' );
4291 if ( $latest_log ) :
4292 if ( 1 < $num ) {
4293 if ( isset( $latest_log['result'] ) && 'OK' !== $latest_log['result'] ) {
4294 $cust_ref = $this->api_customer_reference( $order_data['mem_id'] );
4295 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) {
4296 $status = '';
4297 $class = ' card-' . $status;
4298 $status_name = '';
4299 } else {
4300 $status = 'error';
4301 $class = ' card-' . $status;
4302 $status_name = $this->get_status_name( $status );
4303 }
4304 } else {
4305 $status = $latest_log['status'];
4306 $class = ' card-' . $status;
4307 $status_name = $this->get_status_name( $status );
4308 }
4309 } else {
4310 $status = $latest_log['status'];
4311 $class = ' card-' . $status;
4312 $status_name = $this->get_status_name( $status );
4313 }
4314 $amount = usces_crform( $latest_log['amount'], false, false, 'return', false );
4315 ?>
4316 <tbody>
4317 <tr>
4318 <td><?php echo esc_html( $num ); ?></td>
4319 <td><?php echo esc_html( $data['datetime'] ); ?></td>
4320 <td><span id="settlement-tracking_id-<?php echo esc_attr( $num ); ?>"><?php echo esc_html( $tracking_id ); ?></span></td>
4321 <td class="amount"><span id="settlement-amount-<?php echo esc_attr( $num ); ?>"><?php echo esc_html( $amount ); ?></span></td>
4322 <td><span id="settlement-status-<?php echo esc_attr( $num ); ?>">
4323 <?php if ( $status_name ) : ?>
4324 <span class="acting-status<?php echo esc_attr( $class ); ?>"><?php esc_html_e( $status_name, 'usces' ); ?></span>
4325 <?php endif; ?>
4326 </span></td>
4327 <td>
4328 <input type="button" class="button settlement-information" id="settlement-information-<?php echo esc_attr( $tracking_id ); ?>" data-tracking_id="<?php echo esc_attr( $tracking_id ); ?>" data-num="<?php echo esc_attr( $num ); ?>" value="<?php esc_attr_e( 'Settlement info', 'usces' ); ?>">
4329 </td>
4330 </tr>
4331 </tbody>
4332 <?php
4333 $num--;
4334 endif;
4335 endforeach;
4336 ?>
4337 </table>
4338 </div><!--datatable-->
4339 <input name="member_id" type="hidden" id="member_id" value="<?php echo esc_attr( $member_id ); ?>" />
4340 <input name="order_id" type="hidden" id="order_id" value="<?php echo esc_attr( $order_id ); ?>" />
4341 <input name="con_id" type="hidden" id="con_id" value="<?php echo esc_attr( $con_id ); ?>" />
4342 <input name="usces_referer" type="hidden" id="usces_referer" value="<?php echo esc_url( $curent_url ); ?>" />
4343 <?php wp_nonce_field( 'order_edit', 'wc_nonce' ); ?>
4344 </div><!--usces_admin-->
4345 </div><!--wrap-->
4346 <?php
4347 $order_action = 'edit';
4348 $cart = array();
4349 $action_args = compact( 'order_action', 'order_id', 'cart' );
4350 $this->settlement_dialog( $order_data, $action_args );
4351 include ABSPATH . 'wp-admin/admin-footer.php';
4352 }
4353
4354 /**
4355 * 自動継続課金処理
4356 * dlseller_action_do_continuation_charging
4357 *
4358 * @param string $today Today.
4359 * @param int $member_id Member ID.
4360 * @param int $order_id Order number.
4361 * @param array $continue_data Continuation data.
4362 */
4363 public function auto_continuation_charging( $today, $member_id, $order_id, $continue_data ) {
4364 global $usces;
4365
4366 if ( ! usces_is_membersystem_state() ) {
4367 return;
4368 }
4369
4370 if ( 0 >= $continue_data['price'] ) {
4371 return;
4372 }
4373
4374 $order_data = $usces->get_order_data( $order_id, 'direct' );
4375 if ( ! $order_data || $usces->is_status( 'cancel', $order_data['order_status'] ) ) {
4376 return;
4377 }
4378
4379 if ( 'acting_sbps_card' !== $continue_data['acting'] ) {
4380 return;
4381 }
4382
4383 $acting_opts = $this->get_acting_settings();
4384 $rand = usces_acting_key();
4385 $cust_code = $member_id;
4386 $cust_ref = $this->api_customer_reference( $cust_code );
4387 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) {
4388 $cart = usces_get_ordercartdata( $order_id );
4389 $cart_row = current( $cart );
4390 $item_id = mb_convert_kana( $usces->getItemCode( $cart_row['post_id'] ), 'a', 'UTF-8' );
4391 $item_name = $usces->getCartItemName_byOrder( $cart_row );
4392 if ( 36 < mb_strlen( $item_name, 'UTF-8' ) ) {
4393 $item_name = mb_substr( $item_name, 0, 30, 'UTF-8' ) . '...';
4394 }
4395 $item_name = trim( mb_convert_encoding( $item_name, 'SJIS', 'UTF-8' ) );
4396 $amount = usces_crform( $continue_data['price'], false, false, 'return', false );
4397 $free1 = 'acting_sbps_card';
4398 $order_rowno = '1';
4399 $encrypted_flg = '1';
4400 $request_date = wp_date( 'YmdHis' );
4401 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $cust_code . $rand . $item_id . $item_name . $amount . $free1 . $order_rowno . $encrypted_flg . $request_date . $acting_opts['hash_key'];
4402 $sps_hashcode = sha1( $sps_hashcode );
4403 $connection = $this->get_connection();
4404
4405 /* 決済要求 */
4406 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
4407 <sps-api-request id="ST01-00131-101">
4408 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
4409 <service_id>' . $acting_opts['service_id'] . '</service_id>
4410 <cust_code>' . $cust_code . '</cust_code>
4411 <order_id>' . $rand . '</order_id>
4412 <item_id>' . $item_id . '</item_id>
4413 <item_name>' . base64_encode( $item_name ) . '</item_name>
4414 <amount>' . $amount . '</amount>
4415 <free1>' . base64_encode( $free1 ) . '</free1>
4416 <order_rowno>' . $order_rowno . '</order_rowno>
4417 <encrypted_flg>' . $encrypted_flg . '</encrypted_flg>
4418 <request_date>' . $request_date . '</request_date>
4419 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
4420 </sps-api-request>';
4421 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
4422 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_card, $encrypted_flg );
4423 if ( isset( $response_settlement['res_result'] ) && 'OK' === $response_settlement['res_result'] ) {
4424 $sps_transaction_id = $response_settlement['res_sps_transaction_id'];
4425 $tracking_id = $response_settlement['res_tracking_id'];
4426 $request_date = wp_date( 'YmdHis' );
4427 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $sps_transaction_id . $tracking_id . $request_date . $acting_opts['hash_key'];
4428 $sps_hashcode = sha1( $sps_hashcode );
4429
4430 /* 確定要求 */
4431 $request_credit = '<?xml version="1.0" encoding="Shift_JIS"?>
4432 <sps-api-request id="ST02-00101-101">
4433 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
4434 <service_id>' . $acting_opts['service_id'] . '</service_id>
4435 <sps_transaction_id>' . $sps_transaction_id . '</sps_transaction_id>
4436 <tracking_id>' . $tracking_id . '</tracking_id>
4437 <processing_datetime></processing_datetime>
4438 <request_date>' . $request_date . '</request_date>
4439 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
4440 </sps-api-request>';
4441 $xml_credit = $this->get_xml_response( $connection['api_url'], $request_credit );
4442 $response_credit = $this->xml2assoc( $xml_credit, $this->acting_card );
4443 if ( isset( $response_credit['res_result'] ) && 'OK' === $response_credit['res_result'] ) {
4444 if ( isset( $acting_opts['sales_dlseller'] ) && 'auto' === $acting_opts['sales_dlseller'] ) {
4445 $process_date = $response_credit['res_process_date'];
4446 $request_date = wp_date( 'YmdHis' );
4447 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $sps_transaction_id . $tracking_id . $process_date . $amount . $request_date . $acting_opts['hash_key'];
4448 $sps_hashcode = sha1( $sps_hashcode );
4449
4450 /* 売上要求(自動売上)*/
4451 $request_sales = '<?xml version="1.0" encoding="Shift_JIS"?>
4452 <sps-api-request id="ST02-00201-101">
4453 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
4454 <service_id>' . $acting_opts['service_id'] . '</service_id>
4455 <sps_transaction_id>' . $sps_transaction_id . '</sps_transaction_id>
4456 <tracking_id>' . $tracking_id . '</tracking_id>
4457 <processing_datetime>' . $process_date . '</processing_datetime>
4458 <pay_option_manage>
4459 <amount>' . $amount . '</amount>
4460 </pay_option_manage>
4461 <request_date>' . $request_date . '</request_date>
4462 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
4463 </sps-api-request>';
4464 $xml_sales = $this->get_xml_response( $connection['api_url'], $request_sales );
4465 $response_sales = $this->xml2assoc( $xml_sales, $this->acting_card );
4466 $response_sales = apply_filters( 'usces_filter_sbps_card_auto_continuation_charging_log', $response_sales, $member_id, $order_id, $continue_data );
4467 if ( isset( $response_sales['res_result'] ) && 'OK' === $response_sales['res_result'] ) {
4468 if ( ! isset( $response_sales['amount'] ) ) {
4469 $response_sales['amount'] = $amount;
4470 }
4471 $this->save_acting_log( $response_sales, $this->acting_card, $acting_opts['sales_dlseller'], $response_sales['res_result'], $order_id, $tracking_id );
4472 $this->auto_settlement_mail( $member_id, $order_id, $response_sales, $continue_data );
4473 do_action( 'usces_action_auto_continuation_charging', $member_id, $order_id, $continue_data, $response_sales );
4474 } else {
4475 $res_err_code = ( isset( $response_sales['res_err_code'] ) ) ? $response_sales['res_err_code'] : 'ST02-00201-101 Error';
4476 $data = ( ! empty( $response_sales ) ) ? $response_sales : $xml_sales;
4477 $log = array(
4478 'acting' => $this->acting_card,
4479 'key' => $rand,
4480 'result' => $res_err_code,
4481 'data' => $data,
4482 );
4483 usces_save_order_acting_error( $log );
4484 $this->save_acting_log( $response_sales, $this->acting_card, $acting_opts['sales_dlseller'], 'NG', $order_id, $tracking_id );
4485 $this->auto_settlement_error_mail( $member_id, $order_id, $response_sales, $continue_data );
4486 do_action( 'usces_action_auto_continuation_charging', $member_id, $order_id, $continue_data, $response_sales );
4487 }
4488 } else {
4489 /* 指定売上 */
4490 if ( ! isset( $response_credit['amount'] ) ) {
4491 $response_credit['amount'] = $amount;
4492 }
4493 $response_credit = apply_filters( 'usces_filter_sbps_card_auto_continuation_charging_log', $response_credit, $member_id, $order_id, $continue_data );
4494 $this->save_acting_log( $response_credit, $this->acting_card, $acting_opts['sales_dlseller'], $response_credit['res_result'], $order_id, $tracking_id );
4495 $this->auto_settlement_mail( $member_id, $order_id, $response_credit, $continue_data );
4496 do_action( 'usces_action_auto_continuation_charging', $member_id, $order_id, $continue_data, $response_credit );
4497 }
4498 } else {
4499 $res_err_code = ( isset( $response_credit['res_err_code'] ) ) ? $response_credit['res_err_code'] : 'ST02-00201-101 Error';
4500 $data = ( ! empty( $response_credit ) ) ? $response_credit : $xml_credit;
4501 $log = array(
4502 'acting' => $this->acting_card,
4503 'key' => $rand,
4504 'result' => $res_err_code,
4505 'data' => $data,
4506 );
4507 usces_save_order_acting_error( $log );
4508 $this->save_acting_log( $response_credit, $this->acting_card, $acting_opts['sales_dlseller'], 'NG', $order_id, $tracking_id );
4509 $this->auto_settlement_error_mail( $member_id, $order_id, $response_credit, $continue_data );
4510 do_action( 'usces_action_auto_continuation_charging', $member_id, $order_id, $continue_data, $response_credit );
4511 }
4512 } else {
4513 $res_err_code = ( isset( $response_settlement['res_err_code'] ) ) ? $response_settlement['res_err_code'] : 'ST01-00131-101 Error';
4514 $data = ( ! empty( $response_settlement ) ) ? $response_settlement : $xml_settlement;
4515 $log = array(
4516 'acting' => $this->acting_card,
4517 'key' => $rand,
4518 'result' => $res_err_code,
4519 'data' => $data,
4520 );
4521 usces_save_order_acting_error( $log );
4522 $this->save_acting_log( $response_settlement, $this->acting_card, $acting_opts['sales_dlseller'], 'NG', $order_id, $rand );
4523 $this->auto_settlement_error_mail( $member_id, $order_id, $response_settlement, $continue_data );
4524 do_action( 'usces_action_auto_continuation_charging', $member_id, $order_id, $continue_data, $response_settlement );
4525 }
4526 } else {
4527 $result = ( isset( $cust_ref['result'] ) ) ? $cust_ref['result'] : 'NG';
4528 $log = array(
4529 'acting' => $this->acting_card . '(member_process)',
4530 'key' => $member_id,
4531 'result' => $result,
4532 'data' => $cust_ref,
4533 );
4534 usces_save_order_acting_error( $log );
4535 $this->save_acting_log( $cust_ref, $this->acting_card, 'error', $result, $order_id, $rand );
4536 $this->auto_settlement_error_mail( $member_id, $order_id, $cust_ref, $continue_data );
4537 do_action( 'usces_action_auto_continuation_charging', $member_id, $order_id, $continue_data, $cust_ref );
4538 }
4539 }
4540
4541 /**
4542 * 自動継続課金処理メール(正常)
4543 *
4544 * @param int $member_id Member ID.
4545 * @param int $order_id Order number.
4546 * @param array $response_data Response data.
4547 * @param array $continue_data Continuation data.
4548 */
4549 public function auto_settlement_mail( $member_id, $order_id, $response_data, $continue_data ) {
4550 global $usces;
4551
4552 $acting_opts = $this->get_acting_settings();
4553 $order_data = $usces->get_order_data( $order_id, 'direct' );
4554 $mail_body = $this->auto_settlement_message( $member_id, $order_id, $order_data, $response_data, $continue_data, false );
4555
4556 if ( 'on' === $acting_opts['auto_settlement_mail'] ) {
4557 $subject = apply_filters( 'usces_filter_sbps_auto_settlement_mail_subject', __( 'Announcement of automatic continuing charging process', 'usces' ), $member_id, $order_id, $order_data, $response_data, $continue_data );
4558 $member_info = $usces->get_member_info( $member_id );
4559 $name = usces_localized_name( $member_info['mem_name1'], $member_info['mem_name2'], 'return' );
4560 $mail_data = usces_mail_data();
4561 $mail_header = '';
4562 if ( isset( $usces->options['put_customer_name'] ) && 1 === (int) $usces->options['put_customer_name'] ) {
4563 $mail_header .= sprintf( __( 'Dear %s', 'usces' ), $name ) . "\r\n\r\n";
4564 }
4565 $mail_header .= __( 'We will report automated accounting process was carried out as follows.', 'usces' ) . "\r\n\r\n";
4566 $mail_footer = __( 'If you have any questions, please contact us.', 'usces' ) . "\r\n\r\n" . $mail_data['footer']['thankyou'];
4567 $message = apply_filters( 'usces_filter_sbps_auto_settlement_mail_header', $mail_header, $member_id, $order_id, $order_data, $response_data, $continue_data ) .
4568 apply_filters( 'usces_filter_sbps_auto_settlement_mail_body', $mail_body, $member_id, $order_id, $order_data, $response_data, $continue_data ) .
4569 apply_filters( 'usces_filter_sbps_auto_settlement_mail_footer', $mail_footer, $member_id, $order_id, $order_data, $response_data, $continue_data );
4570 $headers = apply_filters( 'usces_filter_sbps_auto_settlement_mail_headers', '' );
4571 $to_customer = array(
4572 'to_name' => sprintf( _x( '%s', 'honorific', 'usces' ), $name ),
4573 'to_address' => $member_info['mem_email'],
4574 'from_name' => get_option( 'blogname' ),
4575 'from_address' => $usces->options['sender_mail'],
4576 'reply_name' => get_option( 'blogname' ),
4577 'reply_to' => usces_get_first_order_mail(),
4578 'return_path' => $usces->options['sender_mail'],
4579 'subject' => $subject,
4580 'message' => do_shortcode( $message ),
4581 'headers' => $headers,
4582 );
4583 usces_send_mail( $to_customer );
4584 }
4585
4586 $ok = ( empty( $this->continuation_charging_mail['OK'] ) ) ? 0 : $this->continuation_charging_mail['OK'];
4587 $this->continuation_charging_mail['OK'] = $ok + 1;
4588 $this->continuation_charging_mail['mail'][] = $mail_body;
4589 }
4590
4591 /**
4592 * 自動継続課金処理メール(エラー)
4593 *
4594 * @param int $member_id Member ID.
4595 * @param int $order_id Order number.
4596 * @param array $response_data Response data.
4597 * @param array $continue_data Continuation data.
4598 */
4599 public function auto_settlement_error_mail( $member_id, $order_id, $response_data, $continue_data ) {
4600 global $usces;
4601
4602 $acting_opts = $this->get_acting_settings();
4603 $order_data = $usces->get_order_data( $order_id, 'direct' );
4604 $mail_body = $this->auto_settlement_message( $member_id, $order_id, $order_data, $response_data, $continue_data, false );
4605
4606 if ( 'on' === $acting_opts['auto_settlement_mail'] ) {
4607 $subject = apply_filters( 'usces_filter_sbps_auto_settlement_error_mail_subject', __( 'Announcement of automatic continuing charging process', 'usces' ), $member_id, $order_id, $order_data, $response_data, $continue_data );
4608 $member_info = $usces->get_member_info( $member_id );
4609 $name = usces_localized_name( $member_info['mem_name1'], $member_info['mem_name2'], 'return' );
4610 $mail_data = usces_mail_data();
4611 $mail_header = '';
4612 if ( isset( $usces->options['put_customer_name'] ) && 1 === (int) $usces->options['put_customer_name'] ) {
4613 $mail_header .= sprintf( __( 'Dear %s', 'usces' ), $name ) . "\r\n\r\n";
4614 }
4615 $mail_header .= __( 'We will reported that an error occurred in automated accounting process.', 'usces' ) . "\r\n\r\n";
4616 $mail_footer = __( 'If you have any questions, please contact us.', 'usces' ) . "\r\n\r\n" . $mail_data['footer']['thankyou'];
4617 $message = apply_filters( 'usces_filter_sbps_auto_settlement_error_mail_header', $mail_header, $member_id, $order_id, $order_data, $response_data, $continue_data ) .
4618 apply_filters( 'usces_filter_sbps_auto_settlement_error_mail_body', $mail_body, $member_id, $order_id, $order_data, $response_data, $continue_data ) .
4619 apply_filters( 'usces_filter_sbps_auto_settlement_error_mail_footer', $mail_footer, $member_id, $order_id, $order_data, $response_data, $continue_data );
4620 $headers = apply_filters( 'usces_filter_sbps_auto_settlement_error_mail_headers', '' );
4621 $to_customer = array(
4622 'to_name' => sprintf( _x( '%s', 'honorific', 'usces' ), $name ),
4623 'to_address' => $member_info['mem_email'],
4624 'from_name' => get_option( 'blogname' ),
4625 'from_address' => $usces->options['sender_mail'],
4626 'reply_name' => get_option( 'blogname' ),
4627 'reply_to' => usces_get_first_order_mail(),
4628 'return_path' => $usces->options['sender_mail'],
4629 'subject' => $subject,
4630 'message' => do_shortcode( $message ),
4631 'headers' => $headers,
4632 );
4633 usces_send_mail( $to_customer );
4634 }
4635
4636 $error = ( empty( $this->continuation_charging_mail['NG'] ) ) ? 0 : $this->continuation_charging_mail['NG'];
4637 $this->continuation_charging_mail['NG'] = $error + 1;
4638 $this->continuation_charging_mail['mail'][] = $mail_body;
4639 }
4640
4641 /**
4642 * 自動継続課金処理メール本文
4643 *
4644 * @param int $member_id Member ID.
4645 * @param int $order_id Order number.
4646 * @param array $order_data Order data.
4647 * @param array $response_data Response data.
4648 * @param array $continue_data Continuation data.
4649 * @param boolean $html HTML Mail.
4650 * @return string
4651 */
4652 public function auto_settlement_message( $member_id, $order_id, $order_data, $response_data, $continue_data, $html = true ) {
4653 global $usces;
4654
4655 if ( usces_is_html_mail() && $html ) {
4656 $message = $this->auto_settlement_message_htmlbody( $member_id, $order_id, $order_data, $response_data, $continue_data );
4657 } else {
4658 $member_info = $usces->get_member_info( $member_id );
4659 $name = usces_localized_name( $member_info['mem_name1'], $member_info['mem_name2'], 'return' );
4660 $contracted_date = ( isset( $continue_data['contractedday'] ) ) ? $continue_data['contractedday'] : '';
4661 $charged_date = ( isset( $continue_data['chargedday'] ) ) ? $continue_data['chargedday'] : '';
4662
4663 $message = usces_mail_line( 2 ); // --------------------
4664 $message .= __( 'Order ID', 'dlseller' ) . ' : ' . $order_id . "\r\n";
4665 $message .= __( 'Application Date', 'dlseller' ) . ' : ' . $order_data['order_date'] . "\r\n";
4666 $message .= __( 'Member ID', 'dlseller' ) . ' : ' . $member_id . "\r\n";
4667 $message .= __( 'Contractor name', 'dlseller' ) . ' : ' . sprintf( _x( '%s', 'honorific', 'usces' ), $name ) . "\r\n";
4668
4669 $cart = usces_get_ordercartdata( $order_id );
4670 $cart_row = current( $cart );
4671 $item_name = $usces->getCartItemName_byOrder( $cart_row );
4672 $options = ( empty( $cart_row['options'] ) ) ? array() : $cart_row['options'];
4673 $message .= __( 'Items', 'usces' ) . ' : ' . $item_name . "\r\n";
4674 if ( is_array( $options ) && 0 < count( $options ) ) {
4675 $optstr = '';
4676 foreach ( $options as $key => $value ) {
4677 if ( ! empty( $key ) ) {
4678 $key = urldecode( $key );
4679 $value = wel_safe_maybe_unserialize( $value );
4680 if ( is_array( $value ) ) {
4681 $c = '';
4682 $optstr .= '( ' . $key . ' : ';
4683 foreach ( $value as $v ) {
4684 $optstr .= $c . rawurldecode( $v );
4685 $c = ', ';
4686 }
4687 $optstr .= " )\r\n";
4688 } else {
4689 $optstr .= '( ' . $key . ' : ' . rawurldecode( $value ) . " )\r\n";
4690 }
4691 }
4692 }
4693 $message .= $optstr;
4694 }
4695
4696 $message .= __( 'Settlement amount', 'usces' ) . ' : ' . usces_crform( $continue_data['price'], true, false, 'return' ) . "\r\n";
4697 if ( isset( $response_data['reminder'] ) ) {
4698 if ( ! empty( $charged_date ) ) {
4699 $message .= __( 'Next Withdrawal Date', 'dlseller' ) . ' : ' . $charged_date . "\r\n";
4700 }
4701 if ( ! empty( $contracted_date ) ) {
4702 $message .= __( 'Renewal Date', 'dlseller' ) . ' : ' . $contracted_date . "\r\n";
4703 }
4704 } else {
4705 if ( ! empty( $charged_date ) ) {
4706 $message .= __( 'Next Withdrawal Date', 'dlseller' ) . ' : ' . $charged_date . "\r\n";
4707 }
4708 if ( ! empty( $contracted_date ) ) {
4709 $message .= __( 'Renewal Date', 'dlseller' ) . ' : ' . $contracted_date . "\r\n";
4710 }
4711 $message .= "\r\n";
4712
4713 if ( isset( $response_data['res_result'] ) && 'OK' === $response_data['res_result'] ) {
4714 $message .= __( 'Result', 'usces' ) . ' : ' . __( 'Normal done', 'usces' ) . "\r\n";
4715 } else {
4716 $message .= __( 'Result', 'usces' ) . ' : ' . __( 'Error', 'usces' ) . "\r\n";
4717 if ( isset( $response_data['res_err_code'] ) ) {
4718 $message .= 'res_err_code : ' . $response_data['res_err_code'] . "\r\n";
4719 }
4720 }
4721 }
4722 $message .= usces_mail_line( 2 ) . "\r\n";// --------------------
4723 }
4724 return $message;
4725 }
4726
4727 /**
4728 * Automatic renewal billing process email body html
4729 *
4730 * @param int $member_id Member ID.
4731 * @param int $order_id Order number.
4732 * @param array $order_data Order data.
4733 * @param array $response_data Response data.
4734 * @param array $continue_data Continuation data.
4735 * @return string
4736 */
4737 public function auto_settlement_message_htmlbody( $member_id, $order_id, $order_data, $response_data, $continue_data ) {
4738 global $usces;
4739
4740 $member_info = $usces->get_member_info( $member_id );
4741 $name = usces_localized_name( $member_info['mem_name1'], $member_info['mem_name2'], 'return' );
4742 $contracted_date = ( isset( $continue_data['contractedday'] ) ) ? $continue_data['contractedday'] : '';
4743 $charged_date = ( isset( $continue_data['chargedday'] ) ) ? $continue_data['chargedday'] : '';
4744
4745 $message = '<table style="font-size: 14px; margin-bottom: 30px; width: 100%; border-collapse: collapse; border: 1px solid #ddd;"><tbody>';
4746 $message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">';
4747 $message .= __( 'Order ID', 'dlseller' );
4748 $message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">';
4749 $message .= $order_id;
4750 $message .= '</td></tr>';
4751
4752 $message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">';
4753 $message .= __( 'Application Date', 'dlseller' );
4754 $message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">';
4755 $message .= $order_data['order_date'];
4756 $message .= '</td></tr>';
4757
4758 $message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">';
4759 $message .= __( 'Member ID', 'dlseller' );
4760 $message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">';
4761 $message .= $member_id;
4762 $message .= '</td></tr>';
4763
4764 $message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">';
4765 $message .= __( 'Contractor name', 'dlseller' );
4766 $message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">';
4767 $message .= sprintf( _x( '%s', 'honorific', 'usces' ), $name );
4768 $message .= '</td></tr>';
4769
4770 $cart = usces_get_ordercartdata( $order_id );
4771 $cart_row = current( $cart );
4772 $item_name = $usces->getCartItemName_byOrder( $cart_row );
4773 $options = ( empty( $cart_row['options'] ) ) ? array() : $cart_row['options'];
4774 $message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">';
4775 $message .= __( 'Items', 'usces' );
4776 $message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">';
4777 $message .= $item_name;
4778 if ( is_array( $options ) && 0 < count( $options ) ) {
4779 $optstr = '';
4780 foreach ( $options as $key => $value ) {
4781 if ( ! empty( $key ) ) {
4782 $key = urldecode( $key );
4783 $value = wel_safe_maybe_unserialize( $value );
4784 if ( is_array( $value ) ) {
4785 $c = '';
4786 $optstr .= '( ' . $key . ' : ';
4787 foreach ( $value as $v ) {
4788 $optstr .= $c . rawurldecode( $v );
4789 $c = ', ';
4790 }
4791 $optstr .= ' )<br>';
4792 } else {
4793 $optstr .= '( ' . $key . ' : ' . rawurldecode( $value ) . ' )<br>';
4794 }
4795 }
4796 }
4797 $message .= $optstr;
4798 }
4799 $message .= '</td></tr>';
4800
4801 $message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">';
4802 $message .= __( 'Settlement amount', 'usces' );
4803 $message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">';
4804 $message .= usces_crform( $continue_data['price'], true, false, 'return' );
4805 $message .= '</td></tr>';
4806 if ( isset( $response_data['reminder'] ) ) {
4807 if ( ! empty( $charged_date ) ) {
4808 $message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">';
4809 $message .= __( 'Next Withdrawal Date', 'dlseller' );
4810 $message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">';
4811 $message .= $charged_date;
4812 $message .= '</td></tr>';
4813 }
4814 if ( ! empty( $contracted_date ) ) {
4815 $message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">';
4816 $message .= __( 'Renewal Date', 'dlseller' );
4817 $message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">';
4818 $message .= $contracted_date;
4819 $message .= '</td></tr>';
4820 }
4821 } else {
4822 if ( ! empty( $charged_date ) ) {
4823 $message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">';
4824 $message .= __( 'Next Withdrawal Date', 'dlseller' );
4825 $message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">';
4826 $message .= $charged_date;
4827 $message .= '</td></tr>';
4828 }
4829 if ( ! empty( $contracted_date ) ) {
4830 $message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">';
4831 $message .= __( 'Renewal Date', 'dlseller' );
4832 $message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">';
4833 $message .= $contracted_date;
4834 $message .= '</td></tr>';
4835 }
4836
4837 if ( isset( $response_data['res_result'] ) && 'OK' === $response_data['res_result'] ) {
4838 $message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">';
4839 $message .= __( 'Result', 'usces' );
4840 $message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">';
4841 $message .= __( 'Normal done', 'usces' );
4842 $message .= '</td></tr>';
4843 } else {
4844 $message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">';
4845 $message .= __( 'Result', 'usces' );
4846 $message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">';
4847 $message .= __( 'Error', 'usces' );
4848 $message .= '</td></tr>';
4849 if ( isset( $response_data['res_err_code'] ) ) {
4850 $message .= '<tr><td style="background-color: #f9f9f9; padding: 12px; width: 33%; border: 1px solid #ddd; text-align: left;">';
4851 $message .= 'res_err_code';
4852 $message .= '</td><td style="padding: 12px; width: 67%; border: 1px solid #ddd;">';
4853 $message .= $response_data['res_err_code'];
4854 $message .= '</td></tr>';
4855 }
4856 }
4857 }
4858 $message .= '</tbody></table>';
4859 return $message;
4860 }
4861
4862 /**
4863 * 自動継続課金処理
4864 * dlseller_action_do_continuation
4865 *
4866 * @param string $today Today.
4867 * @param array $todays_charging Charged data.
4868 */
4869 public function do_auto_continuation( $today, $todays_charging ) {
4870 global $usces;
4871
4872 if ( empty( $todays_charging ) ) {
4873 return;
4874 }
4875
4876 $ok = ( empty( $this->continuation_charging_mail['OK'] ) ) ? 0 : $this->continuation_charging_mail['OK'];
4877 $error = ( empty( $this->continuation_charging_mail['NG'] ) ) ? 0 : $this->continuation_charging_mail['NG'];
4878 $admin_subject = apply_filters( 'usces_filter_sbps_autobilling_email_admin_subject', __( 'Automatic Continuing Charging Process Result', 'usces' ) . ' ' . $today, $today );
4879 $admin_footer = apply_filters( 'usces_filter_sbps_autobilling_email_admin_mail_footer', __( 'For details, please check on the administration panel > Continuous charge member list > Continuous charge member information.', 'usces' ) );
4880 $admin_message = __( 'Report that automated accounting process has been completed.', 'usces' ) . "\r\n\r\n"
4881 . __( 'Processing date', 'usces' ) . ' : ' . wp_date( 'Y-m-d H:i:s' ) . "\r\n"
4882 . __( 'Normal done', 'usces' ) . ' : ' . $ok . "\r\n"
4883 . __( 'Abnormal done', 'usces' ) . ' : ' . $error . "\r\n\r\n";
4884 foreach ( (array) $this->continuation_charging_mail['mail'] as $mail ) {
4885 $admin_message .= $mail . "\r\n";
4886 }
4887 $admin_message .= $admin_footer . "\r\n";
4888
4889 $to_admin = array(
4890 'to_name' => apply_filters( 'usces_filter_bccmail_to_admin_name', 'Shop Admin' ),
4891 'to_address' => $usces->options['order_mail'],
4892 'from_name' => apply_filters( 'usces_filter_bccmail_from_admin_name', 'Welcart Auto BCC' ),
4893 'from_address' => $usces->options['sender_mail'],
4894 'reply_name' => get_option( 'blogname' ),
4895 'reply_to' => usces_get_first_order_mail(),
4896 'return_path' => $usces->options['sender_mail'],
4897 'subject' => $admin_subject,
4898 'message' => do_shortcode( $admin_message ),
4899 );
4900 usces_send_mail( $to_admin );
4901 unset( $this->continuation_charging_mail );
4902 }
4903
4904 /**
4905 * 課金日通知メール
4906 * dlseller_filter_reminder_mail_body
4907 *
4908 * @param string $mail_body Message body.
4909 * @param int $order_id Order number.
4910 * @param array $continue_data Continuation data.
4911 * @return string
4912 */
4913 public function reminder_mail_body( $mail_body, $order_id, $continue_data ) {
4914 global $usces;
4915
4916 $member_id = $continue_data['member_id'];
4917 $order_id = $continue_data['order_id'];
4918 $order_data = $usces->get_order_data( $order_id, 'direct' );
4919 $response_data = array( 'reminder' => 'reminder' );
4920 $mail_body = $this->auto_settlement_message( $member_id, $order_id, $order_data, $response_data, $continue_data );
4921 return $mail_body;
4922 }
4923
4924 /**
4925 * 契約更新日通知メール
4926 * dlseller_filter_contract_renewal_mail_body
4927 *
4928 * @param string $mail_body Message body.
4929 * @param int $order_id Order number.
4930 * @param array $continue_data Continuation data.
4931 * @return string
4932 */
4933 public function contract_renewal_mail_body( $mail_body, $order_id, $continue_data ) {
4934 global $usces;
4935
4936 $member_id = $continue_data['member_id'];
4937 $order_data = $usces->get_order_data( $order_id, 'direct' );
4938 $response_data = array( 'reminder' => 'contract_renewal' );
4939 $mail_body = $this->auto_settlement_message( $member_id, $order_id, $order_data, $response_data, $continue_data );
4940 return $mail_body;
4941 }
4942
4943 /**
4944 * 継続課金会員データ取得
4945 *
4946 * @param int $member_id Member ID.
4947 * @param int $order_id Order number.
4948 * @return array
4949 */
4950 private function get_continuation_data( $member_id, $order_id ) {
4951 global $wpdb;
4952
4953 $query = $wpdb->prepare(
4954 "SELECT
4955 `con_id` AS `con_id`,
4956 `con_acting` AS `acting`,
4957 `con_order_price` AS `order_price`,
4958 `con_price` AS `price`,
4959 `con_next_charging` AS `chargedday`,
4960 `con_next_contracting` AS `contractedday`,
4961 `con_startdate` AS `startdate`,
4962 `con_status` AS `status`
4963 FROM {$wpdb->prefix}usces_continuation
4964 WHERE `con_order_id` = %d AND `con_member_id` = %d",
4965 $order_id,
4966 $member_id
4967 );
4968 $data = $wpdb->get_row( $query, ARRAY_A );
4969 return $data;
4970 }
4971
4972 /**
4973 * 継続課金会員データ更新
4974 *
4975 * @param int $member_id Member ID.
4976 * @param int $order_id Order number.
4977 * @param array $data Continuation data.
4978 * @param boolean $stop Stop continuous billing.
4979 * @return boolean
4980 */
4981 private function update_continuation_data( $member_id, $order_id, $data, $stop = false ) {
4982 global $wpdb;
4983
4984 if ( $stop ) {
4985 $query = $wpdb->prepare(
4986 "UPDATE {$wpdb->prefix}usces_continuation SET
4987 `con_status` = 'cancellation'
4988 WHERE `con_order_id` = %d AND `con_member_id` = %d",
4989 $order_id,
4990 $member_id
4991 );
4992 } else {
4993 $query = $wpdb->prepare(
4994 "UPDATE {$wpdb->prefix}usces_continuation SET
4995 `con_price` = %f,
4996 `con_next_charging` = %s,
4997 `con_next_contracting` = %s,
4998 `con_status` = %s
4999 WHERE `con_order_id` = %d AND `con_member_id` = %d",
5000 $data['price'],
5001 $data['chargedday'],
5002 $data['contractedday'],
5003 $data['status'],
5004 $order_id,
5005 $member_id
5006 );
5007 }
5008 $res = $wpdb->query( $query );
5009 return $res;
5010 }
5011
5012 /**
5013 * ゼウス定期購�
5014 �メッセージ
5015 * wcad_filter_admin_notices
5016 *
5017 * @param string $msg Admin message.
5018 * @return string
5019 */
5020 public function admin_notices_autodelivery( $msg ) {
5021 global $usces;
5022
5023 $acting_opts = $this->get_acting_settings();
5024 if ( ( isset( $acting_opts['activate'] ) && 'on' === $acting_opts['activate'] ) &&
5025 ( isset( $acting_opts['card_activate'] ) && ( 'on' === $acting_opts['card_activate'] || 'on' === $acting_opts['card_activate'] || 'token' === $acting_opts['card_activate'] ) ) &&
5026 ( isset( $acting_opts['cust_manage'] ) && 'on' === $acting_opts['cust_manage'] ) ) {
5027 $msg = '';
5028 } else {
5029 $zeus_opts = $usces->options['acting_settings']['zeus'];
5030 $zeus_flag = ( ( isset( $zeus_opts['activate'] ) && 'on' === $zeus_opts['activate'] ) && ( isset( $zeus_opts['card_activate'] ) && 'on' === $zeus_opts['card_activate'] ) ) ? true : false;
5031 $zeus_batch = ( isset( $zeus_opts['batch'] ) ) ? $zeus_opts['batch'] : 'off';
5032 $welcartpay_opts = $usces->options['acting_settings']['welcart'];
5033 $welcart_flag = ( ( isset( $welcartpay_opts['activate'] ) && 'on' === $welcartpay_opts['activate'] ) && ( isset( $welcartpay_opts['card_activate'] ) && ( 'on' === $welcartpay_opts['card_activate'] || 'link' === $welcartpay_opts['card_activate'] || 'token' === $welcartpay_opts['card_activate'] ) ) ) ? true : false;
5034 $welcart_batch = ( isset( $welcartpay_opts['quickpay'] ) ) ? $welcartpay_opts['quickpay'] : 'off';
5035 if ( ( ! $zeus_flag || 'off' === $zeus_batch ) || ( ! $welcart_flag || 'off' === $welcart_batch ) ) {
5036 $msg = '
5037 <div class="error">
5038 <p>「クレジット決済設定」にて、SBペイメントサービスのクレジットカード�
5039 報保存を「保存する」に設定してください。</p>
5040 </div>';
5041 }
5042 }
5043 return $msg;
5044 }
5045
5046 /**
5047 * 発送�
5048 �リスト利用可能決済
5049 * wcad_filter_shippinglist_acting
5050 *
5051 * @param string $acting Payment method.
5052 * @return string
5053 */
5054 public function set_shippinglist_acting( $acting ) {
5055 $acting = 'acting_sbps_card';
5056 return $acting;
5057 }
5058
5059 /**
5060 * 管理画面利用可能決済メッセージ
5061 * wcad_filter_available_regular_payment_method
5062 *
5063 * @param array $payment_method Payment method.
5064 * @return array
5065 */
5066 public function available_regular_payment_method( $payment_method ) {
5067 $payment_method[] = 'acting_sbps_card';
5068 return $payment_method;
5069 }
5070
5071 /**
5072 * 定期購�
5073 �決済処理
5074 * wcad_action_reg_auto_orderdata
5075 *
5076 * @param string $args {
5077 * The array of Order related data.
5078 * @type array $cart Cart data.
5079 * @type array $entry Entry data.
5080 * @type int $order_id Order ID.
5081 * @type int $member_id Member ID.
5082 * @type array $payments Payment data.
5083 * @type int $charging_type Charging type.
5084 * @type float $total_amount Total amount.
5085 * @type int $reg_id Regular ID.
5086 * }
5087 */
5088 public function register_auto_orderdata( $args ) {
5089 global $usces;
5090 extract( $args );
5091
5092 $acting_flg = $payments['settlement'];
5093 if ( 'acting_sbps_card' !== $acting_flg ) {
5094 return;
5095 }
5096
5097 if ( ! usces_is_membersystem_state() ) {
5098 return;
5099 }
5100
5101 if ( 0 >= $total_amount ) {
5102 return;
5103 }
5104
5105 $settltment_errmsg = '';
5106
5107 $acting_opts = $this->get_acting_settings();
5108 $rand = usces_acting_key();
5109 $cust_code = $member_id;
5110 $cust_ref = $this->api_customer_reference( $cust_code );
5111 if ( isset( $cust_ref['result'] ) && 'OK' === $cust_ref['result'] ) {
5112 $cart_row = current( $cart );
5113 $item_id = mb_convert_kana( $usces->getItemCode( $cart_row['post_id'] ), 'a', 'UTF-8' );
5114 $item_name = $usces->getCartItemName_byOrder( $cart_row );
5115 if ( 1 < count( $cart ) ) {
5116 $item_name .= ' ' . __( 'Others', 'usces' );
5117 }
5118 if ( 36 < mb_strlen( $item_name, 'UTF-8' ) ) {
5119 $item_name = mb_substr( $item_name, 0, 30, 'UTF-8' ) . '...';
5120 }
5121 $item_name = trim( mb_convert_encoding( $item_name, 'SJIS', 'UTF-8' ) );
5122 $amount = usces_crform( $total_amount, false, false, 'return', false );
5123 $free1 = $acting_flg;
5124 $order_rowno = '1';
5125 $encrypted_flg = '1';
5126 $request_date = wp_date( 'YmdHis' );
5127 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $cust_code . $rand . $item_id . $item_name . $amount . $free1 . $order_rowno . $encrypted_flg . $request_date . $acting_opts['hash_key'];
5128 $sps_hashcode = sha1( $sps_hashcode );
5129 $connection = $this->get_connection();
5130
5131 /* 決済要求 */
5132 $request_settlement = '<?xml version="1.0" encoding="Shift_JIS"?>
5133 <sps-api-request id="ST01-00131-101">
5134 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
5135 <service_id>' . $acting_opts['service_id'] . '</service_id>
5136 <cust_code>' . $cust_code . '</cust_code>
5137 <order_id>' . $rand . '</order_id>
5138 <item_id>' . $item_id . '</item_id>
5139 <item_name>' . base64_encode( $item_name ) . '</item_name>
5140 <amount>' . $amount . '</amount>
5141 <free1>' . base64_encode( $free1 ) . '</free1>
5142 <order_rowno>' . $order_rowno . '</order_rowno>
5143 <encrypted_flg>' . $encrypted_flg . '</encrypted_flg>
5144 <request_date>' . $request_date . '</request_date>
5145 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
5146 </sps-api-request>';
5147 $xml_settlement = $this->get_xml_response( $connection['api_url'], $request_settlement );
5148 $response_settlement = $this->xml2assoc( $xml_settlement, $this->acting_card, $encrypted_flg );
5149 if ( isset( $response_settlement['res_result'] ) && 'OK' === $response_settlement['res_result'] ) {
5150 $sps_transaction_id = $response_settlement['res_sps_transaction_id'];
5151 $tracking_id = $response_settlement['res_tracking_id'];
5152 $request_date = wp_date( 'YmdHis' );
5153 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $sps_transaction_id . $tracking_id . $request_date . $acting_opts['hash_key'];
5154 $sps_hashcode = sha1( $sps_hashcode );
5155
5156 /* 確定要求 */
5157 $request_credit = '<?xml version="1.0" encoding="Shift_JIS"?>
5158 <sps-api-request id="ST02-00101-101">
5159 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
5160 <service_id>' . $acting_opts['service_id'] . '</service_id>
5161 <sps_transaction_id>' . $sps_transaction_id . '</sps_transaction_id>
5162 <tracking_id>' . $tracking_id . '</tracking_id>
5163 <processing_datetime></processing_datetime>
5164 <request_date>' . $request_date . '</request_date>
5165 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
5166 </sps-api-request>';
5167 $xml_credit = $this->get_xml_response( $connection['api_url'], $request_credit );
5168 $response_credit = $this->xml2assoc( $xml_credit, $this->acting_card );
5169 if ( isset( $response_credit['res_result'] ) && 'OK' === $response_credit['res_result'] ) {
5170 if ( isset( $acting_opts['sales'] ) && 'auto' === $acting_opts['sales'] ) {
5171 $process_date = $response_credit['res_process_date'];
5172 $request_date = wp_date( 'YmdHis' );
5173 $sps_hashcode = $acting_opts['merchant_id'] . $acting_opts['service_id'] . $sps_transaction_id . $tracking_id . $process_date . $amount . $request_date . $acting_opts['hash_key'];
5174 $sps_hashcode = sha1( $sps_hashcode );
5175
5176 /* 売上要求(自動売上)*/
5177 $request_sales = '<?xml version="1.0" encoding="Shift_JIS"?>
5178 <sps-api-request id="ST02-00201-101">
5179 <merchant_id>' . $acting_opts['merchant_id'] . '</merchant_id>
5180 <service_id>' . $acting_opts['service_id'] . '</service_id>
5181 <sps_transaction_id>' . $sps_transaction_id . '</sps_transaction_id>
5182 <tracking_id>' . $tracking_id . '</tracking_id>
5183 <processing_datetime>' . $process_date . '</processing_datetime>
5184 <pay_option_manage>
5185 <amount>' . $amount . '</amount>
5186 </pay_option_manage>
5187 <request_date>' . $request_date . '</request_date>
5188 <sps_hashcode>' . $sps_hashcode . '</sps_hashcode>
5189 </sps-api-request>';
5190 $xml_sales = $this->get_xml_response( $connection['api_url'], $request_sales );
5191 $response_sales = $this->xml2assoc( $xml_sales, $this->acting_card );
5192 $response_sales = apply_filters( 'usces_filter_sbps_card_register_auto_orderdata_log', $response_sales, $args );
5193 if ( isset( $response_sales['res_result'] ) && 'OK' === $response_sales['res_result'] ) {
5194 if ( ! isset( $response_sales['amount'] ) ) {
5195 $response_sales['amount'] = $amount;
5196 }
5197 $this->save_acting_log( $response_sales, $this->acting_card, $acting_opts['sales'], $response_sales['res_result'], $order_id, $tracking_id );
5198 $usces->set_order_meta_value( 'res_tracking_id', $tracking_id, $order_id );
5199 $usces->set_order_meta_value( 'wc_trans_id', $tracking_id, $order_id );
5200 $usces->set_order_meta_value( 'trans_id', $rand, $order_id );
5201 if ( ! isset( $response_sales['acting'] ) ) {
5202 $response_sales['acting'] = $this->acting_card;
5203 }
5204 $usces->set_order_meta_value( $acting_flg, usces_serialize( $response_sales ), $order_id );
5205 } else {
5206 $usces->set_order_meta_value( 'trans_id', $rand, $order_id );
5207 $this->save_acting_log( $response_sales, $this->acting_card, $acting_opts['sales'], $response_sales['res_result'], $order_id, $tracking_id );
5208 $settltment_errmsg = __( '[Regular purchase] Settlement was not completed.', 'autodelivery' );
5209 $log = array(
5210 'acting' => $this->acting_card,
5211 'key' => $rand,
5212 'result' => $response_sales['res_err_code'],
5213 'data' => $response_sales,
5214 );
5215 usces_save_order_acting_error( $log );
5216 }
5217 do_action( 'usces_action_register_auto_orderdata', $args, $response_sales );
5218 } else {
5219 /* 指定売上 */
5220 if ( ! isset( $response_credit['amount'] ) ) {
5221 $response_credit['amount'] = $amount;
5222 }
5223 $response_credit = apply_filters( 'usces_filter_sbps_card_register_auto_orderdata_log', $response_credit, $args );
5224 $this->save_acting_log( $response_credit, $this->acting_card, $acting_opts['sales'], $response_credit['res_result'], $order_id, $tracking_id );
5225 $usces->set_order_meta_value( 'res_tracking_id', $tracking_id, $order_id );
5226 $usces->set_order_meta_value( 'wc_trans_id', $tracking_id, $order_id );
5227 $usces->set_order_meta_value( 'trans_id', $rand, $order_id );
5228 if ( ! isset( $response_credit['acting'] ) ) {
5229 $response_credit['acting'] = $this->acting_card;
5230 }
5231 $usces->set_order_meta_value( $acting_flg, usces_serialize( $response_credit ), $order_id );
5232 do_action( 'usces_action_register_auto_orderdata', $args, $response_credit );
5233 }
5234 } else {
5235 $usces->set_order_meta_value( 'trans_id', $rand, $order_id );
5236 $this->save_acting_log( $response_credit, $this->acting_card, $acting_opts['sales'], $response_credit['res_result'], $order_id, $tracking_id );
5237 $settltment_errmsg = __( '[Regular purchase] Settlement was not completed.', 'autodelivery' );
5238 $log = array(
5239 'acting' => $this->acting_card,
5240 'key' => $rand,
5241 'result' => $response_credit['res_err_code'],
5242 'data' => $response_credit,
5243 );
5244 usces_save_order_acting_error( $log );
5245 do_action( 'usces_action_register_auto_orderdata', $args, $response_credit );
5246 }
5247 } else {
5248 $usces->set_order_meta_value( 'trans_id', $rand, $order_id );
5249 $this->save_acting_log( $response_settlement, $this->acting_card, $acting_opts['sales'], $response_settlement['res_result'], $order_id, $tracking_id );
5250 $settltment_errmsg = __( '[Regular purchase] Settlement was not completed.', 'autodelivery' );
5251 $log = array(
5252 'acting' => $this->acting_card,
5253 'key' => $rand,
5254 'result' => $response_settlement['res_err_code'],
5255 'data' => $response_settlement,
5256 );
5257 usces_save_order_acting_error( $log );
5258 do_action( 'usces_action_register_auto_orderdata', $args, $response_settlement );
5259 }
5260 } else {
5261 $usces->set_order_meta_value( 'trans_id', $rand, $order_id );
5262 $result = ( isset( $cust_ref['result'] ) ) ? $cust_ref['result'] : 'NG';
5263 $this->save_acting_log( $cust_ref, $this->acting_card, 'error', $result, $order_id, $rand );
5264 $settltment_errmsg = __( '[Regular purchase] Member information acquisition error.', 'autodelivery' );
5265 $log = array(
5266 'acting' => $this->acting_card . '(member_process)',
5267 'key' => $member_id,
5268 'result' => $result,
5269 'data' => $cust_ref,
5270 );
5271 usces_save_order_acting_error( $log );
5272 do_action( 'usces_action_register_auto_orderdata', $args, $cust_ref );
5273 }
5274 if ( '' !== $settltment_errmsg ) {
5275 $settlement = array(
5276 'settltment_status' => __( 'Failure', 'autodelivery' ),
5277 'settltment_errmsg' => $settltment_errmsg,
5278 );
5279 $usces->set_order_meta_value( $acting_flg, usces_serialize( $settlement ), $order_id );
5280 wcad_settlement_error_mail( $order_id, $settltment_errmsg );
5281 }
5282 }
5283
5284 /**
5285 * 決済ログ更新
5286 *
5287 * @param string $acting Acting type.
5288 * @param int $order_id Order number.
5289 * @param string $tracking_id Tracking ID.
5290 * @param string $trans_id Transaction ID.
5291 * @return array
5292 */
5293 private function update_acting_log( $acting, $order_id, $tracking_id, $trans_id ) {
5294 global $wpdb;
5295
5296 $res = false;
5297
5298 $acting_log = $wpdb->get_row(
5299 $wpdb->prepare(
5300 "SELECT * FROM {$wpdb->prefix}usces_acting_log WHERE `acting` = %d AND `order_id` = %d AND `tracking_id` = %s",
5301 $acting,
5302 $order_id,
5303 $trans_id
5304 ),
5305 ARRAY_A
5306 );
5307
5308 if ( $acting_log && isset( $acting_log['status'] ) && 'error' === $acting_log['status'] ) {
5309 $res = $wpdb->query(
5310 $wpdb->prepare(
5311 "UPDATE {$wpdb->prefix}usces_acting_log SET `tracking_id` = %s WHERE `ID` = %d",
5312 $tracking_id,
5313 $acting_log['ID']
5314 )
5315 );
5316 }
5317 return $res;
5318 }
5319 }
5320