|
| 1 | +package com.docusign.controller.notary.services; |
| 2 | + |
| 3 | +import com.docusign.common.WorkArguments; |
| 4 | +import com.docusign.controller.eSignature.examples.EnvelopeHelpers; |
| 5 | +import com.docusign.core.common.DocumentType; |
| 6 | +import com.docusign.esign.api.EnvelopesApi; |
| 7 | +import com.docusign.esign.model.*; |
| 8 | +import com.docusign.webforms.client.ApiException; |
| 9 | + |
| 10 | +import java.io.IOException; |
| 11 | +import java.nio.charset.StandardCharsets; |
| 12 | +import java.util.Collections; |
| 13 | + |
| 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 | + |
| 19 | + //ds-snippet-start:Notary4Step4 |
| 20 | + public static String sendWithNotary(String signerEmail, String signerName, String accountId, |
| 21 | + EnvelopesApi envelopesApi, WorkArguments args) |
| 22 | + throws ApiException, com.docusign.esign.client.ApiException, IOException { |
| 23 | + EnvelopeDefinition envelopeDefinition = makeEnvelope(signerEmail, signerName, args); |
| 24 | + |
| 25 | + EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envelopeDefinition); |
| 26 | + return envelopeSummary.getEnvelopeId(); |
| 27 | + } |
| 28 | + //ds-snippet-end:Notary4Step4 |
| 29 | + |
| 30 | + //ds-snippet-start:Notary4Step3 |
| 31 | + private static EnvelopeDefinition makeEnvelope(String signerEmail, String signerName, WorkArguments args) |
| 32 | + throws IOException { |
| 33 | + EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition(); |
| 34 | + envelopeDefinition.setEmailSubject("Please sign this document set"); |
| 35 | + |
| 36 | + envelopeDefinition.setDocuments(getDocuments(signerEmail, signerName, args)); |
| 37 | + |
| 38 | + Recipients recipients = new Recipients(); |
| 39 | + recipients.setSigners(getSigners(signerEmail, signerName)); |
| 40 | + recipients.setNotaries(getNotaryRecipients()); |
| 41 | + |
| 42 | + envelopeDefinition.setRecipients(recipients); |
| 43 | + envelopeDefinition.setStatus("sent"); |
| 44 | + |
| 45 | + return envelopeDefinition; |
| 46 | + } |
| 47 | + |
| 48 | + private static java.util.List<Document> getDocuments(String signerEmail, String signerName, WorkArguments args) |
| 49 | + throws IOException { |
| 50 | + byte[] htmlDoc = EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args) |
| 51 | + .getBytes(StandardCharsets.UTF_8); |
| 52 | + Document document = EnvelopeHelpers.createDocument(htmlDoc, HTML_DOCUMENT_NAME, |
| 53 | + DocumentType.HTML.getDefaultFileExtention(), "1"); |
| 54 | + |
| 55 | + return Collections.singletonList(document); |
| 56 | + } |
| 57 | + |
| 58 | + private static java.util.List<Signer> getSigners(String signerEmail, String signerName) { |
| 59 | + Signer signer = new Signer(); |
| 60 | + signer.setClientUserId("1000"); |
| 61 | + signer.setEmail(signerEmail); |
| 62 | + signer.setName(signerName); |
| 63 | + signer.setRecipientId("2"); |
| 64 | + signer.setRoutingOrder("1"); |
| 65 | + signer.setNotaryId("1"); |
| 66 | + |
| 67 | + SignHere signHere1 = new SignHere(); |
| 68 | + signHere1.setDocumentId("1"); |
| 69 | + signHere1.setXPosition("200"); |
| 70 | + signHere1.setYPosition("235"); |
| 71 | + signHere1.setPageNumber("1"); |
| 72 | + |
| 73 | + SignHere signHere2 = new SignHere(); |
| 74 | + signHere2.setStampType("stamp"); |
| 75 | + signHere2.setDocumentId("1"); |
| 76 | + signHere2.setXPosition("200"); |
| 77 | + signHere2.setYPosition("150"); |
| 78 | + signHere2.setPageNumber("1"); |
| 79 | + |
| 80 | + Tabs signerTabs = new Tabs(); |
| 81 | + signerTabs.setSignHereTabs(java.util.Arrays.asList(signHere1, signHere2)); |
| 82 | + signer.setTabs(signerTabs); |
| 83 | + |
| 84 | + return Collections.singletonList(signer); |
| 85 | + } |
| 86 | + |
| 87 | + private static java.util.List<NotaryRecipient> getNotaryRecipients() { |
| 88 | + NotarySeal notarySealTabs = new NotarySeal(); |
| 89 | + notarySealTabs.setXPosition("300"); |
| 90 | + notarySealTabs.setYPosition("235"); |
| 91 | + notarySealTabs.setDocumentId("1"); |
| 92 | + notarySealTabs.setPageNumber("1"); |
| 93 | + |
| 94 | + SignHere notarySignHere = new SignHere(); |
| 95 | + notarySignHere.setXPosition("300"); |
| 96 | + notarySignHere.setYPosition("150"); |
| 97 | + notarySignHere.setDocumentId("1"); |
| 98 | + notarySignHere.setPageNumber("1"); |
| 99 | + |
| 100 | + Tabs notaryTabs = new Tabs(); |
| 101 | + notaryTabs.setSignHereTabs(Collections.singletonList(notarySignHere)); |
| 102 | + notaryTabs.setNotarySealTabs(Collections.singletonList(notarySealTabs)); |
| 103 | + |
| 104 | + NotaryRecipient notaryRecipient = new NotaryRecipient(); |
| 105 | + notaryRecipient.setName("Notary"); |
| 106 | + notaryRecipient.setRecipientId("1"); |
| 107 | + notaryRecipient.setRoutingOrder("1"); |
| 108 | + notaryRecipient.setTabs(notaryTabs); |
| 109 | + notaryRecipient.setNotaryType("remote"); |
| 110 | + notaryRecipient.setNotarySourceType("thirdparty"); |
| 111 | + notaryRecipient.setNotaryThirdPartyPartner("onenotary"); |
| 112 | + |
| 113 | + RecipientSignatureProvider signatureProvider = new RecipientSignatureProvider(); |
| 114 | + signatureProvider.setSealDocumentsWithTabsOnly("false"); |
| 115 | + signatureProvider.setSignatureProviderName("ds_authority_idv"); |
| 116 | + signatureProvider.setSignatureProviderOptions(new RecipientSignatureProviderOptions()); |
| 117 | + |
| 118 | + notaryRecipient.setRecipientSignatureProviders(Collections.singletonList(signatureProvider)); |
| 119 | + |
| 120 | + return Collections.singletonList(notaryRecipient); |
| 121 | + } |
| 122 | + //ds-snippet-end:Notary4Step3 |
| 123 | +} |
0 commit comments