| 1 |
<?php |
| 2 |
$usces_payment = false; |
| 3 |
$payments = usces_get_system_option( 'usces_payment_method', 'sort' ); |
| 4 |
foreach( (array)$payments as $id => $payment ) { |
| 5 |
if( 'acting_paypal_ec' == $payment['settlement'] ) { $usces_payment = true; break; } |
| 6 |
} |
| 7 |
if( $usces_payment ) { |
| 8 |
add_action( 'init', 'usces_paypal_add_stylesheet' ); |
| 9 |
add_action( 'usces_after_main', 'usces_paypal_add_script' ); |
| 10 |
add_action( 'usces_front_ajax', 'usces_paypal_front_ajax' ); |
| 11 |
add_filter( 'usces_filter_uscesL10n', 'usces_paypal_filter_uscesL10n' ); |
| 12 |
add_filter( 'usces_filter_paypal_ec_cancelurl', 'usces_paypal_filter_paypal_ec_cancelurl', 10, 2 ); |
| 13 |
add_action( 'usces_action_cart_page_footer', 'usces_paypal_action_cart_page_footer' ); |
| 14 |
//add_filter( 'usces_filter_cart_page_footer', 'usces_paypal_filter_cart_page_footer' ); |
| 15 |
add_filter( 'usces_filter_cartContent', 'usces_paypal_filter_cart_page_footer' ); |
| 16 |
add_action( 'usces_action_customerinfo', 'usces_paypal_action_customerinfo' ); |
| 17 |
} |
| 18 |
|
| 19 |
function usces_paypal_add_stylesheet() { |
| 20 |
global $usces; |
| 21 |
if( $usces->is_cart_page($_SERVER['REQUEST_URI']) ) { |
| 22 |
$jquery_ui_style_url = USCES_FRONT_PLUGIN_URL.'/css/jquery/jquery-ui-1.10.3.custom.min.css'; |
| 23 |
$jquery_usces_paypal_style_url = USCES_FRONT_PLUGIN_URL.'/css/usces_paypal_style.css'; |
| 24 |
wp_register_style( 'jquery-ui-style', $jquery_ui_style_url ); |
| 25 |
wp_register_style( 'usces_paypal_style', $jquery_usces_paypal_style_url ); |
| 26 |
wp_enqueue_style( 'jquery-ui-style' ); |
| 27 |
wp_enqueue_style( 'usces_paypal_style' ); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
function usces_paypal_add_script() { |
| 32 |
global $usces; |
| 33 |
if( $usces->is_cart_page($_SERVER['REQUEST_URI']) ) { |
| 34 |
wp_enqueue_script( 'jquery-ui-dialog' ); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
function usces_paypal_filter_uscesL10n() { |
| 39 |
global $usces; |
| 40 |
if( $usces->is_cart_page($_SERVER['REQUEST_URI']) ) { |
| 41 |
echo "'frontAjaxUrl': '".USCES_SSL_URL."',\n"; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
function usces_paypal_action_cart_page_footer() { |
| 46 |
$footer = usces_paypal_cart_page_footer(); |
| 47 |
echo $footer; |
| 48 |
} |
| 49 |
|
| 50 |
function usces_paypal_filter_cart_page_footer( $html ) { |
| 51 |
global $usces; |
| 52 |
$footer = ( 'cart' == $usces->page ) ? usces_paypal_cart_page_footer( false ) : ''; |
| 53 |
return $html.$footer; |
| 54 |
} |
| 55 |
|
| 56 |
function usces_paypal_cart_page_footer( $include = true ) { |
| 57 |
global $usces; |
| 58 |
$html = ''; |
| 59 |
|
| 60 |
$member = $usces->get_member(); |
| 61 |
if( !usces_paypal_set_session( $member['ID'] ) ) return $html; |
| 62 |
if( false === $usces->cart->num_row() ) return $html; |
| 63 |
if( defined('WCEX_AUTO_DELIVERY') and wcad_have_regular_order() ) return $html; |
| 64 |
|
| 65 |
$usces_entries = $usces->cart->get_entry(); |
| 66 |
$usces->set_cart_fees( $member, $usces_entries ); |
| 67 |
|
| 68 |
$usces_entries = $usces->cart->get_entry(); |
| 69 |
$total_price = $usces_entries['order']['total_items_price'] + $usces_entries['order']['discount'] + $usces_entries['order']['shipping_charge'] + $usces_entries['order']['cod_fee']; |
| 70 |
$item_price = $usces_entries['order']['total_items_price'] + $usces_entries['order']['discount']; |
| 71 |
|
| 72 |
if( $include ) { |
| 73 |
include( USCES_PLUGIN_DIR."/includes/delivery_info_script.php" ); |
| 74 |
} else { |
| 75 |
ob_start(); |
| 76 |
include( USCES_PLUGIN_DIR."/includes/delivery_info_script.php" ); |
| 77 |
$html .= ob_get_clean(); |
| 78 |
} |
| 79 |
|
| 80 |
$html .= ' |
| 81 |
<script type="text/javascript"> |
| 82 |
jQuery(function($) { |
| 83 |
paypalfunc = { |
| 84 |
settings: { |
| 85 |
url: uscesL10n.frontAjaxUrl + "/", |
| 86 |
type: "POST", |
| 87 |
cache: false, |
| 88 |
error: function( res, dataType ) { |
| 89 |
alert( "Ajax error" ); |
| 90 |
} |
| 91 |
}, |
| 92 |
deliveryMethodSelect: function() { |
| 93 |
var s = this.settings; |
| 94 |
s.data = "usces_ajax_action=paypal_delivery_method&selected=" + $("#delivery_method_select option:selected").val() + "&delivery_date=" + $("#delivery_date_select").val() + "&delivery_time=" + $("#delivery_time_select").val(); |
| 95 |
s.success = function( res, dataType ) { |
| 96 |
var r = res.split( "#usces#" ); |
| 97 |
if( r[0] == "error" ) { |
| 98 |
$("#paypal_error_message_delivery_method").html( r[1] ); |
| 99 |
} else { |
| 100 |
$("#paypal_error_message_delivery_method").empty(); |
| 101 |
$("#paypal_confirm").empty(); |
| 102 |
$("#paypal_purchase").empty(); |
| 103 |
$("#paypal_confirm").html( r[1] ); |
| 104 |
$("#paypal_purchase").html( r[2] ); |
| 105 |
$("#delivery_date_select").bind("change", function(){ this.deliveryDateSelect(); }); |
| 106 |
$("#delivery_time_select").bind("change", function(){ this.deliveryTimeSelect(); }); |
| 107 |
} |
| 108 |
}; |
| 109 |
$.ajax( s ); |
| 110 |
return false; |
| 111 |
}, |
| 112 |
deliveryDateSelect: function() { |
| 113 |
var s = this.settings; |
| 114 |
s.data = "usces_ajax_action=paypal_delivery_date_select&selected=" + $("#delivery_date_select option:selected").val(); |
| 115 |
s.success = function( res, dataType ) { |
| 116 |
}; |
| 117 |
$.ajax( s ); |
| 118 |
return false; |
| 119 |
}, |
| 120 |
deliveryTimeSelect: function() { |
| 121 |
var s = this.settings; |
| 122 |
s.data = "usces_ajax_action=paypal_delivery_time_select&selected=" + $("#delivery_time_select option:selected").val(); |
| 123 |
s.success = function( res, dataType ) { |
| 124 |
}; |
| 125 |
$.ajax( s ); |
| 126 |
return false; |
| 127 |
}, |
| 128 |
usePoint: function() { |
| 129 |
var s = this.settings; |
| 130 |
s.data = "usces_ajax_action=paypal_use_point&usepoint=" + $("#set_usedpoint").val() + "&total_price='.$total_price.'&item_price='.$item_price.'"; |
| 131 |
s.success = function( res, dataType ) { |
| 132 |
var r = res.split( "#usces#" ); |
| 133 |
if( r[0] == "error" ) { |
| 134 |
$("#paypal_error_message_use_point").html( r[1] ); |
| 135 |
} else { |
| 136 |
$("#paypal_error_message_use_point").empty(); |
| 137 |
$("#paypal_confirm").empty(); |
| 138 |
$("#paypal_purchase").empty(); |
| 139 |
$("#paypal_confirm").html( r[1] ); |
| 140 |
$("#paypal_purchase").html( r[2] ); |
| 141 |
$("#delivery_date_select").bind("change", function(){ this.deliveryDateSelect(); }); |
| 142 |
$("#delivery_time_select").bind("change", function(){ this.deliveryTimeSelect(); }); |
| 143 |
} |
| 144 |
}; |
| 145 |
$.ajax( s ); |
| 146 |
return false; |
| 147 |
} |
| 148 |
}; |
| 149 |
$("#paypal_dialog").dialog({ |
| 150 |
bgiframe: true, |
| 151 |
autoOpen: false, |
| 152 |
height: "auto", |
| 153 |
width: 400, |
| 154 |
resizable: true, |
| 155 |
modal: true, |
| 156 |
position: ["top",100], |
| 157 |
open: function( event, ui ) { |
| 158 |
$(".ui-dialog-titlebar", ui.panel).hide(); |
| 159 |
} |
| 160 |
}); |
| 161 |
$("#paypal_button").click( function() { |
| 162 |
$("#paypal_dialog").dialog( "open" ); |
| 163 |
}); |
| 164 |
$("#paypal_close").click( function() { |
| 165 |
$("#paypal_dialog").dialog( "close" ); |
| 166 |
}); |
| 167 |
if( $("#delivery_method_select option").length > 1 ) { |
| 168 |
$("#delivery_method_select").bind("change", function(){ paypalfunc.deliveryMethodSelect(); }); |
| 169 |
} |
| 170 |
$("#delivery_date_select").bind("change", function(){ paypalfunc.deliveryDateSelect(); }); |
| 171 |
$("#delivery_time_select").bind("change", function(){ paypalfunc.deliveryTimeSelect(); }); |
| 172 |
if( $("#paypal_use_point") != undefined ) { |
| 173 |
$("#paypal_use_point").bind("click", function(){ paypalfunc.usePoint(); }); |
| 174 |
} |
| 175 |
}); |
| 176 |
</script> |
| 177 |
<div class="send"><input type="image" src="https://www.paypal.com/'.( USCES_JP ? 'ja_JP/JP' : 'en_US' ).'/i/btn/btn_xpressCheckout.gif" border="0" class="paypal_button" id="paypal_button" alt="PayPal" /></div> |
| 178 |
<div id="paypal_dialog"> |
| 179 |
<div id="paypal_confirm">'.usces_paypal_confirm_form().'</div> |
| 180 |
<div id="paypal_shipping">'.usces_paypal_shipping_form().'</div> |
| 181 |
<div id="paypal_point">'.usces_paypal_point_form( $member['point'] ).'</div> |
| 182 |
<div id="paypal_purchase">'.usces_paypal_purchase_form().'</div> |
| 183 |
<div class="send"><input name="paypal_close" type="button" id="paypal_close" class="back_to_delivery_button" value="'.__('Cancel', 'usces').'" /></div> |
| 184 |
</div>'; |
| 185 |
|
| 186 |
return $html; |
| 187 |
} |
| 188 |
|
| 189 |
function usces_paypal_set_session( $member_id, $uscesid = NULL ) { |
| 190 |
global $usces, $wpdb; |
| 191 |
|
| 192 |
$member_table = $wpdb->prefix."usces_member"; |
| 193 |
$query = $wpdb->prepare( "SELECT * FROM $member_table WHERE ID = %d", $member_id ); |
| 194 |
$member = $wpdb->get_row( $query, ARRAY_A ); |
| 195 |
if( empty($member) ) return false; |
| 196 |
|
| 197 |
$_SESSION['usces_member']['ID'] = $member['ID']; |
| 198 |
$_SESSION['usces_member']['mailaddress1'] = $member['mem_email']; |
| 199 |
$_SESSION['usces_member']['mailaddress2'] = $member['mem_email']; |
| 200 |
$_SESSION['usces_member']['point'] = $member['mem_point']; |
| 201 |
$_SESSION['usces_member']['name1'] = $member['mem_name1']; |
| 202 |
$_SESSION['usces_member']['name2'] = $member['mem_name2']; |
| 203 |
$_SESSION['usces_member']['name3'] = $member['mem_name3']; |
| 204 |
$_SESSION['usces_member']['name4'] = $member['mem_name4']; |
| 205 |
$_SESSION['usces_member']['zipcode'] = $member['mem_zip']; |
| 206 |
$_SESSION['usces_member']['pref'] = $member['mem_pref']; |
| 207 |
$_SESSION['usces_member']['address1'] = $member['mem_address1']; |
| 208 |
$_SESSION['usces_member']['address2'] = $member['mem_address2']; |
| 209 |
$_SESSION['usces_member']['address3'] = $member['mem_address3']; |
| 210 |
$_SESSION['usces_member']['tel'] = $member['mem_tel']; |
| 211 |
$_SESSION['usces_member']['fax'] = $member['mem_fax']; |
| 212 |
$_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag']; |
| 213 |
$_SESSION['usces_member']['delivery'] = ( !empty($member['mem_delivery']) ) ? unserialize($member['mem_delivery']) : ''; |
| 214 |
$_SESSION['usces_member']['registered'] = $member['mem_registered']; |
| 215 |
$_SESSION['usces_member']['nicename'] = $member['mem_nicename']; |
| 216 |
$_SESSION['usces_member']['country'] = $usces->get_member_meta_value( 'customer_country', $member['ID'] ); |
| 217 |
$_SESSION['usces_member']['status'] = $member['mem_status']; |
| 218 |
$usces->set_session_custom_member( $member['ID'] ); |
| 219 |
|
| 220 |
foreach( $_SESSION['usces_member'] as $key => $value ) { |
| 221 |
if( 'custom_member' == $key ) { |
| 222 |
foreach( $_SESSION['usces_member']['custom_member'] as $mbkey => $mbvalue ) { |
| 223 |
//if( empty($_SESSION['usces_entry']['custom_customer'][$mbkey]) ) { |
| 224 |
if( is_array($mbvalue) ) { |
| 225 |
foreach( $mbvalue as $k => $v ) { |
| 226 |
$_SESSION['usces_entry']['custom_customer'][$mbkey][$v] = $v; |
| 227 |
} |
| 228 |
} else { |
| 229 |
$_SESSION['usces_entry']['custom_customer'][$mbkey] = $mbvalue; |
| 230 |
} |
| 231 |
//} |
| 232 |
} |
| 233 |
} else { |
| 234 |
if( 'country' == $key and empty( $value ) ) { |
| 235 |
$_SESSION['usces_entry']['customer'][$key] = usces_get_base_country(); |
| 236 |
} else { |
| 237 |
$_SESSION['usces_entry']['customer'][$key] = trim( $value ); |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
foreach( $_SESSION['usces_entry']['customer'] as $key => $value ) { |
| 242 |
if( 'country' == $key and empty( $value ) ) { |
| 243 |
$_SESSION['usces_entry']['delivery'][$key] = usces_get_base_country(); |
| 244 |
} else { |
| 245 |
$_SESSION['usces_entry']['delivery'][$key] = trim( $value ); |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
return true; |
| 250 |
} |
| 251 |
|
| 252 |
function usces_paypal_confirm_form() { |
| 253 |
global $usces; |
| 254 |
|
| 255 |
$usces_entries = $usces->cart->get_entry(); |
| 256 |
$html = ' |
| 257 |
<table> |
| 258 |
<tr> |
| 259 |
<th>'.__('total items', 'usces').'</th> |
| 260 |
<td>'.usces_crform( $usces_entries['order']['total_items_price'], true, false, 'return', true ).'</td> |
| 261 |
</tr>'; |
| 262 |
if( usces_is_member_system_point() && !empty($usces_entries['order']['usedpoint']) ) { |
| 263 |
$html .= ' |
| 264 |
<tr> |
| 265 |
<th>'.__('Used points', 'usces').'</th> |
| 266 |
<td><span class="confirm_usedpoint">'.usces_crform( $usces_entries['order']['usedpoint'], false, false, 'return', true ).'</span></td> |
| 267 |
</tr>'; |
| 268 |
} |
| 269 |
if( !empty($usces_entries['order']['discount']) ) { |
| 270 |
$html .= ' |
| 271 |
<tr> |
| 272 |
<th>'.apply_filters( 'usces_confirm_discount_label', __('Campaign disnount', 'usces') ).'</th> |
| 273 |
<td>'.usces_crform( $usces_entries['order']['discount'], true, false, 'return', true ).'</td> |
| 274 |
</tr>'; |
| 275 |
} |
| 276 |
$html .= ' |
| 277 |
<tr> |
| 278 |
<th>'.__('Shipping', 'usces').'</th> |
| 279 |
<td>'.usces_crform( $usces_entries['order']['shipping_charge'], true, false, 'return', true ).'</td> |
| 280 |
</tr>'; |
| 281 |
if( !empty($usces_entries['order']['cod_fee']) ) { |
| 282 |
$html .= ' |
| 283 |
<tr> |
| 284 |
<th>'.apply_filters( 'usces_filter_cod_label', __('COD fee', 'usces') ).'</th> |
| 285 |
<td>'.usces_crform( $usces_entries['order']['cod_fee'], true, false, 'return', true ).'</td> |
| 286 |
</tr>'; |
| 287 |
} |
| 288 |
if( !empty($usces_entries['order']['tax']) ) { |
| 289 |
$html .= ' |
| 290 |
<tr> |
| 291 |
<th>'.__('consumption tax', 'usces').'</th> |
| 292 |
<td>'.usces_crform( $usces_entries['order']['tax'], true, false, 'return', true ).'</td> |
| 293 |
</tr>'; |
| 294 |
} |
| 295 |
$html .= ' |
| 296 |
<tr> |
| 297 |
<th>'.__('Total Amount', 'usces').'</th> |
| 298 |
<td>'.usces_crform( $usces_entries['order']['total_full_price'], true, false, 'return', true ).'</td> |
| 299 |
</tr> |
| 300 |
</table>'; |
| 301 |
return $html; |
| 302 |
} |
| 303 |
|
| 304 |
function usces_paypal_shipping_form() { |
| 305 |
global $usces; |
| 306 |
|
| 307 |
$html = ''; |
| 308 |
$cart = $usces->cart->get_cart(); |
| 309 |
if( 'shipped' == $usces->getItemDivision( $cart[0]['post_id'] ) ) { |
| 310 |
$usces_entries = $usces->cart->get_entry(); |
| 311 |
$html = ' |
| 312 |
<div class="error_message" id="paypal_error_message_delivery_method"></div> |
| 313 |
<table> |
| 314 |
<tr> |
| 315 |
<th>'.__('shipping option', 'usces').'</th> |
| 316 |
<td>'.usces_the_delivery_method( $usces_entries['order']['delivery_method'], 'return' ).'</td> |
| 317 |
</tr> |
| 318 |
<tr> |
| 319 |
<th>'.__('Delivery date', 'usces').'</th> |
| 320 |
<td>'.usces_the_delivery_date( $usces_entries['order']['delivery_date'], 'return' ).'</td> |
| 321 |
</tr> |
| 322 |
<tr> |
| 323 |
<th>'.__('Delivery Time', 'usces').'</th> |
| 324 |
<td>'.usces_the_delivery_time( $usces_entries['order']['delivery_time'], 'return' ).'</td> |
| 325 |
</tr> |
| 326 |
</table>'; |
| 327 |
} |
| 328 |
return $html; |
| 329 |
} |
| 330 |
|
| 331 |
function usces_paypal_point_form( $point ) { |
| 332 |
global $usces; |
| 333 |
|
| 334 |
$html = ''; |
| 335 |
if( usces_is_member_system_point() ) { |
| 336 |
$usces_entries = $usces->cart->get_entry(); |
| 337 |
$usedpoint = ( 0 < $usces_entries['order']['usedpoint'] ) ? $usces_entries['order']['usedpoint'] : ''; |
| 338 |
$html = ' |
| 339 |
<div class="error_message" id="paypal_error_message_use_point"></div> |
| 340 |
<table> |
| 341 |
<tr> |
| 342 |
<th>'.__('The current point', 'usces').'</th> |
| 343 |
<td><span class="point">'.$point.'</span>pt</td> |
| 344 |
</tr> |
| 345 |
<tr> |
| 346 |
<th>'.__('Points you are using here', 'usces').'</th> |
| 347 |
<td><input name="offer[usedpoint]" class="used_point" id="set_usedpoint" type="text" value="'.$usedpoint.'" />pt</td> |
| 348 |
</tr> |
| 349 |
<tr> |
| 350 |
<td colspan="2"><input name="use_point" type="button" class="use_point_button" id="paypal_use_point" value="'.__('Use the points', 'usces').'" /></td> |
| 351 |
</tr> |
| 352 |
</table>'; |
| 353 |
} |
| 354 |
return $html; |
| 355 |
} |
| 356 |
|
| 357 |
function usces_paypal_purchase_form() { |
| 358 |
global $usces, $payments; |
| 359 |
|
| 360 |
$usces_entries = $usces->cart->get_entry(); |
| 361 |
$acting_opts = $usces->options['acting_settings']['paypal']; |
| 362 |
$currency_code = $usces->get_currency_code(); |
| 363 |
|
| 364 |
$payment_paypal = array(); |
| 365 |
foreach( (array)$payments as $id => $payment ) { |
| 366 |
if( 'acting_paypal_ec' == $payment['settlement'] ) { |
| 367 |
$usces->cart->set_order_entry( array( 'payment_name' => $payment['name'] ) ); |
| 368 |
$payment_paypal = $payment; |
| 369 |
break; |
| 370 |
} |
| 371 |
} |
| 372 |
$acting_flag = 'acting_paypal_ec'; |
| 373 |
$rand = usces_rand(); |
| 374 |
//$purchase_disabled = ( '' != $usces->error_message ) ? ' disabled="true"' : ''; |
| 375 |
$purchase_disabled = ''; |
| 376 |
|
| 377 |
$cart = $usces->cart->get_cart(); |
| 378 |
$html = ' |
| 379 |
<form id="purchase_form" action="'.USCES_CART_URL.'" method="post" onKeyDown="if (event.keyCode == 13) {return false;}"> |
| 380 |
<input type="hidden" name="SOLUTIONTYPE" value="Sole"> |
| 381 |
<input type="hidden" name="LANDINGPAGE" value="Billing"> |
| 382 |
<input type="hidden" name="EMAIL" value="'.esc_attr( $usces_entries['customer']['mailaddress1'] ).'"> |
| 383 |
<input type="hidden" name="PAYMENTREQUEST_0_CURRENCYCODE" value="'.$currency_code.'">'; |
| 384 |
if( 'shipped' == $usces->getItemDivision( $cart[0]['post_id'] ) ) { |
| 385 |
$name = apply_filters( 'usces_filter_paypalec_shiptoname', esc_attr( $usces_entries['delivery']['name2'].' '.$usces_entries['delivery']['name1'] ) ); |
| 386 |
$address2 = apply_filters( 'usces_filter_paypalec_shiptostreet', esc_attr( $usces_entries['delivery']['address2'] ) ); |
| 387 |
$address3 = apply_filters( 'usces_filter_paypalec_shiptostreet2', esc_attr( $usces_entries['delivery']['address3'] ) ); |
| 388 |
$address1 = apply_filters( 'usces_filter_paypalec_shiptocity', esc_attr( $usces_entries['delivery']['address1'] ) ); |
| 389 |
$pref = apply_filters( 'usces_filter_paypalec_shiptostate', esc_attr( $usces_entries['delivery']['pref'] ) ); |
| 390 |
$country = ( !empty($usces_entries['delivery']['country']) ) ? $usces_entries['delivery']['country'] : usces_get_base_country(); |
| 391 |
$country_code = apply_filters( 'usces_filter_paypalec_shiptocountrycode', $country ); |
| 392 |
$zip = apply_filters( 'usces_filter_paypalec_shiptozip', $usces_entries['delivery']['zipcode'] ); |
| 393 |
$tel = apply_filters( 'usces_filter_paypalec_shiptophonenum', ltrim( str_replace( '-', '', $usces_entries['delivery']['tel'] ), '0' ) ); |
| 394 |
$html .= ' |
| 395 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTONAME" value="'.$name.'"> |
| 396 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOSTREET" value="'.$address2.'"> |
| 397 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOSTREET2" value="'.$address3.'"> |
| 398 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOCITY" value="'.$address1.'"> |
| 399 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOSTATE" value="'.$pref.'"> |
| 400 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE" value="'.$country_code.'"> |
| 401 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOZIP" value="'.$zip.'"> |
| 402 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOPHONENUM" value="'.$tel.'">'; |
| 403 |
} |
| 404 |
if( 'shipped' != $usces->getItemDivision( $cart[0]['post_id'] ) ) { |
| 405 |
$html .= '<input type="hidden" name="NOSHIPPING" value="1">'; |
| 406 |
} |
| 407 |
$charging_type = $usces->getItemChargingType( $cart[0]['post_id'], $cart ); |
| 408 |
if( 'continue' != $charging_type ) { |
| 409 |
//通常購� |
| 410 |
� |
| 411 |
$item_total_price = 0; |
| 412 |
$i = 0; |
| 413 |
foreach( $cart as $cart_row ) { |
| 414 |
$html .= ' |
| 415 |
<input type="hidden" name="L_PAYMENTREQUEST_0_NAME'.$i.'" value="'.esc_attr( $usces->getItemName($cart_row['post_id']) ).'"> |
| 416 |
<input type="hidden" name="L_PAYMENTREQUEST_0_AMT'.$i.'" value="'.usces_crform( $cart_row['price'], false, false, 'return', false ) .'"> |
| 417 |
<input type="hidden" name="L_PAYMENTREQUEST_0_NUMBER'.$i.'" value="'.esc_attr( $usces->getItemCode($cart_row['post_id']) ).'"> |
| 418 |
<input type="hidden" name="L_PAYMENTREQUEST_0_QTY'.$i.'" value="'.esc_attr( $cart_row['quantity'] ).'">'; |
| 419 |
$item_total_price += ( $cart_row['price'] * $cart_row['quantity'] ); |
| 420 |
$i++; |
| 421 |
} |
| 422 |
if( !empty($usces_entries['order']['discount']) ) { |
| 423 |
$html .= ' |
| 424 |
<input type="hidden" name="L_PAYMENTREQUEST_0_NAME'.$i.'" value="'.esc_attr( __('Campaign disnount', 'usces') ).'"> |
| 425 |
<input type="hidden" name="L_PAYMENTREQUEST_0_AMT'.$i.'" value="'.usces_crform( $usces_entries['order']['discount'], false, false, 'return', false ).'">'; |
| 426 |
$item_total_price += $usces_entries['order']['discount']; |
| 427 |
$i++; |
| 428 |
} |
| 429 |
if( !empty($usces_entries['order']['usedpoint']) ) { |
| 430 |
$html .= ' |
| 431 |
<input type="hidden" name="L_PAYMENTREQUEST_0_NAME'.$i.'" value="'.esc_attr(__('Used points', 'usces')).'"> |
| 432 |
<input type="hidden" name="L_PAYMENTREQUEST_0_AMT'.$i.'" value="'.usces_crform( $usces_entries['order']['usedpoint']*(-1), false, false, 'return', false ).'">'; |
| 433 |
$item_total_price -= $usces_entries['order']['usedpoint']; |
| 434 |
$i++; |
| 435 |
} |
| 436 |
$html .= ' |
| 437 |
<input type="hidden" name="PAYMENTREQUEST_0_ITEMAMT" value="'.usces_crform( $item_total_price, false, false, 'return', false ).'"> |
| 438 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPPINGAMT" value="'.usces_crform( $usces_entries['order']['shipping_charge'], false, false, 'return', false ).'"> |
| 439 |
<input type="hidden" name="PAYMENTREQUEST_0_AMT" value="'.usces_crform( $usces_entries['order']['total_full_price'], false, false, 'return', false ).'"> |
| 440 |
'; |
| 441 |
if( !empty($usces_entries['order']['cod_fee']) ) $html .= '<input type="hidden" name="PAYMENTREQUEST_0_HANDLINGAMT" value="'.usces_crform( $usces_entries['order']['cod_fee'], false, false, 'return', false ).'">'; |
| 442 |
if( !empty($usces_entries['order']['tax']) ) $html .= '<input type="hidden" name="PAYMENTREQUEST_0_TAXAMT" value="'.usces_crform( $usces_entries['order']['tax'], false, false, 'return', false ).'">'; |
| 443 |
} else { |
| 444 |
//定期支払い |
| 445 |
$desc = usces_make_agreement_description( $cart, $usces_entries['order']['total_full_price'] ); |
| 446 |
$html .= '<input type="hidden" name="L_BILLINGTYPE0" value="RecurringPayments"> |
| 447 |
<input type="hidden" name="L_BILLINGAGREEMENTDESCRIPTION0" value="'.esc_attr($desc).'"> |
| 448 |
<input type="hidden" name="AMT" value="0">'; |
| 449 |
} |
| 450 |
if( !empty($acting_opts['logoimg']) ) $html .= '<input type="hidden" name="LOGOIMG" value="'.esc_attr( $acting_opts['logoimg'] ).'">'; |
| 451 |
if( !empty($acting_opts['cartbordercolor']) ) $html .= '<input type="hidden" name="CARTBORDERCOLOR" value="'.esc_attr( $acting_opts['cartbordercolor'] ).'">'; |
| 452 |
$html .= '<input type="hidden" name="purchase" value="acting_paypal_ec">'; |
| 453 |
$html .= '<input type="hidden" name="paypal_from_cart" value="1">'; |
| 454 |
$html .= '<div class="send"><input type="image" src="https://www.paypal.com/'.( USCES_JP ? 'ja_JP/JP' : 'en_US' ).'/i/btn/btn_xpressCheckout.gif" border="0" name="submit" value="submit" alt="PayPal"'.apply_filters( 'usces_filter_confirm_nextbutton', NULL ).$purchase_disabled.' /></div>'; |
| 455 |
$html = apply_filters( 'usces_filter_confirm_inform', $html, $payment_paypal, $acting_flag, $rand, $purchase_disabled ); |
| 456 |
$html .= '</form>'; |
| 457 |
return $html; |
| 458 |
} |
| 459 |
|
| 460 |
function usces_paypal_front_ajax() { |
| 461 |
switch( $_POST['usces_ajax_action'] ) { |
| 462 |
case 'paypal_delivery_method': |
| 463 |
usces_paypal_delivery_method( $_POST['selected'], $_POST['delivery_date'], $_POST['delivery_time'] ); |
| 464 |
break; |
| 465 |
case 'paypal_use_point': |
| 466 |
usces_paypal_use_point( $_POST['usepoint'], $_POST['total_price'], $_POST['item_price'] ); |
| 467 |
break; |
| 468 |
case 'paypal_delivery_date_select': |
| 469 |
usces_paypal_delivery_date_select( $_POST['selected'] ); |
| 470 |
break; |
| 471 |
case 'paypal_delivery_time_select': |
| 472 |
usces_paypal_delivery_time_select( $_POST['selected'] ); |
| 473 |
break; |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
function usces_paypal_delivery_method( $delivery_method_select, $delivery_date, $delivery_time ) { |
| 478 |
global $usces; |
| 479 |
|
| 480 |
$usces_entries = $usces->cart->get_entry(); |
| 481 |
$usces->cart->set_order_entry( array( 'delivery_method' => $delivery_method_select, 'delivery_date' => $delivery_date, 'delivery_time' => $delivery_time ) ); |
| 482 |
$usces_entries['order']['delivery_method'] = $delivery_method_select; |
| 483 |
$usces->set_cart_fees( $member, $usces_entries ); |
| 484 |
$res = "ok#usces#".usces_paypal_confirm_form()."#usces#".usces_paypal_purchase_form(); |
| 485 |
die( $res ); |
| 486 |
} |
| 487 |
|
| 488 |
function usces_paypal_use_point( $usepoint, $total_price, $item_price ) { |
| 489 |
global $usces; |
| 490 |
|
| 491 |
$res = ''; |
| 492 |
$mes = ''; |
| 493 |
$member = $usces->get_member(); |
| 494 |
$usces_entries = $usces->cart->get_entry(); |
| 495 |
|
| 496 |
if( WCUtils::is_blank( $usepoint ) || !preg_match( "/^[0-9]+$/", $usepoint ) || (int)$usepoint < 0 ) { |
| 497 |
$mes = __('Invalid value. Please enter in the numbers.', 'usces'); |
| 498 |
} else { |
| 499 |
if( $usepoint > (int)$member['point'] ) { |
| 500 |
$mes = __('You have exceeded the maximum available.', 'usces')."max".(int)$member['point']."pt"; |
| 501 |
} elseif( $usces->options['point_coverage'] && $usepoint > $total_price ) { |
| 502 |
$mes = __('You have exceeded the maximum available.', 'usces')."max".$total_price."pt"; |
| 503 |
} elseif( !$usces->options['point_coverage'] && $usepoint > $item_price ) { |
| 504 |
$mes = __('You have exceeded the maximum available.', 'usces')."max".$item_price."pt"; |
| 505 |
} |
| 506 |
} |
| 507 |
if( '' != $mes ) { |
| 508 |
$usces->cart->set_order_entry( array( 'usedpoint' => 0 ) ); |
| 509 |
$res = "error#usces#".$mes; |
| 510 |
} else { |
| 511 |
$usces->cart->set_order_entry( array( 'usedpoint' => $usepoint ) ); |
| 512 |
$usces_entries['order']['usedpoint'] = $usepoint; |
| 513 |
$usces->set_cart_fees( $member, $usces_entries ); |
| 514 |
$res = "ok#usces#".usces_paypal_confirm_form()."#usces#".usces_paypal_purchase_form(); |
| 515 |
} |
| 516 |
die( $res ); |
| 517 |
} |
| 518 |
|
| 519 |
function usces_paypal_filter_paypal_ec_cancelurl( $cancelurl, $query ) { |
| 520 |
global $usces; |
| 521 |
$pos = strpos( $query, 'paypal_from_cart' ); |
| 522 |
if( false !== $pos ) { |
| 523 |
$cancelurl = urlencode( USCES_CART_URL ); |
| 524 |
} |
| 525 |
return $cancelurl; |
| 526 |
} |
| 527 |
|
| 528 |
function usces_paypal_delivery_date_select( $selected ) { |
| 529 |
global $usces; |
| 530 |
$usces->cart->set_order_entry( array( 'delivery_date' => $selected ) ); |
| 531 |
die( "ok" ); |
| 532 |
} |
| 533 |
|
| 534 |
function usces_paypal_delivery_time_select( $selected ) { |
| 535 |
global $usces; |
| 536 |
$usces->cart->set_order_entry( array( 'delivery_time' => $selected ) ); |
| 537 |
die( "ok" ); |
| 538 |
} |
| 539 |
|
| 540 |
function usces_paypal_action_customerinfo() { |
| 541 |
global $usces; |
| 542 |
if( $usces->is_member_logged_in() ) { |
| 543 |
$usces->cart->set_order_entry( array( 'payment_name' => '' ) ); |
| 544 |
} |
| 545 |
} |
| 546 |
|
| 547 |
?> |
| 548 |
|