javascript - "Amount"字段未传递到 PayPal

标签 javascript jquery paypal e-commerce

我正在为一个非营利客户开发一个网站,其中包含一个自定义捐赠表格。该表格包括供用户选择预定义捐赠金额或输入他们自己的金额的选项,然后单击“捐赠”,将他们带到 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 端的托管按钮中,但仍然没有任何乐趣。

最佳答案

经过进一步研究,事实证明托管 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>

关于javascript - "Amount"字段未传递到 PayPal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19286423/

相关文章:

javascript - 发送 'nil' 表示未选中的复选框 - UJS、Rails 4

paypal - 我是否需要在选择更改时重新呈现 PayPal 的智能按钮?

javascript - Node.js 主机名/IP 与证书的别名不匹配

javascript - 在 uitableview 单元格中显示项目的评分

javascript - 将数组从 Controller 传递到 Javascript

javascript - ngFor 中的数据绑定(bind)函数参数

javascript - 如何访问另一个 JS 对象中匹配的对象属性

jquery - 使用 jquery 远程验证发送附加静态参数

paypal - 如何使用 PayPal PHP REST API 设置账单或送货地址?

php - Paypal API : Exception: 401 when accessing https://api. sandbox.paypal.com/v1/oauth2/token