- Subscribe to RSS Feed
- Mark Thread as New
- Mark Thread as Read
- Float this Thread for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
API INT ERROR
In My database Totals are shown as DECIMAL with values showing as [123.45] USD
Your API want me to send price data as INT with values [12345] so it can then change it back to [123.45]
I can't do that! all of my features, estimates, invoices, products, items, credit statements, etc all post, pull and echo data from tables using DECIMAL.
Not only that, INT rounds UP or DOWN I send a customer an invoice priced at $123.89 only to have Square round up and charge them $124.00 because I'm forced to use INT to send price data. Heck I even tried using FLOAT but I get the following error:
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"}]}
My code (throws errors) is as follows:
$data['total']=floatval($data['total']); $data['total']=$data['total']*100; $posted = [];
This code works but, sends incorrect price format:
$data['total']=intval($data['total']); $data['total']=$data['total']*100; $posted = [];
How would I fix this without using INT and having an invoice of $123.45 turn into an invoice of $12345
Thanks
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report
- Subscribe to RSS Feed
- Mark Thread as New
- Mark Thread as Read
- Float this Thread for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Hello @Sagelawn!
It looks like you've been in touch with our API Support Team. In this situation you'll want to use intval and multiple by 100.
$data['total']=intval($data['total'] * 100);
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report
- Subscribe to RSS Feed
- Mark Thread as New
- Mark Thread as Read
- Float this Thread for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
I'm not quite sure what this changes.
my prices and totals use DECIMAL. if I have ten dollars and ninety nine cents in `invoicetotal` my invoice will show $10.99.
If I use $data['total']=intval($data['total'] * 100); it will then show $11.00 at checkout.
I can't use Intval without rewriting my entire site.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report
- Subscribe to RSS Feed
- Mark Thread as New
- Mark Thread as Read
- Float this Thread for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
The code above multiplies the value before it's converted into an integer. That way you don't loose the cents and it doesn't round up or down.
If you're still having trouble, could you share a screenshot of the $data["total"] value before and after you do intval?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report