-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.php
66 lines (51 loc) · 1.58 KB
/
create.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
<?php
include('include.php');
try {
$id = get('id', null, 'POST');
$entity = get('entity', null, 'POST');
$fields = get('fields', null, 'POST');
$class = '\Rangka\Quickbooks\Services\\' . ucfirst($entity);
$service = new $class;
$builder = $service->getBuilder();
$all = [];
foreach ($fields as $field=>$value) {
$method = $field;
$exploded = explode('.', $field);
if (count($exploded) > 1) {
$method = $exploded[0];
unset($exploded[0]);
$reversed = array_reverse($exploded);
foreach ($reversed as $now) {
$value = [$now => $value];
}
}
if (is_string($value) && substr($value, 0, 1) == '{') {
$value = json_decode($value, true);
$value = $value['Data'];
}
$all[$method] = isset($all[$method]) ? array_replace_recursive($all[$method], $value) : $value;
}
foreach ($all as $field => $row) {
$method = 'set'.$field;
if ($value === 'true') {
$builder->{$method}(true);
}
else if ($value === 'false') {
$builder->{$method}(false);
}
else {
$builder->{$method}($row);
}
}
$response = $builder->create();
echo json_encode($response);
}
catch (\GuzzleHttp\Exception\ClientException $e) {
echo (string) $e->getResponse()->getBody();
}
catch (\GuzzleHttp\Exception\ServerException $e) {
echo (string) $e->getResponse()->getBody();
}
catch (\Exception $e) {
echo (string) $e->getResponse()->getBody();
}