|
| 1 | +// <copyright file="SendWithThirdPartyNotary.cs" company="DocuSign"> |
| 2 | +// Copyright (c) DocuSign. All rights reserved. |
| 3 | +// </copyright> |
| 4 | + |
| 5 | +namespace DocuSign.CodeExamples.Examples |
| 6 | +{ |
| 7 | + using System; |
| 8 | + using System.Collections.Generic; |
| 9 | + using System.Text; |
| 10 | + using DocuSign.eSign.Api; |
| 11 | + using DocuSign.eSign.Client; |
| 12 | + using DocuSign.eSign.Model; |
| 13 | + |
| 14 | + public static class SendWithThirdPartyNotary |
| 15 | + { |
| 16 | + public static string SendWithNotary(string signerEmail, string signerName, string accessToken, string basePath, string accountId, string envStatus) |
| 17 | + { |
| 18 | + //ds-snippet-start:Notary4Step2 |
| 19 | + EnvelopeDefinition env = MakeEnvelope(signerEmail, signerName, envStatus); |
| 20 | + var docuSignClient = new DocuSignClient(basePath); |
| 21 | + docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken); |
| 22 | + //ds-snippet-end:Notary4Step2 |
| 23 | + |
| 24 | + //ds-snippet-start:Notary4Step4 |
| 25 | + var envelopesApi = new EnvelopesApi(docuSignClient); |
| 26 | + EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, env); |
| 27 | + return results.EnvelopeId; |
| 28 | + //ds-snippet-end:Notary4Step4 |
| 29 | + } |
| 30 | + |
| 31 | + //ds-snippet-start:Notary4Step3 |
| 32 | + private static EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, string envStatus) |
| 33 | + { |
| 34 | + var env = new EnvelopeDefinition |
| 35 | + { |
| 36 | + EmailSubject = "Please sign this document set", |
| 37 | + }; |
| 38 | + |
| 39 | + env.Documents = GetDocuments(signerEmail, signerName); |
| 40 | + |
| 41 | + var signers = GetSigners(signerEmail, signerName); |
| 42 | + |
| 43 | + var notaryRecipients = GetNotaryRecipients(); |
| 44 | + |
| 45 | + // Add the recipients to the envelope object |
| 46 | + var recipients = new Recipients |
| 47 | + { |
| 48 | + Signers = signers, |
| 49 | + Notaries = notaryRecipients, |
| 50 | + }; |
| 51 | + env.Recipients = recipients; |
| 52 | + |
| 53 | + // Request that the envelope be sent by setting |status| to "sent". |
| 54 | + // To request that the envelope be created as a draft, set to "created" |
| 55 | + env.Status = envStatus; |
| 56 | + |
| 57 | + return env; |
| 58 | + } |
| 59 | + |
| 60 | + private static List<Document> GetDocuments(string signerEmail, string signerName) |
| 61 | + { |
| 62 | + // Create document objects, one per document |
| 63 | + var doc1 = new Document(); |
| 64 | + var b64 = Convert.ToBase64String(GetDocumentExample(signerEmail, signerName)); |
| 65 | + doc1.DocumentBase64 = b64; |
| 66 | + doc1.Name = "Order acknowledgement"; // can be different from actual file name |
| 67 | + doc1.FileExtension = "html"; // Source data format. Signed docs are always pdf. |
| 68 | + doc1.DocumentId = "1"; // a label used to reference the doc |
| 69 | + |
| 70 | + return new List<Document> { doc1 }; |
| 71 | + } |
| 72 | + |
| 73 | + private static byte[] GetDocumentExample(string signerEmail, string signerName) |
| 74 | + { |
| 75 | + return Encoding.UTF8.GetBytes(" <!DOCTYPE html>\n" |
| 76 | + + " <html>\n" |
| 77 | + + " <head>\n" |
| 78 | + + " <meta charset=\"UTF-8\">\n" |
| 79 | + + " </head>\n" |
| 80 | + + " <body style=\"font-family:sans-serif;margin-left:2em;\">\n" |
| 81 | + + " <h1 style=\"font-family: 'Trebuchet MS', Helvetica, sans-serif;\n" |
| 82 | + + " color: darkblue;margin-bottom: 0;\">World Wide Corp</h1>\n" |
| 83 | + + " <h2 style=\"font-family: 'Trebuchet MS', Helvetica, sans-serif;\n" |
| 84 | + + " margin-top: 0px;margin-bottom: 3.5em;font-size: 1em;\n" |
| 85 | + + " color: darkblue;\">Order Processing Division</h2>\n" |
| 86 | + + " <h4>Ordered by " |
| 87 | + + signerName |
| 88 | + + "</h4>\n" |
| 89 | + + " <p style=\"margin-top:0em; margin-bottom:0em;\">Email: " |
| 90 | + + signerEmail |
| 91 | + + "</p>\n" |
| 92 | + + " <p style=\"margin-top:3em;\">\n" |
| 93 | + + " Candy bonbon pastry jujubes lollipop wafer biscuit biscuit. Topping brownie sesame snaps sweet roll pie. Croissant danish biscuit soufflé caramels jujubes jelly. Dragée danish caramels lemon drops dragée. Gummi bears cupcake biscuit tiramisu sugar plum pastry. Dragée gummies applicake pudding liquorice. Donut jujubes oat cake jelly-o. Dessert bear claw chocolate cake gummies lollipop sugar plum ice cream gummies cheesecake.\n" |
| 94 | + + " </p>\n" |
| 95 | + + " <!-- Note the anchor tag for the signature field is in white. -->\n" |
| 96 | + + " <h3 style=\"margin-top:3em;\">Agreed: <span style=\"color:white;\">**signature_1**/</span></h3>\n" |
| 97 | + + " </body>\n" |
| 98 | + + " </html>"); |
| 99 | + } |
| 100 | + |
| 101 | + private static List<Signer> GetSigners(string signerEmail, string signerName) |
| 102 | + { |
| 103 | + // create a signer recipient to sign the document, identified by name and email |
| 104 | + // We're setting the parameters via the object creation |
| 105 | + var signer1 = new Signer |
| 106 | + { |
| 107 | + ClientUserId = "1000", |
| 108 | + Email = signerEmail, |
| 109 | + Name = signerName, |
| 110 | + RecipientId = "2", |
| 111 | + RoutingOrder = "1", |
| 112 | + NotaryId = "1", |
| 113 | + }; |
| 114 | + |
| 115 | + // Create signHere fields (also known as tabs) on the documents, |
| 116 | + // We're using anchor (autoPlace) positioning |
| 117 | + // |
| 118 | + // The DocuSign platform searches throughout your envelope's |
| 119 | + // documents for matching anchor strings. So the |
| 120 | + // signHere2 tab will be used in both document 2 and 3 since they |
| 121 | + // use the same anchor string for their "signer 1" tabs. |
| 122 | + var signHere1 = new SignHere |
| 123 | + { |
| 124 | + DocumentId = "1", |
| 125 | + XPosition = "200", |
| 126 | + YPosition = "235", |
| 127 | + PageNumber = "1", |
| 128 | + }; |
| 129 | + |
| 130 | + var signHere2 = new SignHere |
| 131 | + { |
| 132 | + StampType = "stamp", |
| 133 | + DocumentId = "1", |
| 134 | + XPosition = "200", |
| 135 | + YPosition = "150", |
| 136 | + PageNumber = "1", |
| 137 | + }; |
| 138 | + |
| 139 | + // Tabs are set per recipient |
| 140 | + var signer1Tabs = new Tabs |
| 141 | + { |
| 142 | + SignHereTabs = new List<SignHere> { signHere1, signHere2 }, |
| 143 | + }; |
| 144 | + signer1.Tabs = signer1Tabs; |
| 145 | + |
| 146 | + return new List<Signer> { signer1 }; |
| 147 | + } |
| 148 | + |
| 149 | + private static List<NotaryRecipient> GetNotaryRecipients() |
| 150 | + { |
| 151 | + var notarySealTabs = new NotarySeal |
| 152 | + { |
| 153 | + XPosition = "300", |
| 154 | + YPosition = "235", |
| 155 | + DocumentId = "1", |
| 156 | + PageNumber = "1", |
| 157 | + }; |
| 158 | + |
| 159 | + var notarySignHere = new SignHere |
| 160 | + { |
| 161 | + XPosition = "300", |
| 162 | + YPosition = "150", |
| 163 | + DocumentId = "1", |
| 164 | + PageNumber = "1", |
| 165 | + }; |
| 166 | + |
| 167 | + var notaryTabs = new Tabs |
| 168 | + { |
| 169 | + SignHereTabs = new List<SignHere> { notarySignHere }, |
| 170 | + NotarySealTabs = new List<NotarySeal> { notarySealTabs }, |
| 171 | + }; |
| 172 | + |
| 173 | + var notaryRecipient = new List<NotaryRecipient> |
| 174 | + { |
| 175 | + new NotaryRecipient |
| 176 | + { |
| 177 | + Email = string.Empty, |
| 178 | + Name = "Notary", |
| 179 | + RecipientId = "1", |
| 180 | + RoutingOrder = "1", |
| 181 | + Tabs = notaryTabs, |
| 182 | + NotaryType = "remote", |
| 183 | + NotarySourceType = "thirdparty", |
| 184 | + NotaryThirdPartyPartner = "onenotary", |
| 185 | + RecipientSignatureProviders = new List<RecipientSignatureProvider> |
| 186 | + { |
| 187 | + new RecipientSignatureProvider |
| 188 | + { |
| 189 | + SealDocumentsWithTabsOnly = "false", |
| 190 | + SignatureProviderName = "ds_authority_idv", |
| 191 | + SignatureProviderOptions = new RecipientSignatureProviderOptions(), |
| 192 | + }, |
| 193 | + }, |
| 194 | + }, |
| 195 | + }; |
| 196 | + |
| 197 | + return notaryRecipient; |
| 198 | + } |
| 199 | + |
| 200 | + //ds-snippet-end:Notary4Step3 |
| 201 | + } |
| 202 | +} |
0 commit comments