[英]Can't pass variable to value for Paypal Smart Button api
我正在嘗試在我的網站上為 paypal 集成智能按鈕 api。 這是代碼:
paypal.Buttons({
createOrder: function(data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
amount: {
value: '10'
}
}]
});
}
}).render('#paypal-button-container');
我的價格變量是這樣的:
var price = '100'
我嘗試添加價格而不是“100”,但我不斷收到未捕獲的參考錯誤,告訴我它尚未定義。
在執行 PayPal 按鈕之前,您需要確保它在足夠全局的 scope 中定義。
如果它是在不同的 function 中定義的,而不是在單擊按鈕之前,您將收到該錯誤。
一個快速的解決方法是設置window.myPrice = '100';
,然后參考value: window.myPrice
從您的按鈕
當然,有更簡潔的非全局變量方法可以做到這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.