public IEnumerable <EnvelopeTemplate> GetTemplates(Action <EnvelopeTemplate> callback = null)
        {
            try
            {
                this.DocusignAuthenticator.Authenticate(ApiClient);

                var templatesApi = new TemplatesApi(ApiClient.Configuration);
                var templates    = templatesApi.ListTemplates(this.AccountId);

                if (callback != null)
                {
                    foreach (var template in templates.EnvelopeTemplates)
                    {
                        callback(template);
                    }
                }

                return(templates.EnvelopeTemplates.ToList());
            }
            catch (Exception e)
            {
                this.Logger.LogError(e.Message);
                throw;
            }
        }
Пример #2
0
        public void RequestSignatureViaTemplateTest()
        {
            try
            {
                // upload template if one doesn't exist
                // FAILED - CANT UPLOAD A TEMPLATE - API-3002 submitted
                // use predefined template
                AuthenticationApiTests authTests = new AuthenticationApiTests();
                authTests.LoginTest();

                // get pre-existing template with Signer1 role
                // since I can't upload a template right now
                TemplatesApi            templatesApi    = new TemplatesApi();
                EnvelopeTemplateResults templateResults = templatesApi.ListTemplates(TestConfig.AccountId);
                Assert.IsNotNull(templateResults);
                Assert.IsNotNull(templateResults.EnvelopeTemplates);
                string templateId = null;
                foreach (EnvelopeTemplateResult et in templateResults.EnvelopeTemplates)
                {
                    if (et.Name == "Test Template")
                    {
                        templateId = et.TemplateId;
                        break;
                    }
                }
                Assert.IsNotNull(templateId);

                EnvelopeDefinition envDef = new EnvelopeDefinition();
                envDef.TemplateId = templateId;

                envDef.TemplateRoles = new List <TemplateRole>();
                TemplateRole templateRole = new TemplateRole();
                templateRole.Email    = TestConfig.DefaultEmail;
                templateRole.Name     = TestConfig.DefaultName;
                templateRole.RoleName = "Signer1";
                envDef.TemplateRoles.Add(templateRole);
                envDef.Status = "sent"; // trigger the envelope to be sent (vs. Draft/Created)


                // send envelope using template roles
                EnvelopesApi    envelopesApi = new EnvelopesApi();
                EnvelopeSummary es           = envelopesApi.CreateEnvelope(TestConfig.AccountId, envDef);
                Assert.IsNotNull(es);
                Assert.IsNotNull(es.EnvelopeId);
                Trace.WriteLine("Envelope: " + es.ToJson());
            }
            catch (DocuSign.eSign.Client.ApiException apiEx)
            {
                Assert.IsNotNull(apiEx.ErrorCode);
                Assert.IsTrue(!string.IsNullOrWhiteSpace(apiEx.Message));
                Assert.IsTrue(false, "Failed with ErrorCode: " + apiEx.ErrorCode + ", Message: " + apiEx.Message);
            }
        }
Пример #3
0
        public IntegrationTest()
        {
            Configuration config = new Configuration();

            config.ApiKey.Add(
                "Authorization",
                Environment.GetEnvironmentVariable("DYSPATCH_API_KEY")
                );
            config.ApiKeyPrefix.Add("Authorization", "Bearer");

            drafts    = new DraftsApi(config);
            templates = new TemplatesApi(config);
        }
Пример #4
0
        public List <KeyValueDTO> GetTemplatesList(DocuSignApiConfiguration conf)
        {
            var tmpApi = new TemplatesApi(conf.Configuration);
            var result = tmpApi.ListTemplates(conf.AccountId);

            if (result.EnvelopeTemplates != null && result.EnvelopeTemplates.Count > 0)
            {
                return(result.EnvelopeTemplates.Where(a => !string.IsNullOrEmpty(a.Name))
                       .Select(a => new KeyValueDTO(a.Name, a.TemplateId)).ToList());
            }

            return(new List <KeyValueDTO>());
        }
Пример #5
0
        private (bool createdNewTemplate, string templateId, string resultsTemplateName) DoWork(
            string accessToken, string basePath, string accountId)
        {
            // Data for this method
            // accessToken
            // basePath
            // accountId


            // Step 1. List templates to see if ours exists already
            var config = new Configuration(new ApiClient(basePath));

            config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
            TemplatesApi templatesApi = new TemplatesApi(config);

            TemplatesApi.ListTemplatesOptions options = new TemplatesApi.ListTemplatesOptions();
            //options.searchText = "Example Signer and CC template";
            options.searchText = "CoD"; //Added by DT
            EnvelopeTemplateResults results = templatesApi.ListTemplates(accountId, options);

            string templateId;
            string resultsTemplateName;
            bool   createdNewTemplate;

            // Step 2. Process results
            if (int.Parse(results.ResultSetSize) > 0)
            {
                // Found the template! Record its id
                templateId          = results.EnvelopeTemplates[0].TemplateId;
                resultsTemplateName = results.EnvelopeTemplates[0].Name;
                createdNewTemplate  = false;
            }
            else
            {
                // No template! Create one!
                EnvelopeTemplate templateReqObject = MakeTemplate(templateName);

                TemplateSummary template = templatesApi.CreateTemplate(accountId, templateReqObject);

                // Retrieve the new template Name / TemplateId
                EnvelopeTemplateResults templateResults = templatesApi.ListTemplates(accountId, options);
                templateId          = templateResults.EnvelopeTemplates[0].TemplateId;
                resultsTemplateName = templateResults.EnvelopeTemplates[0].Name;
                createdNewTemplate  = true;
            }

            return(createdNewTemplate : createdNewTemplate,
                   templateId : templateId, resultsTemplateName : resultsTemplateName);
        }
Пример #6
0
        public JObject DownloadDocuSignTemplate(DocuSignApiConfiguration config, string selectedDocusignTemplateId)
        {
            var templatesApi = new TemplatesApi(config.Configuration);
            var template     = templatesApi.Get(config.AccountId, selectedDocusignTemplateId);

            foreach (var doc in template.Documents)
            {
                var document = templatesApi.GetDocument(config.AccountId, selectedDocusignTemplateId, doc.DocumentId);
                var ms       = new MemoryStream();
                document.CopyTo(ms);
                string base64 = Convert.ToBase64String(ms.ToArray());
                template.Documents.Where(a => a.DocumentId == doc.DocumentId).FirstOrDefault().DocumentBase64 = base64;
            }
            var result = JsonConvert.SerializeObject(template);

            return(JObject.Parse(result));
        }
