-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinkdit.php
77 lines (59 loc) · 2.31 KB
/
inkdit.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
70
71
72
73
74
75
76
77
<?php
/*
inkdit_offer_url: constructs a URL that a user can visit to sign an offer
with some prefilled information.
$user_opts is an array that can contain the keys:
redirect
email
first_name
last_name
$inputs is an array that can contains a key for each input field in the
contract.
See https://inkdit.desk.com/customer/portal/articles/685178 for a
description of these options.
inkdit_offer_url($offer_url,
$private_key,
array('email' => '[email protected]', 'redirect' => 'http://example.org/'),
array('contract-input-1' => 'St. Louis'));
*/
function inkdit_offer_url($offer_url, $private_key, $user_opts, $inputs) {
$query_string = inkdit_build_query($user_opts, $inputs);
return _inkdit_offer_url($offer_url, $private_key, $query_string);
}
/*
inkdit_verify_signing: verifies that the result parameters returned in the
redirect are genuine.
$query_string = $_SERVER['QUERY_STRING'];
$result = inkdit_verify_signing($query_string, $private_key);
// ensure that the signing was created recently (PHP 5.3+)
$t = DateTime::createFromFormat(DateTime::ISO8601, $result['signed_at']);
if((time() - $t->getTimeStamp()) > 300)
throw new Exception('This signing was created more than 5 minutes ago!');
*/
function inkdit_verify_signing($query_string, $private_key) {
$pieces = explode('&confirmation=', $query_string, 2);
$data = $pieces[0];
$validation_code = $pieces[1];
if(inkdit_validation_code($private_key, $data) != $validation_code)
return;
parse_str($query_string, $params);
$contract_url = 'https://inkdit.com/c/' . $params['contract_id'];
return array(
'contract_id' => $params['contract_id'],
'contract_url' => $contract_url,
'signed_at' => $params['signed_at']
);
}
function inkdit_validation_code($private_key, $query_string) {
return hash_hmac('sha1', $query_string, $private_key);
}
function _inkdit_offer_url($offer_url, $private_key, $query_string) {
$validation_code = inkdit_validation_code($private_key, $query_string);
return $offer_url . "/" . $validation_code . "?" . $query_string;
}
function inkdit_build_query($user_opts, $inputs) {
$opts = $user_opts;
$opts['inputs'] = $inputs;
return http_build_query($opts, '', '&');
}
?>