Does square accepts decimal values? - square-connect

i have read some issues regarding this but not clarified if they accept or not an amount with decimal value.
im a beginner to square. Please Help... Below is my error
errors
:
Array(1)
0
:
category
:
"INVALID_REQUEST_ERROR"
code
:
"EXPECTED_INTEGER"
detail
:
"Expected an integer value."
field
:
"amount_money.amount"

The "amount" field is always in the lowest denomination for the currency being used. If you're using USD this would be in cents, for example. If you need to charge $1.50, then for the amount you will need to supply "150" in terms of cents.
Also asked here: EXPECTED_INTEGER — Issues with Square payment portal

Related

I need help writing a code for this question

Im using pycharm
Write a program that will calculate tax on the user's annual salary. It must :
1. ask the user to enter their name,
2. ask the user to enter their annual salary
3. print their tax bill on screen
However, Australian tax laws are complicated.
They follow these rules:
•0 – $18,200 Nil ($0 tax paid)
•$18,201 – $45,000 19 cents for each $1 over $18,200
•$45,001 – $120,000 $5,092 plus 32.5 cents for each $1 over $45,000
•$120,001 – $180,000 $29,467 plus 37 cents for each $1 over $120,000
•$180,001 and over, $51,667 plus 45 cents for each $1 over $180,000
This function works and does not require any dependencies to work.
def taxesDue(x:float):
'''Function that takes in a person's yearly salary (unit: AUD) and returns the taxes due (unit: AUD)'''
if(x <= 18200):
return 0 # lucky person
elif(x <= 45000):
return round(0.19*(x-18200), 2)
elif(x<= 120000):
return round(5092+0.325*(x-45000), 2)
elif(x <= 180000):
return round(29467+0.37*(x-120000),2)
else:
return round(51667+0.45*(x-180000)*0.45, 2)
The sample output is
taxesDue(16500)
>0
taxesDue(18201)
>0.19
taxesDue(1e6) # scientific notation for 1 million (float)
>217717.0
Since all of us were new to coding at one point. Some explanation on things you will likely encounter on your journey deeper into Python.
The function's input is the salary in AUD (can be an integer like 20000 or a float such as 20000.95 where the decimals represent cents. Therefore, I rounded the taxes due to two digits through round(y, 2). In case the input salary is always of type int you can leave the rounding out as the output will naturally only have two decimals.
Speaking of float and int. Types in Python are dynamic so the float:x in the function's argument list is syntactic sugar (nice to look at for the developer/user but no impact on the rest of the code) to emphasize that a floating point number (the salary) goes in rather than a string str like x=Hello IRS. Note that int is a subset of float so float is more general.
The if/elif/else iterates through the conditions (e.g. x <= 45000). elif and the final else is only checked if none of the previous conditions was met. Note that this naturally reflects your task at hand.
Any function is exited as soon as any of the return's is reached.
Comments such as #lucky or the the comment right underneath the function's head '''Function... will go into the docstring. In turn, the developer can retrieve it when running
?taxesDue
If you need to print the result run
x = 475000 # or whatever salary you can think of
print(taxesDue(x))

Weigthing a dataset

I'm looking for possible algorithms/techniques to give weight to a data set. I have a set of let us call them ID's which need to be weighted based on different criteria. To make the example a little bit easier, the beginning weight (value) of every record will be 1.
For example we use the following data set
<table><tbody><tr><th>ID</th><th>Age</th><th>Postalcode</th><th>Status Insurance A</th><th>Marital Status Number of childeren</th><th> </th></tr><tr><td>1</td><td>30</td><td>10000</td><td>ON HOLD</td><td>SINGLE</td><td>0</td></tr><tr><td>2</td><td>35</td><td>15000</td><td>ACTIVE</td><td>DIVORCED</td><td>2</td></tr><tr><td>3</td><td>36</td><td>15000</td><td>ACTIVE</td><td>MARRIED</td><td>2</td></tr></tbody></table>
Next to the data set we have a set of rules we need to apply to give it a weight (addition):
ages (> 10 and < 20): +0.5
ages (> 20 and < 30): +0.7
ages (> 30 and < 99): +0.85
martial status : (married) : +0.50
martial status : (divorced) : +0.45
martial status : (single) : +0.35
status insurance (ACTIVE) : +0.05
status insurance (ON HOLD) : +0.1
Now we need to apply these rules to the data set, so for example record with ID=1 would have a weight of
1 + 0.85 (age>30) + 0.1 (status: ON HOLD) + 0.35 (martial status : SINGLE) = 2.3
This is just a small example, but the set of rules is more complex can be manipulated by the user and weights can be changed.
I could off-course implement this the naive way, just write some hard coded logic to go over the data set record by record and test if the rule applies.
I was however wondering if there are better more generic solutions to this kind of problem ?