Пример #7
0
        //this is purely for Send_DocuSign_Envelope activity
        public Tuple <IEnumerable <KeyValueDTO>, IEnumerable <DocuSignTabDTO> > GetTemplateRecipientsTabsAndDocuSignTabs(DocuSignApiConfiguration conf, string templateId)
        {
            var tmpApi            = new TemplatesApi(conf.Configuration);
            var recipientsAndTabs = new List <KeyValueDTO>();
            var docuTabs          = new List <DocuSignTabDTO>();

            var recipients = GetRecipients(conf, tmpApi, templateId);

            recipientsAndTabs.AddRange(MapRecipientsToFieldDTO(recipients));

            foreach (var signer in recipients.Signers)
            {
                var tabs            = tmpApi.ListTabs(conf.AccountId, templateId, signer.RecipientId, new Tabs());
                var signersdocutabs = DocuSignTab.ExtractTabs(JObject.Parse(tabs.ToJson()), signer.RoleName).ToList();
                docuTabs.AddRange(signersdocutabs);
                recipientsAndTabs.AddRange(DocuSignTab.MapTabsToFieldDTO(signersdocutabs));
            }

            return(new Tuple <IEnumerable <KeyValueDTO>, IEnumerable <DocuSignTabDTO> >(recipientsAndTabs, docuTabs));
        }
        /// <summary>
        /// Generates a new DocuSign Template based on static information in this class
        /// </summary>
        /// <param name="accessToken">Access Token for API call (OAuth)</param>
        /// <param name="basePath">BasePath for API calls (URI)</param>
        /// <param name="accountId">The DocuSign Account ID (GUID or short version) for which the APIs call would be made</param>
        /// <returns>Template name, templateId and a flag to indicate if this is a new template or it exited prior to calling this method</returns>
        public static (bool createdNewTemplate, string templateId, string resultsTemplateName) CreateTemplate(string accessToken, string basePath, string accountId)
        {
            // Step 1. List templates to see if ours exists already
            var apiClient = new ApiClient(basePath);

            apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
            TemplatesApi templatesApi = new TemplatesApi(apiClient);

            TemplatesApi.ListTemplatesOptions options = new TemplatesApi.ListTemplatesOptions();
            options.searchText = "Example Signer and CC template";
            EnvelopeTemplateResults results = templatesApi.ListTemplates(accountId, options);

            string templateId;
            string resultsTemplateName;
            bool   createdNewTemplate;

            // Step 2. Process results
            if (int.Parse(results.ResultSetSize) > 0)
            {
                // Found the template! Record its id
                templateId          = results.EnvelopeTemplates[0].TemplateId;
                resultsTemplateName = results.EnvelopeTemplates[0].Name;
                createdNewTemplate  = false;
            }
            else
            {
                // No template! Create one!
                EnvelopeTemplate templateReqObject = MakeTemplate(templateName);

                TemplateSummary template = templatesApi.CreateTemplate(accountId, templateReqObject);

                // Retrieve the new template Name / TemplateId
                EnvelopeTemplateResults templateResults = templatesApi.ListTemplates(accountId, options);
                templateId          = templateResults.EnvelopeTemplates[0].TemplateId;
                resultsTemplateName = templateResults.EnvelopeTemplates[0].Name;
                createdNewTemplate  = true;
            }

            return(createdNewTemplate : createdNewTemplate,
                   templateId : templateId, resultsTemplateName : resultsTemplateName);
        }
Пример #9
0
        public EnvelopeSummary GenerateDocument(string name, string email)
        {
            var docuSignClient = new DocuSignClient(this.DocuSignCredentials);
            var accountId      = docuSignClient.AccountId;

            //get TAB's (requiredFields) from document
            TemplatesApi     templateInstanceApi = new TemplatesApi();
            EnvelopeTemplate templateBase        = templateInstanceApi.Get(accountId, this.DocuSignTemplate.TemplateId);

            Tabs requiredFields = new Tabs();

            if (templateBase != null && templateBase.Recipients != null && templateBase.Recipients.Signers.Any())
            {
                requiredFields = templateBase.Recipients.Signers.FirstOrDefault().Tabs;
            }

            // assign recipient to template role by setting name, email, and role name.  Note that the
            // template role name must match the placeholder role name saved in your account template.
            List <TemplateRole> templateRoles = this.DocuSignTemplate.TemplateRoleNames.Select(m => new TemplateRole
            {
                Email    = email,
                Name     = name,
                RoleName = m,
                Tabs     = requiredFields
            }).ToList();

            // create a new envelope which we will use to send the signature request
            EnvelopeDefinition envelope = new EnvelopeDefinition
            {
                EmailSubject  = this.EmailTemplate.Subject,
                EmailBlurb    = this.EmailTemplate.MessageBody,
                TemplateId    = this.DocuSignTemplate.TemplateId,
                TemplateRoles = templateRoles,
                Status        = "sent"
            };

            // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
            var envelopesApi = new EnvelopesApi();

            return(envelopesApi.CreateEnvelope(accountId, envelope));
        }
Пример #10
0
        protected override void InitializeInternal()
        {
            // Data for this method
            // signerEmail
            // signerName
            var basePath    = RequestItemsService.Session.BasePath + "/restapi";
            var accessToken = RequestItemsService.User.AccessToken;  // Represents your {ACCESS_TOKEN}
            var accountId   = RequestItemsService.Session.AccountId; // Represents your {ACCOUNT_ID
            var apiClient   = new ApiClient(basePath);

            apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);

            var accountsApi = new AccountsApi(apiClient);
            var brands      = accountsApi.ListBrands(accountId);

            ViewBag.Brands = brands.Brands;
            var templatesApi = new TemplatesApi(apiClient);
            var templates    = templatesApi.ListTemplates(accountId);

            ViewBag.EnvelopeTemplates = templates.EnvelopeTemplates;
        }
Пример #11
0
        private List <TemplateRole> GetDocuSignTemplateRoles(string accountId, string clientName, string clientEmail, string brokerName, string brokerEmail)
        {
            //get TAB's (requiredFields) from document
            var templateInstanceApi       = new TemplatesApi();
            EnvelopeTemplate templateBase = templateInstanceApi.Get(accountId, TemplateId);

            List <TemplateRole> templateRoles = new List <TemplateRole>();

            if (templateBase != null && templateBase.Recipients != null && templateBase.Recipients.Signers.Any())
            {
                foreach (var signer in templateBase.Recipients.Signers)
                {
                    if (signer.RoleName.Contains("Broker"))
                    {
                        templateRoles.Add(new TemplateRole
                        {
                            Name         = brokerName,
                            Email        = brokerEmail,
                            RoleName     = "Broker",
                            Tabs         = signer.Tabs,
                            RoutingOrder = "99"
                        });
                    }
                    else
                    {
                        templateRoles.Add(new TemplateRole
                        {
                            Name         = clientName,
                            Email        = clientEmail,
                            RoleName     = "Cliente",
                            Tabs         = signer.Tabs,
                            RoutingOrder = "1"
                        });
                    }
                }
            }

            return(templateRoles);
        }
        public void CreateTemplateTest()
        {
            try
            {
                AuthenticationApiTests authTests = new AuthenticationApiTests();
                authTests.LoginTest();

                EnvelopeTemplate templateDef = Utils.CreateDefaultTemplate();

                TemplatesApi    templatesApi = new TemplatesApi();
                TemplateSummary tempSummary  = templatesApi.CreateTemplate(TestConfig.AccountId, templateDef);
                Assert.IsNotNull(tempSummary);
                Assert.IsNotNull(tempSummary.TemplateId);
                Trace.WriteLine("TemplateSummary: " + tempSummary.ToJson());
            }
            catch (DocuSign.eSign.Client.ApiException apiEx)
            {
                // FAILS - API-3002 submitted.
                Assert.IsNotNull(apiEx.ErrorCode);
                Assert.IsTrue(!string.IsNullOrWhiteSpace(apiEx.Message));
                Assert.IsTrue(false, "Failed with ErrorCode: " + apiEx.ErrorCode + ", Message: " + apiEx.Message);
            }
        }
        public EnvelopeTemplate FindTemplate(Predicate <EnvelopeTemplate> match)
        {
            try
            {
                this.DocusignAuthenticator.Authenticate(ApiClient);

                var templatesApi = new TemplatesApi(ApiClient.Configuration);
                var templates    = templatesApi.ListTemplates(this.AccountId);

                foreach (var template in templates.EnvelopeTemplates)
                {
                    if (match(template))
                    {
                        return(templatesApi.Get(this.AccountId, template.TemplateId));
                    }
                }
                return(null);
            }
            catch (Exception e)
            {
                this.Logger.LogError(e.Message);
                throw;
            }
        }
