【问题标题】:pass amount total to PayPal express checkout将总金额传递给 PayPal 快速结帐
【发布时间】:2018-08-14 18:40:53
【问题描述】:

我的 ASP.NET 网络表单网页上有快速结帐按钮,但似乎无法弄清楚单击按钮时如何将总变量(存储在页面上的标签中)传递给 PayPal 弹出窗口。

我知道已经有人问过这个问题 (How Can pass order Total to (amount: { total: '0.01', currency: 'USD' } ) in paypal),但答案对我来说意义不大,并且没有像初学者程序员那样详细说明。

<meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <script src="https://www.paypalobjects.com/api/checkout.js"></script>
     <script>
        paypal.Button.render({
            env: 'sandbox', // sandbox | production
            style: {
                label: 'pay',
                size: 'small', // small | medium | large | responsive
                shape: 'rect',   // pill | rect
                color: 'gold'   // gold | blue | silver | black
            },
            // PayPal Client IDs - replace with your own
            // Create a PayPal app: https://developer.paypal.com/developer/applications/create
            client: {
                sandbox:    'AWDwdGr-KZK4jJi0WBUZmFowgG6oCtLpNDxtXuiOfAT1UdNUYeSlvoXYkrKW7SRdcYqqjHCo7IcYPmJf',
                production: 'Production ClientID'
            },
            // payment() is called when the button is clicked
            payment: function(data, actions) {
                // Make a call to the REST api to create the payment
                return actions.payment.create({
                    payment: {
                        transactions: [
                            {
                                amount: { total: '0.01' , currency: 'EUR' }
                            }
                        ]
                    }
                });
            },
            // onAuthorize() is called when the buyer approves the payment
            onAuthorize: function(data, actions) {

                // Make a call to the REST api to execute the payment
                return actions.payment.execute().then(function() {
                    window.alert('Payment Complete!');
                });
            }
        }, '#paypal-button-container');
    </script>

有人能给我一些指导吗?

【问题讨论】:

    标签: javascript asp.net paypal webforms paypal-sandbox


    【解决方案1】:

    您链接的答案确实很好地解释了这一点,但您需要更多解释,在 WebForms 中,您可以使用 asp.net 内联服务器标签来访问页面中的元素,只要它们位于 aspx 文件中即可。语法如下:

    <%=ElementName.Property%>
    

    这允许您直接访问该值或将其分配给 javascript 变量。在您的情况下,任何一个都应该可以正常工作,对于标签和包含文本的东西等元素,您要查找的属性通常是 innerHTML 或 innerText,因此以下内容应该为您提供所需的结果:

    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <script src="https://www.paypalobjects.com/api/checkout.js"></script>
         <script>
            paypal.Button.render({
                env: 'sandbox', // sandbox | production
                style: {
                    label: 'pay',
                    size: 'small', // small | medium | large | responsive
                    shape: 'rect',   // pill | rect
                    color: 'gold'   // gold | blue | silver | black
                },
                // PayPal Client IDs - replace with your own
                // Create a PayPal app: https://developer.paypal.com/developer/applications/create
                client: {
                    sandbox:    'AWDwdGr-KZK4jJi0WBUZmFowgG6oCtLpNDxtXuiOfAT1UdNUYeSlvoXYkrKW7SRdcYqqjHCo7IcYPmJf',
                    production: 'Production ClientID'
                },
                // payment() is called when the button is clicked
                payment: function(data, actions) {
                    // Make a call to the REST api to create the payment
                    return actions.payment.create({
                        payment: {
                            transactions: [
                                {
                                    amount: { total: '<%=TheNameOfYourLabel.innerText%>' , currency: 'EUR' }
                                }
                            ]
                        }
                    });
                },
                // onAuthorize() is called when the buyer approves the payment
                onAuthorize: function(data, actions) {
    
                    // Make a call to the REST api to execute the payment
                    return actions.payment.execute().then(function() {
                        window.alert('Payment Complete!');
                    });
                }
            }, '#paypal-button-container');
        </script>
    

    【讨论】:

      猜你喜欢
      • 2014-12-29
      • 2016-11-15
      • 1970-01-01
      • 2013-04-24
      • 2014-12-07
      • 2013-03-05
      • 2017-11-22
      • 2013-07-10
      • 1970-01-01
      相关资源
      最近更新 更多