@@ -22,43 +22,59 @@ class DocumentGenerationService
22
22
{
23
23
public static function worker (array $ args , $ clientService , $ documentPath ): string
24
24
{
25
+
26
+ // Step 2a start
25
27
$ templatesApi = $ clientService ->getTemplatesApi ();
26
28
27
29
$ envelopeTemplate = DocumentGenerationService::makeTemplate ();
28
30
$ templatesListResponse = $ templatesApi ->createTemplate ($ args ['account_id ' ], $ envelopeTemplate );
29
31
$ templateId = $ templatesListResponse ['template_id ' ];
32
+ // Step 2a end
30
33
34
+ // Step 3a start
31
35
$ templatesApi ->updateDocument ($ args ['account_id ' ], "1 " , $ templateId , self ::addDocumentTemplate ($ documentPath ));
36
+ // Step 3a end
37
+
38
+ // Step 4a start
32
39
$ templatesApi ->createTabs ($ args ['account_id ' ], "1 " , $ templateId , self ::prepareTabs ());
40
+ // Step 4a end
33
41
42
+ // Step 5a start
34
43
$ envelopeApi = $ clientService ->getEnvelopeApi ();
35
44
$ envelopeResponse = $ envelopeApi ->createEnvelope (
36
45
$ args ['account_id ' ],
37
46
DocumentGenerationService::makeEnvelope ($ args ["form_data " ], $ templateId )
38
47
);
39
48
$ envelopeId = $ envelopeResponse ["envelope_id " ];
49
+ // Step 5a end
40
50
51
+ // Step 6 start
41
52
$ documents = $ envelopeApi ->getEnvelopeDocGenFormFields ($ args ['account_id ' ], $ envelopeId );
42
53
$ documentId = $ documents ["doc_gen_form_fields " ][0 ]["document_id " ];
43
-
54
+ // Step 6 end
55
+
56
+ // Step 7a start
44
57
$ formFields = DocumentGenerationService::formFields ($ args ["form_data " ], $ documentId );
45
58
$ envelopeApi ->updateEnvelopeDocGenFormFields (
46
59
$ args ['account_id ' ],
47
60
$ envelopeId ,
48
61
$ formFields
49
62
);
63
+ // Step 7a end
50
64
65
+ // Step 8 start
51
66
$ envelopeResponse = $ envelopeApi ->update (
52
67
$ args ['account_id ' ],
53
68
$ envelopeId ,
54
69
new Envelope ([
55
70
'status ' => 'sent '
56
71
])
57
72
);
73
+ // Step 8 end
58
74
59
75
return $ envelopeResponse ->getEnvelopeId ();
60
76
}
61
-
77
+ // Step 2b start
62
78
public static function makeTemplate (): EnvelopeTemplate
63
79
{
64
80
$ signer = new Signer ([
@@ -80,7 +96,10 @@ public static function makeTemplate(): EnvelopeTemplate
80
96
]
81
97
);
82
98
}
99
+ // Step 2b end
83
100
101
+
102
+ // Step 4b start
84
103
public static function prepareTabs (): TemplateTabs
85
104
{
86
105
$ signHere = new SignHere ([
@@ -102,7 +121,9 @@ public static function prepareTabs(): TemplateTabs
102
121
'date_signed_tabs ' => [$ dateSigned ],
103
122
]);
104
123
}
124
+ // Step4b end
105
125
126
+ // Step 3b start
106
127
public static function addDocumentTemplate (string $ documentPath ): EnvelopeDefinition
107
128
{
108
129
$ documentFile = $ GLOBALS ['DS_CONFIG ' ]['offer_doc_docx ' ];
@@ -122,7 +143,9 @@ public static function addDocumentTemplate(string $documentPath): EnvelopeDefini
122
143
'documents ' => [$ document ],
123
144
]);
124
145
}
125
-
146
+ // Step 3b end
147
+
148
+ // Step 5b start
126
149
public static function makeEnvelope (array $ args , $ templateId ): EnvelopeDefinition
127
150
{
128
151
$ signer = new TemplateRole ([
@@ -139,7 +162,8 @@ public static function makeEnvelope(array $args, $templateId): EnvelopeDefinitio
139
162
]
140
163
);
141
164
}
142
-
165
+ // Step 5b end
166
+ // Step 7b start
143
167
public static function formFields (array $ args , $ documentId ): DocGenFormFieldRequest
144
168
{
145
169
return new DocGenFormFieldRequest (
@@ -174,4 +198,5 @@ public static function formFields(array $args, $documentId): DocGenFormFieldRequ
174
198
]
175
199
);
176
200
}
201
+ // Step 7b end
177
202
}
0 commit comments