public ActionResult SendSignatureRequest() { string ds_signer1_name = WebhookLibrary.GetFakeName(); string ds_signer1_email = WebhookLibrary.GetFakeEmail(ds_signer1_name); string ds_cc1_name = WebhookLibrary.GetFakeName(); string ds_cc1_email = WebhookLibrary.GetFakeEmail(ds_cc1_name); string webhook_url = Request.Url.GetLeftPart(UriPartial.Authority) + "/api/Webhook"; if (WebhookLibrary.AccountId == null) { return(Content("[\"ok\" => false, \"html\" => \"<h3>Problem</h3><p>Couldn't login to DocuSign: \"]")); } // The envelope request includes a signer-recipient and their tabs object, // and an eventNotification object which sets the parameters for // webhook notifications to us from the DocuSign platform List <EnvelopeEvent> envelope_events = new List <EnvelopeEvent>(); EnvelopeEvent envelope_event1 = new EnvelopeEvent(); envelope_event1.EnvelopeEventStatusCode = "sent"; envelope_events.Add(envelope_event1); EnvelopeEvent envelope_event3 = new EnvelopeEvent(); envelope_event3.EnvelopeEventStatusCode = "completed"; envelope_events.Add(envelope_event3); EnvelopeEvent envelope_event4 = new EnvelopeEvent(); envelope_event4.EnvelopeEventStatusCode = "declined"; envelope_events.Add(envelope_event4); EnvelopeEvent envelope_event5 = new EnvelopeEvent(); envelope_event5.EnvelopeEventStatusCode = "voided"; envelope_events.Add(envelope_event5); List <RecipientEvent> recipient_events = new List <RecipientEvent>(); RecipientEvent recipient_event2 = new RecipientEvent(); recipient_event2.RecipientEventStatusCode = "Delivered"; recipient_events.Add(recipient_event2); RecipientEvent recipient_event3 = new RecipientEvent(); recipient_event3.RecipientEventStatusCode = "Completed"; recipient_events.Add(recipient_event3); RecipientEvent recipient_event4 = new RecipientEvent(); recipient_event4.RecipientEventStatusCode = "Declined"; recipient_events.Add(recipient_event4); EventNotification event_notification = new EventNotification(); event_notification.Url = webhook_url; event_notification.LoggingEnabled = "true"; event_notification.RequireAcknowledgment = "true"; event_notification.UseSoapInterface = "false"; event_notification.IncludeCertificateWithSoap = "false"; event_notification.SignMessageWithX509Cert = "false"; event_notification.IncludeDocuments = "true"; event_notification.IncludeEnvelopeVoidReason = "true"; event_notification.IncludeTimeZone = "true"; event_notification.IncludeSenderAccountAsCustomField = "false"; event_notification.IncludeDocumentFields = "true"; event_notification.IncludeCertificateOfCompletion = "false"; event_notification.EnvelopeEvents = envelope_events; event_notification.RecipientEvents = recipient_events; Document document = new Document(); document.DocumentId = "1"; document.Name = "NDA.pdf"; //string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Documents\NDA.pdf"); Byte[] bytes = System.IO.File.ReadAllBytes(Server.MapPath("~/Documents/NDA.pdf")); document.DocumentBase64 = Convert.ToBase64String(bytes); SignHere sign_here_tab = new SignHere(); sign_here_tab.AnchorString = "signer1sig"; sign_here_tab.AnchorXOffset = "0"; sign_here_tab.AnchorYOffset = "0"; sign_here_tab.AnchorUnits = "mms"; sign_here_tab.RecipientId = "1"; sign_here_tab.Name = "Please sign here"; sign_here_tab.Optional = "false"; sign_here_tab.ScaleValue = 1; sign_here_tab.TabLabel = "signer1sig"; FullName full_name_tab = new FullName(); full_name_tab.AnchorString = "signer1name"; full_name_tab.AnchorYOffset = "-6"; full_name_tab.FontSize = "Size12"; full_name_tab.RecipientId = "1"; full_name_tab.TabLabel = "Full Name"; full_name_tab.Name = "Full Name"; DocuSign.eSign.Model.Text text_tab = new DocuSign.eSign.Model.Text(); text_tab.AnchorString = "signer1company"; text_tab.AnchorYOffset = "-8"; text_tab.FontSize = "Size12"; text_tab.RecipientId = "1"; text_tab.TabLabel = "Company"; text_tab.Name = "Company"; text_tab.Required = "false"; DateSigned date_signed_tab = new DateSigned(); date_signed_tab.AnchorString = "signer1date"; date_signed_tab.AnchorYOffset = "-6"; date_signed_tab.FontSize = "Size12"; date_signed_tab.RecipientId = "1"; date_signed_tab.Name = "Date Signed"; date_signed_tab.TabLabel = "Company"; DocuSign.eSign.Model.Tabs tabs = new DocuSign.eSign.Model.Tabs(); tabs.SignHereTabs = new List <SignHere>(); tabs.SignHereTabs.Add(sign_here_tab); tabs.FullNameTabs = new List <FullName>(); tabs.FullNameTabs.Add(full_name_tab); tabs.TextTabs = new List <Text>(); tabs.TextTabs.Add(text_tab); tabs.DateSignedTabs = new List <DateSigned>(); tabs.DateSignedTabs.Add(date_signed_tab); Signer signer = new Signer(); signer.Email = ds_signer1_email; signer.Name = ds_signer1_name; signer.RecipientId = "1"; signer.RoutingOrder = "1"; signer.Tabs = tabs; Signer signer2 = new Signer(); signer2.Email = "*****@*****.**"; signer2.Name = "Mario Beko"; signer2.RecipientId = "3"; signer2.RoutingOrder = "1"; CarbonCopy carbon_copy = new CarbonCopy(); carbon_copy.Email = ds_cc1_email; carbon_copy.Name = ds_cc1_name; carbon_copy.RecipientId = "2"; carbon_copy.RoutingOrder = "2"; Recipients recipients = new Recipients(); recipients.Signers = new List <Signer>(); recipients.Signers.Add(signer); recipients.Signers.Add(signer2); recipients.CarbonCopies = new List <CarbonCopy>(); recipients.CarbonCopies.Add(carbon_copy); EnvelopeDefinition envelope_definition = new EnvelopeDefinition(); envelope_definition.EmailSubject = "Please sign the " + "NDA.pdf" + " document.URL:" + webhook_url; envelope_definition.Documents = new List <Document>(); envelope_definition.Documents.Add(document); envelope_definition.Recipients = recipients; envelope_definition.EventNotification = event_notification; envelope_definition.Status = "sent"; EnvelopesApi envelopesApi = new EnvelopesApi(WebhookLibrary.Configuration); EnvelopeSummary envelope_summary = envelopesApi.CreateEnvelope(WebhookLibrary.AccountId, envelope_definition, null); if (envelope_summary == null || envelope_summary.EnvelopeId == null) { return(Content("[\"ok\" => false, html => \"<h3>Problem</h3>\" \"<p>Error calling DocuSign</p>\"]")); } string envelope_id = envelope_summary.EnvelopeId; // Create instructions for reading the email string html = "<h2>Signature request sent!</h2>" + "<p>Envelope ID: " + envelope_id + "</p>" + "<h2>Next steps</h2>" + "<h3>1. Open the Webhook Event Viewer</h3>" + "<p><a href='" + Request.Url.GetLeftPart(UriPartial.Authority) + "/Webhook010/status?envelope_id=" + envelope_id + "'" + " class='btn btn-primary' role='button' target='_blank' style='margin-right:1.5em;'>" + "View Events</a> (A new tab/window will be used.)</p>" + "<h3>2. Respond to the Signature Request</h3>"; string email_access = WebhookLibrary.GetFakeEmailAccess(ds_signer1_email); if (email_access != null) { // A temp account was used for the email html += "<p>Respond to the request via your mobile phone by using the QR code: </p>" + "<p>" + WebhookLibrary.GetFakeEmailAccessQRCode(email_access) + "</p>" + "<p> or via <a target='_blank' href='" + email_access + "'>your web browser.</a></p>"; } else { // A regular email account was used html += "<p>Respond to the request via your mobile phone or other mail tool.</p>" + "<p>The email was sent to " + ds_signer1_name + " <" + ds_signer1_email + "></p>"; } //return Content("['ok' => true,'envelope_id' => "+envelope_id+",'html' => "+ html+",'js' => [['disable_button' => 'sendbtn']]]"); // js is an array of items return(Content(html)); }
public async Task <Boolean> sendRequestSign(string signerName, string signerEmail, string accountId, string returnUrl, string authHeader, Dictionary <string, SymitarVars> symitarVars, string fileName) { List <EnvelopeEvent> envelope_events = new List <EnvelopeEvent>(); EnvelopeEvent envelope_event1 = new EnvelopeEvent(); envelope_event1.EnvelopeEventStatusCode = "sent"; envelope_events.Add(envelope_event1); EnvelopeEvent envelope_event2 = new EnvelopeEvent(); envelope_event2.EnvelopeEventStatusCode = "delivered"; envelope_events.Add(envelope_event2); EnvelopeEvent envelope_event3 = new EnvelopeEvent(); envelope_event3.EnvelopeEventStatusCode = "completed"; List <RecipientEvent> recipient_events = new List <RecipientEvent>(); RecipientEvent recipient_event1 = new RecipientEvent(); recipient_event1.RecipientEventStatusCode = "Sent"; recipient_events.Add(recipient_event1); RecipientEvent recipient_event2 = new RecipientEvent(); recipient_event2.RecipientEventStatusCode = "Delivered"; recipient_events.Add(recipient_event2); RecipientEvent recipient_event3 = new RecipientEvent(); recipient_event3.RecipientEventStatusCode = "Completed"; EventNotification event_notification = new EventNotification(); event_notification.Url = returnUrl; event_notification.LoggingEnabled = "true"; event_notification.RequireAcknowledgment = "true"; event_notification.UseSoapInterface = "false"; event_notification.IncludeCertificateWithSoap = "false"; event_notification.SignMessageWithX509Cert = "false"; event_notification.IncludeDocuments = "true"; event_notification.IncludeEnvelopeVoidReason = "true"; event_notification.IncludeTimeZone = "true"; event_notification.IncludeSenderAccountAsCustomField = "true"; event_notification.IncludeDocumentFields = "true"; event_notification.IncludeCertificateOfCompletion = "true"; event_notification.EnvelopeEvents = envelope_events; event_notification.RecipientEvents = recipient_events; Tabs tabs = new Tabs(); tabs.TextTabs = new List <Text>(); tabs.SignHereTabs = new List <SignHere>(); tabs.DateSignedTabs = new List <DateSigned>(); int index = 1; foreach (KeyValuePair <string, SymitarVars> data in symitarVars) { System.Console.WriteLine(data.Value.FieldLabel); System.Console.WriteLine(data.Value.FieldValue); if (data.Value.FieldType.ToUpper() != "SETTING" && (data.Value.FieldType != "DocuSignField" || (data.Value.FieldType == "DocuSignField" && !String.IsNullOrWhiteSpace(data.Value.FieldValue)))) { switch (data.Value.FieldType) { case "DocuSignField": Text text_tab = new Text(); text_tab.AnchorString = "/*" + data.Value.FieldLabel + "*/"; text_tab.AnchorYOffset = "-8"; text_tab.AnchorXOffset = "0"; text_tab.RecipientId = string.Concat("", index); text_tab.TabLabel = data.Value.FieldLabel; text_tab.Name = data.Value.FieldValue; text_tab.Value = data.Value.FieldValue; // text_tab.Required = data.Value.Required; tabs.TextTabs.Add(text_tab); break; case "SignatureField": SignHere sign_here_tab = new SignHere(); sign_here_tab.AnchorString = "/*" + data.Value.FieldLabel + "*/"; sign_here_tab.AnchorXOffset = "0"; sign_here_tab.AnchorYOffset = "0"; sign_here_tab.Name = ""; sign_here_tab.Optional = data.Value.Required; sign_here_tab.ScaleValue = "1"; sign_here_tab.TabLabel = data.Value.FieldLabel; tabs.SignHereTabs.Add(sign_here_tab); break; case "DateSigned": DateSigned date_signed_tab = new DateSigned(); date_signed_tab.AnchorString = "/*" + data.Value.FieldLabel + "*/"; date_signed_tab.AnchorYOffset = "-6"; date_signed_tab.RecipientId = string.Concat("", index); date_signed_tab.Name = ""; date_signed_tab.TabLabel = data.Value.FieldLabel; // date_signed_tab.Required = data.Value.Required; tabs.DateSignedTabs.Add(date_signed_tab); break; default: break; index++; } } } Signer signer = new Signer(); signer.Email = signerEmail; signer.Name = signerName; signer.RecipientId = "1"; signer.RoutingOrder = "1"; signer.Tabs = tabs; Task <Stream> getS3PDF = S3Data.ReadS3PDF("eSignature/PDFTemplate/" + fileName + ".pdf"); Stream newPdf = await getS3PDF; var bytes = S3Data.ReadByteStream(newPdf); Document document = new Document(); document.DocumentId = "1"; document.Name = fileName; // byte[] buffer = System.IO.File.ReadAllBytes("AUTOPYMT2.pdf"); document.DocumentBase64 = Convert.ToBase64String(bytes); Recipients recipients = new Recipients(); recipients.Signers = new List <Signer>(); recipients.Signers.Add(signer); EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition(); envelopeDefinition.EmailSubject = "Please sign the " + "AUTOPYMT.pdf" + " document"; envelopeDefinition.Documents = new List <Document>(); envelopeDefinition.Documents.Add(document); envelopeDefinition.Recipients = recipients; envelopeDefinition.EventNotification = event_notification; envelopeDefinition.Status = "sent"; ApiClient apiClient = new ApiClient(basePath); apiClient.Configuration.AddDefaultHeader("X-DocuSign-Authentication", authHeader); EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration); EnvelopeSummary envelope_summary = envelopesApi.CreateEnvelope(accountId, envelopeDefinition); if (envelope_summary == null || envelope_summary.EnvelopeId == null) { return(false); } // apiClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken); // EnvelopesApi envelopesApi = new EnvelopesApi(WebhookLibrary.Configuration); // EnvelopeSummary envelope_summary = envelopesApi.CreateEnvelope(WebhookLibrary.AccountId, envelope_definition, null); // string envelope_id = envelope_summary.EnvelopeId; Console.WriteLine(envelope_summary); return(true); }
protected EventNotification getConnectSetup() { EventNotification eventNotification = new EventNotification(); // First define the envelope events eventNotification.EnvelopeEvents = new List <EnvelopeEvent>(); EnvelopeEvent event1 = new EnvelopeEvent(); event1.envelopeEventStatusCode = "Sent"; eventNotification.EnvelopeEvents.Add(event1); EnvelopeEvent event2 = new EnvelopeEvent(); event2.envelopeEventStatusCode = "Completed"; eventNotification.EnvelopeEvents.Add(event2); EnvelopeEvent event3 = new EnvelopeEvent(); event3.envelopeEventStatusCode = "Delivered"; eventNotification.EnvelopeEvents.Add(event3); EnvelopeEvent event4 = new EnvelopeEvent(); event4.envelopeEventStatusCode = "Declined"; eventNotification.EnvelopeEvents.Add(event4); EnvelopeEvent event5 = new EnvelopeEvent(); event5.envelopeEventStatusCode = "Voided"; eventNotification.EnvelopeEvents.Add(event5); // Next define the recipient events eventNotification.RecipientEvents = new List <RecipientEvent>(); RecipientEvent recipEvent1 = new RecipientEvent(); recipEvent1.recipientEventStatusCode = "Sent"; eventNotification.RecipientEvents.Add(recipEvent1); RecipientEvent recipEvent2 = new RecipientEvent(); recipEvent2.recipientEventStatusCode = "Delivered"; eventNotification.RecipientEvents.Add(recipEvent2); RecipientEvent recipEvent3 = new RecipientEvent(); recipEvent3.recipientEventStatusCode = "Completed"; eventNotification.RecipientEvents.Add(recipEvent3); RecipientEvent recipEvent4 = new RecipientEvent(); recipEvent4.recipientEventStatusCode = "Declined"; eventNotification.RecipientEvents.Add(recipEvent4); RecipientEvent recipEvent5 = new RecipientEvent(); recipEvent5.recipientEventStatusCode = "AuthenticationFailed"; eventNotification.RecipientEvents.Add(recipEvent5); RecipientEvent recipEvent6 = new RecipientEvent(); recipEvent6.recipientEventStatusCode = "AutoResponded"; eventNotification.RecipientEvents.Add(recipEvent6); eventNotification.includeDocuments = "true"; eventNotification.includeEnvelopeVoidReason = "true"; eventNotification.includeSenderAccountasCustomField = "true"; eventNotification.includeTimeZoneInformation = "true"; eventNotification.url = ConfigurationManager.AppSettings["ConnectListener"]; return(eventNotification); }