Symfony Range in validation.yml

I would like to know about this particular validation behaviour, although is more out of curiosity than to solve a real life problem, I'm interested to know the answer.
Entity property price is defined as:
/**
* #ORM\Column(name="price", type="float", nullable=false)
*/
In the Symfony manual targeting 2.7, range min and max options are 'integer' types. But actually using a float, it does work as expected:
#validation.yml
Project\MyBundle\Entity\Product:
properties:
price:
- Range:
min: 0.01
max: 12.90
minMessage: Price can't be lower than 0,01€
maxMessage: Price can't be lower than 12,90€
max validation works without any problem making any value higher than 12,90 fail as seen in the picture.
min validation does not:
Entering 0,009 will pass validation although is minor than 0,01.
Is there any reason that min and max values are documented as type: integer but work to validate float values ?
Has anyone a valid answer for this one ?
Price type has a precision point 2, so your number is rounded
0.009 which is equivalent 0.01

validation on discount between 0 and 0.999 in laravel 5

I need to apply validation on discount filed accept value between 0 and 0.999
like: 0.25, 0.0125, 0.09
I tried
'discount' => 'required|max:0.999'
but got: The discount may not be greater than 0.999 characters.
The max rule looks at the type of the variable being sent to it and applies the appropriate logic. For numbers, it works like you intend - it compares the numerical value.
But for strings, it means that the string may not be longer than the max. In your case, Laravel thinks you're sending a string and tries to validate it as such. Your variables probably aren't 0.25, 0.5, etc., but rather "0.25", "0.5", etc. If you convert them to floats, it should work fine.
If, for instance, your values come directly from forms, they're most likely in string form, not float.
Size is what you need here
The field under validation must have a size matching the given value.
For string data, value corresponds to the number of characters. For
numeric data, value corresponds to a given integer value. For files,
size corresponds to the file size in kilobytes.
'discount' => 'required|size:0.999'
'discount' => 'required|numeric|max:0.999'

What is the minimum length of a valid international phone number?

I need to validate user input of an international phone number. According to E.164, the maximum length is 15 digits, but I was unable to find any information about the minimum. I consider digits only, no plus sign or separators.
As per different sources, I think the minimum length in E-164 format depends on country to country. For eg:
For Israel: The minimum phone number length (excluding the
country code) is 8 digits. - Official Source
(Country Code 972)
For Sweden : The minimum number length (excluding
the country code) is 7 digits. - Official Source‎ (country code 46)
For Solomon Islands its 5 for fixed line phones. - Source (country code 677)
... and so on.
So including country code, the minimum length is 9 digits for Sweden and 11 for Israel and 8 for Solomon Islands.
Edit (Clean Solution): Actually, Instead of validating an international phone number by having different checks like length etc, you can use the Google's libphonenumber library. It can validate a phone number in E164 format directly. It will take into account everything and you don't even need to give the country if the number is in valid E164 format. Its pretty good!
Taking an example:
String phoneNumberE164Format = "+14167129018"
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try {
PhoneNumber phoneNumberProto = phoneUtil.parse(phoneNumberE164Format, null);
boolean isValid = phoneUtil.isValidNumber(phoneNumberProto); // returns true if valid
if (isValid) {
// Actions to perform if the number is valid
} else {
// Do necessary actions if its not valid
}
} catch (NumberParseException e) {
System.err.println("NumberParseException was thrown: " + e.toString());
}
If you know the country for which you are validating the numbers, you don;t even need the E164 format and can specify the country in .parse function instead of passing null.
The minimum length is 4 for Saint Helena (Format: +290 XXXX) and Niue (Format: +683 XXXX).
EDIT 2015-06-27: Minimum is actually 8, including country code. My bad.
Original post
The minimum phone number that I use is 10 digits. International users should always be putting their country code, and as far as I know there are no countries with fewer than ten digits if you count country code.
More info here: https://en.wikipedia.org/wiki/Telephone_numbering_plan

Resources