Giter VIP home page Giter VIP logo

vendapi's Introduction

Vend API class

This is a basic PHP class for using the API for Vend (vendhq.com). It is at a really basic state but it does exactly what I need at the moment. Feel free to add any issues/bugs and send me any pull requests.

NB: Updated to use oauth for July 2015 deprecation, if you have sample code for handling oauth authorization and token refreshes submit a pull requst

Installation and Basic Usage

With Composer

The easiest way to install Vend API is via composer. Create the following composer.json file and run the php composer.phar install command to install it.

{
    "require": {
        "vendapi/vendapi": "dev-master"
    }
}

Without Composer

Why are you not using composer? Download and extract the zip file from the repo into your project path somewhere.

<?php
require 'path/to/src/VendApi/VendApi.php';

$vend = new VendAPI\VendAPI('https://shopname.vendhq.com','VEND_TOKEN_TYPE','VEND_ACCESS_TOKEN');
$products = $vend->getProducts();

API Usage

Get Products

$vend = new VendAPI\VendAPI('https://shopname.vendhq.com','VEND_TOKEN_TYPE','VEND_ACCESS_TOKEN');
$products = $vend->getProducts();

NB this will only grab the first 20 or so results. To grab all results set $vend->automatic_depage to true

$vend->automatic_depage = true;
$products = $vend->getProducts();

Add a Product

$donut = new \VendAPI\VendProduct(null, $vend);
$donut->handle = 'donut01';
$donut->sku = '343434343';
$donut->retail_price = 2.99;
$donut->name = 'Donut w/ Sprinkles';
$donut->save();
echo 'Donut product id is '.$donut->id;

Add a Sale

$sale = new \VendAPI\VendSale(null, $vend);
$sale->register_id = $register_id;
$sale->customer_id = $customer_id;
$sale->status = 'OPEN';
$products = array();
foreach ($items as $item) {
    $products[] = array(
        'product_id' => $item->product_id,
        'quantity' => $item->quantity,
        'price' => $item->price
    );
}
$sale->register_sale_products = $products;
$sale->save();

echo "Created new order with id: ".$sale->id;

Other cool stuff

$vend->getProducts(array('active' => '1', 'since' => '2012-09-15 20:55:00'));

NB Check the vend api docs for supported search fields. If a search field isn't supported all results will be returned rather than the zero I was expecting

$coffee = $vend->getProduct('42c2ccc4-fbf4-11e1-b195-4040782fde00');
echo $coffee->name; // outputs "Hot Coffee"
if ($product->getInventory() == 0) {
  $coffee->setInventory(10);
  $coffee->name = 'Iced Coffee';
  $coffee->save();
}

Debugging

To debug make a call to the debug() function. eg:

$vend->debug(true);

vendapi's People

Contributors

brucealdridge avatar samwalshnz avatar tomcawthorn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vendapi's Issues

Can't fetch and update products and inventory.

Hi,

I have set up your this code to localhost and after setup got following error. Can you please tell us what i did't wrong?

Fatal error: Uncaught exception 'VendAPI\Exception' with message 'Error: Recieved null result from API' in D:\xampp\htdocs\Drake\Source\VendAPI-master\VendAPI-master\src\VendAPI\VendAPI.php:320 Stack trace: #0 D:\xampp\htdocs\Drake\Source\VendAPI-master\VendAPI-master\src\VendAPI\VendAPI.php(207): VendAPI\VendAPI->_request('/api/products') #1 D:\xampp\htdocs\Drake\Source\VendAPI-master\VendAPI-master\src\VendAPI\VendAPI.php(108): VendAPI\VendAPI->apiGetProducts('') #2 D:\xampp\htdocs\Drake\Source\VendAPI-master\VendAPI-master\example.php(9): VendAPI\VendAPI->getProducts() #3 {main} thrown in D:\xampp\htdocs\Drake\Source\VendAPI-master\VendAPI-master\src\VendAPI\VendAPI.php on line 320

I want to update product inventory by API to vend but don't understand how to do. Please help.

Thanks,
Vish

More explicit pagination options

Currently trying to sync a huge number of products and it's overwhelming a 512MB allocated memory limit.

It would be nice if there was a way to handle pagination explicitly to reduce the memory overhead, I'm going to fork and add a basic solution in for now.. But it won't be beautiful.

Getting an error when adding a sale

When I try to send a sale I keep getting the following error

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`vend`.`vend_register_payment_count`, CONSTRAINT `vrvi_4` FOREIGN KEY (`retailer_payment_type_id`) REFERENCES `vend_retailer_payment_type` (`id`))

This is the data that I am sending

