代码之家  ›  专栏  ›  技术社区  ›  Brian Fleishman

方形销售点的美元金额读数不正确

  •  -3
  • Brian Fleishman  · 技术社区  · 7 年前

    我试图使用文档中的示例代码测试Web API。我可以成功调用该应用程序并生成任何错误,但我硬编码到脚本中的金额传递不正确。好像差了两位数。

    一、 E$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>
    

    我做错了什么?

    1 回复  |  直到 7 年前
        1
  •  1
  •   ceejayoz    7 年前

    它完全按照预期工作。每 the documentation :

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

    因此,值为 500 美元代表5美元。