-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image upload / VAT bug #25
Comments
Hi @chatlumo, You should be able to add a new product like this: use GuzzleHttp\Client;
use LauLamanApps\IzettleApi\API\Product\Product;
use LauLamanApps\IzettleApi\GuzzleIzettleClient;
use LauLamanApps\IzettleApi\IzettleClientFactory;
$accessToken = '<AccessToken>'; //-- Get from cache
$iZettleClient = new GuzzleIzettleClient(new Client(), 'clientId', 'clientSecret');
$iZettleClient->setAccessToken($accessToken);
$productClient = IzettleClientFactory::getProductClient($iZettleClient);
$product = Product::new(/*..required data..*/);
$productClient->createProduct($product); |
Hi @LauLaman, Thank you for your reply ! I tried this: require_once './vendor/autoload.php';
use GuzzleHttp\Client;
use LauLamanApps\IzettleApi\API\Product\Product;
use LauLamanApps\IzettleApi\GuzzleIzettleClient;
use LauLamanApps\IzettleApi\IzettleClientFactory;
$iZettleClient = new GuzzleIzettleClient(new Client(), $clientId, $clientSecret);
$accessToken = $iZettleClient->getAccessTokenFromUserLogin($login, $password);
$productClient = IzettleClientFactory::getProductClient($iZettleClient);
$category = \LauLamanApps\IzettleApi\API\Product\Category::new('Home');
$categoryCollection = new \LauLamanApps\IzettleApi\API\Product\CategoryCollection();
$categoryCollection->add($category);
$currency = new \Money\Currency('EUR');
$variant = \LauLamanApps\IzettleApi\API\Product\Variant::new('test article', 'test', 'TEST', null, 0, null, new \Money\Money(500, $currency), null, 2.1);
$variantCollection = new \LauLamanApps\IzettleApi\API\Product\VariantCollection();
$variantCollection->add($variant);
$image = new \LauLamanApps\IzettleApi\API\Image('https://mydomain.tld/images/2018.jpg');
$imageCollection = new \LauLamanApps\IzettleApi\API\ImageCollection();
$imageCollection->add($image);
$product = Product::new('test article', '', $categoryCollection, $imageCollection, $variantCollection, 'TEST');
$productClient->createProduct($product); But i always have:
Do you have an idea why ? |
Hi @chatlumo I tried your example data and got the following exception back from iZettle: {
"developerMessage": "VAT value=2.1 is not allowed in country=NL, allowedVats=[21, 6, 0]",
"errorType": "VAT_NOT_ALLOWED_IN_COUNTRY",
"violations": []
} Can you put a try catch block around the createProduct() like so to get the error message? try {
$productClient->createProduct($product);
} catch (\Exception $exception) {
echo $exception->getResponse()->getBody()->getContents();
}
with version 0.9.3 you can now catch
|
Thansk, now i have this message:
|
OK to be sure that we send the correct data to iZettle can you please output the following information: if you did not update to v 0.9.3 yet: try {
$productClient->createProduct($product);
} catch (\Exception $exception) {
echo GuzzleHttp\Psr7\str($err->getRequest());
} otherwise you'll need to change the GuzzleIzettleClient.php file on line 158 # LauLamanApps\IzettleApi\GuzzleIzettleClient.php:L158
try {
return $this->guzzleClient->post($url, $options);
} catch (ClientException $exception) {
echo GuzzleHttp\Psr7\str($exception->getRequest());
} the output should look something like this
|
Thanks, This is the result:
I don't know why my VAT which is 2.1 become 2.100000000000000088817841970012523233890533447265625. |
However if i test with a VAT of 5.5 it's working. In addition of that, how to add an online image to the product ? |
@chatlumo very interesting. You're using a curl version that is slightly newer than the version i'm using the same goes for your PHP version, So that should not be it. I am very curious on where the float changes in the process. I'm, not being able to duplicate the problem. And can't debug the french restrictions. Can you do some debugging on the float? Clearly it changes somewhere. You directly access it by doing something like: $variant = Variant::new('test article', 'test', 'TEST', null, 0, null, Money::Eur(500), null, 2.1);
echo $variant->getVatPercentage(); you can also play around with some casting like: $variant = Variant::new('test article', 'test', 'TEST', null, 0, null, Money::Eur(500), null, (float)'2.1');
$variant = Variant::new('test article', 'test', 'TEST', null, 0, null, Money::Eur(500), null, floatval('2.1')); Let me know what you'll find. I'll take a look at the Image. |
You should be able to create images like this: $imageClient = IzettleClientFactory::getImageClient($iZettleClient);
//use a url
$image = new ImageUrlUpload('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png');
// or upload a file form disk
$image = new ImageFileUpload('/var/whatever/your/path/may/be/file.jpg');
// post to iZettle
$image = $imageClient->postImage($image); however i was not able to do this and checked the iZettle documentation which is broken at this moment. I've opened a issue in the official iZettle Api documentation: |
Hi, I tried all variants to put 2.1, echo is always good but the json in the request is always bad. For the image (with url), i have |
Floats are a b*tch in PHP. Lets change them to a string value, that should fix it. To be changed in v 1.0 |
Hello,
How to submit a new product with this API ?
If i use:
$library->getProducts()->add($product)
;I do have a collection with my new product, but how to submit (post) that to iZettle ?
Thanks.
The text was updated successfully, but these errors were encountered: