| 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 |
$cart = $usces->cart->get_cart(); |
| 66 |
if( 'shipped' != $usces->getItemDivision( $cart[0]['post_id'] ) ) return $html; |
| 67 |
|
| 68 |
$usces_entries = $usces->cart->get_entry(); |
| 69 |
$usces->set_cart_fees( $member, $usces_entries ); |
| 70 |
|
| 71 |
$usces_entries = $usces->cart->get_entry(); |
| 72 |
$total_price = $usces_entries['order']['total_items_price'] + $usces_entries['order']['discount'] + $usces_entries['order']['shipping_charge'] + $usces_entries['order']['cod_fee']; |
| 73 |
$item_price = $usces_entries['order']['total_items_price'] + $usces_entries['order']['discount']; |
| 74 |
|
| 75 |
if( $include ) { |
| 76 |
include( USCES_PLUGIN_DIR."/includes/delivery_info_script.php" ); |
| 77 |
} else { |
| 78 |
ob_start(); |
| 79 |
include( USCES_PLUGIN_DIR."/includes/delivery_info_script.php" ); |
| 80 |
$html .= ob_get_clean(); |
| 81 |
} |
| 82 |
|
| 83 |
$html .= ' |
| 84 |
<script type="text/javascript"> |
| 85 |
jQuery(function($) { |
| 86 |
paypalfunc = { |
| 87 |
settings: { |
| 88 |
url: uscesL10n.frontAjaxUrl + "/", |
| 89 |
type: "POST", |
| 90 |
cache: false, |
| 91 |
error: function( res, dataType ) { |
| 92 |
alert( "Ajax error" ); |
| 93 |
} |
| 94 |
}, |
| 95 |
deliveryMethodSelect: function() { |
| 96 |
var s = this.settings; |
| 97 |
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(); |
| 98 |
s.success = function( res, dataType ) { |
| 99 |
var r = res.split( "#usces#" ); |
| 100 |
if( r[0] == "error" ) { |
| 101 |
$("#paypal_error_message_delivery_method").html( r[1] ); |
| 102 |
} else { |
| 103 |
$("#paypal_error_message_delivery_method").empty(); |
| 104 |
$("#paypal_confirm").empty(); |
| 105 |
$("#paypal_purchase").empty(); |
| 106 |
$("#paypal_confirm").html( r[1] ); |
| 107 |
$("#paypal_purchase").html( r[2] ); |
| 108 |
$("#delivery_date_select").bind("change", function(){ this.deliveryDateSelect(); }); |
| 109 |
$("#delivery_time_select").bind("change", function(){ this.deliveryTimeSelect(); }); |
| 110 |
} |
| 111 |
}; |
| 112 |
$.ajax( s ); |
| 113 |
return false; |
| 114 |
}, |
| 115 |
deliveryDateSelect: function() { |
| 116 |
var s = this.settings; |
| 117 |
s.data = "usces_ajax_action=paypal_delivery_date_select&selected=" + $("#delivery_date_select option:selected").val(); |
| 118 |
s.success = function( res, dataType ) { |
| 119 |
}; |
| 120 |
$.ajax( s ); |
| 121 |
return false; |
| 122 |
}, |
| 123 |
deliveryTimeSelect: function() { |
| 124 |
var s = this.settings; |
| 125 |
s.data = "usces_ajax_action=paypal_delivery_time_select&selected=" + $("#delivery_time_select option:selected").val(); |
| 126 |
s.success = function( res, dataType ) { |
| 127 |
}; |
| 128 |
$.ajax( s ); |
| 129 |
return false; |
| 130 |
}, |
| 131 |
usePoint: function() { |
| 132 |
var s = this.settings; |
| 133 |
s.data = "usces_ajax_action=paypal_use_point&usepoint=" + $("#set_usedpoint").val() + "&total_price='.$total_price.'&item_price='.$item_price.'"; |
| 134 |
s.success = function( res, dataType ) { |
| 135 |
var r = res.split( "#usces#" ); |
| 136 |
if( r[0] == "error" ) { |
| 137 |
$("#paypal_error_message_use_point").html( r[1] ); |
| 138 |
} else { |
| 139 |
$("#paypal_error_message_use_point").empty(); |
| 140 |
$("#paypal_confirm").empty(); |
| 141 |
$("#paypal_purchase").empty(); |
| 142 |
$("#paypal_confirm").html( r[1] ); |
| 143 |
$("#paypal_purchase").html( r[2] ); |
| 144 |
$("#delivery_date_select").bind("change", function(){ this.deliveryDateSelect(); }); |
| 145 |
$("#delivery_time_select").bind("change", function(){ this.deliveryTimeSelect(); }); |
| 146 |
} |
| 147 |
}; |
| 148 |
$.ajax( s ); |
| 149 |
return false; |
| 150 |
} |
| 151 |
}; |
| 152 |
$("#paypal_dialog").dialog({ |
| 153 |
bgiframe: true, |
| 154 |
autoOpen: false, |
| 155 |
height: "auto", |
| 156 |
width: 400, |
| 157 |
resizable: true, |
| 158 |
modal: true, |
| 159 |
position: ["top",100], |
| 160 |
open: function( event, ui ) { |
| 161 |
$(".ui-dialog-titlebar", ui.panel).hide(); |
| 162 |
} |
| 163 |
}); |
| 164 |
$("#paypal_button").click( function() { |
| 165 |
$("#paypal_dialog").dialog( "open" ); |
| 166 |
}); |
| 167 |
$("#paypal_close").click( function() { |
| 168 |
$("#paypal_dialog").dialog( "close" ); |
| 169 |
}); |
| 170 |
if( $("#delivery_method_select option").length > 1 ) { |
| 171 |
$("#delivery_method_select").bind("change", function(){ paypalfunc.deliveryMethodSelect(); }); |
| 172 |
} |
| 173 |
$("#delivery_date_select").bind("change", function(){ paypalfunc.deliveryDateSelect(); }); |
| 174 |
$("#delivery_time_select").bind("change", function(){ paypalfunc.deliveryTimeSelect(); }); |
| 175 |
if( $("#paypal_use_point") != undefined ) { |
| 176 |
$("#paypal_use_point").bind("click", function(){ paypalfunc.usePoint(); }); |
| 177 |
} |
| 178 |
}); |
| 179 |
</script> |
| 180 |
<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> |
| 181 |
<div id="paypal_dialog"> |
| 182 |
<div id="paypal_confirm">'.usces_paypal_confirm_form().'</div> |
| 183 |
<div id="paypal_shipping">'.usces_paypal_shipping_form().'</div> |
| 184 |
<div id="paypal_point">'.usces_paypal_point_form( $member['point'] ).'</div> |
| 185 |
<div id="paypal_purchase">'.usces_paypal_purchase_form().'</div> |
| 186 |
<div class="send"><input name="paypal_close" type="button" id="paypal_close" class="back_to_delivery_button" value="'.__('Cancel', 'usces').'" /></div> |
| 187 |
</div>'; |
| 188 |
|
| 189 |
return $html; |
| 190 |
} |
| 191 |
|
| 192 |
function usces_paypal_set_session( $member_id, $uscesid = NULL ) { |
| 193 |
global $usces, $wpdb; |
| 194 |
|
| 195 |
$member_table = $wpdb->prefix."usces_member"; |
| 196 |
$query = $wpdb->prepare( "SELECT * FROM $member_table WHERE ID = %d", $member_id ); |
| 197 |
$member = $wpdb->get_row( $query, ARRAY_A ); |
| 198 |
if( empty($member) ) return false; |
| 199 |
|
| 200 |
$_SESSION['usces_member']['ID'] = $member['ID']; |
| 201 |
$_SESSION['usces_member']['mailaddress1'] = $member['mem_email']; |
| 202 |
$_SESSION['usces_member']['mailaddress2'] = $member['mem_email']; |
| 203 |
$_SESSION['usces_member']['point'] = $member['mem_point']; |
| 204 |
$_SESSION['usces_member']['name1'] = $member['mem_name1']; |
| 205 |
$_SESSION['usces_member']['name2'] = $member['mem_name2']; |
| 206 |
$_SESSION['usces_member']['name3'] = $member['mem_name3']; |
| 207 |
$_SESSION['usces_member']['name4'] = $member['mem_name4']; |
| 208 |
$_SESSION['usces_member']['zipcode'] = $member['mem_zip']; |
| 209 |
$_SESSION['usces_member']['pref'] = $member['mem_pref']; |
| 210 |
$_SESSION['usces_member']['address1'] = $member['mem_address1']; |
| 211 |
$_SESSION['usces_member']['address2'] = $member['mem_address2']; |
| 212 |
$_SESSION['usces_member']['address3'] = $member['mem_address3']; |
| 213 |
$_SESSION['usces_member']['tel'] = $member['mem_tel']; |
| 214 |
$_SESSION['usces_member']['fax'] = $member['mem_fax']; |
| 215 |
$_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag']; |
| 216 |
$_SESSION['usces_member']['delivery'] = ( !empty($member['mem_delivery']) ) ? unserialize($member['mem_delivery']) : ''; |
| 217 |
$_SESSION['usces_member']['registered'] = $member['mem_registered']; |
| 218 |
$_SESSION['usces_member']['nicename'] = $member['mem_nicename']; |
| 219 |
$_SESSION['usces_member']['country'] = $usces->get_member_meta_value( 'customer_country', $member['ID'] ); |
| 220 |
$_SESSION['usces_member']['status'] = $member['mem_status']; |
| 221 |
$usces->set_session_custom_member( $member['ID'] ); |
| 222 |
|
| 223 |
foreach( $_SESSION['usces_member'] as $key => $value ) { |
| 224 |
if( 'custom_member' == $key ) { |
| 225 |
foreach( $_SESSION['usces_member']['custom_member'] as $mbkey => $mbvalue ) { |
| 226 |
//if( empty($_SESSION['usces_entry']['custom_customer'][$mbkey]) ) { |
| 227 |
if( is_array($mbvalue) ) { |
| 228 |
foreach( $mbvalue as $k => $v ) { |
| 229 |
$_SESSION['usces_entry']['custom_customer'][$mbkey][$v] = $v; |
| 230 |
} |
| 231 |
} else { |
| 232 |
$_SESSION['usces_entry']['custom_customer'][$mbkey] = $mbvalue; |
| 233 |
} |
| 234 |
//} |
| 235 |
} |
| 236 |
} else { |
| 237 |
if( 'country' == $key and empty( $value ) ) { |
| 238 |
$_SESSION['usces_entry']['customer'][$key] = usces_get_base_country(); |
| 239 |
} else { |
| 240 |
$_SESSION['usces_entry']['customer'][$key] = trim( $value ); |
| 241 |
} |
| 242 |
} |
| 243 |
} |
| 244 |
foreach( $_SESSION['usces_entry']['customer'] as $key => $value ) { |
| 245 |
if( 'country' == $key and empty( $value ) ) { |
| 246 |
$_SESSION['usces_entry']['delivery'][$key] = usces_get_base_country(); |
| 247 |
} else { |
| 248 |
$_SESSION['usces_entry']['delivery'][$key] = trim( $value ); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
return true; |
| 253 |
} |
| 254 |
|
| 255 |
function usces_paypal_confirm_form() { |
| 256 |
global $usces; |
| 257 |
|
| 258 |
$usces_entries = $usces->cart->get_entry(); |
| 259 |
$html = ' |
| 260 |
<table> |
| 261 |
<tr> |
| 262 |
<th>'.__('total items', 'usces').'</th> |
| 263 |
<td>'.usces_crform( $usces_entries['order']['total_items_price'], true, false, 'return', true ).'</td> |
| 264 |
</tr>'; |
| 265 |
if( usces_is_member_system_point() && !empty($usces_entries['order']['usedpoint']) ) { |
| 266 |
$html .= ' |
| 267 |
<tr> |
| 268 |
<th>'.__('Used points', 'usces').'</th> |
| 269 |
<td><span class="confirm_usedpoint">'.usces_crform( $usces_entries['order']['usedpoint'], false, false, 'return', true ).'</span></td> |
| 270 |
</tr>'; |
| 271 |
} |
| 272 |
if( !empty($usces_entries['order']['discount']) ) { |
| 273 |
$html .= ' |
| 274 |
<tr> |
| 275 |
<th>'.apply_filters( 'usces_confirm_discount_label', __('Campaign disnount', 'usces') ).'</th> |
| 276 |
<td>'.usces_crform( $usces_entries['order']['discount'], true, false, 'return', true ).'</td> |
| 277 |
</tr>'; |
| 278 |
} |
| 279 |
$html .= ' |
| 280 |
<tr> |
| 281 |
<th>'.__('Shipping', 'usces').'</th> |
| 282 |
<td>'.usces_crform( $usces_entries['order']['shipping_charge'], true, false, 'return', true ).'</td> |
| 283 |
</tr>'; |
| 284 |
if( !empty($usces_entries['order']['cod_fee']) ) { |
| 285 |
$html .= ' |
| 286 |
<tr> |
| 287 |
<th>'.apply_filters( 'usces_filter_cod_label', __('COD fee', 'usces') ).'</th> |
| 288 |
<td>'.usces_crform( $usces_entries['order']['cod_fee'], true, false, 'return', true ).'</td> |
| 289 |
</tr>'; |
| 290 |
} |
| 291 |
if( !empty($usces_entries['order']['tax']) ) { |
| 292 |
$html .= ' |
| 293 |
<tr> |
| 294 |
<th>'.__('consumption tax', 'usces').'</th> |
| 295 |
<td>'.usces_crform( $usces_entries['order']['tax'], true, false, 'return', true ).'</td> |
| 296 |
</tr>'; |
| 297 |
} |
| 298 |
$html .= ' |
| 299 |
<tr> |
| 300 |
<th>'.__('Total Amount', 'usces').'</th> |
| 301 |
<td>'.usces_crform( $usces_entries['order']['total_full_price'], true, false, 'return', true ).'</td> |
| 302 |
</tr> |
| 303 |
</table>'; |
| 304 |
return $html; |
| 305 |
} |
| 306 |
|
| 307 |
function usces_paypal_shipping_form() { |
| 308 |
global $usces; |
| 309 |
|
| 310 |
$html = ''; |
| 311 |
$cart = $usces->cart->get_cart(); |
| 312 |
if( 'shipped' == $usces->getItemDivision( $cart[0]['post_id'] ) ) { |
| 313 |
$usces_entries = $usces->cart->get_entry(); |
| 314 |
$html = ' |
| 315 |
<div class="error_message" id="paypal_error_message_delivery_method"></div> |
| 316 |
<table> |
| 317 |
<tr> |
| 318 |
<th>'.__('shipping option', 'usces').'</th> |
| 319 |
<td>'.usces_the_delivery_method( $usces_entries['order']['delivery_method'], 'return' ).'</td> |
| 320 |
</tr> |
| 321 |
<tr> |
| 322 |
<th>'.__('Delivery date', 'usces').'</th> |
| 323 |
<td>'.usces_the_delivery_date( $usces_entries['order']['delivery_date'], 'return' ).'</td> |
| 324 |
</tr> |
| 325 |
<tr> |
| 326 |
<th>'.__('Delivery Time', 'usces').'</th> |
| 327 |
<td>'.usces_the_delivery_time( $usces_entries['order']['delivery_time'], 'return' ).'</td> |
| 328 |
</tr> |
| 329 |
</table>'; |
| 330 |
} |
| 331 |
return $html; |
| 332 |
} |
| 333 |
|
| 334 |
function usces_paypal_point_form( $point ) { |
| 335 |
global $usces; |
| 336 |
|
| 337 |
$html = ''; |
| 338 |
if( usces_is_member_system_point() ) { |
| 339 |
$usces_entries = $usces->cart->get_entry(); |
| 340 |
$usedpoint = ( 0 < $usces_entries['order']['usedpoint'] ) ? $usces_entries['order']['usedpoint'] : ''; |
| 341 |
$html = ' |
| 342 |
<div class="error_message" id="paypal_error_message_use_point"></div> |
| 343 |
<table> |
| 344 |
<tr> |
| 345 |
<th>'.__('The current point', 'usces').'</th> |
| 346 |
<td><span class="point">'.$point.'</span>pt</td> |
| 347 |
</tr> |
| 348 |
<tr> |
| 349 |
<th>'.__('Points you are using here', 'usces').'</th> |
| 350 |
<td><input name="offer[usedpoint]" class="used_point" id="set_usedpoint" type="text" value="'.$usedpoint.'" />pt</td> |
| 351 |
</tr> |
| 352 |
<tr> |
| 353 |
<td colspan="2"><input name="use_point" type="button" class="use_point_button" id="paypal_use_point" value="'.__('Use the points', 'usces').'" /></td> |
| 354 |
</tr> |
| 355 |
</table>'; |
| 356 |
} |
| 357 |
return $html; |
| 358 |
} |
| 359 |
|
| 360 |
function usces_paypal_purchase_form() { |
| 361 |
global $usces, $payments; |
| 362 |
|
| 363 |
$usces_entries = $usces->cart->get_entry(); |
| 364 |
$acting_opts = $usces->options['acting_settings']['paypal']; |
| 365 |
$currency_code = $usces->get_currency_code(); |
| 366 |
|
| 367 |
$payment_paypal = array(); |
| 368 |
foreach( (array)$payments as $id => $payment ) { |
| 369 |
if( 'acting_paypal_ec' == $payment['settlement'] ) { |
| 370 |
$usces->cart->set_order_entry( array( 'payment_name' => $payment['name'] ) ); |
| 371 |
$payment_paypal = $payment; |
| 372 |
break; |
| 373 |
} |
| 374 |
} |
| 375 |
$acting_flag = 'acting_paypal_ec'; |
| 376 |
$rand = usces_acting_key(); |
| 377 |
//$purchase_disabled = ( '' != $usces->error_message ) ? ' disabled="true"' : ''; |
| 378 |
$purchase_disabled = ''; |
| 379 |
|
| 380 |
$cart = $usces->cart->get_cart(); |
| 381 |
$html = ' |
| 382 |
<form id="purchase_form" action="'.USCES_CART_URL.'" method="post" onKeyDown="if (event.keyCode == 13) {return false;}"> |
| 383 |
<input type="hidden" name="SOLUTIONTYPE" value="Sole"> |
| 384 |
<input type="hidden" name="LANDINGPAGE" value="Billing"> |
| 385 |
<input type="hidden" name="EMAIL" value="'.esc_attr( $usces_entries['customer']['mailaddress1'] ).'"> |
| 386 |
<input type="hidden" name="PAYMENTREQUEST_0_CURRENCYCODE" value="'.$currency_code.'">'; |
| 387 |
if( 'shipped' == $usces->getItemDivision( $cart[0]['post_id'] ) ) { |
| 388 |
$name = apply_filters( 'usces_filter_paypalec_shiptoname', esc_attr( $usces_entries['delivery']['name2'].' '.$usces_entries['delivery']['name1'] ) ); |
| 389 |
$address2 = apply_filters( 'usces_filter_paypalec_shiptostreet', esc_attr( $usces_entries['delivery']['address2'] ) ); |
| 390 |
$address3 = apply_filters( 'usces_filter_paypalec_shiptostreet2', esc_attr( $usces_entries['delivery']['address3'] ) ); |
| 391 |
$address1 = apply_filters( 'usces_filter_paypalec_shiptocity', esc_attr( $usces_entries['delivery']['address1'] ) ); |
| 392 |
$pref = apply_filters( 'usces_filter_paypalec_shiptostate', esc_attr( $usces_entries['delivery']['pref'] ) ); |
| 393 |
$country = ( !empty($usces_entries['delivery']['country']) ) ? $usces_entries['delivery']['country'] : usces_get_base_country(); |
| 394 |
$country_code = apply_filters( 'usces_filter_paypalec_shiptocountrycode', $country ); |
| 395 |
$zip = apply_filters( 'usces_filter_paypalec_shiptozip', $usces_entries['delivery']['zipcode'] ); |
| 396 |
$tel = apply_filters( 'usces_filter_paypalec_shiptophonenum', ltrim( str_replace( '-', '', $usces_entries['delivery']['tel'] ), '0' ) ); |
| 397 |
$html .= ' |
| 398 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTONAME" value="'.$name.'"> |
| 399 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOSTREET" value="'.$address2.'"> |
| 400 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOSTREET2" value="'.$address3.'"> |
| 401 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOCITY" value="'.$address1.'"> |
| 402 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOSTATE" value="'.$pref.'"> |
| 403 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE" value="'.$country_code.'"> |
| 404 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOZIP" value="'.$zip.'"> |
| 405 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPTOPHONENUM" value="'.$tel.'">'; |
| 406 |
} |
| 407 |
if( 'shipped' != $usces->getItemDivision( $cart[0]['post_id'] ) ) { |
| 408 |
$html .= '<input type="hidden" name="NOSHIPPING" value="1">'; |
| 409 |
} |
| 410 |
$charging_type = $usces->getItemChargingType( $cart[0]['post_id'], $cart ); |
| 411 |
if( 'continue' != $charging_type ) { |
| 412 |
//通常購� |
| 413 |
� |
| 414 |
$item_total_price = 0; |
| 415 |
$i = 0; |
| 416 |
foreach( $cart as $cart_row ) { |
| 417 |
$html .= ' |
| 418 |
<input type="hidden" name="L_PAYMENTREQUEST_0_NAME'.$i.'" value="'.esc_attr( $usces->getItemName($cart_row['post_id']) ).'"> |
| 419 |
<input type="hidden" name="L_PAYMENTREQUEST_0_AMT'.$i.'" value="'.usces_crform( $cart_row['price'], false, false, 'return', false ) .'"> |
| 420 |
<input type="hidden" name="L_PAYMENTREQUEST_0_NUMBER'.$i.'" value="'.esc_attr( $usces->getItemCode($cart_row['post_id']) ).'"> |
| 421 |
<input type="hidden" name="L_PAYMENTREQUEST_0_QTY'.$i.'" value="'.esc_attr( $cart_row['quantity'] ).'">'; |
| 422 |
$item_total_price += ( $cart_row['price'] * $cart_row['quantity'] ); |
| 423 |
$i++; |
| 424 |
} |
| 425 |
if( !empty($usces_entries['order']['discount']) ) { |
| 426 |
$html .= ' |
| 427 |
<input type="hidden" name="L_PAYMENTREQUEST_0_NAME'.$i.'" value="'.esc_attr( __('Campaign disnount', 'usces') ).'"> |
| 428 |
<input type="hidden" name="L_PAYMENTREQUEST_0_AMT'.$i.'" value="'.usces_crform( $usces_entries['order']['discount'], false, false, 'return', false ).'">'; |
| 429 |
$item_total_price += $usces_entries['order']['discount']; |
| 430 |
$i++; |
| 431 |
} |
| 432 |
if( !empty($usces_entries['order']['usedpoint']) ) { |
| 433 |
$html .= ' |
| 434 |
<input type="hidden" name="L_PAYMENTREQUEST_0_NAME'.$i.'" value="'.esc_attr(__('Used points', 'usces')).'"> |
| 435 |
<input type="hidden" name="L_PAYMENTREQUEST_0_AMT'.$i.'" value="'.usces_crform( $usces_entries['order']['usedpoint']*(-1), false, false, 'return', false ).'">'; |
| 436 |
$item_total_price -= $usces_entries['order']['usedpoint']; |
| 437 |
$i++; |
| 438 |
} |
| 439 |
$html .= ' |
| 440 |
<input type="hidden" name="PAYMENTREQUEST_0_ITEMAMT" value="'.usces_crform( $item_total_price, false, false, 'return', false ).'"> |
| 441 |
<input type="hidden" name="PAYMENTREQUEST_0_SHIPPINGAMT" value="'.usces_crform( $usces_entries['order']['shipping_charge'], false, false, 'return', false ).'"> |
| 442 |
<input type="hidden" name="PAYMENTREQUEST_0_AMT" value="'.usces_crform( $usces_entries['order']['total_full_price'], false, false, 'return', false ).'"> |
| 443 |
'; |
| 444 |
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 ).'">'; |
| 445 |
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 ).'">'; |
| 446 |
} else { |
| 447 |
//定期支払い |
| 448 |
$desc = usces_make_agreement_description( $cart, $usces_entries['order']['total_full_price'] ); |
| 449 |
$html .= '<input type="hidden" name="L_BILLINGTYPE0" value="RecurringPayments"> |
| 450 |
<input type="hidden" name="L_BILLINGAGREEMENTDESCRIPTION0" value="'.esc_attr($desc).'"> |
| 451 |
<input type="hidden" name="AMT" value="0">'; |
| 452 |
} |
| 453 |
if( !empty($acting_opts['logoimg']) ) $html .= '<input type="hidden" name="LOGOIMG" value="'.esc_attr( $acting_opts['logoimg'] ).'">'; |
| 454 |
if( !empty($acting_opts['cartbordercolor']) ) $html .= '<input type="hidden" name="CARTBORDERCOLOR" value="'.esc_attr( $acting_opts['cartbordercolor'] ).'">'; |
| 455 |
$html .= '<input type="hidden" name="purchase" value="acting_paypal_ec">'; |
| 456 |
$html .= '<input type="hidden" name="paypal_from_cart" value="1">'; |
| 457 |
$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>'; |
| 458 |
$html = apply_filters( 'usces_filter_confirm_inform', $html, $payment_paypal, $acting_flag, $rand, $purchase_disabled ); |
| 459 |
$html .= '</form>'; |
| 460 |
return $html; |
| 461 |
} |
| 462 |
|
| 463 |
function usces_paypal_front_ajax() { |
| 464 |
switch( $_POST['usces_ajax_action'] ) { |
| 465 |
case 'paypal_delivery_method': |
| 466 |
usces_paypal_delivery_method( $_POST['selected'], $_POST['delivery_date'], $_POST['delivery_time'] ); |
| 467 |
break; |
| 468 |
case 'paypal_use_point': |
| 469 |
usces_paypal_use_point( $_POST['usepoint'], $_POST['total_price'], $_POST['item_price'] ); |
| 470 |
break; |
| 471 |
case 'paypal_delivery_date_select': |
| 472 |
usces_paypal_delivery_date_select( $_POST['selected'] ); |
| 473 |
break; |
| 474 |
case 'paypal_delivery_time_select': |
| 475 |
usces_paypal_delivery_time_select( $_POST['selected'] ); |
| 476 |
break; |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
function usces_paypal_delivery_method( $delivery_method_select, $delivery_date, $delivery_time ) { |
| 481 |
global $usces; |
| 482 |
|
| 483 |
$usces_entries = $usces->cart->get_entry(); |
| 484 |
$usces->cart->set_order_entry( array( 'delivery_method' => $delivery_method_select, 'delivery_date' => $delivery_date, 'delivery_time' => $delivery_time ) ); |
| 485 |
$usces_entries['order']['delivery_method'] = $delivery_method_select; |
| 486 |
$usces->set_cart_fees( $member, $usces_entries ); |
| 487 |
$res = "ok#usces#".usces_paypal_confirm_form()."#usces#".usces_paypal_purchase_form(); |
| 488 |
die( $res ); |
| 489 |
} |
| 490 |
|
| 491 |
function usces_paypal_use_point( $usepoint, $total_price, $item_price ) { |
| 492 |
global $usces; |
| 493 |
|
| 494 |
$res = ''; |
| 495 |
$mes = ''; |
| 496 |
$member = $usces->get_member(); |
| 497 |
$usces_entries = $usces->cart->get_entry(); |
| 498 |
|
| 499 |
if( WCUtils::is_blank( $usepoint ) || !preg_match( "/^[0-9]+$/", $usepoint ) || (int)$usepoint < 0 ) { |
| 500 |
$mes = __('Invalid value. Please enter in the numbers.', 'usces'); |
| 501 |
} else { |
| 502 |
if( $usepoint > (int)$member['point'] ) { |
| 503 |
$mes = __('You have exceeded the maximum available.', 'usces')."max".(int)$member['point']."pt"; |
| 504 |
// } elseif( $usces->options['point_coverage'] && $usepoint > $total_price ) { |
| 505 |
// $mes = __('You have exceeded the maximum available.', 'usces')."max".$total_price."pt"; |
| 506 |
// } elseif( !$usces->options['point_coverage'] && $usepoint > $item_price ) { |
| 507 |
} elseif( $usepoint >= $item_price ) { |
| 508 |
$mes = __("In the case of settlement method you choose, the upper limit of the point you'll find that will change. If you became a settlement error, please reduce the point that you want to use.", 'usces'); |
| 509 |
} |
| 510 |
} |
| 511 |
if( '' != $mes ) { |
| 512 |
$usces->cart->set_order_entry( array( 'usedpoint' => 0 ) ); |
| 513 |
$res = "error#usces#".$mes; |
| 514 |
} else { |
| 515 |
$usces->cart->set_order_entry( array( 'usedpoint' => $usepoint ) ); |
| 516 |
$usces_entries['order']['usedpoint'] = $usepoint; |
| 517 |
$usces->set_cart_fees( $member, $usces_entries ); |
| 518 |
$res = "ok#usces#".usces_paypal_confirm_form()."#usces#".usces_paypal_purchase_form(); |
| 519 |
} |
| 520 |
die( $res ); |
| 521 |
} |
| 522 |
|
| 523 |
function usces_paypal_filter_paypal_ec_cancelurl( $cancelurl, $query ) { |
| 524 |
global $usces; |
| 525 |
$pos = strpos( $query, 'paypal_from_cart' ); |
| 526 |
if( false !== $pos ) { |
| 527 |
$cancelurl = urlencode( USCES_CART_URL ); |
| 528 |
} |
| 529 |
return $cancelurl; |
| 530 |
} |
| 531 |
|
| 532 |
function usces_paypal_delivery_date_select( $selected ) { |
| 533 |
global $usces; |
| 534 |
$usces->cart->set_order_entry( array( 'delivery_date' => $selected ) ); |
| 535 |
die( "ok" ); |
| 536 |
} |
| 537 |
|
| 538 |
function usces_paypal_delivery_time_select( $selected ) { |
| 539 |
global $usces; |
| 540 |
$usces->cart->set_order_entry( array( 'delivery_time' => $selected ) ); |
| 541 |
die( "ok" ); |
| 542 |
} |
| 543 |
|
| 544 |
function usces_paypal_action_customerinfo() { |
| 545 |
global $usces; |
| 546 |
if( $usces->is_member_logged_in() ) { |
| 547 |
$usces->cart->set_order_entry( array( 'payment_name' => '' ) ); |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
function usces_paypal_ipn_check( $usces_paypal_url ) { |
| 552 |
|
| 553 |
// read the post from PayPal system and add 'cmd' |
| 554 |
$req = 'cmd=_notify-validate'; |
| 555 |
|
| 556 |
foreach( $_POST as $key => $value ) { |
| 557 |
$value = urlencode( stripslashes($value) ); |
| 558 |
$req .= '&'.$key.'='.$value; |
| 559 |
} |
| 560 |
|
| 561 |
// post back to PayPal system to validate |
| 562 |
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; |
| 563 |
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
| 564 |
$header .= "Host: ".$usces_paypal_url."\r\n"; |
| 565 |
$header .= "Content-Length: ".strlen($req)."\r\n"; |
| 566 |
$header .= "Connection: close\r\n\r\n"; |
| 567 |
$fp = fsockopen( 'ssl://'.$usces_paypal_url, 443, $errno, $errstr, 30 ); |
| 568 |
|
| 569 |
$order_id = isset( $_POST['custom'] ) ? $_POST['custom'] : ''; |
| 570 |
$txn_id = isset( $_POST['txn_id'] ) ? $_POST['txn_id'] : ''; |
| 571 |
|
| 572 |
$results = array(); |
| 573 |
if( !$fp ) { |
| 574 |
$results[0] = false; |
| 575 |
usces_log( __('IPN Connection Error', 'usces'), 'acting_transaction.log' ); |
| 576 |
|
| 577 |
} else { |
| 578 |
fputs( $fp, $header.$req ); |
| 579 |
// read the body data |
| 580 |
$res = ''; |
| 581 |
$headerdone = false; |
| 582 |
while( !feof($fp) ) { |
| 583 |
$line = fgets( $fp, 1024 ); |
| 584 |
if( strcmp( $line, "\r\n" ) == 0 ) { |
| 585 |
// read the header |
| 586 |
$headerdone = true; |
| 587 |
} elseif( $headerdone ) { |
| 588 |
// header has been read. now read the contents |
| 589 |
$res .= $line; |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
// parse the data |
| 594 |
$lines = explode( "\n", $res ); |
| 595 |
if( preg_match( "/VERIFIED/mi", $res ) == 1 ) { |
| 596 |
$results[0] = true; |
| 597 |
$results['order_id'] = $order_id; |
| 598 |
$results['txn_id'] = $txn_id; |
| 599 |
usces_log( 'IPN [SUCCESS]', 'acting_transaction.log' ); |
| 600 |
|
| 601 |
} else { |
| 602 |
$results[0] = false; |
| 603 |
//usces_log( __('IPN Refusal', 'usces')."\n\t\t\t".__("PayPal gives back 'FAIL'. Please confirm setting.", 'usces'), 'acting_transaction.log' ); |
| 604 |
} |
| 605 |
|
| 606 |
fclose( $fp ); |
| 607 |
} |
| 608 |
return $results; |
| 609 |
} |
| 610 |
|
| 611 |
?> |
| 612 |
|