sebsoftnl / moodle-enrol_gwpayments

Other
2 stars 3 forks source link

Error checking coupon when locale decimal separator is not . #7

Closed vicencarlos closed 3 years ago

vicencarlos commented 3 years ago

The problem seems in the ajax call enrol_gwpayments_check_coupon This is the response: [{"error":true,"exception":{"message":"Detectado valor de respuesta no v\u00e1lido","errorcode":"invalidresponse","link":"http:\/\/192.168.1.106\/","moreinfourl":"https:\/\/docs.moodle.org\/311\/es\/error\/debug\/invalidresponse"}}]

vicencarlos commented 3 years ago

The problem is that in that check_coupon_returns certain return parameters are defined as float. For example 'newprice' => new external_value(PARAM_FLOAT, 'New cost amount'), but in the method the value is filled as string: $rs['newprice'] = format_float($enrol->cost - $discount, 2, true); (format_float returns a string with the float number in the user locale format) if you are in a locale with decimal separator '.' there is no problem, because this is the PHP float standar format and made the conversion automatically, but in another locales, this raises an error in the checking of response that the moodle lib made previous to return the value to the browser.

The solution is or to define the return as text or not to use format_float, and return a float value.

rogiervandongen commented 3 years ago

WIll be fixed soon: the result will return float values. The reason being is due to possible future usage/calculations using the returned floating point value.

vicencarlos commented 3 years ago

Thanks