-3

I am trying to test out the Web API using the example code from the documentation. I can successfully call the APP with generating any errors, but the dollar amount that I am hard coding into my script is not passing over correct. It seems to be two digits off.

I.E $500 translates to $5

I have tried using the value of a text field as well as hard coding in the value. Same result each time.

I call the code when I click a button on my web form:

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

What am I doing wrong?

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Brian Fleishman
  • 1,237
  • 3
  • 21
  • 43

1 Answers1

1

It's working exactly as it's supposed to. Per the documentation:

Note that you specify the amount in the smallest denomination of the applicable currency. For example, US dollar amounts are specified in cents. See Working with monetary amounts for details.

So, a value of 500 for USD represents $5.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368