forked from revosystems/sage-accounting
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
125 lines (71 loc) · 3 KB
/
index.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
include_once('vendor/autoload.php');
use RevoSystems\SageAccounting\Auth;
use RevoSystems\SageAccounting\Api;
use RevoSystems\SageAccounting\SObjects\Contact;
use RevoSystems\SageAccounting\SObjects\ContactPerson;
use RevoSystems\SageAccounting\SObjects\SalesInvoice;
use Dotenv\Dotenv;
(new Dotenv(__DIR__, "./.env"))->load();
echo "<pre>";
$sage_config = array(
'CLIENT_ID' => getenv('SAGE_CLIENT_ID'),
'CLIENT_SECRET' => getenv('SAGE_CLIENT_SECRET'),
'COUNTRY' => getenv('SAGE_COUNTRY'),
'SAGE_RESOURCE_OWNER_ID' => getenv('SAGE_RESOURCE_OWNER_ID'),
'SAGE_SUBSCRIPTION_ID' => getenv('SAGE_SUBSCRIPTION_ID'),
);
try {
$auth = new Auth($sage_config['CLIENT_ID'], $sage_config['CLIENT_SECRET']);
}
catch(Exception $ex) {
echo $ex->getMessage();
return;
}
$auth = $auth->setAuthKeys([
"access_token" => getenv('SAGE_ACCESS_TOKEN'),
"refresh_token" => getenv('SAGE_REFRESH_TOKEN'),
], [
"country" => $sage_config['SAGE_COUNTRY'],
"resource_owner_id" => $sage_config['SAGE_RESOURCE_OWNER_ID'],
"subscription_id" => $sage_config['SAGE_SUBSCRIPTION_ID'],
]);
$api = new Api($auth, $sage_config['COUNTRY']);
// create_new_contact($api);
create_new_contact_person($api);
// create_new_sales_invoice($api);
function create_new_contact($api) {
$contactResource = (new Contact($api));
echo "\n\n\n\n <h2>COUNT CONTACTS: ".$contactResource->count()."</h2>";
echo "\n\n\n\n <h2>INSERT NEW CONTACT:</h2>";
$contact_json = json_decode(file_get_contents("./src/Fixtures/contact.json"), true);
$contact = new Contact($api, $contact_json);
$result = $contact->create();
// echo "\n\n\n\n <h2>CREATE RESPONSE:</h2>";
var_dump($result);
echo "\n\n\n\n <h2>COUNT CONTACTS: ".$contactResource->count()."</h2>";
// echo "\n\n\n\n <h2>ALL CONTACTS:</h2>";
// $res = $contactResource->all();
}
function create_new_contact_person($api) {
$contactResource = (new ContactPerson($api));
echo "\n\n\n\n <h2>COUNT CONTACTS: ".$contactResource->count()."</h2>";
echo "\n\n\n\n <h2>INSERT NEW CONTACT:</h2>";
$contact_json = json_decode(file_get_contents("./src/Fixtures/contactPerson.json"), true);
$contact = new ContactPerson($api, $contact_json);
$result = $contact->create();
// echo "\n\n\n\n <h2>CREATE RESPONSE:</h2>";
var_dump($result);
echo "\n\n\n\n <h2>COUNT CONTACTS: ".$contactResource->count()."</h2>";
// echo "\n\n\n\n <h2>ALL CONTACTS:</h2>";
// $res = $contactResource->all();
}
function create_new_sales_invoice($api) {
$salesInvoiceResource = (new SalesInvoice($api));
echo "\n\nSales_Invoice count: " . $salesInvoiceResource->count();
echo "\n\ninsert new Sales_Invoice: ";
$sales_invoice_json = json_decode(file_get_contents("./src/Fixtures/invoice.json"), true);
$sales_invoice = new SalesInvoice($api, $sales_invoice_json);
$result = $sales_invoice->create();
echo "\n\nSales_Invoice count: " . $salesInvoiceResource->count();
}