This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
sample2.php
145 lines (119 loc) · 3.18 KB
/
sample2.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use Clicksign\Client;
date_default_timezone_set('America/Bahia');
function setup() {
$client = new Client();
$client->setAccessToken("my_token");
$client->setUrl("https://api.clicksign-demo.com/");
$client->setAccessToken("xababa");
$client->setUrl("http://localhost:3000/api/");
return $client;
}
/**
* List all documents
*/
function all() {
global $client;
$docs = $client->documents->all();
foreach ($docs as $d) {
print "{$d->document->key} - {$d->document->status} - {$d->document->original_name}\n";
}
}
/**
* Find a document by key and print it
*/
function find($key) {
global $client;
$d = $client->documents->find($key);
print "{$d->document->key} - {$d->document->status} - {$d->document->original_name}\n";
}
/**
* Helper function
*/
function new_file() {
$name = "./" . strftime("%Y-%m-%d-%H-%M-%S") . ".txt";
$string = "This is a very important document\n";
file_put_contents($name, $string);
return $name;
}
/**
* Upload a document
*/
function create() {
global $client;
$d = $client->documents->upload(new_file());
return $d->document->key;
}
/**
* Create a signature list for a uploaded document
*/
function create_signature_list($key) {
global $client;
$signers = array(
array("email" => "[email protected]", "act" => 'sign'),
array("email" => "[email protected]", "act" => 'sign'),
array("email" => "[email protected]", "act" => 'witness')
);
$result = $client->documents->createList($key, $signers, "Sign the document", false);
return $key;
}
/**
* Upload a document and create signature list
*/
function create_with_list() {
global $client;
$name = new_file();
$signers = array(
array("email" => "[email protected]", "act" => 'sign'),
array("email" => "[email protected]", "act" => 'sign'),
array("email" => "[email protected]", "act" => 'witness')
);
$options = array("signers" => $signers, "message" => "Please sign this documentationssasss", "skipEmail" => false);
$result = $client->documents->upload($name, $options);
return $result->document->key;
}
/**
* Resend a document
*/
function resend($key)
{
global $client;
$email = "[email protected]";
$message = "Rapotchus";
return $client->documents->resend($key,$email,$message);
}
/**
* Cancel a document
*/
function cancel($key)
{
global $client;
return $client->documents->cancel($key);
}
/**
* Download a document
* Code send by: José Alexandre Monteiro - Webclasses
*/
$file = $client->documents->download($_GET['key']);
$file_array = explode("\n\r", $file, 2);
$header_array = explode("\n", $file_array[0]);
foreach($header_array as $header_value) {
$header_pieces = explode(':', $header_value);
if(count($header_pieces) == 2) {
$headers[$header_pieces[0]] = trim($header_pieces[1]);
}
}
header('Content-type: ' . $headers['Content-Type']);
header('Content-Disposition: ' . $headers['Content-Disposition']);
echo substr($file_array[1], 1);
$client = setup();
all();
$key = "sample_uuid";
find($key);
try {
cancel($key);
} catch (Clicksign\ClicksignException $e) {
var_dump($e);
}
find($key);