-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdropbox-EventCallbackHelper.mustache
74 lines (64 loc) · 1.8 KB
/
dropbox-EventCallbackHelper.mustache
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
<?php
/**
* EventCallbackValidate
*
* PHP version {{phpVersion}}
*
* @category Class
* @package {{invokerPackage}}
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
{{>partial_header}}
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
namespace {{invokerPackage}};
/**
* EventCallbackHelper Class Doc Comment
*
* @category Class
{{#description}}
* @description {{.}}
{{/description}}
* @package {{invokerPackage}}
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
abstract class EventCallbackHelper
{
public const EVENT_TYPE_ACCOUNT_CALLBACK = 'account_callback';
public const EVENT_TYPE_APP_CALLBACK = 'app_callback';
/**
* Verify that a callback came from HelloSign.com
*/
public static function isValid(
string $api_key,
Model\EventCallbackRequest $event_callback
): bool {
$event = $event_callback->getEvent();
$hash = hash_hmac(
'sha256',
$event->getEventTime() . $event->getEventType(),
$api_key
);
return $event->getEventHash() === $hash;
}
/**
* Identifies the callback type, one of "account_callback" or
* "app_callback".
*
* "app_callback" will always include a value for "reported_for_app_id"
*/
public static function getCallbackType(
Model\EventCallbackRequest $event_callback
): string {
$meta_data = $event_callback->getEvent()->getEventMetadata();
if (empty($meta_data) || empty($meta_data->getReportedForAppId())) {
return self::EVENT_TYPE_ACCOUNT_CALLBACK;
}
return self::EVENT_TYPE_APP_CALLBACK;
}
}