forked from coopsymbiotic/hosting_restapi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hosting_restapi.site-config.inc
82 lines (67 loc) · 1.87 KB
/
hosting_restapi.site-config.inc
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
<?php
/**
* @file
* Hosting REST API functions, and Drupal hooks.
*/
/**
* Implements the 'site/config' API.
*/
function hosting_restapi_site_config() {
$method = strtolower($_SERVER['REQUEST_METHOD']);
$f = 'hosting_restapi_site_config_' . $method;
try {
if (function_exists($f)) {
$result = $f();
}
else {
$result = array(
'status' => 'error',
'message' => 'Unknown method for site_config: ' . $_SERVER['REQUEST_METHOD'],
);
}
}
catch (Exception $e) {
$result = array(
'status' => 'error',
'message' => $e->getMessage(),
);
}
echo json_encode($result);
// NB: in Drupal7, this becomes only drupal_exit();
module_invoke_all('exit');
exit();
}
/**
* Implements the 'site/config GET' API.
*/
function hosting_restapi_site_config_get() {
$url = $_GET['url'];
$token = $_GET['token'];
if (! $url) {
throw new Exception(t('The "url" parameter was empty.'));
}
if (! $token) {
throw new Exception(t('The "token" parameter was empty.'));
}
$invoice_id = hosting_restapi_get_invoice_id_from_token($url, $token);
if (! $invoice_id) {
throw new Exception(t('Invalid token.'));
}
// TODO:
$settings = array();
$api = hosting_restapi_civicrmapi();
$api->Contribution->Getsingle(array('trxn_id' => $invoice_id));
$api->Contact->Getsingle(array('contact_id' => $api->result->contact_id));
$settings['organization'] = array(
'name' => $api->result->display_name,
'street_address' => $api->result->street_address,
'city' => $api->result->city,
'state_province_id' => $api->result->state_province_id,
'country_id' => $api->result->country_id,
'phone' => $api->result->phone,
'email' => $api->result->email,
);
// TODO: individual information
// must fetch using the relation?
return array('status' => 'success', 'data' => $settings);
}