Is it wrong to implement a payment system using JavaScript?

I am wondering if it is a bad idea to implement a legal payment system using JavaScript on the client side and PHP on the server side? I mostly worry about IEEE floating point and too weak languages.

+3
source share
3 answers

The main problem is Javascript, which doesn't even have a real integer type, not to mention the (official) correct decimal library (PHP has BC Math ). There is an old third-party Java BigDecimal port for Javascript that you can use on the client side. Alternatively, calculate everything in cents, since the double IEEE can accurately represent integers up to 53 bits long, which is enough to hold even the entire sovereign debt of the United States for at least another 10 years (possibly).

+6
source

, , . Javascript . . , , , Javascript .

, PhP , Javascript, , Javascript, .

, , , .

+3

The real problem, as others have noted, is that you cannot trust the client. Ever. No calculations should be performed on the client side or using data (such as price) from the client. Other than that, I would never use float to represent monetary amounts. Money should always be represented as an integer, where 1 represents a single unit of the base unit of the currency (for example, a cent). it complicates the situation a bit, but does itself a favor and creates some simple access functions, and your life will be easier for her.

+1
source

Source: https://habr.com/ru/post/1777214/


All Articles