|
11 | 11 | use DocuSign\eSign\Model\Tabs;
|
12 | 12 | use DocuSign\eSign\Model\Text;
|
13 | 13 | use DocuSign\eSign\Model\TextCustomField;
|
| 14 | +use DocuSign\eSign\Model\Numerical; |
| 15 | +use DocuSign\eSign\Model\LocalePolicyTab; |
14 | 16 |
|
15 | 17 | class SetTabValuesService
|
16 | 18 | {
|
@@ -43,108 +45,132 @@ public static function setTabValues(array $args, $demoDocsPath, $clientService):
|
43 | 45 | * @param $demoDocsPath
|
44 | 46 | * @return mixed -- returns an envelope definition
|
45 | 47 | */
|
46 |
| - public static function make_envelope(array $args, $demoDocsPath): EnvelopeDefinition |
47 |
| - { |
48 |
| - # document 1 (pdf) has tags |
49 |
| - # /sn1/ - signature field |
50 |
| - # /salary/ - yearly salary |
51 |
| - # /legal/ - legal name |
52 |
| - # /familiar/ - person's familiar name |
53 |
| - # |
54 |
| - # The envelope has one recipient. |
55 |
| - # recipient 1 - signer |
56 |
| - # |
57 |
| - # The salary is set both as a readable number in the |
58 |
| - # /salary/ text field, and as a pure number in a |
59 |
| - # custom field ('salary') in the envelope. |
60 |
| - |
61 |
| - # Salary that will be used. |
62 |
| - $salary = 123000; |
63 |
| - |
64 |
| - # Read the file |
65 |
| - $doc_name = 'World_Wide_Corp_salary.docx'; |
66 |
| - $content_bytes = file_get_contents($demoDocsPath . $doc_name); |
67 |
| - $base64_file_content = base64_encode($content_bytes); |
68 |
| - |
69 |
| - # Create the document model |
70 |
| - $document = new Document([ # create the DocuSign document object |
71 |
| - 'document_base64' => $base64_file_content, |
72 |
| - 'name' => 'Salary action', # can be different from actual file name |
73 |
| - 'file_extension' => 'docx', # many different document types are accepted |
74 |
| - 'document_id' => 1 # a label used to reference the doc |
75 |
| - ]); |
76 |
| - |
77 |
| - # Create the signer recipient model |
78 |
| - $signer = new Signer([ # The signer |
79 |
| - 'email' => $args['signer_email'], 'name' => $args['signer_name'], |
80 |
| - 'recipient_id' => "1", 'routing_order' => "1", |
81 |
| - # Setting the client_user_id marks the signer as embedded |
82 |
| - 'client_user_id' => $args['signer_client_id'] |
83 |
| - ]); |
84 |
| - |
85 |
| - # Create a sign_here tab (field on the document) |
86 |
| - $sign_here = new SignHere([ # DocuSign SignHere field/tab |
87 |
| - 'anchor_string' => '/sn1/', 'anchor_units' => 'pixels', |
88 |
| - 'anchor_y_offset' => '10', 'anchor_x_offset' => '20' |
89 |
| - ]); |
90 |
| - |
91 |
| - # Create the legal and familiar text fields. |
92 |
| - # Recipients can update these values if they wish to. |
93 |
| - $text_legal = new Text([ |
94 |
| - 'anchor_string' => '/legal/', 'anchor_units' => 'pixels', |
95 |
| - 'anchor_y_offset' => '-9', 'anchor_x_offset' => '5', |
96 |
| - 'font' => "helvetica", 'font_size' => "size11", |
97 |
| - 'bold' => 'true', 'value' => $args['signer_name'], |
98 |
| - 'locked' => 'false', 'tab_id' => 'legal_name', |
99 |
| - 'tab_label' => 'Legal name']); |
100 |
| - $text_familiar = new Text([ |
101 |
| - 'anchor_string' => '/familiar/', 'anchor_units' => 'pixels', |
102 |
| - 'anchor_y_offset' => '-9', 'anchor_x_offset' => '5', |
103 |
| - 'font' => "helvetica", 'font_size' => "size11", |
104 |
| - 'bold' => 'true', 'value' => $args['signer_name'], |
105 |
| - 'locked' => 'false', 'tab_id' => 'familiar_name', |
106 |
| - 'tab_label' => 'Familiar name']); |
107 |
| - |
108 |
| - # Create the salary field. It should be human readable, so |
109 |
| - # add a comma before the thousands number, a currency indicator, etc. |
110 |
| - $salary_readable = '$' . number_format($salary); |
111 |
| - $text_salary = new Text([ |
112 |
| - 'anchor_string' => '/salary/', 'anchor_units' => 'pixels', |
113 |
| - 'anchor_y_offset' => '-9', 'anchor_x_offset' => '5', |
114 |
| - 'font' => "helvetica", 'font_size' => "size11", |
115 |
| - 'bold' => 'true', 'value' => $salary_readable, |
116 |
| - 'locked' => 'true', # mark the field as readonly |
117 |
| - 'tab_id' => 'salary', 'tab_label' => 'Salary' |
118 |
| - ]); |
119 |
| - |
120 |
| - # Add the tabs model (including the sign_here tab) to the signer |
121 |
| - # The Tabs object wants arrays of the different field/tab types |
122 |
| - $signer->settabs(new Tabs( |
123 |
| - ['sign_here_tabs' => [$sign_here], |
124 |
| - 'text_tabs' => [$text_legal, |
125 |
| - $text_familiar, |
126 |
| - $text_salary]] |
127 |
| - )); |
128 |
| - |
129 |
| - # Create an envelope custom field to save the "real" (numeric) |
130 |
| - # version of the salary |
131 |
| - $salary_custom_field = new TextCustomField([ |
132 |
| - 'name' => 'salary', |
133 |
| - 'required' => 'false', |
134 |
| - 'show' => 'true', # Yes, include in the CoC |
135 |
| - 'value' => $salary]); |
136 |
| - $custom_fields = new CustomFields([ |
137 |
| - 'text_custom_fields' => [$salary_custom_field]]); |
138 |
| - |
139 |
| - # Next, create the top level envelope definition and populate it. |
140 |
| - return new EnvelopeDefinition([ |
141 |
| - 'email_subject' => "Please sign this document sent from the PHP SDK", |
142 |
| - 'documents' => [$document], |
143 |
| - # The Recipients object wants arrays for each recipient type |
144 |
| - 'recipients' => new Recipients(['signers' => [$signer]]), |
145 |
| - 'status' => "sent", # requests that the envelope be created and sent. |
146 |
| - 'custom_fields' => $custom_fields |
147 |
| - ]); |
148 |
| - } |
149 |
| - # ***DS.snippet.0.end |
| 48 | + |
| 49 | + # Step 4 start |
| 50 | +public static function make_envelope(array $args, $demoDocsPath): EnvelopeDefinition |
| 51 | +{ |
| 52 | + # document 1 (pdf) has tags |
| 53 | + # /sn1/ - signature field |
| 54 | + # /salary/ - yearly salary |
| 55 | + # /legal/ - legal name |
| 56 | + # /familiar/ - person's familiar name |
| 57 | + # |
| 58 | + # The envelope has one recipient. |
| 59 | + # recipient 1 - signer |
| 60 | + # |
| 61 | + # The salary is set both as a readable number in the |
| 62 | + # /salary/ text field, and as a pure number in a |
| 63 | + # custom field ('salary') in the envelope. |
| 64 | + |
| 65 | + |
| 66 | + # Read the file |
| 67 | + $doc_name = 'World_Wide_Corp_salary.docx'; |
| 68 | + $content_bytes = file_get_contents($demoDocsPath . $doc_name); |
| 69 | + $base64_file_content = base64_encode($content_bytes); |
| 70 | + |
| 71 | + # Step 3 start |
| 72 | + # Create the document model |
| 73 | + $document = new Document([ # create the DocuSign document object |
| 74 | + 'document_base64' => $base64_file_content, |
| 75 | + 'name' => 'Salary action', # can be different from actual file name |
| 76 | + 'file_extension' => 'docx', # many different document types are accepted |
| 77 | + 'document_id' => 1 # a label used to reference the doc |
| 78 | + ]); |
| 79 | + |
| 80 | + # Create the signer recipient model |
| 81 | + $signer = new Signer([ # The signer |
| 82 | + 'email' => $args['signer_email'], 'name' => $args['signer_name'], |
| 83 | + 'recipient_id' => "1", 'routing_order' => "1", |
| 84 | + # Setting the client_user_id marks the signer as embedded |
| 85 | + 'client_user_id' => $args['signer_client_id'] |
| 86 | + ]); |
| 87 | + |
| 88 | + # Create a sign_here tab (field on the document) |
| 89 | + $sign_here = new SignHere([ # DocuSign SignHere field/tab |
| 90 | + 'anchor_string' => '/sn1/', 'anchor_units' => 'pixels', |
| 91 | + 'anchor_y_offset' => '10', 'anchor_x_offset' => '20' |
| 92 | + ]); |
| 93 | + |
| 94 | + # Create the legal and familiar text fields. |
| 95 | + # Recipients can update these values if they wish to. |
| 96 | + $text_legal = new Text([ |
| 97 | + 'anchor_string' => '/legal/', 'anchor_units' => 'pixels', |
| 98 | + 'anchor_x_offset' => '5', |
| 99 | + 'anchor_y_offset' => '-6', |
| 100 | + 'font' => "helvetica", 'font_size' => "size11", |
| 101 | + 'bold' => 'true', 'value' => $args['signer_name'], |
| 102 | + 'locked' => 'false', 'tab_id' => 'legal_name', |
| 103 | + 'tab_label' => 'Legal name']); |
| 104 | + $text_familiar = new Text([ |
| 105 | + 'anchor_string' => '/familiar/', 'anchor_units' => 'pixels', |
| 106 | + 'anchor_y_offset' => '-6', 'anchor_x_offset' => '5', |
| 107 | + 'font' => "helvetica", 'font_size' => "size11", |
| 108 | + 'bold' => 'true', 'value' => $args['signer_name'], |
| 109 | + 'locked' => 'false', 'tab_id' => 'familiar_name', |
| 110 | + 'tab_label' => 'Familiar name']); |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + # Create the salary field. It should be human readable, so |
| 115 | + # add a comma before the thousands number, a currency indicator, etc. |
| 116 | + $salary = 123000; |
| 117 | + |
| 118 | + $locale_policy_tab = new LocalePolicyTab([ |
| 119 | + "culture_name" => "en-US", |
| 120 | + "currency_code" => "usd", |
| 121 | + "currency_positive_format" => "csym_1_comma_234_comma_567_period_89", |
| 122 | + "currency_negative_format" => "minus_csym_1_comma_234_comma_567_period_89", |
| 123 | + "use_long_currency_format" => "true" |
| 124 | + ]); |
| 125 | + |
| 126 | + $numerical_salary = new Numerical([ |
| 127 | + 'page_number' => '1', |
| 128 | + 'document_id' => '1', |
| 129 | + 'x_position' => '210', |
| 130 | + 'y_position' => '233', |
| 131 | + 'height' => "20", |
| 132 | + 'width' => "70", |
| 133 | + 'min_numerical_value' => "0", |
| 134 | + 'max_numerical_value' => "1000000", |
| 135 | + 'validation_type' => 'Currency', |
| 136 | + 'font' => "helvetica", 'font_size' => "size11", |
| 137 | + 'bold' => 'true', |
| 138 | + 'tab_id' => 'salary', 'tab_label' => 'Salary', |
| 139 | + 'numerical_value' => strval($salary), |
| 140 | + 'locale_policy' => $locale_policy_tab |
| 141 | + ]); |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + # Add the tabs model (including the sign_here tab) to the signer |
| 147 | + # The Tabs object wants arrays of the different field/tab types |
| 148 | + $signer->settabs(new Tabs( |
| 149 | + ['sign_here_tabs' => [$sign_here], |
| 150 | + 'text_tabs' => [$text_legal, $text_familiar], |
| 151 | + 'numerical_tabs'=>[$numerical_salary]] |
| 152 | + )); |
| 153 | + |
| 154 | + # Create an envelope custom field to save the "real" (numeric) |
| 155 | + # version of the salary |
| 156 | + $salary_custom_field = new TextCustomField([ |
| 157 | + 'name' => 'salary', |
| 158 | + 'required' => 'false', |
| 159 | + 'show' => 'true', # Yes, include in the CoC |
| 160 | + 'value' => strval($salary)]); |
| 161 | + $custom_fields = new CustomFields([ |
| 162 | + 'text_custom_fields' => [$salary_custom_field]]); |
| 163 | + |
| 164 | + # Step 3 end |
| 165 | + # Next, create the top level envelope definition and populate it. |
| 166 | + return new EnvelopeDefinition([ |
| 167 | + 'email_subject' => "Please sign this document sent from the PHP SDK", |
| 168 | + 'documents' => [$document], |
| 169 | + # The Recipients object wants arrays for each recipient type |
| 170 | + 'recipients' => new Recipients(['signers' => [$signer]]), |
| 171 | + 'status' => "sent", # requests that the envelope be created and sent. |
| 172 | + 'custom_fields' => $custom_fields |
| 173 | + ]); |
| 174 | +} |
| 175 | +# Step 4 end |
150 | 176 | }
|
0 commit comments