在服务器模板上带有选项卡的 C# DocusignAPI 复合模板

C# DocusignAPI Composite template with tabs on server template

我正在使用 Embedded Signing Ceremony from a template with an added document code example 13 and am trying to add tabs to my composite template. I have added some test fields and values as is from the code examples (on this page) 预填充我的服务器模板。但是在测试时这些值没有显示在收件人视图中。

抱歉,如果这是一个简单的问题。但是有人可以帮我解决我可能遗漏或配置错误的问题吗?

这是我现在正在为此测试的 C# 代码。

public Eg013AddDocToTemplateController(DSConfiguration config, IRequestItemsService requestItemsService) 
    : base(config, requestItemsService)
{
}

public override string EgName => "eg013";

// ***DS.snippet.0.start
private string DoWork(string signerEmail, string signerName, string ccEmail,
    string ccName, string accessToken, string basePath,
    string accountId, string item, string quantity, string dsReturnUrl)
{
    // Data for this method
    // signerEmail 
    // signerName
    // ccEmail
    // ccName
    // item
    // quantity
    // accessToken
    // basePath 
    // accountId 
    // dsReturnUrl
    var config = new Configuration(new ApiClient(basePath));
    config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
    EnvelopesApi envelopesApi = new EnvelopesApi(config);

    // Step 1. Make the envelope request body
    EnvelopeDefinition envelope = MakeEnvelope(signerEmail, signerName, ccEmail, ccName, item, quantity);

    // Step 2. call Envelopes::create API method
    // Exceptions will be caught by the calling function
    EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelope);
    String envelopeId = results.EnvelopeId;
    Console.WriteLine("Envelope was created. EnvelopeId " + envelopeId);

    // Step 3. create the recipient view, the Signing Ceremony
    RecipientViewRequest viewRequest = MakeRecipientViewRequest(signerEmail, signerName, dsReturnUrl);
    ViewUrl results1 = envelopesApi.CreateRecipientView(accountId, envelopeId, viewRequest);
    return results1.Url;
}


private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string signerName, 
    string dsReturnUrl)
{
    // Data for this method
    // signerEmail 
    // signerName
    // dsReturnUrl
    // signerClientId -- class global

    RecipientViewRequest viewRequest = new RecipientViewRequest
    {
        // Set the url where you want the recipient to go once they are done signing
        // should typically be a callback route somewhere in your app.
        ReturnUrl = dsReturnUrl,

        // How has your app authenticated the user? In addition to your app's
        // authentication, you can include authenticate steps from DocuSign.
        // Eg, SMS authentication
        AuthenticationMethod = "none",

        // Recipient information must match embedded recipient info
        // we used to create the envelope.
        Email = signerEmail,
        UserName = signerName,
        ClientUserId = signerClientId
    };

    // DocuSign recommends that you redirect to DocuSign for the
    // Signing Ceremony. There are multiple ways to save state.

    return viewRequest;
}

