public void docusign(string path, string recipientName, string recipientEmail) { try { ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi"); Configuration.Default.ApiClient = apiClient; //Verify Account Details string accountId = loginApi(credential.UserName, credential.Password); // Read a file from disk to use as a document. byte[] fileBytes = System.IO.File.ReadAllBytes(path); EnvelopeDefinition envDef = new EnvelopeDefinition(); envDef.EmailSubject = "Please sign this doc"; // Add a document to the envelope Document doc = new Document(); doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes); doc.Name = Path.GetFileName(path); doc.DocumentId = "1"; envDef.Documents = new List <Document>(); envDef.Documents.Add(doc); // Add a recipient to sign the documeent DocuSign.eSign.Model.Signer signer = new DocuSign.eSign.Model.Signer(); signer.Email = recipientEmail; signer.Name = recipientName; signer.RecipientId = "1"; envDef.Recipients = new DocuSign.eSign.Model.Recipients(); envDef.Recipients.Signers = new List <DocuSign.eSign.Model.Signer>(); envDef.Recipients.Signers.Add(signer); //set envelope status to "sent" to immediately send the signature request envDef.Status = "sent"; // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests) EnvelopesApi envelopesApi = new EnvelopesApi(); EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef); // print the JSON response var result = JsonConvert.SerializeObject(envelopeSummary); if (result != null) { Console.WriteLine("Document sent Successfully!"); } else { Console.WriteLine("Something went wrong!"); } } catch (Exception ex) { } }
private static EnvelopeDefinition CreateEnvelopeDefinition(Doc document, CreateEnvelopeRequestModel request) { return(new EnvelopeDefinition { Documents = new List <Doc> { document }, EmailSubject = request.EnvelopeInfo.Theme, EmailBlurb = request.EnvelopeInfo.MessageBody, Status = EnvelopeStatus.DocuSign.Created, Notification = CreateNotification(request.EnvelopeInfo), Recipients = new Recipients { CarbonCopies = ParseCarbonCopy(request.CarbonRecipients, request.EnvelopeInfo).ToList(), Signers = ParseSigners(request.Recipients, request.EnvelopeInfo).ToList() } }); }
public async Task <ViewUrl> digiSign(IList <TimesheetVm> tempTimesheetVm, User user, User clientUser) { // Embedded Signing Ceremony // 1. Create envelope request obj // 2. Use the SDK to create and send the envelope // 3. Create Envelope Recipient View request obj // 4. Use the SDK to obtain a Recipient View URL // 5. Redirect the user's browser to the URL // 1. Create envelope request object // Start with the different components of the request // Create the document object DocuSign.eSign.Model.Document document = new DocuSign.eSign.Model.Document { DocumentBase64 = Convert.ToBase64String(WriteBytes(tempTimesheetVm, user, clientUser)), Name = user.FirstName + "_" + user.LastName + " Timesheet", FileExtension = "pdf", DocumentId = "1" }; DocuSign.eSign.Model.Document[] documents = new DocuSign.eSign.Model.Document[] { document }; // Create the signer recipient object Signer signer = new Signer { Email = signerEmail, Name = signerName, ClientUserId = DocuSignConstants.SIGNER_CLIENT_ID, RecipientId = "1", RoutingOrder = "1" }; // Create the sign here tab (signing field on the document) SignHere signHereTab = new SignHere { DocumentId = "1", PageNumber = "1", RecipientId = "1", TabLabel = "Sign Here Tab", XPosition = "195", YPosition = "400" }; SignHere[] signHereTabs = new SignHere[] { signHereTab }; // Add the sign here tab array to the signer object. signer.Tabs = new Tabs { SignHereTabs = new List <SignHere>(signHereTabs) }; // Create array of signer objects Signer[] signers = new Signer[] { signer }; // Create recipients object Recipients recipients = new Recipients { Signers = new List <Signer>(signers) }; // Bring the objects together in the EnvelopeDefinition EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition { EmailSubject = "Please sign the document", Documents = new List <DocuSign.eSign.Model.Document>(documents), Recipients = recipients, Status = "sent" }; // 2. Use the SDK to create and send the envelope ApiClient apiClient = new ApiClient(DocuSignConstants.BASE_PATH); apiClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + DocuSignConstants.ACCESS_TOKEN); EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration); EnvelopeSummary results = await envelopesApi.CreateEnvelopeAsync(DocuSignConstants.ACCOUNT_ID, envelopeDefinition); // 3. Create Envelope Recipient View request obj string envelopeId = results.EnvelopeId; RecipientViewRequest viewOptions = new RecipientViewRequest { ReturnUrl = DocuSignConstants.RETURN_URL, ClientUserId = DocuSignConstants.SIGNER_CLIENT_ID, AuthenticationMethod = "none", UserName = signerName, Email = signerEmail }; // 4. Use the SDK to obtain a Recipient View URL ViewUrl viewUrl = await envelopesApi.CreateRecipientViewAsync(DocuSignConstants.ACCOUNT_ID, envelopeId, viewOptions); return(viewUrl); //return Redirect(viewUrl.Url); }
public void docusign(string path, string recipientName, string recipientEmail) { try { ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi"); Configuration.Default.ApiClient = apiClient; //Verify Account Details string accountId = loginApi(credential.UserName, credential.Password); // Read a file from disk to use as a document. byte[] fileBytes = System.IO.File.ReadAllBytes(path); List <EnvelopeEvent> _lstEnvelopeEvents = new List <EnvelopeEvent>(); _lstEnvelopeEvents.Add(new EnvelopeEvent() { EnvelopeEventStatusCode = "sent" }); _lstEnvelopeEvents.Add(new EnvelopeEvent() { EnvelopeEventStatusCode = "delivered" }); _lstEnvelopeEvents.Add(new EnvelopeEvent() { EnvelopeEventStatusCode = "completed" }); _lstEnvelopeEvents.Add(new EnvelopeEvent() { EnvelopeEventStatusCode = "declined" }); _lstEnvelopeEvents.Add(new EnvelopeEvent() { EnvelopeEventStatusCode = "voided" }); List <RecipientEvent> _lstRecipientEvents = new List <RecipientEvent>(); _lstRecipientEvents.Add(new RecipientEvent() { RecipientEventStatusCode = "Sent" }); _lstRecipientEvents.Add(new RecipientEvent() { RecipientEventStatusCode = "Delivered" }); _lstRecipientEvents.Add(new RecipientEvent() { RecipientEventStatusCode = "Completed" }); _lstRecipientEvents.Add(new RecipientEvent() { RecipientEventStatusCode = "Declined" }); _lstRecipientEvents.Add(new RecipientEvent() { RecipientEventStatusCode = "AuthenticationFailed" }); _lstRecipientEvents.Add(new RecipientEvent() { RecipientEventStatusCode = "AutoResponded" }); EventNotification _eventNotification = new EventNotification(); EnvelopeDefinition envDef = new EnvelopeDefinition(); _eventNotification.Url = "https://docusigndemoapp.azurewebsites.net/api/DocusignDemoo/WebhookDocuSignResponse"; _eventNotification.LoggingEnabled = "true"; _eventNotification.RequireAcknowledgment = "true"; _eventNotification.UseSoapInterface = "true"; _eventNotification.IncludeCertificateWithSoap = "false"; _eventNotification.SignMessageWithX509Cert = "false"; _eventNotification.IncludeDocuments = "true"; _eventNotification.IncludeEnvelopeVoidReason = "true"; _eventNotification.IncludeTimeZone = "true"; _eventNotification.IncludeSenderAccountAsCustomField = "true"; _eventNotification.IncludeDocumentFields = "true"; _eventNotification.IncludeCertificateOfCompletion = "true"; _eventNotification.EnvelopeEvents = _lstEnvelopeEvents; _eventNotification.RecipientEvents = _lstRecipientEvents; envDef.EmailSubject = "Please sign this doc"; // Add a document to the envelope Document doc = new Document(); doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes); doc.Name = Path.GetFileName(path); doc.DocumentId = "1"; envDef.Documents = new List <Document>(); envDef.Documents.Add(doc); // Add a recipient to sign the documeent DocuSign.eSign.Model.Signer signer = new DocuSign.eSign.Model.Signer(); signer.Email = recipientEmail; signer.Name = recipientName; signer.RecipientId = "1"; envDef.Recipients = new DocuSign.eSign.Model.Recipients(); envDef.Recipients.Signers = new List <DocuSign.eSign.Model.Signer>(); envDef.Recipients.Signers.Add(signer); envDef.EventNotification = _eventNotification; envDef.PurgeState = "documents_and_metadata_queued"; //set envelope status to "sent" to immediately send the signature request envDef.Status = "sent"; // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests) EnvelopesApi envelopesApi = new EnvelopesApi(); EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef, null); // envelopesApi.Update("", "", new EnvelopesApi.UpdateOptions() { "purgeState": "documents_and_metadata_queued" }); // EnvelopesApi.UpdateOptions obj = new EnvelopesApi.UpdateOptions(); //envelopesApi.DeleteDocuments(accountId, envelopeSummary.EnvelopeId, envDef); if (envelopeSummary != null || envelopeSummary.EnvelopeId == null) { } // print the JSON response var result = JsonConvert.SerializeObject(envelopeSummary); if (result != null) { // Console.WriteLine("Document sent Successfully!"); string successMessage = "Document sent Successfully!"; ViewBag.SucMessage = successMessage; } else { //Console.WriteLine("Something went wrong!"); ViewBag.SucMessage = "Something went wrong!"; } } catch (Exception ex) { } }
public static EnvelopeSummary RequestStudentSignatureFromTemplate(Student student) { // instantiate api client with appropriate environment (for production change to www.docusign.net/restapi) //configureApiClient("https://na2.docusign.net/restapi"); configureApiClient("https://demo.docusign.net/restapi"); // var envID = envDef.EnvelopeId; //AUA --> DME --> ?PRECEPTOR? var envDef = new EnvelopeDefinition { CompositeTemplates = new List <CompositeTemplate>() }; // studentSigner = CreateSigner(student.StudentEmailSchool, student.StudentName, templateRoleName, routingOrder, recipientId); Signer studentSigner = new Signer(); Signer preceptorSigner = new Signer(); Signer DMESigner = new Signer(); Signer signer = new Signer(); Agent agent = new Agent(); CarbonCopy DME_CC = new CarbonCopy(); SetEnvelopeReminders(student, envDef); string formName = ""; //Assign the correct template //Adds all controls to List<Recipients> //Make a list of forms to var formsList = new List <string>(); // if Student formsList.Add("1"); //formsList.Add("2"); //formsList.Add("4"); // if DME/Preceptor //formsList.Add("3"); //formsList.Add("5"); int i = 1; foreach (string form in formsList) { CompositeTemplate ct = new CompositeTemplate { ServerTemplates = new List <ServerTemplate>(), InlineTemplates = new List <InlineTemplate>() }; ServerTemplate st = new ServerTemplate(); //?? InlineTemplate it = new InlineTemplate { Recipients = new Recipients(), Documents = new List <Document>() }; st.Sequence = i.ToString(); ct.ServerTemplates.Add(st); Recipients r = new Recipients(); r.Signers = new List <Signer>(); string documentId = string.Empty; switch (form) { case "1": formName = "Student Clerkship Evaluation Form"; st.TemplateId = StudentClerkshipEvaluationForm; documentId = StudentClerkshipEvaluationDocumentId; envDef.EmailBlurb = "Please complete your Clerkship Evaluation on the last Friday of this rotation."; envDef.EmailSubject = "AUA - Student Clerkship Evaluation Form"; studentSigner = CreateSigner(student.StudentEmailSchool, student.StudentName, "Student", "1", "1"); r.Signers.Add(studentSigner); signer = studentSigner; break; case "2": formName = "Student Faculty Evaluation Form"; st.TemplateId = StudentFacultyEvaluationForm; documentId = ""; envDef.EmailBlurb = "Please complete your Faculty Evaluation on the last Friday of this rotation."; envDef.EmailSubject = "AUA - Student Faculty Evaluation Form"; studentSigner = CreateSigner(student.StudentEmailSchool, student.StudentName, "Student", "1", "1"); r.Signers.Add(studentSigner); signer = studentSigner; break; case "3": formName = "Mid Clerkship Assessment Form"; st.TemplateId = MidClerkshipAssessmentForm; documentId = ""; envDef.EmailBlurb = "Please complete this Mid-Clerkship Assessment Form at the middle of the rotation."; envDef.EmailSubject = "AUA - Mid Clerkship Assessment Form"; //DME FIRST (1) // DMESigner = CreateSigner("*****@*****.**", "Chris Grenard", "DME", "2", "3"); // r.Signers.Add(DMESigner); // CarbonCopy carbonCopy = new CarbonCopy(); DME_CC = CreateCarbonCopy("*****@*****.**", "Chris Grenard", "DME", "2", "3"); if (r.CarbonCopies == null) { r.CarbonCopies = new List <CarbonCopy>(); } r.CarbonCopies.Add(DME_CC); //BEGIN PRECEPTOR CHECK //If we don't know the preceptor then create agent. //AGENT SECOND (2) agent = CreateAgent("*****@*****.**", "Chris G", "DMEAgent", "1", "4"); if (r.Agents == null) { r.Agents = new List <Agent>(); } r.Agents.Add(agent); //else Create a precpetor using their ACTUAL INFO*** //PRECEP (3) preceptorSigner = CreateSigner("", "", "Preceptor", "3", "1"); r.Signers.Add(preceptorSigner); //end if //Student (4) studentSigner = CreateSigner(student.StudentEmailSchool, student.StudentName, "Student", "4", "2"); r.Signers.Add(studentSigner); // Commented out b/c I don't need to prepopulate signer = preceptorSigner; break; case "4": formName = "Student Portfolio Form"; st.TemplateId = StudentPortfolioForm; documentId = ""; envDef.EmailBlurb = "Please complete your Student Portfolio prior to the end of this rotation."; envDef.EmailSubject = "AUA - Student Portfolio"; studentSigner = CreateSigner(student.StudentEmailSchool, student.StudentName, "Student", "1", "1"); r.Signers.Add(studentSigner); signer = studentSigner; break; case "5": formName = "Comprehensive Student Clerkship Assessment Form"; st.TemplateId = ComprehensiveStudentClerkshipAssessmentForm; documentId = ""; envDef.EmailBlurb = "Please complete this Comprehensive Clerkship Assessment Form for each respective student."; envDef.EmailSubject = "AUA - Comprehensive Student Clerkship Assessment Form"; preceptorSigner = CreateSigner("*****@*****.**", "Dr. Gometi", "Preceptor", "1", "2"); DMESigner = CreateSigner("*****@*****.**", "Janes Rice, PHd.", "DME", "2", "3"); r.Signers.Add(preceptorSigner); r.Signers.Add(DMESigner); signer = preceptorSigner; break; default: break; } it.Recipients = r; //might need to change it.Sequence = i.ToString(); Document doc = new Document { Name = formName, DocumentBase64 = CreatePersonalizedForm(student, Convert.ToInt32(form)), DocumentId = documentId }; //why #2? it.Documents.Add(doc); ct.InlineTemplates.Add(it); envDef.CompositeTemplates.Add(ct); #region FormTabs /* * The font type used for the information in the tab. Possible values are: * Arial, ArialNarrow, Calibri, CourierNew, Garamond, Georgia, Helvetica, LucidaConsole, Tahoma, TimesNewRoman, Trebuchet, and Verdana. * * The font size used for the information in the tab. * Possible values are: Size7, Size8, Size9, Size10, Size11, Size12, Size14, Size16, Size18, Size20, Size22, Size24, Size26, Size28, Size36, Size48, or Size72. * * The font color used for the information in the tab. Possible values are: Black, BrightBlue, BrightRed, DarkGreen, DarkRed, Gold, Green, NavyBlue, Purple, or White. */ //Create a List<> for Checkboxes and add them to the collection //REFACTOR SOMEDAY INTO NEW METHOD SO WE CAN DYNAMICALLY ASSIGN TABS PER ROLE TYPE... signer.Tabs.CheckboxTabs = new List <Checkbox>(); string core = "false"; string elective = "false"; string rotationType = ""; rotationType = student.ClinicalRotation; // rotationType = rotationType.ToUpper(); if (rotationType.ToUpper().Contains("CORE")) { core = "true"; } else { elective = "true"; } Checkbox chkCore = new Checkbox { TabLabel = "chkCore", Selected = core }; signer.Tabs.CheckboxTabs.Add(chkCore); Checkbox chkElective = new Checkbox { TabLabel = "chkElective", Selected = elective }; signer.Tabs.CheckboxTabs.Add(chkElective); Text StudentName = new Text { TabLabel = "StudentName", Value = student.StudentFirstName + " " + student.StudentLastName }; signer.Tabs.TextTabs.Add(StudentName); Text CourseId = new Text { TabLabel = "CourseId", Value = student.CourseId, FontColor = "White" }; signer.Tabs.TextTabs.Add(CourseId); Text ClinicalRotationName = new Text { TabLabel = "ClinicalRotationName", Value = student.ClinicalRotation }; signer.Tabs.TextTabs.Add(ClinicalRotationName); Text ClinicalRotationSite = new Text { TabLabel = "ClinicalRotationSite", Value = student.ClinicalSite }; signer.Tabs.TextTabs.Add(ClinicalRotationSite); Text StartDate = new Text { TabLabel = "StartDate", Value = student.StartDate }; signer.Tabs.TextTabs.Add(StartDate); Text EndDate = new Text { TabLabel = "EndDate", Value = student.EndDate }; signer.Tabs.TextTabs.Add(EndDate); Text txtStudentID = new Text { TabLabel = "txtStudentID", Value = student.StudentId }; signer.Tabs.TextTabs.Add(txtStudentID); #endregion FormTabs i++; } //Setting Status to sent sends the email envDef.Status = "sent"; // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests) EnvelopesApi envelopesApi = new EnvelopesApi(); EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(ConfigurationManager.AppSettings["accountId"], envDef); // print the JSON response Console.WriteLine("EnvelopeSummary:\n{0}", JsonConvert.SerializeObject(envelopeSummary)); //write a log file method or store to DB to show file was sent return(envelopeSummary); }
public IActionResult RequestSignature(string id) { var doc = _FileDocumentService.Get(new Guid(id)); var owner = _PersonnelService.Get(doc.PERSONNEL_OWNER); string Username = "******"; string Password = "******"; string IntegrationKey = "a9d661a1-c751-40fa-9fc5-4b1a5865b08b"; string filepath = Path.Combine(_HostingEnvironment.WebRootPath, "Templates\\" + doc.PDF_FILENAME); string basePath = "https://demo.docusign.net/restapi"; ApiClient apiClient = new ApiClient(basePath); Configuration.Default.ApiClient = apiClient; string authHeader = "{\"Username\":\"" + Username + "\", \"Password\":\"" + Password + "\", \"IntegratorKey\":\"" + IntegrationKey + "\"}"; Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader); AuthenticationApi authApi = new AuthenticationApi(); LoginInformation loginInfo = authApi.Login(); string accountID = loginInfo.LoginAccounts[0].AccountId; MemoryStream ms = new MemoryStream(); PDFStampTemplates.Stamp(filepath, ms, owner); byte[] fileBytes = ms.ToArray(); ms.Dispose(); EnvelopeDefinition enDef = new EnvelopeDefinition(); enDef.EmailSubject = "[C# DocuSign Sig Request]"; DocuSign.eSign.Model.Document document = new DocuSign.eSign.Model.Document(); document.DocumentBase64 = Convert.ToBase64String(fileBytes); document.Name = doc.DOCUMENT_NAME; document.DocumentId = "1"; enDef.Documents = new List <DocuSign.eSign.Model.Document>(); enDef.Documents.Add(document); Signer signer = new Signer(); signer.Email = "*****@*****.**"; signer.Name = "Mitchell"; signer.RecipientId = "1"; signer.ClientUserId = owner.PERSONNEL_ID.ToString(); signer.Tabs = new Tabs(); signer.Tabs.SignHereTabs = new List <SignHere>(); SignHere signHere = new SignHere(); signHere.DocumentId = "1"; signHere.PageNumber = "1"; signHere.RecipientId = "1"; signHere.XPosition = "300"; signHere.YPosition = "170"; signer.Tabs.SignHereTabs.Add(signHere); enDef.Recipients = new Recipients(); enDef.Recipients.Signers = new List <Signer>(); enDef.Recipients.Signers.Add(signer); enDef.Status = "sent"; EnvelopesApi envelopesApi = new EnvelopesApi(); EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountID, enDef); RecipientViewRequest viewOptions = new RecipientViewRequest() { ReturnUrl = "https://localhost:44372/api/Signed/?id=" + doc.FILLED_DOCUMENT_GUID, ClientUserId = doc.PERSONNEL_OWNER.ToString(), AuthenticationMethod = "email", UserName = enDef.Recipients.Signers[0].Name, Email = enDef.Recipients.Signers[0].Email }; ViewUrl recipientView = envelopesApi.CreateRecipientView(accountID, envelopeSummary.EnvelopeId, viewOptions); Console.WriteLine("ViewUrl:\n{0}", JsonConvert.SerializeObject(recipientView)); //System.Diagnostics.Process.Start(recipientView.Url); return(Redirect(recipientView.Url)); }