“金额”字段未传递到PayPal

"Amount" field not passing through to PayPal

本文关键字:PayPal 金额 字段      更新时间:2023-09-26

我正在为一个非营利客户开发一个网站,其中包括一个定制的捐赠表格。该表单包括用户选择预定义捐赠金额的选项,或输入自己的金额,然后单击"捐赠",这会将他们带到PayPal。我已经通过我的沙盒帐户进行了三次成功的测试,确认了实际的捐赠按钮有效。我还能够确认自定义表单正确计算了所选金额并填充了"金额"字段的值,因为我能够在控制台中记录这些结果。据我所知,"金额"字段符合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端的托管按钮中,但仍然没有乐趣。

经过进一步研究,事实证明托管PayPal按钮不接受"金额"自定义字段。为了创建此功能,必须使用非托管按钮。最终结果是从PayPal生成一个非托管按钮,其结果在前端代码中如下所示(JavaScript保持不变(:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <input type="hidden" name="cmd" value="_donations">
    <input type="hidden" name="business" value="(Place you PayPal key here)">
    <input type="hidden" name="lc" value="US">
    <input type="hidden" name="item_name" value="Test Charity">
    <input type="hidden" name="no_note" value="1">
    <input type="hidden" name="no_shipping" value="2">
    <input type="hidden" name="rm" value="1">
    <input type="hidden" name="return" value="(Your success URL here)">
    <input type="hidden" name="cancel_return" value="(Your cancel landing URL here)">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHosted">
    <input id="donation-amount" type="hidden" name="amount" value="">                       
    <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>