C#.net

时间:2016-07-15 08:03:43

标签: c# docusignapi

使用DocuSign Api签署文件。现在我在DocuSign中创建了模板并在那里上传了PDF。

现在,当用户点击提交时,我们需要自动填充docusign pdf,并且我没有在docusign添加自定义字段,它应该是动态的。以下是无效的代码。

 public string SignDocument()
            {
                var accountId = Login();
                var url = GetRecipientDocumentUrl(accountId);
                return url;
            }
    private string Login()
            {

                string authHeader = "{\"Username\":\"" + Username + "\", \"Password\":\"" + Password + "\", \"IntegratorKey\":\"" + IntegratorKey + "\"}";
                DocuSign.eSign.Client.Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

                // we will retrieve this from the login() results
                string accountId = null;

                // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
                var authApi = new AuthenticationApi();
                LoginInformation loginInfo = authApi.Login();

                // find the default account for this user
                foreach (LoginAccount loginAcct in loginInfo.LoginAccounts)
                {
                    if (loginAcct.IsDefault == "true")
                    {
                        accountId = loginAcct.AccountId;
                        break;
                    }
                }
                if (accountId == null)
                { // if no default found set to first account
                    accountId = loginInfo.LoginAccounts[0].AccountId;
                }
                return accountId;
            }
    private string GetRecipientDocumentUrl(string accountId)
            {
                //var envelope = BuildEnvelopeDefinition(documents);
                var envelope = BuildEnvelopeDefinition();
                // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
                var envelopesApi = new EnvelopesApi();
                //TemplateCustomFields 
                var summary = envelopesApi.CreateEnvelope(accountId, envelope);
                //===========================================================
                // Step 3: Create Embedded Signing View (URL)
                //===========================================================
                var viewOptions = BuildRecipientViewRequest(envelope);
                var recipientView = envelopesApi.CreateRecipientView(accountId, summary.EnvelopeId, viewOptions);
                return recipientView.Url;
            }

    private EnvelopeDefinition BuildEnvelopeDefinition()
            {

                TemplateRole templateRole = new TemplateRole();
                templateRole.Email = "kpothireddy@firstam.com";
                templateRole.Name = "Sample";
                templateRole.RoleName = "1";


                templateRole.Tabs = new Tabs();
                templateRole.Tabs.TextTabs = new List<Text>();
                Text textTab = new Text();
                textTab.TabLabel = "Approved by";
                textTab.Value = "Kranthi";
                //textTab.XPosition = "100";
                //textTab.YPosition = "100";
                templateRole.Tabs.TextTabs.Add(textTab);
                templateRole.ClientUserId = Guid.NewGuid().ToString();

                List<TemplateRole> rolesList = new List<TemplateRole>();
                rolesList.Add(templateRole);
                //rolesList.Add(templateRole1);

                var envelope = new EnvelopeDefinition
                {
                    TemplateRoles = rolesList,
                    //TemplateId = "3b07a774-5ec5-4bbd-928a-a4b0bace2fc5",
                    TemplateId = "44d25c06-4fc3-4cbe-a9d0-7e0e1e3013bc", //Prefill
                    Status = "sent"
                };
                //Envelope e = new Envelope();

                return envelope;
            }
    private RecipientViewRequest BuildRecipientViewRequest(EnvelopeDefinition envelope)
            {
                RecipientViewRequest viewOptions = new RecipientViewRequest()
                {
                    ReturnUrl = ReturnUrl,
                    ClientUserId = envelope.TemplateRoles.First().ClientUserId,  // must match clientUserId set in step #2!
                    AuthenticationMethod = "email",
                    UserName = envelope.TemplateRoles.First().Name,
                    Email = envelope.TemplateRoles.First().Email
                    //UserName = envelope.Recipients.Signers.First().Name,
                    //Email = envelope.Recipients.Signers.First().Email
                };
                return viewOptions;
            }

能帮帮我吗。

0 个答案:

没有答案