Skip to content
This repository was archived by the owner on Jan 17, 2023. It is now read-only.

Commit fef39b5

Browse files
committed
Update the README for 1.0
1 parent 29cc433 commit fef39b5

1 file changed

Lines changed: 21 additions & 92 deletions

File tree

README.md

Lines changed: 21 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ A simple [Vend API](https://developers.vendhq.com/) client in PHP.
55
The canoncial repository for this stream of development is
66
[https://github.com/TeamOffshoot/vend-php](https://github.com/TeamOffshoot/vend-php)
77

8-
This API Client is still in a pre-1.0 state, so you can expect:
9-
* some bugs (feel free to submit a pull request with bug fixes and test coverage)
10-
* possibly some breaking API changes between v0.9 and v1.0
11-
128
## Requirements
139

1410
* PHP 5.3 (or higher)
@@ -28,7 +24,7 @@ root directory and require vend-php:
2824

2925
{
3026
"require": {
31-
"offshoot/vend-php": "0.9.x"
27+
"offshoot/vend-php": "~1.*"
3228
}
3329
}
3430

@@ -46,7 +42,7 @@ might look something like this:
4642

4743
{
4844
"require": {
49-
"offshoot/vend-php": "0.9.x",
45+
"offshoot/vend-php": "~1.*",
5046
"haxx-se/curl": "1.0.0"
5147
},
5248
"repositories": [
@@ -70,12 +66,15 @@ You will be able to find the cacert.pem file in `vendor/haxx-se/curl/cacert.pem`
7066

7167
### Authentication
7268

69+
#### Getting an Access Token
70+
7371
If you do not already have a Vend API Permanent Access Token, you will need
7472
you authenticate with the Vend API first
7573

7674
$pathToCertificateFile = 'vendor/haxx-se/curl/cacert.pem';
7775
$httpClient = new \Offshoot\HttpClient\CurlHttpClient($pathToCertificateFile);
7876
$redirector = new \Offshoot\Redirector\HeaderRedirector();
77+
7978
$authenticate = new \Vend\Api\AuthenticationGateway($httpClient, $redirector);
8079

8180
$authenticate->forStoreName('mycoolstore')
@@ -90,103 +89,33 @@ perform a GET request to your redirect URI, that will look like:
9089
GET http://wherever.you/like?code=TEMP_TOKEN&domain_prefix=YOUR_STORE_NAME
9190

9291
Your application will need to capture the `code` query param from the request
93-
and use that to get the permanent access token from Vend
94-
95-
$client = new Vend\Api\Client($httpClient);
96-
$client->setClientSecret('ABC123XYZ'); // get this from your Vend Account
92+
and use that to get the access token from Vend
9793

9894
// validate the Vend Request
9995
if ($client->isValidRequest($_GET)) {
10096

10197
// exchange the token
102-
$permanentAccessToken = $authenticate->forStoreName('mycoolshop')
103-
->usingClientId('XXX1234567890')
104-
->usingClientSecret('ABC123XYZ')
98+
$accessToken = $authenticate->forStoreName('mycoolstore')
99+
->usingClientId('XXX1234567890') // get this from your Vend Account
100+
->usingClientSecret('ABC123XYZ') // get this from your Vend Account
101+
->andReturningTo('http://wherever.you/like')
105102
->toExchange($_GET['code']);
106103

107104
}
108105

106+
#### Refreshing an Access Token
107+
108+
TBD
109+
109110
### Interacting with the Vend API
110111

111-
```php
112-
require 'vendapi.php';
113-
114-
$request = new VendAPI\VendRequest(
115-
'https://shopname.vendhq.com',
116-
'username',
117-
'password',
118-
array(
119-
'CURLOPT_CAINFO' => 'path/to/your/cacert.pem'
120-
)
121-
);
122-
123-
$vend = new VendAPI\VendAPI($request);
124-
$products = $vend->getProducts();
125-
```
126-
127-
*NB* this will only grab the first 20 or so results. To grab all results set `$vend->automatic_depage` to `true`
128-
129-
```php
130-
$vend->automatic_depage = true;
131-
$products = $vend->getProducts();
132-
```
133-
### Add a Product
134-
135-
```php
136-
$donut = new \VendAPI\VendProduct(null, $vend);
137-
$donut->handle = 'donut01';
138-
$donut->sku = '343434343';
139-
$donut->retail_price = 2.99;
140-
$donut->name = 'Donut w/ Sprinkles';
141-
$donut->save();
142-
echo 'Donut product id is '.$donut->id;
143-
```
144-
145-
### Add a Sale
146-
147-
```php
148-
$sale = new \VendAPI\VendSale(null, $vend);
149-
$sale->register_id = $register_id;
150-
$sale->customer_id = $customer_id;
151-
$sale->status = 'OPEN';
152-
$products = array();
153-
foreach ($items as $item) {
154-
$products[] = array(
155-
'product_id' => $item->product_id,
156-
'quantity' => $item->quantity,
157-
'price' => $item->price
158-
);
159-
}
160-
$sale->register_sale_products = $products;
161-
$sale->save();
162-
163-
echo "Created new order with id: ".$sale->id;
164-
```
165-
166-
### Other cool stuff
167-
168-
```php
169-
$vend->getProducts(array('active' => '1', 'since' => '2012-09-15 20:55:00'));
170-
```
171-
*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
172-
173-
```php
174-
$coffee = $vend->getProduct('42c2ccc4-fbf4-11e1-b195-4040782fde00');
175-
echo $coffee->name; // outputs "Hot Coffee"
176-
if ($product->getInventory() == 0) {
177-
$coffee->setInventory(10);
178-
$coffee->name = 'Iced Coffee';
179-
$coffee->save();
180-
}
181-
```
182-
183-
### Debugging
184-
185-
To debug make a call to the ```debug()``` function.
186-
eg:
187-
```php
188-
$vend->debug(true);
189-
```
112+
#### Set up the API Client
113+
114+
$vend = new \Vend\Api\Client($httpClient);
115+
$vend->setStoreName('mycoolstore');
116+
$vend->setAccessToken($accessToken);
117+
118+
190119

191120
## Contributing
192121

0 commit comments

Comments
 (0)