-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhosting_restapi.site-welcome.inc
84 lines (69 loc) · 1.62 KB
/
hosting_restapi.site-welcome.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
83
84
<?php
/**
* @file
* Hosting REST API functions, and Drupal hooks.
*/
/**
* Implements the 'site/welcome' API.
*/
function hosting_restapi_site_welcome() {
$method = strtolower($_SERVER['REQUEST_METHOD']);
$f = 'hosting_restapi_site_welcome_' . $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);
drupal_exit();
}
/**
* Implements the 'site/welcome POST' API.
*/
function hosting_restapi_site_welcome_post() {
$url = $_POST['url'];
$token = $_POST['token'];
$loginurl = $_POST['loginurl'];
if (!$url) {
throw new Exception(t('The "url" parameter was empty.'));
}
if (!$token) {
throw new Exception(t('The "token" parameter was empty.'));
}
if (!$loginurl) {
throw new Exception(t('The "loginurl" parameter was empty.'));
}
$invoice_id = hosting_restapi_get_invoice_id_from_token($url, $token);
if (!$invoice_id) {
throw new Exception(t('Invalid token.'));
}
$api = hosting_restapi_civicrmapi();
$api->Symbiocivicrm->Welcome([
'invoice_id' => $invoice_id,
'loginurl' => $loginurl,
]);
$settings = $api->result->values;
if ($api->is_error()) {
return [
'status' => 'error',
'invoice_id' => $invoice_id,
'data' => $api->errorMsg(),
];
}
return [
'status' => 'success',
'data' => $settings,
];
}