|
1 | 1 | package com.docusign.controller.notary.services; |
2 | 2 |
|
| 3 | +import com.docusign.common.WorkArguments; |
| 4 | +import com.docusign.controller.eSignature.examples.EnvelopeHelpers; |
| 5 | +import com.docusign.core.common.DocumentType; |
3 | 6 | import com.docusign.esign.api.EnvelopesApi; |
4 | 7 | import com.docusign.esign.model.*; |
5 | 8 | import com.docusign.webforms.client.ApiException; |
| 9 | + |
| 10 | +import java.io.IOException; |
6 | 11 | import java.nio.charset.StandardCharsets; |
7 | 12 | import java.util.Collections; |
8 | 13 |
|
9 | 14 | public final class SendWithThirdPartyNotaryService { |
| 15 | + private static final String HTML_DOCUMENT_FILE_NAME = "order_form.html"; |
| 16 | + |
| 17 | + private static final String HTML_DOCUMENT_NAME = "Order form"; |
| 18 | + |
10 | 19 | public static String sendWithNotary(String signerEmail, String signerName, String accountId, |
11 | | - EnvelopesApi envelopesApi, String envStatus) throws ApiException, com.docusign.esign.client.ApiException { |
12 | | - EnvelopeDefinition env = makeEnvelope(signerEmail, signerName, envStatus); |
| 20 | + EnvelopesApi envelopesApi, WorkArguments args) |
| 21 | + throws ApiException, com.docusign.esign.client.ApiException, IOException { |
| 22 | + EnvelopeDefinition envelopeDefinition = makeEnvelope(signerEmail, signerName, args); |
13 | 23 |
|
14 | | - EnvelopeSummary results = envelopesApi.createEnvelope(accountId, env); |
15 | | - return results.getEnvelopeId(); |
| 24 | + EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envelopeDefinition); |
| 25 | + return envelopeSummary.getEnvelopeId(); |
16 | 26 | } |
17 | 27 |
|
18 | | - private static EnvelopeDefinition makeEnvelope(String signerEmail, String signerName, String envStatus) { |
19 | | - EnvelopeDefinition env = new EnvelopeDefinition(); |
20 | | - env.setEmailSubject("Please sign this document set"); |
| 28 | + private static EnvelopeDefinition makeEnvelope(String signerEmail, String signerName, WorkArguments args) |
| 29 | + throws IOException { |
| 30 | + EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition(); |
| 31 | + envelopeDefinition.setEmailSubject("Please sign this document set"); |
21 | 32 |
|
22 | | - env.setDocuments(getDocuments(signerEmail, signerName)); |
| 33 | + envelopeDefinition.setDocuments(getDocuments(signerEmail, signerName, args)); |
23 | 34 |
|
24 | 35 | Recipients recipients = new Recipients(); |
25 | 36 | recipients.setSigners(getSigners(signerEmail, signerName)); |
26 | 37 | recipients.setNotaries(getNotaryRecipients()); |
27 | 38 |
|
28 | | - env.setRecipients(recipients); |
29 | | - env.setStatus(envStatus); |
| 39 | + envelopeDefinition.setRecipients(recipients); |
| 40 | + envelopeDefinition.setStatus("sent"); |
30 | 41 |
|
31 | | - return env; |
| 42 | + return envelopeDefinition; |
32 | 43 | } |
33 | 44 |
|
34 | | - private static java.util.List<Document> getDocuments(String signerEmail, String signerName) { |
35 | | - Document doc1 = new Document(); |
36 | | - String b64 = java.util.Base64.getEncoder().encodeToString(getDocumentExample(signerEmail, signerName)); |
37 | | - doc1.setDocumentBase64(b64); |
38 | | - doc1.setName("Order acknowledgement"); |
39 | | - doc1.setFileExtension("html"); |
40 | | - doc1.setDocumentId("1"); |
41 | | - |
42 | | - return Collections.singletonList(doc1); |
43 | | - } |
| 45 | + private static java.util.List<Document> getDocuments(String signerEmail, String signerName, WorkArguments args) |
| 46 | + throws IOException { |
| 47 | + byte[] htmlDoc = EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args) |
| 48 | + .getBytes(StandardCharsets.UTF_8); |
| 49 | + Document document = EnvelopeHelpers.createDocument(htmlDoc, HTML_DOCUMENT_NAME, |
| 50 | + DocumentType.HTML.getDefaultFileExtention(), "1"); |
44 | 51 |
|
45 | | - private static byte[] getDocumentExample(String signerEmail, String signerName) { |
46 | | - String document = "<!DOCTYPE html>\n" |
47 | | - + "<html>\n" |
48 | | - + " <head>\n" |
49 | | - + " <meta charset=\"UTF-8\">\n" |
50 | | - + " </head>\n" |
51 | | - + " <body style=\"font-family:sans-serif;margin-left:2em;\">\n" |
52 | | - + " <h1 style=\"font-family: 'Trebuchet MS', Helvetica, sans-serif; color: darkblue;margin-bottom: 0;\">World Wide Corp</h1>\n" |
53 | | - + " <h2 style=\"font-family: 'Trebuchet MS', Helvetica, sans-serif; margin-top: 0px;margin-bottom: 3.5em;font-size: 1em; color: darkblue;\">Order Processing Division</h2>\n" |
54 | | - + " <h4>Ordered by " + signerName + "</h4>\n" |
55 | | - + " <p>Email: " + signerEmail + "</p>\n" |
56 | | - + " <h3>Agreed: <span style=\"color:white;\">**signature_1**/</span></h3>\n" |
57 | | - + " </body>\n" |
58 | | - + "</html>"; |
59 | | - return document.getBytes(StandardCharsets.UTF_8); |
| 52 | + return Collections.singletonList(document); |
60 | 53 | } |
61 | 54 |
|
62 | 55 | private static java.util.List<Signer> getSigners(String signerEmail, String signerName) { |
|
0 commit comments