Пример #14
0
        //TODO: need to add try catch and seprate out the logic
        public Tabs GetValidTabs()
        {
            Tabs tabs      = new Tabs();
            var  apiClient = new ApiClient(lingkCredentials.credentialsJson.isSandbox ? LingkConst.DocusignDemoUrl : LingkConst.DocusignProdUrl);

            apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + this.lingkCredentials.docuSignToken.access_token);
            var  templateApi = new TemplatesApi(apiClient);
            Tabs results     = templateApi.GetDocumentTabsAsync(accountId, templateId, "1").Result;

            var validTabs = results.GetType()
                            .GetProperties()                         //get all properties on object
                            .Select(pi => pi.GetValue(results))
                            .Where(value => value != null).ToList(); //get value for the propery
            Dictionary <Type, int> typeDict = new Dictionary <Type, int>
            {
                { typeof(List <Text>), 0 },
                { typeof(List <SignHere>), 1 },
                { typeof(List <Checkbox>), 2 },
                { typeof(List <RadioGroup>), 3 },
                { typeof(List <List>), 4 }
            };

            //TODO: This need to be refactored as there should be batter way of doing this
            validTabs.ForEach((tab) =>
            {
                Type type = tab.GetType();
                var key   = typeDict.ContainsKey(type) ? typeDict[type] : -1;
                switch (key)
                {
                case 0:
                    List <Text> textTabs     = new List <Text>();
                    List <Text> docusignTabs = tab as List <Text>;
                    docusignTabs.ForEach((docTextTab) =>
                    {
                        var foundTab = GetSelectedTab(docTextTab.TabLabel);
                        if (foundTab != null)
                        {
                            textTabs.Add(new Text
                            {
                                TabLabel = foundTab.Id,
                                Value    = GetTabValue(foundTab)
                            });
                        }
                    });
                    tabs.TextTabs = textTabs;
                    break;

                case 1:
                    tabs.SignHereTabs = new List <SignHere> {
                    };
                    break;

                case 2:
                    List <Checkbox> CheckboxTabs         = new List <Checkbox>();
                    List <Checkbox> docusignCheckboxTabs = tab as List <Checkbox>;
                    docusignCheckboxTabs.ForEach((docCheckboxTab) =>
                    {
                        var foundTab = GetSelectedTab(docCheckboxTab.TabLabel);
                        if (foundTab != null)
                        {
                            CheckboxTabs.Add(new Checkbox
                            {
                                TabLabel = foundTab.Id,
                                Selected = GetTabValue(foundTab)
                            });
                        }
                    });
                    tabs.CheckboxTabs = CheckboxTabs;
                    break;

                case 3:
                    List <RadioGroup> radioTabs         = new List <RadioGroup>();
                    List <RadioGroup> docusignRadioTabs = tab as List <RadioGroup>;
                    docusignRadioTabs.ForEach((docRadioTab) =>
                    {
                        var foundTab = GetSelectedTab(docRadioTab.GroupName);
                        if (foundTab != null)
                        {
                            radioTabs.Add(new RadioGroup
                            {
                                GroupName = foundTab.Id,
                                Radios    = new List <Radio> {
                                    new Radio
                                    {
                                        Value    = GetTabValue(foundTab),
                                        Selected = "true"
                                    }
                                }
                            });
                        }
                    });
                    tabs.RadioGroupTabs = radioTabs;
                    break;

                case 4:
                    List <List> listTabs         = new List <List>();
                    List <List> docusignListTabs = tab as List <List>;
                    docusignListTabs.ForEach((docListTab) =>
                    {
                        var foundTab = GetSelectedTab(docListTab.TabLabel);
                        if (foundTab != null)
                        {
                            listTabs.Add(new List
                            {
                                TabLabel = foundTab.Id,
                                Value    = GetTabValue(foundTab)
                            });
                        }
                    });
                    tabs.ListTabs = listTabs;
                    break;

                case -1:
                    _logger.LogWarning("Tab " + type.ToString() + " is not implemented");
                    break;

                default:
                    break;
                }
            });
            return(tabs);
        }
Пример #15
0
 public Templates()
 {
     _templatesApi = new TemplatesApi();
 }
Пример #16
0
 public void Init()
 {
     instance = new TemplatesApi();
 }
