我正在为一个包含自定义捐赠表格的非营利客户开发一个网站。该表格包括供用户选择预定义捐赠金额的选项,或输入他们自己的金额,然后单击“捐赠”,这会将他们带到 PayPal。我已经通过我的 Sandbox 帐户通过三个成功的测试确认了实际的捐赠按钮有效。我还能够确认自定义表单正确计算了所选金额并填充了“金额”字段的值,因为我能够在控制台中记录这些结果。据我所知,“金额”字段符合 PayPal 的准则。但是,该金额不会转入 PayPal。
前端代码:
<div id="main-donate-container" class="form_container">
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<div id="small-button-container" class="">
<div id="twenty-five" class="lightred general_button blue_button form_small_button selected_amount select_state_color_btn"><span>25</span></div>
<div id="fifty" class="general_button blue_button form_small_button select_state_color_btn"><span>50</span></div>
<div id="one-hundred" class="general_button blue_button form_small_button select_state_color_btn"><span>100</span></div>
<div id="two-hundred" class="general_button blue_button form_small_button select_state_color_btn"><span>200</span></div>
</div>
<div id="other-amount" class="general_button blue_button form_other_amount">
<span><img src="<?php $root ?>/images/close.png"/></span>
<label>$</label><input class="whitetext" type="text" name="other-amount" value="143">
</div>
<div id="other-amount-button" class="general_button blue_button select_state_color_btn">
<span>OTHER</span>
</div>
<input id="donation-amount" type="hidden" name="amount" value="">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="(PayPal key here)">
<input type="submit" class="general_button blue_button submit_button" id="submit" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" value="Donate!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</div> <!-- end main donate container -->
还有幕后的 JavaScript:
//initialize variables to track donation amounts
var donation_amount = 25;
var previous_donation = 0;
//format the amounts displayed in buttons as US currency
$('#donate-content .form_small_button span').formatCurrency({roundToDecimalPlace:0});
$('#donate-content #other-amount-button').on('click',function(){
//save the previously selected donation amount in case use cancels out of "other"
previous_donation = donation_amount;
//set new donation amount to the default "other" amount
donation_amount = $('#other-amount input').val();
//change background of other button and other amount field to #FFB310 and show the other amount field
$(this).css('background-color','#BB6098');
$('#donate-content #other-amount').css('background-color','#BB6098').show();
$('#donate-content #other-amount-button').addClass('selected_amount');
//format the amounts displayed in other amount field for US currency
$('#donate-content #other-amount input').formatCurrency({symbol:'',roundToDecimalPlace:0});
$('#donate-content #other-amount input').select();
});
$('#donate-content #other-amount span').on('click',function(){
donation_amount = previous_donation;
$('#donate-content #other-amount-button').css('background-color','rgba(67, 80, 164, .9)').removeClass('selected_amount');;
$('#donate-content #other-amount').hide();
$('#donate-content #other-amount input').val('143');
});
$('#donate-content #other-amount input').keyup(function(){
donation_amount = $(this).val();
});
$('#donate-content #other-amount input').keypress(function(event){
return isNumber(event);
});
$('#donate-content #twenty-five').on('click',function(){
$('#donate-content .select_state_color_btn').css('background-color','rgba(67, 80, 164, .9)').removeClass('selected_amount');
$(this).addClass('selected_amount').css('background-color','#C25252');
donation_amount = $(this).text();
donation_amount = donation_amount.slice(1);
});
$('#donate-content #fifty').on('click',function(){
$('#donate-content .select_state_color_btn').css('background-color','rgba(67, 80, 164, .9)').removeClass('selected_amount');
$(this).addClass('selected_amount').css('background-color','#CA9859');
donation_amount = $(this).text();
donation_amount = donation_amount.slice(1);
});
$('#donate-content #one-hundred').on('click',function(){
$('#donate-content .select_state_color_btn').css('background-color','rgba(67, 80, 164, .9)').removeClass('selected_amount');
$(this).addClass('selected_amount').css('background-color','#7E0B80');
donation_amount = $(this).text();
donation_amount = donation_amount.slice(1);
});
$('#donate-content #two-hundred').on('click',function(){
$('#donate-content .select_state_color_btn').css('background-color','rgba(67, 80, 164, .9)').removeClass('selected_amount');
$(this).addClass('selected_amount').css('background-color','#59ABB7');
donation_amount = $(this).text();
donation_amount = donation_amount.slice(1);
});
$('#donate-content .select_state_color_btn').hover(
function(){
if ($(this).hasClass('selected_amount')){
var color = $(this).css('background-color');
$(this).css('background-color',color);
}
else{
$(this).css('background-color','#ccc');
}
},
function(){
if ($(this).hasClass('selected_amount')){
var color = $(this).css('background-color');
$(this).css('background-color',color);
}
else{
$(this).css('background-color','rgba(67, 80, 164, .9)');
}
});
$('#donate-content #other-amount-button').hover(
function(){
if ($(this).hasClass('selected_amount')){
var color = $(this).css('background-color');
$(this).css('background-color',color);
}
else{
$(this).css('background-color','#ccc'); }
},
function(){
if ($(this).hasClass('selected_amount')){
var color = $(this).css('background-color');
$(this).css('background-color',color);
}
else{
$(this).css('background-color','rgba(67, 80, 164, .9)');
}
});
$('#donate-content #submit').hover(
function(){
$(this).css('background-color','#96BA5F');
},
function(){
$(this).css('background-color','rgba(67, 80, 164, .9)');
});
$('#donate-content #submit').on('click',function(e){
$('#donate-content #donation-amount').val(donation_amount);
谁能指出我确定的是我缺少的小细节?
提前致谢!
更新:我已经确定“金额”变量已添加到 PayPal 端的托管按钮中,但仍然没有乐趣。