Skip to content

Devdocs-1187 #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
236 changes: 236 additions & 0 deletions eg-03-csharp-auth-code-grant-core/Controllers/Eg016SetTabValues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
using System;
using System.Collections.Generic;
using DocuSign.eSign.Api;
using DocuSign.eSign.Model;
using eg_03_csharp_auth_code_grant_core.Models;
using Microsoft.AspNetCore.Mvc;
using System.Text;
using DocuSign.eSign.Client;

namespace eg_03_csharp_auth_code_grant_core.Controllers
{
[Route("eg016")]
public class Eg016SetTabValuesController : EgController
{
//Setup the Ping Url, signerClientId, and the
//Return (callback) URL for Embedded Signing Ceremony

private string dsPingUrl;
private readonly string signerClientId = "1000";
private string dsReturnUrl;

public Eg016SetTabValuesController(DSConfiguration config, IRequestItemsService requestItemsService)
: base(config, requestItemsService)
{
ViewBag.title = "SetTabValues";
dsPingUrl = config.AppUrl + "/";
dsReturnUrl = config.AppUrl + "/dsReturn";
}

public override string EgName => "eg016";


[HttpPost]
public IActionResult Create(string signerEmail, string signerName)
{
// Check the token with minimal buffer time.
bool tokenOk = CheckToken(3);
if (!tokenOk)
{
// We could store the parameters of the requested operation so it could be
// restarted automatically. But since it should be rare to have a token issue
// here, we'll make the user re-enter the form data after authentication.
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}

// The envelope will be sent first to the signer.
// After it is signed, a copy is sent to the cc person.
// read files from a local directory
// The reads could raise an exception if the file is not available!

var basePath = RequestItemsService.Session.BasePath + "/restapi";

// Step 1: Obtain your OAuth token
var accessToken = RequestItemsService.User.AccessToken; //represents your {ACCESS_TOKEN}
var accountId = RequestItemsService.Session.AccountId; //represents your {ACCOUNT_ID}

// Step 2: Construct your API headers
var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);

// Step 3: Create Tabs and CustomFields
SignHere signHere = new SignHere
{
AnchorString = "/sn1/",
AnchorUnits = "pixels",
AnchorYOffset = "10",
AnchorXOffset = "20"
};

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

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",
Value = salary.ToString("C2"),
Locked = "true",
TabId = "salary",
TabLabel = "Salary"
};

// The SDK can't create a number tab at this time. Bug DCM-2732
TextCustomField salaryCustomField = new TextCustomField
{
Name = "salary",
Required = "false",
Show = "true", //to view on CoC
Value = salary.ToString()

};

CustomFields cf = new CustomFields
{
TextCustomFields = new List<TextCustomField> { salaryCustomField }
};

// create a signer recipient to sign the document, identified by name and email
// We're setting the parameters via the object creation
Signer signer1 = new Signer
{
Email = signerEmail,
Name = signerName,
RecipientId = "1",
RoutingOrder = "1",
ClientUserId = signerClientId

};

// Add the tabs model (including the SignHere tab) to the signer.
// The Tabs object wants arrays of the different field/tab types
// Tabs are set per recipient / signer
Tabs signer1Tabs = new Tabs
{
SignHereTabs = new List<SignHere> { signHere },
TextTabs = new List<Text> { textLegal, textFamiliar, textSalary }
};
signer1.Tabs = signer1Tabs;

// Add the recipients to the envelope object
Recipients recipients = new Recipients
{
Signers = new List<Signer> { signer1 }
};


string doc1b64 = Convert.ToBase64String(System.IO.File.ReadAllBytes(Config.tabsDocx));

// Create document objects, one per document

Document doc1 = new Document
{
DocumentBase64 = doc1b64,
Name = "Lorem Ipsum", // can be different from actual file name
FileExtension = "docx",
DocumentId = "1"
};

// Step 4: Create the envelope definition.
EnvelopeDefinition envelopeAttributes = new EnvelopeDefinition()
{

EnvelopeIdStamping = "true",
EmailSubject = "Please Sign",
EmailBlurb = "Sample text for email body",
Status = "Sent",
Recipients = recipients,
CustomFields = cf,
Documents = new List<Document> { doc1 }

};

// Step 5: Call the eSignature REST API and subsequent View Request
EnvelopesApi envelopesApi = new EnvelopesApi(config);
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelopeAttributes);

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.
// The query parameter is included as an example of how
// to save/recover state information during the redirect to
// the DocuSign signing ceremony. It's usually better to use
// the session mechanism of your web framework. Query parameters
// can be changed/spoofed very easily.
viewRequest.ReturnUrl = dsReturnUrl + "?state=123";

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

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