Пример #17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            EnvelopeDefinition envDef = new EnvelopeDefinition();

            envDef.CompositeTemplates = new List <CompositeTemplate>();
            CompositeTemplate ct = new CompositeTemplate();

            ct.CompositeTemplateId = "1";

            ct.ServerTemplates = new List <ServerTemplate>();
            ServerTemplate st = new ServerTemplate();

            st.Sequence = "1";

            ct.InlineTemplates = new List <InlineTemplate>();
            InlineTemplate it = new InlineTemplate();

            it.Sequence           = "1";
            it.Recipients         = new Recipients();
            it.Recipients.Signers = new List <Signer>();

            Signer Signer1 = new Signer();

            Signer1.RecipientId         = "1";
            Signer1.Tabs                = new Tabs();
            Signer1.Tabs.TextTabs       = new List <Text>();
            Signer1.Tabs.CheckboxTabs   = new List <Checkbox>();
            Signer1.Tabs.ListTabs       = new List <List>();
            Signer1.Tabs.RadioGroupTabs = new List <RadioGroup>();
            Signer Signer2 = new Signer();

            Signer2.RecipientId         = "2";
            Signer2.Tabs                = new Tabs();
            Signer2.Tabs.TextTabs       = new List <Text>();
            Signer2.Tabs.CheckboxTabs   = new List <Checkbox>();
            Signer2.Tabs.ListTabs       = new List <List>();
            Signer2.Tabs.RadioGroupTabs = new List <RadioGroup>();

            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

            foreach (string key in Request.Form)
            {
                if (key.Length > 9)
                {
                    switch (key.Substring(0, 10))
                    {
                    case "signer1_us":
                        Signer1.Name = Request[key];
                        break;

                    case "signer1_em":
                        Signer1.Email = Request[key];
                        break;

                    case "signer1_ro":
                        Signer1.RoleName       = Request[key];
                        envelope.dsSigner1Role = Request[key];
                        break;

                    case "signer1_ty":
                        if (Request[key] == "embedded")
                        {
                            Random random1 = new Random();
                            envelope.dsSigner1CID = new string(Enumerable.Repeat(chars, 10)
                                                               .Select(s => s[random1.Next(s.Length)]).ToArray());
                            Signer1.ClientUserId = envelope.dsSigner1CID;
                        }
                        break;

                    case "signer1_au":
                        envelope.dsSigner1AuthMethod = Request[key];
                        break;

                    case "signer1_nu":
                        envelope.dsSigner1AuthNumber = Request[key];
                        break;

                    case "signer1_si":
                        envelope.dsSigner1SP = Request[key];
                        break;

                    case "signer1_tx":
                        Text   tempText1    = new Text();
                        string tempTxtLabel = key;
                        tempTxtLabel       = tempTxtLabel.Substring(12);
                        tempText1.TabLabel = tempTxtLabel;
                        tempText1.Value    = Request[key];
                        Signer1.Tabs.TextTabs.Add(tempText1);
                        break;

                    case "signer1_rb":
                        RadioGroup tempRG1     = new RadioGroup();
                        string     tempRBLabel = key;
                        tempRBLabel       = tempRBLabel.Substring(11);
                        tempRG1.GroupName = tempRBLabel;
                        tempRG1.Radios    = new List <Radio>();
                        Radio tempRB1 = new Radio();
                        tempRB1.Selected = "true";
                        tempRB1.Value    = Request[key];
                        tempRG1.Radios.Add(tempRB1);
                        Signer1.Tabs.RadioGroupTabs.Add(tempRG1);
                        break;

                    case "signer1_li":
                        List   tempList1     = new List();
                        string tempListLabel = key;
                        tempListLabel      = tempListLabel.Substring(13);
                        tempList1.TabLabel = tempListLabel;
                        tempList1.Value    = Request[key];
                        Signer1.Tabs.ListTabs.Add(tempList1);
                        break;

                    case "signer1_cb":
                        Checkbox tempCB1     = new Checkbox();
                        string   tempCBLabel = key;
                        tempCBLabel      = tempCBLabel.Substring(11);
                        tempCB1.TabLabel = tempCBLabel;
                        tempCB1.Selected = "true";
                        Signer1.Tabs.CheckboxTabs.Add(tempCB1);
                        break;


                    case "signer2_us":
                        Signer2.Name           = Request[key];
                        envelope.dsSigner2Name = Signer2.Name;
                        break;

                    case "signer2_em":
                        Signer2.Email           = Request[key];
                        envelope.dsSigner2Email = Request[key];
                        break;

                    case "signer2_ro":
                        Signer2.RoleName       = Request[key];
                        envelope.dsSigner2Role = Request[key];
                        break;

                    case "signer2_ty":
                        if (Request[key] == "embedded")
                        {
                            Random random2 = new Random();
                            envelope.dsSigner2CID = new string(Enumerable.Repeat(chars, 10)
                                                               .Select(s => s[random2.Next(s.Length)]).ToArray());
                            Signer2.ClientUserId = envelope.dsSigner2CID;
                        }
                        break;

                    case "signer2_au":
                        envelope.dsSigner2AuthMethod = Request[key];
                        break;

                    case "signer2_nu":
                        envelope.dsSigner2AuthNumber = Request[key];
                        break;

                    case "signer2_si":
                        envelope.dsSigner2SP = Request[key];
                        break;

                    case "signer2_tx":
                        Text   tempText2     = new Text();
                        string tempTxtLabel2 = key;
                        tempTxtLabel2      = tempTxtLabel2.Substring(12);
                        tempText2.TabLabel = tempTxtLabel2;
                        tempText2.Value    = Request[key];
                        Signer2.Tabs.TextTabs.Add(tempText2);
                        break;

                    case "signer2_rb":
                        RadioGroup tempRG2      = new RadioGroup();
                        string     tempRBLabel2 = key;
                        tempRBLabel2      = tempRBLabel2.Substring(11);
                        tempRG2.GroupName = tempRBLabel2;
                        tempRG2.Radios    = new List <Radio>();
                        Radio tempRB2 = new Radio();
                        tempRB2.Selected = "true";
                        tempRB2.Value    = Request[key];
                        tempRG2.Radios.Add(tempRB2);
                        Signer2.Tabs.RadioGroupTabs.Add(tempRG2);
                        break;

                    case "signer2_li":
                        List   tempList2      = new List();
                        string tempListLabel2 = key;
                        tempListLabel2     = tempListLabel2.Substring(13);
                        tempList2.TabLabel = tempListLabel2;
                        tempList2.Value    = Request[key];
                        Signer2.Tabs.ListTabs.Add(tempList2);
                        break;

                    case "signer2_cb":
                        Checkbox tempCB2      = new Checkbox();
                        string   tempCBLabel2 = key;
                        tempCBLabel2     = tempCBLabel2.Substring(13);
                        tempCB2.TabLabel = tempCBLabel2;
                        tempCB2.Selected = "true";
                        Signer2.Tabs.CheckboxTabs.Add(tempCB2);
                        break;

                    case "accountnum":
                        envelope.dsAccountId = Request[key];
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    switch (key)
                    {
                    case "usr":
                        envelope.dsUser = Request[key];
                        break;

                    case "pd":
                        envelope.dsPassword = Request[key];
                        break;

                    case "dst":
                        envelope.dsTemplateId = Request[key];
                        break;

                    case "logo":
                        envelope.dsLogo = Request[key];
                        break;

                    default:
                        break;
                    }
                }
            }
            switch (envelope.dsSigner1AuthMethod.ToLower())
            {
            case "access code":
                Signer1.AccessCode = envelope.dsSigner1AuthNumber;
                break;

            case "sms":
                Signer1.IdCheckConfigurationName = "SMS Auth $";
                Signer1.RequireIdLookup          = "true";
                Signer1.SmsAuthentication        = new RecipientSMSAuthentication();
                Signer1.SmsAuthentication.SenderProvidedNumbers = new List <string>();
                Signer1.SmsAuthentication.SenderProvidedNumbers.Add("+" + envelope.dsSigner1AuthNumber);
                break;

            case "phone":
                Signer1.IdCheckConfigurationName = "Phone Auth $";
                Signer1.RequireIdLookup          = "true";
                Signer1.PhoneAuthentication      = new RecipientPhoneAuthentication();
                Signer1.PhoneAuthentication.SenderProvidedNumbers = new List <string>();
                Signer1.PhoneAuthentication.SenderProvidedNumbers.Add("+" + envelope.dsSigner1AuthNumber);
                Signer1.PhoneAuthentication.RecipMayProvideNumber = "false";
                break;

            case "idcheck":
                Signer1.IdCheckConfigurationName = "ID Check $";
                Signer1.RequireIdLookup          = "true";
                break;

            default:
                break;
            }

            switch (envelope.dsSigner1SP.ToLower())
            {
            case "ds electronic":
                Signer1.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspE = new RecipientSignatureProvider();
                rspE.SignatureProviderName = "UniversalSignaturePen_ImageOnly";
                Signer1.RecipientSignatureProviders.Add(rspE);
                break;

            case "ds express":
                Signer1.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspD = new RecipientSignatureProvider();
                rspD.SignatureProviderName = "UniversalSignaturePen_Default";
                Signer1.RecipientSignatureProviders.Add(rspD);
                break;

            case "ds aes ac":
                Signer1.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspAESAC = new RecipientSignatureProvider();
                rspAESAC.SignatureProviderName    = "UniversalSignaturePen_OpenTrust_Hash_TSP";
                rspAESAC.SignatureProviderOptions = new RecipientSignatureProviderOptions();
                rspAESAC.SignatureProviderOptions.OneTimePassword = envelope.dsSigner1AuthNumber;
                Signer1.RecipientSignatureProviders.Add(rspAESAC);
                break;

            case "ds aes sms":
                Signer1.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspAESSMS = new RecipientSignatureProvider();
                rspAESSMS.SignatureProviderName        = "UniversalSignaturePen_OpenTrust_Hash_TSP";
                rspAESSMS.SignatureProviderOptions     = new RecipientSignatureProviderOptions();
                rspAESSMS.SignatureProviderOptions.Sms = "+" + envelope.dsSigner1AuthNumber;
                Signer1.RecipientSignatureProviders.Add(rspAESSMS);
                break;

            case "dsa":
                Signer1.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspDSA = new RecipientSignatureProvider();
                rspDSA.SignatureProviderName = "universalsignaturepen_docusignsigningappliance_tsp";
                Signer1.RecipientSignatureProviders.Add(rspDSA);
                break;

            case "id now":
                Signer1.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspIDNOW = new RecipientSignatureProvider();
                rspIDNOW.SignatureProviderName = "UniversalSignaturePen_IDNow_TSP";
                Signer1.RecipientSignatureProviders.Add(rspIDNOW);
                break;

            case "us piv":
                Signer1.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspUSPIV = new RecipientSignatureProvider();
                rspUSPIV.SignatureProviderName = "UniversalSignaturePen_PIV_Test_TSP";
                Signer1.RecipientSignatureProviders.Add(rspUSPIV);
                break;

            case "it agile":
                Signer1.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspAgile = new RecipientSignatureProvider();
                rspAgile.SignatureProviderName = "UniversalSignaturePen_ItAgile_TSP";
                Signer1.RecipientSignatureProviders.Add(rspAgile);
                break;

            case "icp":
                Signer1.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspICP = new RecipientSignatureProvider();
                rspICP.SignatureProviderName = "UniversalSignaturePen_ICP_SmartCard_TSP";
                Signer1.RecipientSignatureProviders.Add(rspICP);
                break;

            case "ds smart card":
                Signer1.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspSMART = new RecipientSignatureProvider();
                rspSMART.SignatureProviderName = "universalsignaturepen_ds_smartcard_tsp";
                Signer1.RecipientSignatureProviders.Add(rspSMART);
                break;

            default:
                break;
            }

            switch (envelope.dsSigner2AuthMethod.ToLower())
            {
            case "access code":
                Signer2.AccessCode = envelope.dsSigner2AuthNumber;
                break;

            case "sms":
                Signer2.IdCheckConfigurationName = "SMS Auth $";
                Signer2.RequireIdLookup          = "true";
                Signer2.SmsAuthentication        = new RecipientSMSAuthentication();
                Signer2.SmsAuthentication.SenderProvidedNumbers = new List <string>();
                Signer2.SmsAuthentication.SenderProvidedNumbers.Add("+" + envelope.dsSigner2AuthNumber);
                break;

            case "phone":
                Signer2.IdCheckConfigurationName = "Phone Auth $";
                Signer2.RequireIdLookup          = "true";
                Signer2.PhoneAuthentication      = new RecipientPhoneAuthentication();
                Signer2.PhoneAuthentication.SenderProvidedNumbers = new List <string>();
                Signer2.PhoneAuthentication.SenderProvidedNumbers.Add("+" + envelope.dsSigner2AuthNumber);
                Signer2.PhoneAuthentication.RecipMayProvideNumber = "false";
                break;

            case "idcheck":
                Signer2.IdCheckConfigurationName = "ID Check $";
                Signer2.RequireIdLookup          = "true";
                break;

            default:
                break;
            }

            switch (envelope.dsSigner2SP.ToLower())
            {
            case "ds electronic":
                Signer2.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspE = new RecipientSignatureProvider();
                rspE.SignatureProviderName = "UniversalSignaturePen_ImageOnly";
                Signer2.RecipientSignatureProviders.Add(rspE);
                break;

            case "ds express":
                Signer2.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspD = new RecipientSignatureProvider();
                rspD.SignatureProviderName = "UniversalSignaturePen_Default";
                Signer2.RecipientSignatureProviders.Add(rspD);
                break;

            case "ds aes ac":
                Signer2.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspAESAC = new RecipientSignatureProvider();
                rspAESAC.SignatureProviderName    = "UniversalSignaturePen_OpenTrust_Hash_TSP";
                rspAESAC.SignatureProviderOptions = new RecipientSignatureProviderOptions();
                rspAESAC.SignatureProviderOptions.OneTimePassword = envelope.dsSigner1AuthNumber;
                Signer2.RecipientSignatureProviders.Add(rspAESAC);
                break;

            case "ds aes sms":
                Signer2.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspAESSMS = new RecipientSignatureProvider();
                rspAESSMS.SignatureProviderName        = "UniversalSignaturePen_OpenTrust_Hash_TSP";
                rspAESSMS.SignatureProviderOptions     = new RecipientSignatureProviderOptions();
                rspAESSMS.SignatureProviderOptions.Sms = "+" + envelope.dsSigner1AuthNumber;
                Signer2.RecipientSignatureProviders.Add(rspAESSMS);
                break;

            case "dsa":
                Signer2.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspDSA = new RecipientSignatureProvider();
                rspDSA.SignatureProviderName = "universalsignaturepen_docusignsigningappliance_tsp";
                Signer2.RecipientSignatureProviders.Add(rspDSA);
                break;

            case "id now":
                Signer2.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspIDNOW = new RecipientSignatureProvider();
                rspIDNOW.SignatureProviderName = "UniversalSignaturePen_IDNow_TSP";
                Signer2.RecipientSignatureProviders.Add(rspIDNOW);
                break;

            case "us piv":
                Signer2.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspUSPIV = new RecipientSignatureProvider();
                rspUSPIV.SignatureProviderName = "UniversalSignaturePen_PIV_Test_TSP";
                Signer2.RecipientSignatureProviders.Add(rspUSPIV);
                break;

            case "it agile":
                Signer2.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspAgile = new RecipientSignatureProvider();
                rspAgile.SignatureProviderName = "UniversalSignaturePen_ItAgile_TSP";
                Signer2.RecipientSignatureProviders.Add(rspAgile);
                break;

            case "icp":
                Signer2.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspICP = new RecipientSignatureProvider();
                rspICP.SignatureProviderName = "UniversalSignaturePen_ICP_SmartCard_TSP";
                Signer2.RecipientSignatureProviders.Add(rspICP);
                break;

            case "ds smart card":
                Signer2.RecipientSignatureProviders = new List <RecipientSignatureProvider>();
                RecipientSignatureProvider rspSMART = new RecipientSignatureProvider();
                rspSMART.SignatureProviderName = "universalsignaturepen_ds_smartcard_tsp";
                Signer2.RecipientSignatureProviders.Add(rspSMART);
                break;

            default:
                break;
            }

            it.Recipients.Signers.Add(Signer1);
            if (Signer2.Email != "")
            {
                it.Recipients.Signers.Add(Signer2);
            }

            st.TemplateId = envelope.dsTemplateId;

            ct.ServerTemplates.Add(st);
            ct.InlineTemplates.Add(it);

            envDef.CompositeTemplates.Add(ct);

            envDef.Status = "sent";

            string json = JsonConvert.SerializeObject(envDef, Formatting.Indented);

            System.Diagnostics.Debug.Write(json);

            ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");

            Configuration.Default.ApiClient = apiClient;
            envelope.dsAuthHeader           = "{\"Username\":\"" + envelope.dsUser + "\", \"Password\":\"" + envelope.dsPassword + "\", \"IntegratorKey\":\"49cfeb67-7406-4cef-bac9-7594a8802986\"}";
            Configuration.Default.DefaultHeader.Remove("X-DocuSign-Authentication");
            Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", envelope.dsAuthHeader);

            TemplatesApi     tempApi  = new TemplatesApi();
            EnvelopeTemplate tempInfo = tempApi.Get(envelope.dsAccountId, envelope.dsTemplateId);
            string           brandId  = tempInfo.BrandId;

            AccountsApi acctApi   = new AccountsApi();
            Brand       brandInfo = acctApi.GetBrand(envelope.dsAccountId, brandId);

            foreach (var key in brandInfo.Colors)
            {
                if (key.Name == "headerBackground")
                {
                    envelope.dsHeaderColor = key.Value;
                }
                if (key.Name == "headerText")
                {
                    envelope.dsFontColor = key.Value;
                }
            }
            if (envelope.dsHeaderColor == "")
            {
                envelope.dsHeaderColor = "#5376B7";
            }
            if (envelope.dsFontColor == "")
            {
                envelope.dsFontColor = "#FFFFFF";
            }

            EnvelopesApi envelopesApi = new EnvelopesApi();

            EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(envelope.dsAccountId, envDef);

            envelope.dsEnvelopeId = envelopeSummary.EnvelopeId;

            using (StreamWriter file = File.CreateText(Server.MapPath("~/json/" + envelope.dsEnvelopeId + ".json")))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, envDef);
            }

            if (Signer1.ClientUserId != null && Signer2.ClientUserId != null)
            {
                RecipientViewRequest viewOptions = new RecipientViewRequest()
                {
                    ReturnUrl            = "https://innov8ive.app/hmd/signer2start.aspx",
                    ClientUserId         = envelope.dsSigner1CID,
                    AuthenticationMethod = "email",
                    UserName             = Signer1.Name,
                    Email = Signer1.Email
                };

                ViewUrl recipientView = envelopesApi.CreateRecipientView(envelope.dsAccountId, envelope.dsEnvelopeId, viewOptions);

                Response.Redirect(recipientView.Url);
            }
            else if (Signer1.ClientUserId != null && Signer2.ClientUserId == null)
            {
                RecipientViewRequest viewOptions = new RecipientViewRequest()
                {
                    ReturnUrl            = "https://innov8ive.app/hmd/status.aspx",
                    ClientUserId         = envelope.dsSigner1CID,
                    AuthenticationMethod = "email",
                    UserName             = Signer1.Name,
                    Email = Signer1.Email
                };

                ViewUrl recipientView = envelopesApi.CreateRecipientView(envelope.dsAccountId, envelope.dsEnvelopeId, viewOptions);

                Response.Redirect(recipientView.Url);
            }
            else
            {
                Response.Redirect("~/status.aspx");
            }
        }
