【问题标题】:Square Point of Sale not reading correct dollar amountSquare Point of Sale 未读取正确的美元金额
【发布时间】:2017-12-03 10:47:15
【问题描述】:

我正在尝试使用文档中的示例代码来测试 Web API。我可以成功调用 APP 并生成任何错误,但是我硬编码到我的脚本中的美元金额并没有正确传递。好像差了两位数。

即 500 美元转换为 5 美元

我尝试过使用文本字段的值以及值中的硬编码。每次结果都一样。

当我单击 Web 表单上的按钮时调用代码:

 <!--- Square CC Processing --->
   <script>  
          document.getElementById("do_square_payment_btn").onclick = function (e) {

            e.preventDefault();

            var amount = $('#payment_amount_mobile').val();
            //var amountFixed = amount.toFixed(2);
            console.log("Amount being passed in on square button click " + amount);
            var dataParameter = {
                "amount_money": {
                    "amount" : '5000' ,
                    "currency_code" : "USD"
                },
                "callback_url" : "https://jaydien.ezservicetrax.com", // Replace this value with your application's callback URL
                "client_id" : "sq0idp-CHLAPYt9s1L594ZZZysDSQ", // Replace this value with your application's ID
                "version": "1.3",
                "notes": "Computer Service",
                "options" : {
                "supported_tender_types" : ["CREDIT_CARD"] //,"CASH","OTHER","SQUARE_GIFT_CARD","CARD_ON_FILE"
                }
            };

            console.log(amount);
            console.log("Square button clicked");
            console.log("square-commerce-v1://payment/create?data=" + encodeURIComponent(JSON.stringify(dataParameter)));
            location.href = "square-commerce-v1://payment/create?data=" + encodeURIComponent(JSON.stringify(dataParameter));

            };  


          //window.location = "square-commerce-v1://payment/create?data=" + encodeURIComponent(JSON.stringify(dataParameter));

    </script>

我做错了什么?

【问题讨论】:

  • ......Java?

标签: javascript html square square-connect


【解决方案1】:

它完全按照它应该的方式工作。每the documentation

请注意,您以适用货币的最小面额指定金额。例如,美元金额以美分指定。详情请见Working with monetary amounts

因此,500 对 USD 表示 5 美元。

【讨论】:

  • (您会在大多数现代支付 API 中发现这种行为。它让每个人都可以避免 floating point math 的混乱。)
  • 抱歉,这令人困惑。所以如果我想超过 89.10 美元,那应该是什么样子?
  • 好的。那么在javascript中有一种简单的方法可以从数字中删除decial吗?我的用户在我传递给脚本的文本框中输入了一个金额。例如,用户将输入 89.10
  • 或者我猜我可以乘以 100?
  • 是的,乘以 100 是常用的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-10-09
  • 2021-09-24
  • 2020-10-09
  • 2019-12-08
  • 2018-08-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多