R
R
Roman Savitsky2018-09-12 16:50:18
PHP
Roman Savitsky, 2018-09-12 16:50:18

What causes VALIDATION_ERROR "transactions.amount"?

Hello !
I ran into a very interesting bug at the time of Amount formation, I don’t understand why this happens, I use PayPal-PHP-SDK
Case No. 1

$amount = new Amount();
$amount->setTotal(1.99 );
$amount->setCurrency('GBP');

In this case, the payment is successful and we are happy, but I need $amount->setTotal(1.99 ); substitute a variable in which the desired price will be.
So Case #2
$service_price = PricesServicesObject::allParams()[$serviceName]["price"]; //Получаю цену в формате 1.99 или 5.99

$amount = new Amount();
$amount->setTotal($service_price );
$amount->setCurrency('GBP');

Then in this case, after payment, when a redirect to the site occurs, I get the following error:
"name":"VALIDATION_ERROR","details":[{"field":"transactions.amount","issue":"Currency amount must be non-negative number, may optionally contain exactly 2 decimal places separated by '.', optional thousands separator ',', limited to 7 digits before the decimal point and currency which is a valid ISO Currency Code"

How to defeat her, why is this happening?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Smilik, 2018-09-16
@sagechild

There is no mysticism in programming. If the first case works and the second doesn't, then it means that $service_price is still not 1.99 or 5.99, or there is no existing currency code in currency, otherwise there would be no
"Currency amount must be non-negative number, may optionally contain exactly 2 decimal places separated by '.', optional thousands separator ',', limited to 7 digits before the decimal point and currency which is a valid ISO Currency Code". Try to call like this:
Make sure that in the second case in "GBP" B and P are English letters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question