public void DocuSign_CreateAndSedEnvelope() { //arrange //Create the recipient Recipient recipient = new Recipient(); recipient.emailField = string.Empty; recipient.userNameField = string.Empty; recipient.typeField = RecipientTypeCode.Signer; recipient.idField = "1"; recipient.routingOrderField = 1; //Attach the document(s) Document doc = new Document(); doc.idField = "1"; doc.nameField = "test.pdf"; doc.pDFBytesField = new byte[1024]; //Create the envelope content Envelope envelope = new Envelope(); envelope.subjectField = "DocuSign Ask for sign"; envelope.emailBlurbField = "Sign the document"; envelope.recipientsField = new Recipient[] { recipient }; envelope.accountIdField = string.Empty; //Guid envelope.documentsField = new Document[1]; envelope.documentsField[0] = doc; //act EnvelopeStatus envStatus = _docuSignSvc.CreateAndSendEnvelope(_credential, envelope); //assert Assert.AreEqual(envStatus.statusField, EnvelopeStatusCode.Sent); }
/// <summary> /// This method Creates the Envelope and sends the envelope /// </summary> /// <param name="identity"></param> /// <param name="password"></param> /// <param name="subject"></param> /// <param name="emailBlurb"></param> /// <param name="file"></param> /// <param name="fileName"></param> /// <param name="recipients"></param> /// <returns></returns> public static string CreateEnvelope(Account identity, string password, string subject, string emailBlurb, byte[] file, string fileName, List <Recipient> recipients) { DocuSignAPI.APIService.Envelope envelope = new DocuSignAPI.APIService.Envelope(); envelope.AccountId = identity.AccountID; envelope.Subject = subject; envelope.EmailBlurb = emailBlurb; //Populating Recipient Information envelope.Recipients = recipients.ToArray(); //Populating Document information List <Document> documents = new List <Document>(); Document document = new Document(); document.Name = fileName; document.PDFBytes = file; document.ID = "1"; documents.Add(document); envelope.Documents = documents.ToArray(); APIServiceSoap apiService = CreateApiProxy(identity, password); EnvelopeStatus envStatus = apiService.CreateAndSendEnvelope(envelope); return(envStatus.EnvelopeID); }
public void EnvelopesAre( [Default("NULL")] string Note, Guid Id, [SelectionList("channels")][Default("stub://one")] Uri Destination, [Default("NULL")] DateTime?ExecutionTime, [Default("TODAY+1")] DateTime DeliverBy, [SelectionList("status")] EnvelopeStatus Status, [SelectionList("owners")] string Owner) { var ownerId = _owners[Owner]; var envelope = new Envelope { Id = Id, ExecutionTime = ExecutionTime, Status = Status, OwnerId = ownerId, DeliverBy = DeliverBy, Destination = Destination, Message = new Message1() }; var writer = _serializers.JsonWriterFor(envelope.Message.GetType()); envelope.Data = writer.Write(envelope.Message); envelope.ContentType = writer.ContentType; _envelopes.Add(envelope); }
public static void Main() { var authString = $"<DocuSignCredentials><Username>{_userName}</Username><Password>{_password}</Password><IntegratorKey>{_apiKey}</IntegratorKey></DocuSignCredentials>"; var client = new DSAPIServiceSoapClient(); using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) { HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty(); httpRequestProperty.Headers.Add("X-DocuSign-Authentication", authString); OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty; EnvelopeStatus status = client.RequestStatusEx(_envelopeId); Console.WriteLine($"Envelope ID: {_envelopeId}"); Console.WriteLine("Subject: " + status.Subject); // RequestEnvelope Method //var envelope = client.RequestEnvelope(_envelopeId, false); // RequestEnvelopeV2 Method var requestOptions = new RequestEnvelopeV2Options() { IncludeAC = false, IncludeAnchorTabLocations = true, IncludeDocumentBytes = false }; var envelopeV2 = client.RequestEnvelopeV2(_envelopeId, requestOptions); if (envelopeV2.Recipients != null && envelopeV2.Recipients.Any()) { var index = 1; Console.WriteLine($"{Environment.NewLine}Recipients:{Environment.NewLine}"); foreach (var rec in envelopeV2.Recipients) { Console.WriteLine($"{index++}. {rec.UserName} <{rec.Email}>"); } } if (envelopeV2.Tabs != null && envelopeV2.Tabs.Any()) { var index = 1; Console.WriteLine($"{Environment.NewLine}Tab data:{Environment.NewLine}"); foreach (var tab in envelopeV2.Tabs) { var recipient = envelopeV2.Recipients.FirstOrDefault(r => r.ID == tab.RecipientID); Console.WriteLine($"{index++}: ({recipient?.RoleName ?? "[no role]"}/{recipient?.UserName}) {tab.TabLabel}: {tab.Value}"); } } else { Console.WriteLine($"{Environment.NewLine}No tab data found."); } Console.WriteLine($"{Environment.NewLine}Done."); Console.ReadKey(); } }
protected void SignSecond(EnvelopeStatus status) { buttonTable.Visible = false; // Create the assertion using the current time, password and demo information var assertion = new RequestRecipientTokenAuthenticationAssertion { AssertionID = new Guid().ToString(), AuthenticationInstant = DateTime.Now, AuthenticationMethod = RequestRecipientTokenAuthenticationAssertionAuthenticationMethod.Password, SecurityDomain = "DocuSignSample" }; var recipient = status.RecipientStatuses[1]; // Construct the URLs to which the iframe will redirect upon every event // TODO: replace urlBase with your own test url var urlBase = Request.Url.AbsoluteUri.Replace("EmbedDocuSign.aspx", "pop.html") + "?source=embed"; var urls = new RequestRecipientTokenClientURLs { OnSigningComplete = urlBase + "&event=SignComplete2", OnViewingComplete = urlBase + "&event=ViewComplete2", OnCancel = urlBase + "&event=Cancel2", OnDecline = urlBase + "&event=Decline2", OnSessionTimeout = urlBase + "&event=Timeout2", OnTTLExpired = urlBase + "&event=TTLExpired2", OnIdCheckFailed = urlBase + "&event=IDCheck2", OnAccessCodeFailed = urlBase + "&event=AccessCode2", OnException = urlBase + "&event=Exception2" }; var client = CreateAPIProxy(); String token = null; try { // Request the token for a specific recipient token = client.RequestRecipientToken(status.EnvelopeID, recipient.ClientUserId, recipient.UserName, recipient.Email, assertion, urls); } catch (Exception ex) { GoToErrorPage(ex.Message); } // Set the signer message signerMessage = "The first signer has completed the Envelope. Now the second signer will be asked to fill out details in the Envelope."; messagediv.Visible = true; // Set the source of the iframe to the token hostiframe.Visible = true; hostiframe.Attributes[Keys.Source] = token; }
protected void CreateAndSend() { buttonTable.Visible = false; // Construct the envelope basics var envelope = new Envelope { Subject = "DocuSign API SDK Example", EmailBlurb = "This envelope demonstrates embedded signing", AccountId = Session[Keys.ApiAccountId].ToString(), Recipients = ConstructRecipients() }; // Create the recipient(s) // Add the document to the envelope var stockDocument = new Document { PDFBytes = Resources.DocuSign_Demo__111_PDF, Name = "Demo Document", ID = "1", FileExtension = "pdf" }; envelope.Documents = new Document[] { stockDocument }; // Add the tabs to the envelope envelope.Tabs = AddTabs(envelope.Recipients.Length); APIServiceSoapClient client = CreateAPIProxy(); try { // Send the envelope and temporarily store the status in the session EnvelopeStatus status = client.CreateAndSendEnvelope(envelope); if (status.SentSpecified) { Session[Keys.EnvelopeStatus] = status; AddEnvelopeID(status.EnvelopeID); // Start the first signer SignFirst(status); } } catch (Exception ex) { GoToErrorPage(ex.Message); } }
/// <summary> /// This method creates an envelope and returns the url which could be embedded and used for the user signing process /// </summary> /// <param name="identity"></param> /// <param name="password"></param> /// <param name="subject"></param> /// <param name="emailBlurb"></param> /// <param name="file"></param> /// <param name="fileName"></param> /// <param name="recipients"></param> /// <param name="url"></param> /// <returns></returns> public static string CreateEmbedded(Account identity, string password, string subject, string emailBlurb, byte[] file, string fileName, List <Recipient> recipients, string url) { DocuSignAPI.APIService.Envelope envelope = new DocuSignAPI.APIService.Envelope(); envelope.AccountId = identity.AccountID; envelope.Subject = subject; envelope.EmailBlurb = emailBlurb; //Populating Recipient Information envelope.Recipients = recipients.ToArray(); //Populating Document information List <Document> documents = new List <Document>(); Document document = new Document(); document.Name = fileName; document.PDFBytes = file; document.ID = "1"; documents.Add(document); envelope.Documents = documents.ToArray(); APIServiceSoap apiService = CreateApiProxy(identity, password); EnvelopeStatus envStatus = apiService.CreateAndSendEnvelope(envelope); RequestRecipientTokenAuthenticationAssertion assert = new RequestRecipientTokenAuthenticationAssertion(); assert.AssertionID = System.DateTime.Now.Ticks.ToString(); assert.AuthenticationInstant = System.DateTime.Now; assert.AuthenticationMethod = RequestRecipientTokenAuthenticationAssertionAuthenticationMethod.Password; assert.SecurityDomain = "TODO-replace-with-your-app-name"; string retUrl = url.ToLower(); RequestRecipientTokenClientURLs clientURLs = new RequestRecipientTokenClientURLs(); clientURLs.OnSigningComplete = retUrl + "&event=SignComplete&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnAccessCodeFailed = retUrl + "&event=AccessCode&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnCancel = retUrl + "&event=Cancel&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnDecline = retUrl + "&event=Decline&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnException = retUrl + "&event=Exception&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnIdCheckFailed = retUrl + "&event=IDCheck&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnSessionTimeout = retUrl + "&event=Timeout&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnTTLExpired = retUrl + "&event=TTLExpired&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnViewingComplete = retUrl + "&event=ViewComplete&envelopeID=" + envStatus.EnvelopeID; string token = apiService.RequestRecipientToken(envStatus.EnvelopeID, recipients[0].CaptiveInfo.ClientUserId, recipients[0].UserName, recipients[0].Email, assert, clientURLs); return(token); }
protected void Page_Load(object sender, EventArgs e) { if (!LoggedIn()) { Response.Redirect("LogIn.aspx"); } if (!Page.IsPostBack && Request.Form["__EVENTTARGET"] != logoutCtrlName) { // Check to see if we're coming back after signing as the first signer EnvelopeStatus status = (EnvelopeStatus)Session[Keys.EnvelopeStatus]; if (null == status || null == Request[Keys.Event]) { hostiframe.Visible = false; } // If we are, start the second signer else if (Request[Keys.Event].ToString() == "SignComplete1" && status.RecipientStatuses.Length > 1) { SignSecond(status); } // If we're finished altogether, or if one of the signers exited without completed, go to the status page else if ((Request[Keys.Event].ToString() == "SignComplete1" && status.RecipientStatuses.Length == 1) || Request[Keys.Event].ToString() == "SignComplete2" || null != Request["event"].ToString()) { Session[Keys.EnvelopeStatus] = null; Response.Redirect("GetStatusAndDocs.aspx", false); } } else { // Create and send the envelope using the two different options. if (null != Request.Form[Keys.OneSigner]) { _oneSigner = true; CreateAndSend(); } else if (null != Request.Form[Keys.TwoSigners]) { _oneSigner = false; CreateAndSend(); } } }
protected void SendNow(Envelope envelope) { APIServiceSoapClient client = CreateAPIProxy(); try { // Create and send the envelope in one step EnvelopeStatus status = client.CreateAndSendEnvelope(envelope); // If we succeeded, go to the status if (status.SentSpecified) { AddEnvelopeID(status.EnvelopeID); Response.Redirect("GetStatusAndDocs.aspx", false); } } catch (Exception ex) { GoToErrorPage(ex.Message); } }
protected void EmbedSending(Envelope envelope) { APIServiceSoapClient client = CreateAPIProxy(); try { // Create the envelope (but don't send it!) EnvelopeStatus status = client.CreateEnvelope(envelope); AddEnvelopeID(status.EnvelopeID); // If it created successfully, redirect to the embedded host if (status.Status == EnvelopeStatusCode.Created) { string navURL = String.Format("{0}?envelopeID={1}&accountID={2}&source=Document", "EmbeddedHost.aspx", status.EnvelopeID, envelope.AccountId); Response.Redirect(navURL, false); } } catch (Exception ex) { base.GoToErrorPage(ex.Message); } }
/// <summary> /// This method is used to create envelope besed on the give template /// </summary> /// <param name="identity"></param> /// <param name="signers"></param> /// <param name="roleAssignments"></param> /// <param name="template"></param> /// <param name="subject"></param> /// <param name="emailBlurb"></param> /// <param name="fields"></param> /// <param name="password"></param> /// <returns></returns> public static string CreateEnvelopeFromTemplates(Account identity, Recipient[] signers, string template, string subject, string emailBlurb, string password, string url, bool isEmbedded) { // // update the template references // List <TemplateReferenceRoleAssignment> finalRoleAssignments = new List <TemplateReferenceRoleAssignment>(); foreach (Recipient recipient in signers) { TemplateReferenceRoleAssignment templateReferenceRoleAssignment = new TemplateReferenceRoleAssignment(); templateReferenceRoleAssignment.RecipientID = recipient.ID; templateReferenceRoleAssignment.RoleName = recipient.RoleName; finalRoleAssignments.Add(templateReferenceRoleAssignment); } // // setting up the template // TemplateReference templateReference = new TemplateReference(); templateReference.Template = template; templateReference.TemplateLocation = TemplateLocationCode.SOAP; templateReference.RoleAssignments = finalRoleAssignments.ToArray(); // // Envelope wide information // EnvelopeInformation envelopeInfo = new EnvelopeInformation(); envelopeInfo.AccountId = identity.AccountID; envelopeInfo.EmailBlurb = emailBlurb; envelopeInfo.Subject = subject; APIServiceSoap apiService = CreateApiProxy(identity, password); EnvelopeStatus envStatus = apiService.CreateEnvelopeFromTemplates( new TemplateReference[] { templateReference }, signers, envelopeInfo, true); if (!isEmbedded) { return(envStatus.EnvelopeID); } else { RequestRecipientTokenAuthenticationAssertion assert = new RequestRecipientTokenAuthenticationAssertion(); assert.AssertionID = System.DateTime.Now.Ticks.ToString(); assert.AuthenticationInstant = System.DateTime.Now; assert.AuthenticationMethod = RequestRecipientTokenAuthenticationAssertionAuthenticationMethod.Password; assert.SecurityDomain = "TODO-replace-with-your-app-name"; //These are Urls to which Docusign will redirect string retUrl = url.ToLower(); RequestRecipientTokenClientURLs clientURLs = new RequestRecipientTokenClientURLs(); clientURLs.OnSigningComplete = retUrl + "?event=SignComplete&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnAccessCodeFailed = retUrl + "?event=AccessCode&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnCancel = retUrl + "?event=Cancel&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnDecline = retUrl + "?event=Decline&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnException = retUrl + "?event=Exception&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnIdCheckFailed = retUrl + "?event=IDCheck&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnSessionTimeout = retUrl + "?event=Timeout&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnTTLExpired = retUrl + "?event=TTLExpired&envelopeID=" + envStatus.EnvelopeID; clientURLs.OnViewingComplete = retUrl + "?event=ViewComplete&envelopeID=" + envStatus.EnvelopeID; string token = apiService.RequestRecipientToken(envStatus.EnvelopeID, signers[0].CaptiveInfo.ClientUserId, signers[0].UserName, signers[0].Email, assert, clientURLs); return(token); } }
protected void createEnvelope() { FileStream fs = null; try { String userName = ConfigurationManager.AppSettings["API.Email"]; String password = ConfigurationManager.AppSettings["API.Password"]; String integratorKey = ConfigurationManager.AppSettings["API.IntegratorKey"]; String auth = "<DocuSignCredentials><Username>" + userName + "</Username><Password>" + password + "</Password><IntegratorKey>" + integratorKey + "</IntegratorKey></DocuSignCredentials>"; ServiceReference1.DSAPIServiceSoapClient client = new ServiceReference1.DSAPIServiceSoapClient(); using (OperationContextScope scope = new System.ServiceModel.OperationContextScope(client.InnerChannel)) { HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty(); httpRequestProperty.Headers.Add("X-DocuSign-Authentication", auth); OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty; CompositeTemplate template = new CompositeTemplate(); // Set up recipients Recipient[] recipients; if (jointEmail.Value.Trim().Equals("")) { recipients = new Recipient[1]; } else { recipients = new Recipient[2]; } recipients[0] = new Recipient(); recipients[0].ID = "1"; recipients[0].Email = email.Value; recipients[0].Type = RecipientTypeCode.Signer; recipients[0].UserName = firstname.Value + " " + lastname.Value; recipients[0].CaptiveInfo = new RecipientCaptiveInfo(); recipients[0].CaptiveInfo.ClientUserId = RandomizeClientUserID(); recipients[0].RoutingOrder = 1; recipients[0].RoleName = "Signer1"; // If there is a 2nd recipient, configure if (!jointEmail.Value.Equals("")) { recipients[1] = new Recipient(); recipients[1].ID = "2"; recipients[1].Email = jointEmail.Value; recipients[1].Type = RecipientTypeCode.Signer; recipients[1].UserName = jointFirstname.Value + " " + jointLastname.Value; recipients[1].RoleName = "Signer2"; recipients[1].RoutingOrder = 1; } //Configure the inline templates InlineTemplate inlineTemplate = new InlineTemplate(); inlineTemplate.Sequence = "2"; inlineTemplate.Envelope = new Envelope(); inlineTemplate.Envelope.Recipients = recipients; inlineTemplate.Envelope.AccountId = ConfigurationManager.AppSettings["API.TemplatesAccountId"]; template.InlineTemplates = new InlineTemplate[] { inlineTemplate }; // Configure the document template.Document = new Document(); template.Document.ID = "1"; template.Document.Name = "Sample Document"; BinaryReader binReader = null; String filename = uploadFile.Value; if (File.Exists(Server.MapPath("~/App_Data/" + filename))) { fs = new FileStream(Server.MapPath("~/App_Data/" + filename), FileMode.Open); binReader = new BinaryReader(fs); } byte[] PDF = binReader.ReadBytes(System.Convert.ToInt32(fs.Length)); template.Document.PDFBytes = PDF; template.Document.TransformPdfFields = true; template.Document.FileExtension = "pdf"; ServerTemplate serverTemplate = new ServerTemplate(); serverTemplate.Sequence = "1"; serverTemplate.TemplateID = templatesList.SelectedValue; template.ServerTemplates = new ServerTemplate[] { serverTemplate }; // Set up the envelope EnvelopeInformation envInfo = new EnvelopeInformation(); envInfo.AutoNavigation = true; envInfo.AccountId = ConfigurationManager.AppSettings["API.AccountId"]; envInfo.Subject = "Templates Example"; //Create envelope with all the composite template information EnvelopeStatus status = client.CreateEnvelopeFromTemplatesAndForms(envInfo, new CompositeTemplate[] { template }, true); RequestRecipientTokenAuthenticationAssertion assert = new RequestRecipientTokenAuthenticationAssertion(); assert.AssertionID = "12345"; assert.AuthenticationInstant = DateTime.Now; assert.AuthenticationMethod = RequestRecipientTokenAuthenticationAssertionAuthenticationMethod.Password; assert.SecurityDomain = "www.magicparadigm.com"; RequestRecipientTokenClientURLs clientURLs = new RequestRecipientTokenClientURLs(); clientURLs.OnAccessCodeFailed = ConfigurationManager.AppSettings["RecipientTokenClientURLsPrefix"] + "?envelopeId=" + status.EnvelopeID + "&event=OnAccessCodeFailed"; clientURLs.OnCancel = ConfigurationManager.AppSettings["RecipientTokenClientURLsPrefix"] + "?envelopeId=" + status.EnvelopeID + "&event=OnCancel"; clientURLs.OnDecline = ConfigurationManager.AppSettings["RecipientTokenClientURLsPrefix"] + "?envelopeId=" + status.EnvelopeID + "&event=OnDecline"; clientURLs.OnException = ConfigurationManager.AppSettings["RecipientTokenClientURLsPrefix"] + "?envelopeId=" + status.EnvelopeID + "&event=OnException"; clientURLs.OnFaxPending = ConfigurationManager.AppSettings["RecipientTokenClientURLsPrefix"] + "?envelopeId=" + status.EnvelopeID + "&event=OnFaxPending"; clientURLs.OnIdCheckFailed = ConfigurationManager.AppSettings["RecipientTokenClientURLsPrefix"] + "?envelopeId=" + status.EnvelopeID + "&event=OnIdCheckFailed"; clientURLs.OnSessionTimeout = ConfigurationManager.AppSettings["RecipientTokenClientURLsPrefix"] + "?envelopeId=" + status.EnvelopeID + "&event=OnSessionTimeout"; clientURLs.OnTTLExpired = ConfigurationManager.AppSettings["RecipientTokenClientURLsPrefix"] + "?envelopeId=" + status.EnvelopeID + "&event=OnTTLExpired"; clientURLs.OnViewingComplete = ConfigurationManager.AppSettings["RecipientTokenClientURLsPrefix"] + "?envelopeId=" + status.EnvelopeID + "&event=OnViewingComplete"; String url = Request.Url.AbsoluteUri; String recipientToken; clientURLs.OnSigningComplete = url.Substring(0, url.LastIndexOf("/")) + "/EmbeddedSigningComplete0.aspx?envelopeID=" + status.EnvelopeID; recipientToken = client.RequestRecipientToken(status.EnvelopeID, recipients[0].CaptiveInfo.ClientUserId, recipients[0].UserName, recipients[0].Email, assert, clientURLs); Session["envelopeID"] = status.EnvelopeID; if (!Request.Browser.Browser.Equals("InternetExplorer") && (!Request.Browser.Browser.Equals("Safari"))) { docusignFrame.Visible = true; docusignFrame.Src = recipientToken; } else // Handle IE differently since it does not allow dynamic setting of the iFrame width and height { docusignFrameIE.Visible = true; docusignFrameIE.Src = recipientToken; } } } catch (Exception ex) { // Log4Net Piece log4net.ILog logger = log4net.LogManager.GetLogger(typeof(_Default)); logger.Info("\n----------------------------------------\n"); logger.Error(ex.Message); logger.Error(ex.StackTrace); Response.Write(ex.Message); } finally { if (fs != null) { fs.Close(); } } }