{
    "customer_name": "Philip Thompson",
    "invoice_number": "100000001",
    "note": "",
    "register_id": "02d59481-b67d-11e5-f667-e5e3bfef0302",
    "register_sale_payments": {
        "amount": "60.0000",
        "retailer_payment_type_id": "02d59481-b67d-11e5-f667-e5e3bfef5452"
    },
    "register_sale_products": {
        "display_retail_price_tax_inclusive": "1",
        "name": "Cool T-Shirt / xl - PCT10003",
        "price": "25.0000",
        "price_total": "50.0000",
        "product_id": "14",
        "quantity": "2.0000",
        "tax": "0.00",
        "tax_rate": "0.0000",
        "tax_total": "0.0000"
    },
    "sale_date": "2016-03-23 14:24:30",
    "status": "CLOSED",
    "total_price": "60.0000",
    "total_tax": "0.0000",
    "totals": {
        "total_payment": "60.0000",
        "total_price": "60.0000",
        "total_tax": "0.0000",
        "total_to_pay": ""
    }
}

Do you have any idea as what might have been going on here?

Thanks.

How to add images to new product

When adding a new product with basic information such as name, price, sku, description, everything is fine, but how can I add images as well?...

thanks.

Getting Trying to get property of non-object on class

Hi Bruce
first of all thanks for the class you have provided for using the api for vend. But unfortunately It is not working for me.I am getting following error

Notice: Trying to get property of non-object in E:\wamp\www\vend\VendAPI.php on line 113
Warning: Invalid argument supplied for foreach() in E:\wamp\www\vend\VendAPI.php on line 113

I have downloaded zip package which had the class file.
thanks for any help or suggestions in advance

First I was getting fatal error for class. some tech guy help me to correct.
Using the code below way solved the problem

getProducts(); ?>

awaiting reply

Error: Recieved null result from API

I am trying to use your updated library for OAuth2.0 But it seems that it doesn't fetch records. I am trying to use it with Personal Token instead of OAuth2.0 Token.

I feel it though error while trying to use/fetch product list using. my code looks like this

include 'src/VendAPI/VendAPI.php';
$vendapi = new VendAPI\VendAPI('https://shopname.vendhq.com','Bearer','my personal token');
vendapi->getProducts()

Can't seem to connect

Trying your basic 3 line demo.
When I put debug on, it crashed even inside the debug with message "Undefined index: request_header" that's on line 130 of VendRequest.php:
echo $head.$this->curl_debug['request_header'].$foot.

it seems that the script dies at this line: $this->response = $response = curl_exec($this->curl); (returns false)

any ideas what I could be doing wrong?

Still active

WIll this php library still work? I notice there have not been updates in some time. thanks

Unable to register sale

Thanks for the class, has been a huge help and using it extensively.

A few weeks ago I was able to register a sale without any issues, then recently I started getting this error: Fatal error: Uncaught exception 'VendAPI\Exception' with message 'Error: Recieved null result from API', when saving the sale.

The same "save" method works fine for adding a product, this only happens for adding a sale.

Any help with problem solving this issue would be much appreciated. Let me know if you need any further info.
Thanks

Change of license?

Hey @brucealdridge,

Before I get stuck in to try out your API library, I was wondering if you'd consider changing the library to an MIT license instead of GPL?

Cheers mate

No method...

Hey,

Your class has been a great starting point...

Were running PHP 5.2.9 so it needed the name spaces removing, but I just wanted to check that the issue I am having is related to this somehow :)

As per your docs Im trying to update a products inventory, but first I just want to get count.

$obj = $vend->getProduct('42c2ccc4-fbf4-11e1-b195-4040782fde00');

This is great and returns an object, but my problem is when I come to calling the method getInventory its not available. Looking into getProduct in VendAPI, it doesn't create a new VendProduct Object if a result is found. If I change this method to create a new VendProduct eg.

return is_array($result) && isset($result[0]) ? new VendProduct(null, $result[0]) : new VendProduct(null, $this);

This exposes the method but then Im having issues with iterating through the vendObjectProperties to find the inventory key now.

I would really appreciate it if you could tell me where I may be going wrong.

Cheers,

SemVer and releases

It would be great to get a new release to include the most recent changes and use SemVer to keep releases going forward. This would make the next release v1.5.1.

Without this a developer has to a lot of messing around in their composer.json to get anything beyond v1.5 if the dependency tree is at all complex because dev-master is seen as unstable.

Debugging not working?

Hi,

As per the docs/examples I've tried specifying $vend->debug(true) but nothing debuggy appears to happen when the curl calls are made. Am I just doing it wrong?

Cheers,

  • Bob -

How can you register a new order/sale?

I've looked over the sdk but I can't find any functions to create a new order/sale. Is there any way to do this? Thank you for spending time on this!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.