我正在使用docusign-csharp-client在我们的应用程序中启用电子签名。
我有一份PDF,需要客户签名以及销售人员的签名。
我们使用C#客户端为客户和销售人员执行嵌入式签名过程。使用C#客户端,我们创建信封,上传要签名的PDF,并将签名者及其信息添加到信封中。一切似乎都在起作用,除非我无法弄清楚如何让签名盒1出现给顾客签名和签名框2以供销售人员签名。
签名框已添加到PDF中。但当双方中的每一方都进入Docusign时,他们中的任何一方都没有签名框。
如何将客户链接到SignatureBox1,将销售人员链接到SignatureBox2?
以下是我为调用Docusign而创建的课程。方法SendContractToDocusign()
启动了这个过程。
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Core.Domain.Models;
using Core.Interfaces;
using DocuSign.eSign.Api;
using DocuSign.eSign.Client;
using DocuSign.eSign.Model;
using Configuration = DocuSign.eSign.Client.Configuration;
namespace Infrastructure.Econtract
{
public class DocuSignContract : IDigitalContract
{
private readonly IConfigurationSettings _configurationSettings;
public DocuSignContract(IConfigurationSettings configurationSettings)
{
_configurationSettings = configurationSettings;
var username = configurationSettings.DocusignUserName;
var password = configurationSettings.DocusignPassword;
var integratorKey = configurationSettings.DocusignIntegratorKey;
var clientRestUrl = configurationSettings.DocusignClientRestUrl;
var apiClient = new ApiClient(clientRestUrl);
Configuration.Default.ApiClient = apiClient;
if (!Configuration.Default.DefaultHeader.ContainsKey("X-DocuSign-Authentication"))
{
// configure 'X-DocuSign-Authentication' header
string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";
Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
}
}
private static string Authenticate()
{
var authApi = new AuthenticationApi();
LoginInformation loginInfo = authApi.Login();
//user might be a member of multiple accounts
string accountId = loginInfo.LoginAccounts[0].AccountId;
return accountId;
}
private static Document CreateDocusignDocument(ContractDocument document)
{
return new Document
{
DocumentBase64 = Convert.ToBase64String(document.Document),
Name = document.FormCode ?? "DocuSignContract.pdf",
DocumentId = document.TrackingIdentity.ToString(),
TransformPdfFields = "false"
};
}
private EnvelopeDefinition CreateEnvelope(Document doc)
{
//Set envelope status to "sent" to instruct Docusign to immediately send the signature request upon receipt
var envDef = new EnvelopeDefinition
{
EmailSubject = "[DocuSignContract] - Please eSign this doc",
Documents = new List<Document> { doc },
Status = "sent"
};
return envDef;
}
private static void AddSigners(EnvelopeDefinition envelope, List<ContractSigner> signers)
{
envelope.Recipients = new Recipients
{
Signers = new List<Signer>()
};
signers.ForEach(x => envelope.Recipients.Signers.Add(
new Signer
{
Name = x.FullName,
Email = x.Email,
RecipientId = ((int)x.Type).ToString(),
ClientUserId = x.UserId
}
));
}
private string SendContractToDocusign(string accountId, EnvelopeDefinition envelope, List<ContractSigner> signers)
{
if (signers == null) throw new ArgumentNullException(nameof(signers));
// Use the EnvelopesApi to create and send the signature request
var envelopesApi = new EnvelopesApi();
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envelope);
return envelopeSummary.EnvelopeId;
}
public async Task<byte[]> GetSignedDocument(string envelopeId)
{
string accountId = Authenticate();
var envelopesApi = new EnvelopesApi();
var docList = await envelopesApi.ListDocumentsAsync(accountId, envelopeId);
using (var docStream = (MemoryStream)envelopesApi.GetDocument(accountId, envelopeId, docList.EnvelopeDocuments[0].DocumentId))
{
return docStream.ToArray();
}
}
public string SendContractToDocusign(ContractDocument contractData, List<ContractSigner> signers)
{
//Authenticate with Docusign and get account Id
string accountId = Authenticate();
//Create Docusign document from contract
Document doc = CreateDocusignDocument(contractData);
//Create an envelope and insert the document
EnvelopeDefinition envelope = CreateEnvelope(doc);
//Add signers
AddSigners(envelope, signers);
//Send the document to docusign
var envelopeId = SendContractToDocusign(accountId, envelope, signers);
return envelopeId;
}
public string GetSigningUrl(string envelopeId, ContractSigner signer, string returnUrl)
{
//Authenticate with Docusign and get account Id
string accountId = Authenticate();
var envelopesApi = new EnvelopesApi();
var viewOptions = new RecipientViewRequest()
{
ReturnUrl = returnUrl,
ClientUserId = signer.UserId,
AuthenticationMethod = "Password",
UserName = signer.FullName,
Email = signer.Email
};
// create the recipient view (aka signing URL)
ViewUrl recipientView = envelopesApi.CreateRecipientView(accountId, envelopeId, viewOptions);
return recipientView.Url;
}
}
}
答案 0 :(得分:0)
如果您使用表单字段的PDF并希望DocuSign自动将您的PDF表单字段转换为DocuSign标签,那么您需要使用DS标准表单字段名称创建PDF。 PDF Transform Standards将帮助您了解PDF表单字段名称应该是什么。
另外,要自动将PDF字段转换为DS标签,您需要添加TransformPdfFields = true
,这告诉DocuSign将PDF字段转换为DS标签。
或者如果您没有使用上述描述方式,则需要使用锚点字符串或X / Y位置添加DS选项卡。 DS在Recipes
处提供了食谱