/
CreateDocumentWithTwoOrMoreSignersWithOrderScenario.php
72 lines (59 loc) · 3.09 KB
/
CreateDocumentWithTwoOrMoreSignersWithOrderScenario.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
<?php
namespace Lacuna\Scenarios;
use Lacuna\Signer\Model\DocumentsCreateDocumentRequest;
use Lacuna\Signer\Model\DocumentsCreateDocumentResult;
use Lacuna\Signer\Model\FlowActionsFlowActionCreateModel;
use Lacuna\Signer\Model\FlowActionType;
use Lacuna\Signer\Model\UsersParticipantUserModel;
use Lacuna\Signer\PhpClient\Builders\FileUploadBuilder;
use Lacuna\Signer\PhpClient\Models\UploadModel;
class CreateDocumentWithTwoOrMoreSignersWithOrderScenario extends Scenario
{
/**
* This scenario demonstrates the creation of a document with
* two signers and there's a required order for the signatures.
*/
function run()
{
// 1. The file's bytes must be read by the application and uploaded
$filePath = "resources/sample.pdf";
$fileName = basename($filePath);
$file = fopen($filePath, "r");
$uploadModel = new UploadModel($this->signerClient->uploadFile($fileName, $file, "application/pdf"));
fclose($file);
// 2. Define the name of the document which will be visible in the application
$fileUploadModelBuilder = new FileUploadBuilder($uploadModel);
$fileUploadModelBuilder->setDisplayName("Two Signers With Order Sample");
// 3. For each participant on the flow, create one instance of ParticipantUserModel
$participantUserOne = new UsersParticipantUserModel();
$participantUserOne->setName("Jack Bauer");
$participantUserOne->setEmail("jack.bauer@mailinator.com");
$participantUserOne->setIdentifier("75502846369");
$participantUserTwo = new UsersParticipantUserModel();
$participantUserTwo->setName("James Bond");
$participantUserTwo->setEmail("james.bond@mailinator.com");
$participantUserTwo->setIdentifier("95588148061");
/// 4. Create a FlowActionCreateModel instance for each action (signature or approval) in the flow.
// This object is responsible for defining the personal data of the participant, the type of
// action that he will perform on the flow and the order in which this action will take place
// (Step property)
$flowActionCreateModelOne = new FlowActionsFlowActionCreateModel();
$flowActionCreateModelOne->setType(FlowActionType::SIGNER);
$flowActionCreateModelOne->setUser($participantUserOne);
$flowActionCreateModelOne->setStep(1);
$flowActionCreateModelTwo = new FlowActionsFlowActionCreateModel();
$flowActionCreateModelTwo->setType(FlowActionType::SIGNER);
$flowActionCreateModelTwo->setUser($participantUserTwo);
$flowActionCreateModelOne->setStep(2);
// 5. Send the document create request
$documentRequest = new DocumentsCreateDocumentRequest();
$documentRequest->setFiles(
array($fileUploadModelBuilder->toModel())
);
$documentRequest->setFlowActions(
array($flowActionCreateModelOne, $flowActionCreateModelTwo)
);
$docResult = $this->signerClient->createDocument($documentRequest)[0];
echo "Document " . $docResult->getDocumentId() . " created\n";
}
}