-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEventCallbackHelper.php
More file actions
77 lines (66 loc) · 1.79 KB
/
EventCallbackHelper.php
File metadata and controls
77 lines (66 loc) · 1.79 KB
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
<?php
/**
* EventCallbackValidate
*
* PHP version 7.4
*
* @category Class
* @see https://openapi-generator.tech
*/
/**
* Dropbox Sign API
*
* Dropbox Sign v3 API
*
* The version of the OpenAPI document: 3.0.0
* Contact: apisupport@hellosign.com
* Generated by: https://openapi-generator.tech
* Generator version: 7.12.0
*/
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
namespace Dropbox\Sign;
/**
* EventCallbackHelper Class Doc Comment
*
* @category Class
* @see 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;
}
}