Пример #18
0
 public void TestInitialize()
 {
     _testConfig = new TestConfig();
     JwtLoginMethod.RequestJWTUserToken_CorrectInputParameters_ReturnsOAuthToken(ref _testConfig);
     _templatesApi = new TemplatesApi(_testConfig.ApiClient);
 }
Пример #19
0
        private void SendPersonalEnvelope(DocuSignApiConfiguration loginInfo,
                                          List <FieldDTO> rolesList, List <FieldDTO> fieldList, string curTemplateId, string[] names)
        {
            var          templatesApi = new TemplatesApi(loginInfo.Configuration);
            EnvelopesApi envelopesApi = new EnvelopesApi(loginInfo.Configuration);

            var template = templatesApi.ListTemplates(loginInfo.AccountId).EnvelopeTemplates.Where(x => x.Name.Contains("Personnel")).FirstOrDefault();



            EnvelopeDefinition envDef = new EnvelopeDefinition();

            envDef.EmailSubject = "Test message from Fr8";
            envDef.TemplateId   = template.TemplateId;


            envDef.Status = "created";

            var summ = envelopesApi.CreateEnvelope(loginInfo.AccountId, envDef);

            var recipients         = envelopesApi.ListRecipients(loginInfo.AccountId, summ.EnvelopeId);
            var recipientId        = recipients.Signers[0].RecipientId;
            var documentId         = envelopesApi.ListDocuments(loginInfo.AccountId, summ.EnvelopeId).EnvelopeDocuments[0].DocumentId;
            var tabs               = envelopesApi.ListTabs(loginInfo.AccountId, summ.EnvelopeId, recipientId);
            var templateRecepients = templatesApi.ListRecipients(loginInfo.AccountId, curTemplateId);

            tabs.SignHereTabs.FirstOrDefault().RecipientId = recipientId;
            envelopesApi.UpdateTabs(loginInfo.AccountId, summ.EnvelopeId, recipientId, tabs);
            tabs.SignHereTabs = null;


            tabs.TextTabs     = new List <Text>();
            tabs.CheckboxTabs = new List <Checkbox>();

            int i = 0;


            foreach (var person in names)
            {
                var textTab1 = JsonConvert.DeserializeObject <Text>(Tab1);
                var checkBox = JsonConvert.DeserializeObject <Checkbox>(checkBox1);
                var textTab2 = JsonConvert.DeserializeObject <Text>(Tab2);

                textTab1.YPosition = UpdateHeight(textTab1.YPosition, i);
                checkBox.YPosition = UpdateHeight(checkBox.YPosition, i);
                textTab2.YPosition = UpdateHeight(textTab2.YPosition, i);
                textTab1.Value     = person;
                textTab1.TabId     = "";
                checkBox.TabId     = "";
                textTab2.TabId     = "";

                textTab1.Name     = "Name " + i;
                textTab1.TabLabel = textTab1.Name;
                checkBox.Name     = "Present " + i;
                checkBox.TabLabel = checkBox.Name;
                textTab2.Name     = "Zombies " + i;
                textTab2.TabLabel = textTab2.Name;

                textTab1.RecipientId = recipientId;
                checkBox.RecipientId = recipientId;
                textTab2.RecipientId = recipientId;

                tabs.TextTabs.Add(textTab1);
                tabs.TextTabs.Add(textTab2);
                tabs.CheckboxTabs.Add(checkBox);

                i++;
            }

            foreach (var recepient in recipients.Signers)
            {
                var    corresponding_template_recipient = templateRecepients.Signers.Where(a => a.RoutingOrder == recepient.RoutingOrder).FirstOrDefault();
                var    related_fields = rolesList.Where(a => a.Tags.Contains("recipientId:" + corresponding_template_recipient.RecipientId));
                string new_email      = related_fields.Where(a => a.Key.Contains("role email")).FirstOrDefault().Value;
                string new_name       = related_fields.Where(a => a.Key.Contains("role name")).FirstOrDefault().Value;
                recepient.Name  = string.IsNullOrEmpty(new_name) ? recepient.Name : new_name;
                recepient.Email = string.IsNullOrEmpty(new_email) ? recepient.Email : new_email;
            }

            envelopesApi.UpdateRecipients(loginInfo.AccountId, summ.EnvelopeId, recipients);

            envelopesApi.CreateTabs(loginInfo.AccountId, summ.EnvelopeId, recipientId, tabs);
            // sending an envelope
            envelopesApi.Update(loginInfo.AccountId, summ.EnvelopeId, new Envelope()
            {
                Status = "sent"
            });
        }