private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, string ccEmail, 
    string ccName, string item, string quantity)
{
    // Data for this method
    // signerEmail 
    // signerName
    // ccEmail
    // ccName
    // item
    // quantity
    // signerClientId -- class global


    // The envelope request object uses Composite Template to
    // include in the envelope:
    // 1. A template stored on the DocuSign service
    // 2. An additional document which is a custom HTML source document

    // Create Recipients for server template. Note that Recipients object
    // is used, not TemplateRole
    //
    // Create a signer recipient for the signer role of the server template
    Signer signer1 = new Signer
    {
        Email = signerEmail,
        Name = signerName,
        RoleName = "signer",
        RecipientId = "1",
        // Adding clientUserId transforms the template recipient
        // into an embedded recipient:
        ClientUserId = signerClientId
    };
    // Create the cc recipient
    CarbonCopy cc1 = new CarbonCopy
    {
        Email = ccEmail,
        Name = ccName,
        RoleName = "cc",
        RecipientId = "2"
    };
    // Recipients object:
    Recipients recipientsServerTemplate = new Recipients
    {
        CarbonCopies = new List<CarbonCopy> { cc1 },
        Signers = new List<Signer> { signer1 }
    };

    // create a composite template for the Server Template
    CompositeTemplate compTemplate1 = new CompositeTemplate
    {
        CompositeTemplateId = "1"
    };
    ServerTemplate serverTemplates = new ServerTemplate
    {
        Sequence = "1",
        TemplateId = RequestItemsService.TemplateId
    };

    compTemplate1.ServerTemplates = new List<ServerTemplate> { serverTemplates };
    // Add the roles via an inlineTemplate
    InlineTemplate inlineTemplate = new InlineTemplate
    {
        Sequence = "2",
        Recipients = recipientsServerTemplate
    };
    compTemplate1.InlineTemplates = new List<InlineTemplate> { inlineTemplate };
    // The signer recipient for the added document with
    // a tab definition:
    SignHere signHere1 = new SignHere
    {
        AnchorString = "**signature_1**",
        AnchorYOffset = "10",
        AnchorUnits = "pixels",
        AnchorXOffset = "20"
    };

    Text textLegal = new Text
    {
        AnchorString = "/legal/",
        AnchorUnits = "pixels",
        AnchorYOffset = "-9",
        AnchorXOffset = "5",
        Font = "helvetica",
        FontSize = "size11",
        Bold = "true",
        Value = "Legal Name",
        Locked = "false",
        TabId = "legal_name",
        TabLabel = "text",
    };

    Text textFamiliar = new Text
    {
        AnchorString = "/familiar/",
        AnchorUnits = "pixels",
        AnchorYOffset = "-9",
        AnchorXOffset = "5",
        Font = "helvetica",
        FontSize = "size11",
        Bold = "true",
        Value = signerName,
        Locked = "false",
        TabId = "familiar_name",
        TabLabel = "Familiar name"
    };

    // The salary is set both as a readable number in the /salary/ text field,
    // and as a pure number in a custom field ('salary') in the envelope
    int salary = 123000;

    Text textSalary = new Text
    {
        AnchorString = "/salary/",
        AnchorUnits = "pixels",
        AnchorYOffset = "-9",
        AnchorXOffset = "5",
        Font = "helvetica",
        FontSize = "size11",
        Bold = "true",
        Locked = "true",
        // Convert number to String: 'C2' sets the string 
        // to currency format with two decimal places
        Value = salary.ToString("C2"),
        TabId = "salary",
        TabLabel = "Salary"
    };


    Tabs signer1Tabs = new Tabs
    {
        SignHereTabs = new List<SignHere> { signHere1 }
    };
    // Signer definition for the added document
    Signer signer1AddedDoc = new Signer
    {
        Email = signerEmail,
        Name = signerName,
        ClientUserId = signerClientId,
        RoleName = "signer",
        RecipientId = "1",
        Tabs = signer1Tabs
    };
    // Recipients object for the added document:
    Recipients recipientsAddedDoc = new Recipients
    {
        CarbonCopies = new List<CarbonCopy> { cc1 },
        Signers = new List<Signer> { signer1AddedDoc }
    };

    // create the HTML document
    Document doc1 = new Document();
    
    String doc1b64 = Convert.ToBase64String(document1(signerEmail, signerName, ccEmail, ccName, item, quantity));
    doc1.DocumentBase64 = doc1b64;
    doc1.Name = "Membership form"; // can be different from actual file name
    doc1.FileExtension = "html";
    doc1.DocumentId = "1";
    // create a composite template for the added document
    CompositeTemplate compTemplate2 = new CompositeTemplate
    {
        CompositeTemplateId = "1"
    };
    // Add the recipients via an inlineTemplate
    InlineTemplate inlineTemplate2 = new InlineTemplate
    {
        Sequence = "2",
        Recipients = recipientsAddedDoc
    };
    compTemplate2.InlineTemplates = new List<InlineTemplate> { inlineTemplate2};
    compTemplate2.Document = doc1;

    EnvelopeDefinition env = new EnvelopeDefinition
    {
        Status = "sent",
        CompositeTemplates = new List<CompositeTemplate> { compTemplate1, compTemplate2 }
    };

    return env;
}

您创建了很多选项卡,但尚未将它们分配给相关签名者。

Tabs signer1Tabs = new Tabs
{
    SignHereTabs = new List<SignHere> { signHere1 }
};

在 SignHereTabs 行下,您需要添加

TextTabs = new List<Text> { }

所有文本标签都在花括号之间。

附带说明一下,如果您要填写的标签在服务器模板上,您只需要 tabLabelvalue 参数来填充它们。应删除任何其他参数。但是,如果您要在 API 调用中添加新选项卡,那么您所拥有的就是正确的。