Exemplo n.º 1
0
        public CreateEnvelopeResponse CreateEnvelope(
            DocumentType type,
            string accountId,
            string userId,
            LoginType loginType,
            UserDetails additionalUser,
            string redirectUrl,
            string pingAction)
        {
            if (accountId == null)
            {
                throw new ArgumentNullException(nameof(accountId));
            }
            if (userId == null)
            {
                throw new ArgumentNullException(nameof(userId));
            }

            string      rootDir     = _configuration.GetValue <string>(WebHostDefaults.ContentRootKey);
            UserDetails userDetails = _userService.GetUserDetails(accountId, userId, loginType);

            var templateHandler = GetTemplateHandler(type);
            EnvelopeTemplate   envelopeTemplate = templateHandler.BuildTemplate(rootDir);
            EnvelopeDefinition envelope         = templateHandler.BuildEnvelope(userDetails, additionalUser);

            if (type == DocumentType.I9 && loginType == LoginType.JWT)
            {
                EnableIDV(accountId, envelopeTemplate, "New Hire");
            }

            var listTemplates         = _docuSignApiProvider.TemplatesApi.ListTemplates(accountId);
            EnvelopeTemplate template = listTemplates?.EnvelopeTemplates?.FirstOrDefault(x => x.Name == templateHandler.TemplateName);

            if (template != null)
            {
                envelope.TemplateId = template.TemplateId;
            }
            else
            {
                TemplateSummary templateSummary = _docuSignApiProvider.TemplatesApi.CreateTemplate(accountId, envelopeTemplate);
                envelope.TemplateId = templateSummary.TemplateId;
            }
            EnvelopeSummary envelopeSummary = _docuSignApiProvider.EnvelopApi.CreateEnvelope(accountId, envelope);

            if (type != DocumentType.I9)
            {
                ViewUrl recipientView = _docuSignApiProvider.EnvelopApi.CreateRecipientView(
                    accountId,
                    envelopeSummary.EnvelopeId,
                    BuildRecipientViewRequest(
                        userDetails.Email,
                        userDetails.Name,
                        redirectUrl,
                        pingAction)
                    );
                return(new CreateEnvelopeResponse(recipientView.Url, envelopeSummary.EnvelopeId));
            }

            return(new CreateEnvelopeResponse(string.Empty, envelopeSummary.EnvelopeId));
        }
Exemplo n.º 2
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);
        }
        /// <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);
        }
        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);
            }
        }