Пример #20
0
        public IEnumerable <KeyValueDTO> GetTemplateRecipientsAndTabs(DocuSignApiConfiguration conf, string templateId)
        {
            var tmpApi = new TemplatesApi(conf.Configuration);

            return(GetRecipientsAndTabs(conf, tmpApi, templateId));
        }
Пример #21
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            string serverpath     = Server.MapPath(".");
            string signerClientId = "1000";

            StreamReader sr = new StreamReader(serverpath + @"\privatekey2.txt");

            DS_PRIVATE_KEY = sr.ReadToEnd();
            sr.Close();

            ApiClient APClient = new ApiClient();

            OAuth.OAuthToken authToken = APClient.RequestJWTUserToken(DS_CLIENT_ID,
                                                                      DS_IMPERSONATED_USER_GUID,
                                                                      DS_AUTH_SERVER,
                                                                      Encoding.UTF8.GetBytes(DS_PRIVATE_KEY),
                                                                      1);

            AccessToken = authToken.access_token;

            APClient.SetOAuthBasePath(DS_AUTH_SERVER);
            OAuth.UserInfo UserInfoGet = APClient.GetUserInfo(authToken.access_token);

            AccountIDVar = UserInfoGet.Accounts[0].AccountId;
            APClient     = new ApiClient(UserInfoGet.Accounts[0].BaseUri + "/restapi");
            APClient.Configuration.AccessToken = AccessToken;

            TemplatesApi tempAPI  = new TemplatesApi(APClient.Configuration);
            var          template = tempAPI.ListTemplates(AccountIDVar).EnvelopeTemplates.First(x => x.Name == "Steady Property");

            Text LblTxtName = new Text
            {
                TabLabel = "TxtName",
                Value    = TxtName.Text
            };

            Text LblTxtEmail = new Text
            {
                TabLabel = "TxtEmail",
                Value    = TxtEmail.Text
            };

            Text LblTxtDOB = new Text
            {
                TabLabel = "TxtDOB",
                Value    = TxtDOB.Text
            };

            string GenderValue = "";

            GenderValue = RbMale.Checked ? "Male" : "Female";

            Text LblTxtGender = new Text
            {
                TabLabel = "TxtGender",
                Value    = GenderValue
            };

            Text LblTxtPhone = new Text
            {
                TabLabel = "TxtPhone",
                Value    = TxtPhone.Text
            };

            Text LblTxtAddress = new Text
            {
                TabLabel = "TxtAddress",
                Value    = TxtAddress.Text
            };

            Text LblTxtMember = new Text
            {
                TabLabel = "TxtMember",
                Value    = DropMember.Text
            };

            Tabs tabs = new Tabs
            {
                TextTabs = new List <Text> {
                    LblTxtName, LblTxtEmail, LblTxtDOB, LblTxtGender, LblTxtPhone, LblTxtAddress, LblTxtMember
                }
            };

            TemplateRole signer = new TemplateRole
            {
                Email             = TxtEmail.Text,
                Name              = TxtName.Text,
                RoleName          = "Signer1",
                ClientUserId      = signerClientId,
                EmailNotification = new RecipientEmailNotification
                {
                    EmailSubject = "Please sign the membership form",
                    EmailBody    = "Dear " + TxtName.Text + @", <br><br>Please sign the membership form and we will process your application form." +
                                   @"<br>You will recieve email confirmation within 48 hours<br><br>Thank you <br>Steady Property"
                },
                Tabs = tabs                 //Set tab values
            };

            TemplateRole cc = new TemplateRole
            {
                Email             = TxtEmail.Text,
                Name              = TxtName.Text,
                EmailNotification = new RecipientEmailNotification
                {
                    EmailSubject = "Membership registation completed",
                    EmailBody    = "Dear " + TxtName.Text + @", <br><br>We will process your application form." +
                                   @"<br>You will recieve email confirmation within 48 hours<br><br>Thank you <br>Steady Property"
                },
                RoleName = "cc"
            };

            TemplateRole radmin = new TemplateRole
            {
                Email             = "*****@*****.**",
                Name              = "Harry Tim",
                EmailNotification = new RecipientEmailNotification
                {
                    EmailSubject = "New member registraion notification",
                    EmailBody    = "Dear Admin, <br><br>New membership registration for : " + TxtName.Text +
                                   @"<br>Please process it within 48 hours<br><br>Thank you <br>Steady Property"
                },
                RoleName = "admin"
            };

            EnvelopeDefinition envelopeAttributes = new EnvelopeDefinition
            {
                TemplateId    = "5aa70f7a-7a21-496b-9f24-ada8431cf93b",
                Status        = "Sent",
                TemplateRoles = new List <TemplateRole> {
                    signer, cc, radmin
                }
            };

            EnvelopesApi    envelopesApi = new EnvelopesApi(APClient.Configuration);
            EnvelopeSummary results      = envelopesApi.CreateEnvelope(AccountIDVar, envelopeAttributes);

            RecipientViewRequest viewRequest = new RecipientViewRequest();

            viewRequest.ReturnUrl = "https://localhost:44387/Confirm.aspx" + "?envelopeid=" + results.EnvelopeId;

            viewRequest.AuthenticationMethod = "none";

            viewRequest.Email        = TxtEmail.Text;
            viewRequest.UserName     = TxtName.Text;
            viewRequest.ClientUserId = signerClientId;

            viewRequest.PingFrequency = "600";             // seconds
            // NOTE: The pings will only be sent if the pingUrl is an HTTPS address
            viewRequest.PingUrl = "https://localhost";     // Optional setting

            ViewUrl results1 = envelopesApi.CreateRecipientView(AccountIDVar, results.EnvelopeId, viewRequest);

            Response.Redirect(results1.Url);
        }
