从Coinbase付款按钮获取金额

时间:2020-09-07 04:44:44

标签: javascript dom-events payment bitcoin coinbase-api

我正在尝试在我的网站上实施币种支付。

我在这里使用嵌入付款按钮:https://commerce.coinbase.com/docs/#payment-buttons

我正在使用Javascript BuyWithCrypto类注册一个回调,该回调调用在调用该函数后处理客户请求的脚本。被调用的PHP脚本应该使用客户存放的金额来更新数据库表。

BuyWithCrypto.registerCallback('onSuccess', function(e){
    // Charge was successfully completed
    window.location.assign("process.php")

});

一切正常,但我在检测用户向生成的地址存入了多少钱时遇到了问题。

我只想知道在调用onSuccess函数时是否可以获得用户存入的金额。

1 个答案:

答案 0 :(得分:0)

var amt=document.getElementById("amt");
var btn=document.getElementById("btn");
btn.addEventListener("click", purchase);

function purchase() { // put this in first line of callback
  var amtPaid=parseFloat(
    amt.options[amt.selectedIndex].innerText
  );
 console.log(amtPaid);
  // do what you want with amtPaid
}
Amount:
<select id="amt">
  <option> 9.99</option>
  <option>19.99</option>
  <option>29.99</option>
</select>
<button id="btn">Pay</button>