PHP Error: "Must supply amount_money"

I’m using the guide over at Take Online Payments with Square APIs in 3 Steps | Square

Everything is installed; I installed the Square SDK using Composer, made sure I’m using the latest version of PHP, and am using sandbox credentials.

I have a simple form that successfully gets a idempotencyKey, but when I try to process the payment at my “process-payment.php” file, I constantly keep getting the following error:

[
{
“category”: “INVALID_REQUEST_ERROR”,
“code”: “MISSING_REQUIRED_PARAMETER”,
“detail”: “Must supply amount_money”,
“field”: “amount_money”
}
]

I’m using the Money class to create the object, am using setAmount() and setCurrency(Currency:CAD), and no php errors - just the errors from square’s side. Looking at the error, it reqires an “amount_money” field, but looking at the docs over at square-php-sdk/create-payment-request.md at master · square/square-php-sdk · GitHub , it looks like this is actually called “amountMoney”.

The PHP I’m using is:

$money = new Money;
$money->setAmount(floatval($total)*100);
$money->setCurrency(Currency::CAD);
$create_payment_request = new CreatePaymentRequest($token, $idempotencyKey, $money);

Is this an error on Square’s side? I can provide some basic code if needed, but I pulled it all from the Github repo and the Square site.

Figured out the issue. The CreatePaymentRequest’s 3rd parameter doesn’t work, but some of the documentation and examples use it so this was creating confusion.

I fixed it with the following:

$money = new Money;
$money->setAmount(floatval($total)*100);
$money->setCurrency(Currency::CAD);
$create_payment_request = new CreatePaymentRequest($token, $idempotencyKey);
$create_payment_request->setAmountMoney($money);

Works like a charm now!

3 Likes

Thank you for providing the solution. It helped me!

This also solved my problem. Thank you! Weird that the docs have it wrong.