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

Watchers

Ted Feng avatar

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.