如何在PayPal中传递总额至(金额:{total:'0.01',currency:'USD'})
问题描述:
我已经在我的asp.net网页中实现了paypal checkout express按钮。我怎样才能将orderTotal传递给金额:{total:'0.01',currency:'USD'}。默认情况下它是'0.01'我想要显示实际的orderTotal。 这是我的代码 paypal.Button.render({如何在PayPal中传递总额至(金额:{total:'0.01',currency:'USD'})
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');
答
根据您是否使用窗体或MVC。
Web窗体可以使用inline指令 <% =MyTotal %>
,你想总。
随着MVC @ model.MyTotal会在哪里工作MyTotal将是你想总要传递给贝宝。
˚F或者例如,WebForms的
amount: { total: <% =MyTotal %>, currency: 'USD' }
MVC
amount: { total: @Model.MyTotal, currency: 'USD' }
一对夫妇的需要指出的事。总数需要是一个字符串,并且需要舍入到两位小数点。如果你不这样做,它会反弹和错误。