-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanual_test.php
More file actions
277 lines (237 loc) · 8.95 KB
/
Copy pathmanual_test.php
File metadata and controls
277 lines (237 loc) · 8.95 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
/**
* TurboSign PHP SDK - Manual Test Suite
*
* Run: php manual_test.php
*
* Make sure to configure the values below before running.
*/
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use TurboDocx\TurboSign;
use TurboDocx\Config\HttpClientConfig;
use TurboDocx\Types\Recipient;
use TurboDocx\Types\Field;
use TurboDocx\Types\SignatureFieldType;
use TurboDocx\Types\TemplateConfig;
use TurboDocx\Types\FieldPlacement;
use TurboDocx\Types\Requests\CreateSignatureReviewLinkRequest;
use TurboDocx\Types\Requests\SendSignatureRequest;
use TurboDocx\Exceptions\TurboDocxException;
// =============================================
// CONFIGURE THESE VALUES BEFORE RUNNING
// =============================================
const API_KEY = 'TDX-your-api-key-here'; // Replace with your actual TurboDocx API key
const BASE_URL = 'https://api.turbodocx.com'; // Replace with your API URL
const ORG_ID = 'your-organization-uuid-here'; // Replace with your organization UUID
const TEST_PDF_PATH = '/path/to/your/test-document.pdf'; // Replace with path to your test PDF/DOCX
const TEST_EMAIL = 'recipient@example.com'; // Replace with a real email to receive notifications
const FILE_URL = 'https://example.com/sample-document.pdf'; // Replace with publicly accessible PDF URL
// Initialize client
TurboSign::configure(new HttpClientConfig(
apiKey: API_KEY,
orgId: ORG_ID,
baseUrl: BASE_URL,
senderEmail: 'sender@example.com', // Reply-to email for signature requests
senderName: 'Your Company Name' // Sender name shown in emails
));
// =============================================
// TEST FUNCTIONS
// =============================================
/**
* Test 1: Prepare document for review (no emails sent) - using fileLink
*/
function testCreateSignatureReviewLink(): string
{
echo "\n--- Test 1: createSignatureReviewLink (using fileLink) ---\n";
$result = TurboSign::createSignatureReviewLink(
new CreateSignatureReviewLinkRequest(
recipients: [
new Recipient('Signer One', TEST_EMAIL, 1),
],
fields: [
new Field(
type: SignatureFieldType::SIGNATURE,
recipientEmail: TEST_EMAIL,
page: 1,
x: 100,
y: 550,
width: 200,
height: 50
),
new Field(
type: SignatureFieldType::CHECKBOX,
recipientEmail: TEST_EMAIL,
page: 1,
x: 320,
y: 550,
width: 50,
height: 50,
defaultValue: 'true'
),
],
fileLink: FILE_URL,
documentName: 'Review Test Document (fileLink)'
)
);
echo "Result: " . json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
return $result->documentId;
}
/**
* Test 2: Prepare document for signing and send emails
*/
function testSendSignature(): string
{
echo "\n--- Test 2: sendSignature (using file buffer with template fields) ---\n";
$pdfBytes = file_get_contents(TEST_PDF_PATH);
if ($pdfBytes === false) {
throw new \RuntimeException('Failed to read test PDF file');
}
$result = TurboSign::sendSignature(
new SendSignatureRequest(
recipients: [
new Recipient('Test User', TEST_EMAIL, 1),
],
fields: [
// Template-based field using anchor text
new Field(
type: SignatureFieldType::TEXT,
recipientEmail: TEST_EMAIL,
template: new TemplateConfig(
anchor: '{placeholder}',
placement: FieldPlacement::REPLACE,
size: ['width' => 200, 'height' => 80],
offset: ['x' => 0, 'y' => 0],
caseSensitive: true,
useRegex: false
),
defaultValue: 'Sample Text',
isMultiline: true,
required: true
),
// Coordinate-based field (traditional approach)
new Field(
type: SignatureFieldType::LAST_NAME,
recipientEmail: TEST_EMAIL,
page: 1,
x: 100,
y: 650,
width: 200,
height: 50,
defaultValue: 'Doe'
),
],
file: $pdfBytes,
documentName: 'Signing Test Document (Template Fields)',
documentDescription: 'Testing template-based field positioning',
ccEmails: ['cc@example.com']
)
);
echo "Result: " . json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
return $result->documentId;
}
/**
* Test 3: Get document status
*/
function testGetStatus(string $documentId): void
{
echo "\n--- Test 3: getStatus ---\n";
$result = TurboSign::getStatus($documentId);
echo "Result: " . json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
}
/**
* Test 4: Download signed document
*/
function testDownload(string $documentId): void
{
echo "\n--- Test 4: download ---\n";
$result = TurboSign::download($documentId);
echo "Result: PDF received, size: " . strlen($result) . " bytes\n";
// Save to file
$outputPath = './downloaded-document.pdf';
file_put_contents($outputPath, $result);
echo "File saved to: $outputPath\n";
}
/**
* Test 5: Resend signature emails
* @param array<string> $recipientIds
*/
function testResend(string $documentId, array $recipientIds): void
{
echo "\n--- Test 5: resend ---\n";
$result = TurboSign::resend($documentId, $recipientIds);
echo "Result: " . json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
}
/**
* Test 6: Void document
*/
function testVoid(string $documentId): void
{
echo "\n--- Test 6: void ---\n";
$result = TurboSign::void($documentId, 'Testing void functionality');
echo "Result: " . json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
}
/**
* Test 7: Get audit trail
*/
function testGetAuditTrail(string $documentId): void
{
echo "\n--- Test 7: getAuditTrail ---\n";
$result = TurboSign::getAuditTrail($documentId);
echo "Result: " . json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
}
// =============================================
// MAIN TEST RUNNER
// =============================================
function main(): void
{
echo "==============================================\n";
echo "TurboSign PHP SDK - Manual Test Suite\n";
echo "==============================================\n";
// Check if test PDF exists
if (!file_exists(TEST_PDF_PATH)) {
echo "\nError: Test PDF not found at " . TEST_PDF_PATH . "\n";
echo "Please add a test PDF file and update TEST_PDF_PATH.\n";
exit(1);
}
try {
// Uncomment and run tests as needed:
// Test 1: Prepare for Review (uses fileLink, doesn't need PDF file)
// $reviewDocId = testCreateSignatureReviewLink();
// Test 2: Prepare for Signing (creates a new document)
// $signDocId = testSendSignature();
// Test 3: Get Status (replace with actual document ID)
// testGetStatus('document-uuid-here');
// Test 4: Download (replace with actual document ID)
// testDownload('document-uuid-here');
// Test 5: Resend (replace with actual document ID and recipient ID)
// testResend('document-uuid-here', ['recipient-uuid-here']);
// Test 6: Void (do this last as it cancels the document)
// testVoid('document-uuid-here');
// Test 7: Get Audit Trail (replace with actual document ID)
// testGetAuditTrail('document-uuid-here');
echo "\n==============================================\n";
echo "All tests completed successfully!\n";
echo "==============================================\n";
} catch (TurboDocxException $e) {
echo "\n==============================================\n";
echo "TEST FAILED\n";
echo "==============================================\n";
echo "Error: " . $e->getMessage() . "\n";
if ($e->getStatusCode() !== null) {
echo "Status Code: " . $e->getStatusCode() . "\n";
}
if ($e->getErrorCode() !== null) {
echo "Error Code: " . $e->getErrorCode() . "\n";
}
exit(1);
} catch (\Exception $e) {
echo "\n==============================================\n";
echo "TEST FAILED\n";
echo "==============================================\n";
echo "Error: " . $e->getMessage() . "\n";
exit(1);
}
}
// Run the tests
main();