Пример #22
0
        public void SendAnEnvelopeFromTemplate(DocuSignApiConfiguration loginInfo, List <KeyValueDTO> rolesList, List <KeyValueDTO> fieldList, string curTemplateId, StandardFileDescriptionCM fileHandler = null)
        {
            EnvelopesApi    envelopesApi      = new EnvelopesApi(loginInfo.Configuration);
            TemplatesApi    templatesApi      = new TemplatesApi(loginInfo.Configuration);
            bool            override_document = fileHandler != null;
            Recipients      recipients        = null;
            EnvelopeSummary envelopeSummary   = null;

            //creatig an envelope definiton
            EnvelopeDefinition envDef = new EnvelopeDefinition();

            envDef.EmailSubject = "Test message from Fr8";
            envDef.Status       = "created";

            Debug.WriteLine($"sending an envelope from template {curTemplateId} to {loginInfo}");
            var templateRecepients = templatesApi.ListRecipients(loginInfo.AccountId, curTemplateId);

            //adding file or applying template
            if (override_document)
            {
                //if we override document - we don't create an envelope yet
                //we create it with recipients once we've processed recipient values and tabs
                envDef.Documents = new List <Document>()
                {
                    new Document()
                    {
                        DocumentBase64 = fileHandler.TextRepresentation, FileExtension = fileHandler.Filetype,
                        DocumentId     = "1", Name = fileHandler.Filename ?? Path.GetFileName(fileHandler.DirectUrl) ?? "document"
                    }
                };
                recipients = templateRecepients;
            }
            else
            {
                //creating envelope
                envDef.TemplateId = curTemplateId;
                envelopeSummary   = envelopesApi.CreateEnvelope(loginInfo.AccountId, envDef);
                //requesting list of recipients since their Ids might be different from the one we got from tempates
                recipients = envelopesApi.ListRecipients(loginInfo.AccountId, envelopeSummary.EnvelopeId);
            }

            //updating recipients
            foreach (var recepient in recipients.Signers)
            {
                var correspondingTemplateRecipient = templateRecepients.Signers.FirstOrDefault(a => a.RoutingOrder == recepient.RoutingOrder);
                var relatedFields = rolesList.Where(a => a.Tags.Contains("recipientId:" + correspondingTemplateRecipient?.RecipientId)).ToArray();
                var newEmail      = relatedFields.FirstOrDefault(a => a.Key.Contains(DocuSignConstants.DocuSignRoleEmail))?.Value;
                var newName       = relatedFields.FirstOrDefault(a => a.Key.Contains(DocuSignConstants.DocuSignRoleName))?.Value;
                recepient.Name  = string.IsNullOrEmpty(newName) ? recepient.Name : newName;
                recepient.Email = string.IsNullOrEmpty(newEmail) ? recepient.Email : newEmail;

                if (!recepient.Email.IsValidEmailAddress())
                {
                    throw new ApplicationException($"'{recepient.Email}' is not a valid email address");
                }

                //updating tabs
                var tabs = override_document ? templatesApi.ListTabs(loginInfo.AccountId, curTemplateId, correspondingTemplateRecipient.RecipientId, new Tabs()) : envelopesApi.ListTabs(loginInfo.AccountId, envelopeSummary.EnvelopeId, recepient.RecipientId);

                JObject jobj = DocuSignTab.ApplyValuesToTabs(fieldList, correspondingTemplateRecipient, tabs);
                recepient.Tabs = jobj.ToObject <Tabs>();
            }

            if (override_document)
            {
                //deep copy to exclude tabs
                var recps_deep_copy = JsonConvert.DeserializeObject <Recipients>(JsonConvert.SerializeObject(recipients));
                recps_deep_copy.Signers.ForEach(a => a.Tabs = null);
                envDef.Recipients = recps_deep_copy;
                //creating envlope
                envelopeSummary = envelopesApi.CreateEnvelope(loginInfo.AccountId, envDef);
            }
            else
            {
                envelopesApi.UpdateRecipients(loginInfo.AccountId, envelopeSummary.EnvelopeId, recipients);
            }

            foreach (var recepient in recipients.Signers)
            {
                if (override_document)
                {
                    JObject jobj = JObject.Parse(recepient.Tabs.ToJson());
                    foreach (var item in jobj.Properties())
                    {
                        foreach (var tab in (JToken)item.Value)
                        {
                            tab["documentId"] = "1";
                        }
                    }
                    var tabs = jobj.ToObject <Tabs>();
                    envelopesApi.CreateTabs(loginInfo.AccountId, envelopeSummary.EnvelopeId, recepient.RecipientId, tabs);
                }
                else
                if (typeof(Tabs).GetProperties()
                    .Select(prop => prop.GetValue(recepient.Tabs, null))
                    .Any(val => val != null))
                {
                    envelopesApi.UpdateTabs(loginInfo.AccountId, envelopeSummary.EnvelopeId, recepient.RecipientId, recepient.Tabs);
                }
            }

            // sending an envelope
            envelopesApi.Update(loginInfo.AccountId, envelopeSummary.EnvelopeId, new Envelope()
            {
                Status = "sent"
            });
        }
        public override async Task Run()
        {
            DocuSignEnvelopeCM_v2 envelopeStatus = null;
            var eventCrate = Payload.CratesOfType <EventReportCM>().FirstOrDefault()?.Get <EventReportCM>()?.EventPayload;

            if (eventCrate != null)
            {
                envelopeStatus = eventCrate.CrateContentsOfType <DocuSignEnvelopeCM_v2>().SingleOrDefault();
            }

            if (envelopeStatus == null)
            {
                RequestPlanExecutionTermination("Evelope was not found in the payload.");
                return;
            }

            //Create run-time fields
            var eventFields = CreateDocuSignEventValues(envelopeStatus);

            //get currently selected option and its value
            string curSelectedOption, curSelectedValue, curSelectedTemplate;

            GetTemplateRecipientPickerValue(out curSelectedOption, out curSelectedValue, out curSelectedTemplate);
            var envelopeId = string.Empty;

            //retrieve envelope ID based on the selected option and its value
            if (!string.IsNullOrEmpty(curSelectedOption))
            {
                switch (curSelectedOption)
                {
                case "template":
                    //filter the incoming envelope by template value selected by the user
                    var incomingTemplate = string.Join(",", envelopeStatus.Templates.Select(t => t.Name).ToArray());

                    //Dirty quick fix for FR-2858
                    if (string.IsNullOrEmpty(incomingTemplate))
                    {
                        var          manager       = new DocuSignManager();
                        var          config        = manager.SetUp(AuthorizationToken);
                        TemplatesApi api           = new TemplatesApi(config.Configuration);
                        var          templateslist = api.ListTemplates(config.AccountId);
                        if (templateslist.TotalSetSize == "0")
                        {
                            break;
                        }
                        incomingTemplate = string.Join(",", templateslist.EnvelopeTemplates.Select(a => a.Name).ToArray());
                    }

                    if (incomingTemplate.Contains(curSelectedTemplate, StringComparison.InvariantCultureIgnoreCase))
                    {
                        envelopeId = envelopeStatus.EnvelopeId;
                    }
                    else
                    {
                        //this event isn't about us let's stop execution
                        RequestPlanExecutionTermination();
                        return;
                    }

                    break;

                case "recipient":

                    string envelopeCurentRecipientEmail = eventFields.FirstOrDefault(a => a.Key == "CurrentRecipientEmail")?.Value;
                    //filter incoming envelope by recipient email address specified by the user
                    if (envelopeCurentRecipientEmail != null)
                    {
                        //if the incoming envelope's recipient is user specified one, get the envelope ID
                        if (envelopeCurentRecipientEmail.Contains(curSelectedValue, StringComparison.InvariantCultureIgnoreCase))
                        {
                            envelopeId = envelopeStatus.EnvelopeId;
                        }
                        else
                        {
                            //this event isn't about us let's stop execution
                            RequestPlanExecutionTermination();
                            return;
                        }
                    }
                    break;
                }
            }

            var allFields = new List <KeyValueDTO>(eventFields);

            if (curSelectedOption == "template")
            {
                allFields.AddRange(GetEnvelopeData(envelopeId));
                allFields.Add(new KeyValueDTO("TemplateName", curSelectedTemplate));
            }

            Payload.Add(AllFieldsCrateName, new StandardPayloadDataCM(allFields));

            Success();
        }
Пример #24
0
 public TemplatesApiTests()
 {
     instance = new TemplatesApi();
 }