如何使用PayPal API进行总订单数量折扣
我已经暂时接管了合唱协会网页的更新工作,需要对PayPal API的使用进行更改。这是我需要完成的 我们想以20美元(成人)和10美元(学生)的价格出售数量为1-2的音乐会门票。对于成人和/或学生的任何组合,数量为3及以上。价格应该是16.50美元(成人)和8.25美元(学生) 以前,我们的网站为各种组合添加了购物车按钮。这让客户感到困惑,也不可靠,因为贝宝提供了自己的表单,可以更改数量 我想用一个Buy Now按钮替换所有当前的“添加到购物车”按钮,该按钮将导致一个页面,在该页面中,客户可以指定成人票和学生票的任意数量组合(只要两者都不是零),并按照上述定价进行支付 我已经查看了,并看到了几个与折扣相关的字段(见表3),但根本不清楚是否有一个组合可以满足我的需要如何使用PayPal API进行总订单数量折扣,paypal,Paypal,我已经暂时接管了合唱协会网页的更新工作,需要对PayPal API的使用进行更改。这是我需要完成的 我们想以20美元(成人)和10美元(学生)的价格出售数量为1-2的音乐会门票。对于成人和/或学生的任何组合,数量为3及以上。价格应该是16.50美元(成人)和8.25美元(学生) 以前,我们的网站为各种组合添加了购物车按钮。这让客户感到困惑,也不可靠,因为贝宝提供了自己的表单,可以更改数量 我想用一个Buy Now按钮替换所有当前的“添加到购物车”按钮,该按钮将导致一个页面,在该页面中,客户可以指
非常感谢您的帮助。在PayPal支持的帮助下,我在谷歌上搜索了大量的示例代码,我想出了以下在beta版中运行良好的方法。keydown逻辑来自StackOverflow的另一个问题 代码为成人和学生数量创建一对文本框。当客户输入数量以在输入上方显示小计字符串时,将强制执行折扣规则。当客户单击“立即购买”时,总额将作为单个项目发送以创建付款表单。S&H费用也作为总费用的百分比添加,以支付交易成本 为冗长的编码风格道歉。JavaScript不是我常用的语言。欢迎提出改进建议 希望有人觉得它有用 警告--此代码易受具有计算机技能的骗子的欺骗。如果没有某种形式的采购后审计,不要将其用于有价值的交易
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script><script type="text/javascript">// <![CDATA[
$(document).ready(function() {
// Enforce numeric values only.
$('#nadult, #nstudent').keydown(function(event) {
// Allow: backspace, delete, tab, escape, and enter
if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||
// Allow: Ctrl+A
(event.keyCode == 65 && event.ctrlKey === true) ||
// Allow: home, end, left, right
(event.keyCode >= 35 && event.keyCode <= 39)) {
// let it happen, don't do anything
return;
}
else {
// Ensure that it is a number and stop the keypress
if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
event.preventDefault();
}
}
});
$('#nadult, #nstudent').keyup(function(event) {
compute_form_inputs(false);
});
});
function compute_form_inputs(is_submit) {
// called when buyer click "Buy now" after filling in quantities of adult and student tickets
var base_adult_price = 20.00;
var disc_adult_price = 16.50;
var student_discount = 0.50;
var handling_fee = 0.05 // Five percent to cover cost of transaction;
var nadult = $('#nadult').val();
var nstudent = $('#nstudent').val();
var iadult = parseInt(nadult);
if (isNaN(iadult)) { iadult = 0 }
var istudent = parseInt(nstudent);
if (isNaN(istudent)) { istudent = 0 }
var itickets = istudent + iadult;
if (is_submit && itickets <= 0) {
// call off the purchase
alert("Please specify at least one adult or student ticket to purchase!");
return false;
}
else if (itickets < 3) {
var adult_price = base_adult_price;
}
else {
var adult_price = disc_adult_price;
}
var student_price = adult_price * student_discount;
// Build string components that show how many of each were purchased.
// These go into the PayPal item_name field.
if (iadult > 0) {
var adult_info = nadult + " Adult @ $" + adult_price.toFixed(2) + " ea.";
}
else {
var adult_info = "";
}
if (istudent > 0) {
var student_info = nstudent + " Student @ $" + student_price.toFixed(2) +"ea.";
}
else {
var student_info = "";
}
if (iadult>0 && istudent>0) {
var separator = " + ";
}
else {
var separator = "";
}
var item_name_string = "ACS Flex tickets: " + adult_info + separator + student_info;
var amount = iadult * adult_price + istudent * student_price;
//alert(amount);
var handling = (amount * handling_fee).toFixed(2);
//alert(handling);
$('input[name="item_name"]').val(item_name_string);
$('input[name="amount"]').val(amount);
$('input[name="handling"]').val(handling);
$('input[name="custom"]').val(item_name_string);
// alert("about to change label")
$('#subtotal').text(adult_info + separator + student_info + " = $" + amount.toFixed(2))
return true;
};
// ]]></script>
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" onsubmit=compute_form_inputs(true) method="post">
<div style="color: green; margin-bottom: 10px;">
<strong>Subtotal: <label id="subtotal" value=""></strong><super>*</super><br />
</div>
<div>
<input type="text" id="nadult" value="0" size="3"> <strong> Adult </strong>
<input type="text" id="nstudent" value="0" size="3"> <strong> Student </strong>
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="someone@mychoralsociety.org">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="">
<input type="hidden" name="handling" value="">
<input type="hidden" name="amount" value="">
<input type="hidden" name="custom" value="">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</div>
</form>
<br />
<small> * 5% transaction fee will be added to online and credit card purchase to cover bank fees. </small>
/=35&&event.keyCode将这些行添加到按钮代码中。贴现率以百分比表示,为17.5%。添加第一行中的零,以便折扣不适用于第一个项目
<input type="hidden" name="discount_rate" value="0">
<input type="hidden" name="discount_rate2" value="17.5">
资料来源:
<input type="hidden" name="discount_rate" value="0">
<input type="hidden" name="discount_rate2" value="17.5">
discount_rate=0
discount_rate2=17.5