// DocuSign recommends that you redirect to DocuSign for the
// Signing Ceremony. There are multiple ways to save state.
// To maintain your application's session, use the pingUrl
// parameter. It causes the DocuSign Signing Ceremony web page
// (not the DocuSign server) to send pings via AJAX to your
// app,
viewRequest.PingFrequency = "600"; // seconds
// NOTE: The pings will only be sent if the pingUrl is an https address
viewRequest.PingUrl = dsPingUrl; // optional setting

ViewUrl results1 = envelopesApi.CreateRecipientView(accountId, results.EnvelopeId, viewRequest);
//***********
// Don't use an iFrame with embedded signing requests!
//***********
// State can be stored/recovered using the framework's session or a
// query parameter on the returnUrl (see the makeRecipientViewRequest method)
string redirectUrl = results1.Url;
return Redirect(redirectUrl);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class DSConfiguration
public string targetAccountId = null;
public string demoDocPath = "demo_documents";
public string docDocx = "World_Wide_Corp_Battle_Plan_Trafalgar.docx";
public string tabsDocx = "World_Wide_Corp_salary.docx";
public string docPdf = "World_Wide_Corp_lorem.pdf";
public string githubExampleUrl = "https://github.com/docusign/eg-03-csharp-auth-code-grant-core/tree/master/eg-03-csharp-auth-code-grant-core/Controllers/";
public string documentation = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

<h4>16. Set tab values for a envelope</h4>
<p>
This example creates an example with both read-only tabs (fields) and tabs that can
be updated by the recipient.
</p>
<p>The example also sets custom metadata in the envelope via the envelope custom fields feature.</p>


@if (ViewBag.showDoc == true)
{
<p><a target='_blank' href='<%= documentation %>'>Documentation</a> about this example.</p>
}

<p>
API method used:
<a target='_blank' href="https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/create">Envelopes::create</a>.
</p>

<p>
View source file <a target="_blank" href="@ViewBag.source">Eg016SetTabValues.cs</a> on GitHub.
</p>

<form class="eg" action="" method="post" data-busy="form">
<div class="form-group">
<label for="signerEmail">Signer Email</label>
<input type="email" class="form-control" id="signerEmail" name="signerEmail"
aria-describedby="emailHelp" placeholder="pat@example.com" required
value="@ViewBag.Locals.DsConfig.SignerEmail">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="signerName">Signer Name</label>
<input type="text" class="form-control" id="signerName" placeholder="Pat Johnson" name="signerName"
value="@ViewBag.Locals.DsConfig.SignerName" required>
</div>
<input type="hidden" name="_csrf" value="<%- csrfToken %>">
<button type="submit" class="btn btn-primary">Submit</button>
</form>
6 changes: 4 additions & 2 deletions eg-03-csharp-auth-code-grant-core/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@
<a target='_blank' href="https://developers.docusign.com/esign-rest-api/reference/Envelopes/EnvelopeFormData/get">EnvelopeFormData::get</a>.
</p>

<h4 id="example016">16. <a href="#">Set tab values for a envelope</a></h4>
<p>Comming Soon...</p>
<h4 id="example016">16. <a href="eg016">Set tab values for a envelope</a></h4>
<p>This example sets the tab (field) values for an envelope including tabs that can and cannot be changed by the signer.</p>
<p>
API method used:
<a target='_blank' href="https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/create">Envelopes::create</a>.
</p>

<h4 id="example017">17. <a href="#">Set template tab values</a></h4>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DocuSign.eSign.dll" Version="4.0.0-rc" />
<PackageReference Include="DocuSign.eSign.dll" Version="4.0.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
Expand Down