-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.php
77 lines (61 loc) · 1.92 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
require 'vendor/autoload.php';
use Onetoweb\Exact\Client;
use Onetoweb\Exact\Exception\RequestException;
$bearer = 'bearer';
$client = new Client($bearer);
// returns validation errors in dutch
$client->setLanguage('nl');
try {
// get product stock
$results = $client->getProductStocks();
$products = $results['products'];
// get products
$page = 1;
$results = $client->getProducts($page);
$products = $results['products'];
// get product
$sku = 'product sku';
$results = $client->getProduct($sku);
$product = $results['product'];
// create order
$results = $client->createOrder([
'description' => 'test order',
'your_ref' => 'test order',
'remarks' => 'test order',
'delivery_date' => '2021-01-01T12:00:00',
'delivery_address' => [
'address_line_1' => 'street number extension',
'address_line_2' => null,
'address_line_3' => null,
'postcode' => '1000AA',
'city' => 'city',
'country' => 'NL'
],
'order_lines' => [[
'item_code' => 'item code',
'quantity' => 2,
'notes' => 'test order item 1',
], [
'item_code' => 'item code',
'quantity' => 1,
'notes' => 'test order item 2',
]],
]);
$order = $results['order'];
// get order
$orderNumber = 42;
$results = $client->getOrder($orderNumber);
$order = $results['order'];
// get invoices
$page = 1;
$results = $client->getInvoices($page);
$invoices = $results['invoices'];
// get invoice
$invoiceNumber = 42;
$results = $client->getInvoice($invoiceNumber);
$invoice = $results['invoice'];
} catch (RequestException $requestException) {
// contains json with error messages
$errors = json_decode($requestException->getMessage());
}