将总金额传递给 PayPal 快速结帐

Posted

技术标签:

【中文标题】将总金额传递给 PayPal 快速结帐【英文标题】:pass amount total to PayPal express checkout 【发布时间】: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>

有人能给我一些指导吗?

【问题讨论】:

【参考方案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>

【讨论】:

以上是关于将总金额传递给 PayPal 快速结帐的主要内容,如果未能解决你的问题,请参考以下文章

在页面之间传递数据 c# windows 8.1

用于传递产品和金额的简单 PayPal Javascript API

Paypal 定期付款 - 快速结帐 APPID 被拒绝

在 Paypal 的快速结账 API 中显示成本/价格

使用贝宝方法可以进行零金额交易吗?

asp.net 中的简单应用程序,用户在文本框中输入金额并单击使用贝宝结帐