2017-12-03 47 views
-3

我试图用文档中的示例代码来测试Web API。我可以通过生成任何错误来成功调用APP,但是硬编码到我的脚本中的美元金额并没有超过正确的值。这似乎是两位数字了。销售点不读取正确的美元金额

即500 $转化为$ 5

我已经使用文本字段的值值以及硬编码的尝试。每次都有同样的结果。

我打电话的代码,当我点击我的网页表单上的按钮:

<!--- 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> 

我在做什么错?

+0

............. Java? –

回答

1

它的工作原理与其应有的一样。每the documentation

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

因此,对于美元,价值500代表5美元。

+1

(你会在大多数现代支付API中发现这种行为,它可以让每个人避免[浮点运算]的混乱(https://stackoverflow.com/questions/588004/is-floating-point-math-broken)。 ) – ceejayoz

+0

对不起,但那是混乱。所以如果我想通过89.10美元,那应该如何? –

+1

@BrianFleishman你会传递一个'8910'的值。 – ceejayoz

相关问题