Skip to content

pull new stuff in #1

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

Merged
merged 4 commits into from
Oct 18, 2019
Merged
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
53 changes: 53 additions & 0 deletions ExtensionManifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"codeExamples": [
{
"number" : "1",
"name" : "Requesting a Signature via your App (Embedded Signing)",
"description" : "This code example demonstrates how to collect eSignatures via DocuSign from within your app without needing to send the signer an email or direct them to an external URL, a process also known as Embedded Signing.",
"source" : "https://github.com/docusign/TemporaryCSharpCodeExamples/blob/master/eg-03-csharp-auth-code-grant-core/Examples/EmbeddedSigningCeremony.cs",
"method" : "SendEnvelopeForEmbeddedSigning"
},
{
"number" : "2",
"name" : "Requesting a Signature via Email (Remote Signing)",
"description" : "This code example demonstrates how to send a signature request for a signer to read and sign via an email, also known as a remote signature request.",
"source" : "https://github.com/docusign/TemporaryCSharpCodeExamples/blob/master/eg-03-csharp-auth-code-grant-core/Examples/EmbeddedSigningCeremony.cs",
"method" : "SendEnvelopeForEmbeddedSigning"
},
{
"number" : "3",
"name" : "Getting Envelope Information",
"description" : "This code example demonstrates how to get the full set of data associated with an envelope that was sent by your app.",
"source" : "https://github.com/docusign/TemporaryCSharpCodeExamples/blob/master/eg-03-csharp-auth-code-grant-core/Examples/EmbeddedSigningCeremony.cs",
"method" : "SendEnvelopeForEmbeddedSigning"
},
{
"number" : "4",
"name" : "Get an envelope's basic information",
"description" : "This code example demonstrates how to collect e-ignatures via DocuSign from within your app without needing to send the signer an email or direct them to an external URL, a process also known as Embedded Signing.",
"source" : "https://github.com/docusign/TemporaryCSharpCodeExamples/blob/master/eg-03-csharp-auth-code-grant-core/Examples/EmbeddedSigningCeremony.cs",
"method" : "SendEnvelopeForEmbeddedSigning"
},
{
"number" : "5",
"name" : "Listing Envelope Recipients",
"description" : "This code example demonstrates how to retrieve a list of all envelope recipients and their associated status details, such as the signing status for each envelope document.",
"source" : "https://github.com/docusign/TemporaryCSharpCodeExamples/blob/master/eg-03-csharp-auth-code-grant-core/Examples/EmbeddedSigningCeremony.cs",
"method" : "SendEnvelopeForEmbeddedSigning"
},
{
"number" : "6",
"name" : "Listing Envelope Documents",
"description" : "This code example demonstrates how to retrieve a list of all documents within a specific envelope.",
"source" : "https://github.com/docusign/TemporaryCSharpCodeExamples/blob/master/eg-03-csharp-auth-code-grant-core/Examples/EmbeddedSigningCeremony.cs",
"method" : "SendEnvelopeForEmbeddedSigning"
},
{
"number" : "7",
"name" : "Downloading Envelope Documents",
"description" : "This code example demonstrates how to retrieve documents from an envelope, such as the generated seal (which is created when a document is completed), a composite PDF of all documents, a zip file containing everything, or a specific document attachment within the envelope.",
"source" : "https://github.com/docusign/TemporaryCSharpCodeExamples/blob/master/eg-03-csharp-auth-code-grant-core/Examples/EmbeddedSigningCeremony.cs",
"method" : "SendEnvelopeForEmbeddedSigning"
}
]
}
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/Eg016SetTabValues.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
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,22 @@ public Eg015EnvelopeTabDataController(DSConfiguration config, IRequestItemsServi
[HttpPost]
public IActionResult Create()
{
// Check the token with minimal buffer time.
// 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.
// 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");
}

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}
var accessToken = RequestItemsService.User.AccessToken; // Represents your {ACCESS_TOKEN}
var accountId = RequestItemsService.Session.AccountId; // Represents your {ACCOUNT_ID}
var envelopeId = RequestItemsService.EnvelopeId;

// Step 2: Construct your API headers
Expand Down
224 changes: 224 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,224 @@
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
{
// Set up the Ping Url, signer client ID, and the return (callback) URL for embedded signing
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",
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"
};

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
EnvelopesApi envelopesApi = new EnvelopesApi(config);
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelopeAttributes);
RequestItemsService.EnvelopeId = results.EnvelopeId;

// Step 6: Create the View Request
RecipientViewRequest viewRequest = new RecipientViewRequest();
// Set the URL where you want the recipient to go once they are done signing;
// this 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 authentication steps from DocuSign; e.g., SMS authentication
viewRequest.AuthenticationMethod = "none";

// Recipient information must match the embedded recipient info
// that 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 return URL (see the makeRecipientViewRequest method)
string redirectUrl = results1.Url;
return Redirect(redirectUrl);
}
}
}
Loading