-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook.php
69 lines (60 loc) · 2.09 KB
/
webhook.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
<?php
require_once('vendor/autoload.php');
$everyaction_username = ''; // Use an EveryAction Mobilize API key
$everyaction_password = ''; // Should end with |1 or |0
// Create Guzzle HTTP client for EveryAction API
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://api.securevan.com',
'timeout' => 2.0,
]);
// Get the input data from Action Network
$orig = file_get_contents('php://input');
$input = json_decode($orig, true);
if (in_array('osdi:signature',$input[0])) {
$input = $input[0]['osdi:signature'];
}
elseif (in_array('osdi:attendance',$input[0])) {
$input = $input[0]['osdi:attendance'];
}
// Compile data needed for EveryAction API call from Action Network data
$data = new stdClass();
$data->firstName = $input['person']['given_name'];
$data->lastName = $input['person']['family_name'];
// Cycle through Action Network email addresses
foreach ($input['person']['email_addresses'] as $email) {
$emailInput = new stdClass();
$emailInput->email = $email['address'];
$emailInput->type = 'P';
if ($email['primary']) {
$emailInput->isPreferred = true;
}
else {
$emailInput->isPreferred = false;
}
if ((isset($email['status']) && $email['status'] == 'subscribed') || !isset($email['status'])) {
$emailInput->subscriptionStatus = 'S';
}
else {
$emailInput->subscriptionStatus = 'N';
}
$data->emails[] = $emailInput;
}
// Cycle through Action Network postal addresses
foreach ($input['person']['postal_addresses'] as $address) {
$addressInput = new stdClass();
if (isset($address['postal_code'])) $addressInput->zipOrPostalCode = $address['postal_code'];
if (isset($address['country'])) $addressInput->countryCode = $address['country'];
if ($address['primary']) {
$addressInput->isPreferred = true;
}
else {
$addressInput->isPreferred = false;
}
$data->addresses[] = $addressInput;
}
// EveryAction API call
$response = $client->request('POST', '/v4/people/findOrCreate', [
'json' => $data,
'auth' => [$everyaction_username, $everyaction_password],
]);