如何在PayPal中将订单总数传递给(金额:{total:'0.01',货币:'USD'})

时间:2017-08-30 10:27:32

标签: asp.net paypal

我在asp.net网页上实现了paypal checkout express按钮。我如何将orderTotal传递给金额:{total:'0.01',货币:'USD'}。默认情况下它是'0.01'我想显示实际orderTotal。 这是我的代码    paypal.Button.render({

                                                 env: 'sandbox', // sandbox | production

                                                 // PayPal Client IDs - replace with your own
                                                 // Create a PayPal app: https://developer.paypal.com/developer/applications/create
                                                 client: {
                                                     sandbox: 'AZDxjDScFpQtjWTOUtWKbyN_bDt4OgqaF4eYXlewfBP4-8aqX3PiV8e1GWU6liB2CUXlkA59kJXE7M6R',
                                                     //production: 'AVSYgEO5SUewyQ_We4dW5uCXyEZHgcFDfKK15gCqsd7o0edVH5UOhtHK7n2uqkFQOYtjJt0vvemfgNwg'
                                                 },

                                                 // Show the buyer a 'Pay Now' button in the checkout flow
                                                 commit: true,

                                                 // 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: 'USD' }
                                                            }
                                                             ]
                                                         }
                                                     });
                                                 },
                                                 commit: true,
                                                 // 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!');
                                                         onPaypalAuthorize();
                                                     });
                                                 }

                                             }, '#paypal-button-container');

1 个答案:

答案 0 :(得分:0)

取决于您使用的是表单还是MVC。

对于Web表单,您可以使用inline指令 <% =MyTotal %>你想要的总数。

使用MVC @ model.MyTotal适用于MyTotal将要传递给paypal的总数。

例如,WebForms

amount: { total: <% =MyTotal %>, currency: 'USD' }

MVC

amount: { total: @Model.MyTotal, currency: 'USD' }

需要指出的一些事情。总需要是一个字符串,它需要四舍五入到两个小数点。如果你没有这样做,它将会反弹并发生错误。