Skip to content

Ex 16-18 completed #9

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 18 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
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,20 @@ The **refresh token** is not used in this example.
1. **Payments example: an order form, with online payment by credit card.**
[Source.](./eg-03-csharp-auth-code-grant-core/Controllers/Eg014CollectPaymentController.cs)
1. **Get the envelope tab data.**
Coming soon...
Retrieve the tab (field) values for all of the envelope's recipients.
[Source.](./eg-03-csharp-auth-code-grant-core/Controllers/Eg015EnvelopeTabData.cs)
1. **Set envelope tab values.**
Coming soon...
The example creates an envelope and sets the initial values for its tabs (fields). Some of the tabs
are set to be read-only, others can be updated by the recipient. The example also stores
metadata with the envelope.
[Source.](./eg-03-csharp-auth-code-grant-core/Controllers/Eg016StTabValues.cs)
1. **Set template tab values.**
Coming soon...
The example creates an envelope using a template and sets the initial values for its tabs (fields).
The example also stores metadata with the envelope.
[Source.](./eg-03-csharp-auth-code-grant-core/Controllers/Eg017SEtTemplateTabValues.cs)
1. **Get the envelope custom field data (metadata).**
Coming soon...
The example retrieves the custom metadata (custom data fields) stored with the envelope.
[Source.](./eg-03-csharp-auth-code-grant-core/Controllers/Eg018EnvelopeCustomFieldData.cs)
1. **Requiring an Access Code for a Recipient**
[Source.](./eg-03-csharp-auth-code-grant-core/Controllers/Eg019AccessCodeAuthController.cs)
This example sends an envelope that requires an access-code for the purpose of multi-factor authentication.
Expand Down
235 changes: 235 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,235 @@
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", // Yes, include in the 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;
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);

RequestItemsService.EnvelopeId = results.EnvelopeId;
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);
}
}
}
Loading