2017-12-03 101 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