x

Trying to pass data from php form to square code

I've used the Checkout API example code on the square webpage to setup a way for people to pay from my website.  I got to the stage where it works, so than I modified the code so the default info is instead pulled from a php form that my visitors would fill in:

 

//Create a Money object to represent the price of the line item.
$price = new \SquareConnect\Model\Money;
$price->setAmount($_REQUEST['showprice']);
$price->setCurrency('GBP');

//Create the line item and set details
$book = new \SquareConnect\Model\CreateOrderRequestLineItem;
$book->setName($_REQUEST['ticket']);
$book->setQuantity($_REQUEST['quantity']);
$book->setBasePriceMoney($price);

 

I can change the setName and setQuantity without any problem, but when I change the setAmount i get the following error message.  Can anyone tell me what I'm doing wrong?

 

Exception when calling CheckoutApi->createCheckout: [HTTP/1.1 400 Bad Request] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"EXPECTED_INTEGER","detail":"Expected an integer value.","field":"order.line_items[0].base_price_money.amount"}]}

892 Views
Message 1 of 2
Report
1 REPLY 1
Admin

@Marcus2

 

Hopefully this is a relatively simple answer: It looks like the `setAmount` isn't an integer.

 

You'll need to ensure that the amount that you are passing in is an integer.

kellyj
Technical Program Manager: AI
Square Inc
871 Views
Message 2 of 2
Report