diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg001EmbeddedSigningController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg001EmbeddedSigningController.cs index 0e6ec80d..2bbd9f69 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg001EmbeddedSigningController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg001EmbeddedSigningController.cs @@ -3,10 +3,8 @@ using DocuSign.eSign.Api; using DocuSign.eSign.Client; using DocuSign.eSign.Model; -using eg_03_csharp_auth_code_grant_core.Common; using eg_03_csharp_auth_code_grant_core.Controllers; using eg_03_csharp_auth_code_grant_core.Models; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace eg_03_csharp_auth_code_grant_core.Views @@ -29,6 +27,18 @@ public Eg001EmbeddedSigningController(DSConfiguration config, IRequestItemsServi [HttpPost] public IActionResult Create(string signerEmail, string signerName) { + // Data for this method + // signerEmail + // signerName + // dsPingUrl -- class global + // signerClientId -- class global + // dsReturnUrl -- class global + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + + + // Check the token with minimal buffer time. bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -40,18 +50,14 @@ public IActionResult Create(string signerEmail, string signerName) RequestItemsService.EgName = EgName; return Redirect("/ds/mustAuthenticate"); } - var session = RequestItemsService.Session; - var user = RequestItemsService.User; // Step 1. Create the envelope definition EnvelopeDefinition envelope = MakeEnvelope(signerEmail, signerName); // Step 2. Call DocuSign to create the envelope - var config = new Configuration(new ApiClient(session.BasePath+ "/restapi")); - config.AddDefaultHeader("Authorization", "Bearer "+ user.AccessToken); + var config = new Configuration(new ApiClient(basePath)); + config.AddDefaultHeader("Authorization", "Bearer " + accessToken); EnvelopesApi envelopesApi = new EnvelopesApi(config); - - EnvelopeSummary results = envelopesApi.CreateEnvelope(session.AccountId, envelope); - + EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelope); string envelopeId = results.EnvelopeId; // Save for future use within the example launcher @@ -60,7 +66,7 @@ public IActionResult Create(string signerEmail, string signerName) // Step 3. create the recipient view, the Signing Ceremony RecipientViewRequest viewRequest = MakeRecipientViewRequest(signerEmail, signerName); // call the CreateRecipientView API - ViewUrl results1 = envelopesApi.CreateRecipientView(session.AccountId, envelopeId, viewRequest); + ViewUrl results1 = envelopesApi.CreateRecipientView(accountId, envelopeId, viewRequest); // Step 4. Redirect the user to the Signing Ceremony // Don't use an iFrame! @@ -71,6 +77,14 @@ public IActionResult Create(string signerEmail, string signerName) private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string signerName) { + // Data for this method + // signerEmail + // signerName + // dsPingUrl -- class global + // signerClientId -- class global + // dsReturnUrl -- 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. @@ -107,8 +121,15 @@ private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName) { - byte[] buffer = System.IO.File.ReadAllBytes(Config.docPdf); + // Data for this method + // signerEmail + // signerName + // signerClientId -- class global + // Config.docPdf + + byte[] buffer = System.IO.File.ReadAllBytes(Config.docPdf); + EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition(); envelopeDefinition.EmailSubject = "Please sign this document"; Document doc1 = new Document(); diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg002SigningViaEmailController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg002SigningViaEmailController.cs index 18225a37..f13ea63e 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg002SigningViaEmailController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg002SigningViaEmailController.cs @@ -26,6 +26,7 @@ public Eg002SigningViaEmailController(DSConfiguration config, IRequestItemsServi [HttpPost] public IActionResult Create(string signerEmail, string signerName, string ccEmail, string ccName) { + // Check the token with minimal buffer time. bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -46,19 +47,36 @@ public IActionResult Create(string signerEmail, string signerName, string ccEmai public EnvelopeSummary DoWork(string signerEmail, string signerName, string ccEmail, string ccName) { - var session = RequestItemsService.Session; - var user = RequestItemsService.User; + // Data for this method + // signerEmail + // signerName + // ccEmail + // ccName + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + EnvelopeDefinition env = MakeEnvelope(signerEmail, signerName, ccEmail, ccName); - var config = new Configuration(new ApiClient(session.BasePath + "/restapi")); - config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken); + var config = new Configuration(new ApiClient(basePath)); + config.AddDefaultHeader("Authorization", "Bearer " + accessToken); EnvelopesApi envelopesApi = new EnvelopesApi(config); - EnvelopeSummary results = envelopesApi.CreateEnvelope(RequestItemsService.Session.AccountId, env); + EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, env); RequestItemsService.EnvelopeId = results.EnvelopeId; return results; } private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, string ccEmail, string ccName) { + // Data for this method + // signerEmail + // signerName + // ccEmail + // ccName + // Config.docDocx + // Config.docPdf + // RequestItemsService.Status -- the envelope status ('created' or 'sent') + + // document 1 (html) has tag **signature_1** // document 2 (docx) has tag /sn1/ // document 3 (pdf) has tag /sn1/ @@ -75,6 +93,8 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s // create the envelope definition EnvelopeDefinition env = new EnvelopeDefinition(); env.EmailSubject = "Please sign this document set"; + + // Create document objects, one per document Document doc1 = new Document(); string b64 = Convert.ToBase64String(document1(signerEmail, signerName, ccEmail, ccName)); doc1.DocumentBase64 = b64; @@ -87,7 +107,6 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s FileExtension = "docx", DocumentId = "2" }; - Document doc3 = new Document { DocumentBase64 = doc3PdfBytes, @@ -95,8 +114,6 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s FileExtension = "pdf", DocumentId = "3" }; - - // The order in the docs array determines the order in the envelope env.Documents = new List { doc1, doc2, doc3}; @@ -146,12 +163,10 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s AnchorXOffset = "20" }; - // Tabs are set per recipient / signer Tabs signer1Tabs = new Tabs { SignHereTabs = new List { signHere1, signHere2} }; - signer1.Tabs = signer1Tabs; // Add the recipients to the envelope object @@ -160,9 +175,7 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s Signers = new List { signer1 }, CarbonCopies = new List { cc1 } }; - env.Recipients = recipients; - // Request that the envelope be sent by setting |status| to "sent". // To request that the envelope be created as a draft, set to "created" env.Status = RequestItemsService.Status; @@ -172,6 +185,12 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s private byte[] document1(string signerEmail, string signerName, string ccEmail, string ccName) { + // Data for this method + // signerEmail + // signerName + // ccEmail + // ccName + return Encoding.UTF8.GetBytes( " \n" + " \n" + diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg003ListEnvelopesController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg003ListEnvelopesController.cs index 50971f8f..bdb019a1 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg003ListEnvelopesController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg003ListEnvelopesController.cs @@ -26,6 +26,12 @@ public Eg003ListEnvelopesController(DSConfiguration config, IRequestItemsService [HttpPost] public IActionResult Create(string signerEmail, string signerName) { + // Data for this method + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + + // Check the token with minimal buffer time. bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -37,16 +43,13 @@ public IActionResult Create(string signerEmail, string signerName) RequestItemsService.EgName = EgName; return Redirect("/ds/mustAuthenticate"); } - var session = RequestItemsService.Session; - var user = RequestItemsService.User; - var config = new Configuration(new ApiClient(session.BasePath + "/restapi")); - config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken); + var config = new Configuration(new ApiClient(basePath)); + config.AddDefaultHeader("Authorization", "Bearer " + accessToken); EnvelopesApi envelopesApi = new EnvelopesApi(config); - ListStatusChangesOptions options = new ListStatusChangesOptions(); - + ListStatusChangesOptions options = new ListStatusChangesOptions(); options.fromDate = DateTime.Now.AddDays(-30).ToString("yyyy/MM/dd"); - - EnvelopesInformation results = envelopesApi.ListStatusChanges(RequestItemsService.Session.AccountId, options); + // Call the API method: + EnvelopesInformation results = envelopesApi.ListStatusChanges(accountId, options); ViewBag.h1 = "List envelopes results"; ViewBag.message = "Results from the Envelopes::listStatusChanges method:"; diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg004EnvelopeInfoController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg004EnvelopeInfoController.cs index 0f6cc734..ca5c423d 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg004EnvelopeInfoController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg004EnvelopeInfoController.cs @@ -24,6 +24,13 @@ public Eg004EnvelopeInfoController(DSConfiguration config, IRequestItemsService [HttpPost] public IActionResult Create(string signerEmail, string signerName) { + // Data for this method + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + var envelopeId = RequestItemsService.EnvelopeId; + + // Check the token with minimal buffer time. bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -35,14 +42,12 @@ public IActionResult Create(string signerEmail, string signerName) RequestItemsService.EgName = EgName; return Redirect("/ds/mustAuthenticate"); } - var session = RequestItemsService.Session; - var user = RequestItemsService.User; - var config = new Configuration(new ApiClient(session.BasePath + "/restapi")); - config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken); + var config = new Configuration(new ApiClient(basePath)); + config.AddDefaultHeader("Authorization", "Bearer " + accessToken); EnvelopesApi envelopesApi = new EnvelopesApi(config); ViewBag.h1 = "Get envelope status results"; ViewBag.message = "Results from the Envelopes::get method:"; - DocuSign.eSign.Model.Envelope results = envelopesApi.GetEnvelope(RequestItemsService.Session.AccountId, RequestItemsService.EnvelopeId); + DocuSign.eSign.Model.Envelope results = envelopesApi.GetEnvelope(accountId, envelopeId); ViewBag.Locals.Json = JsonConvert.SerializeObject(results, Formatting.Indented); return View("example_done"); diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg005EnvelopeRecipientsController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg005EnvelopeRecipientsController.cs index b1e4b9cb..3e375055 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg005EnvelopeRecipientsController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg005EnvelopeRecipientsController.cs @@ -20,6 +20,12 @@ public Eg005EnvelopeRecipientsController(DSConfiguration config, IRequestItemsSe [HttpPost] public IActionResult Create(string signerEmail, string signerName) { + // Data for this method + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + var envelopeId = RequestItemsService.EnvelopeId; + bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -31,14 +37,12 @@ public IActionResult Create(string signerEmail, string signerName) RequestItemsService.EgName = EgName; return Redirect("/ds/mustAuthenticate"); } - var session = RequestItemsService.Session; - var user = RequestItemsService.User; - var config = new Configuration(new ApiClient(session.BasePath + "/restapi")); - config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken); + var config = new Configuration(new ApiClient(basePath)); + config.AddDefaultHeader("Authorization", "Bearer " + accessToken); EnvelopesApi envelopesApi = new EnvelopesApi(config); ViewBag.h1 = "List envelope recipients result"; ViewBag.message = "Results from the EnvelopeRecipients::list method:"; - var results = envelopesApi.ListRecipients(RequestItemsService.Session.AccountId, RequestItemsService.EnvelopeId); + var results = envelopesApi.ListRecipients(accountId, envelopeId); ViewBag.Locals.Json = JsonConvert.SerializeObject(results, Formatting.Indented); return View("example_done"); diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg006EnvelopeDocsController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg006EnvelopeDocsController.cs index 9b169fb2..a5400fc7 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg006EnvelopeDocsController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg006EnvelopeDocsController.cs @@ -22,6 +22,13 @@ public Eg006EnvelopeDocsController(DSConfiguration config, IRequestItemsService [HttpPost] public IActionResult Create(string signerEmail, string signerName) { + // Data for this method + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + var envelopeId = RequestItemsService.EnvelopeId; + + bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -33,16 +40,12 @@ public IActionResult Create(string signerEmail, string signerName) RequestItemsService.EgName = EgName; return Redirect("/ds/mustAuthenticate"); } - var session = RequestItemsService.Session; - var user = RequestItemsService.User; - var config = new Configuration(new ApiClient(session.BasePath + "/restapi")); - config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken); + var config = new Configuration(new ApiClient(basePath)); + config.AddDefaultHeader("Authorization", "Bearer " + accessToken); EnvelopesApi envelopesApi = new EnvelopesApi(config); - EnvelopeDocumentsResult result = envelopesApi.ListDocuments(RequestItemsService.Session.AccountId, - RequestItemsService.EnvelopeId); + EnvelopeDocumentsResult result = envelopesApi.ListDocuments(accountId, envelopeId); // Save the envelopeId and its list of documents in the session so // they can be used in example 7 (download a document) - List envelopeDocItems = new List(); envelopeDocItems.Add(new EnvelopeDocItem { Name= "Combined", Type= "content", DocumentId = "combined" }); envelopeDocItems.Add(new EnvelopeDocItem { Name = "Zip archive", Type = "zip", DocumentId = "archive" }); @@ -57,7 +60,7 @@ public IActionResult Create(string signerEmail, string signerName) } EnvelopeDocuments envelopeDocuments = new EnvelopeDocuments(); - envelopeDocuments.EnvelopeId = RequestItemsService.EnvelopeId; + envelopeDocuments.EnvelopeId = envelopeId; envelopeDocuments.Documents = envelopeDocItems; RequestItemsService.EnvelopeDocuments = envelopeDocuments; diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg007EnvelopeGetDocController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg007EnvelopeGetDocController.cs index 329b940f..0f18e95a 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg007EnvelopeGetDocController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg007EnvelopeGetDocController.cs @@ -20,6 +20,15 @@ public Eg007EnvelopeGetDocController(DSConfiguration config, IRequestItemsServic [HttpPost] public ActionResult Create(string docSelect) { + // Data for this method + // docSelect -- argument + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + var envelopeId = RequestItemsService.EnvelopeId; + // documents data for the envelope. See example EG006 + var documents = RequestItemsService.EnvelopeDocuments.Documents; + bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -31,17 +40,14 @@ public ActionResult Create(string docSelect) RequestItemsService.EgName = EgName; return Redirect("/ds/mustAuthenticate"); } - var session = RequestItemsService.Session; - var user = RequestItemsService.User; - var config = new Configuration(new ApiClient(session.BasePath + "/restapi")); - config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken); + var config = new Configuration(new ApiClient(basePath)); + config.AddDefaultHeader("Authorization", "Bearer " + accessToken); EnvelopesApi envelopesApi = new EnvelopesApi(config); // Step 1. EnvelopeDocuments::get. // Exceptions will be caught by the calling function - System.IO.Stream results = envelopesApi.GetDocument(RequestItemsService.Session.AccountId, - RequestItemsService.EnvelopeId, docSelect); - var documents = RequestItemsService.EnvelopeDocuments.Documents; + System.IO.Stream results = envelopesApi.GetDocument(accountId, + envelopeId, docSelect); EnvelopeDocItem docItem = documents.FirstOrDefault(d => docSelect.Equals(d.DocumentId)); string docName = docItem.Name; diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg008CreateTemplateController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg008CreateTemplateController.cs index ea254a6c..da343bad 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg008CreateTemplateController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg008CreateTemplateController.cs @@ -22,6 +22,12 @@ public Eg008CreateTemplateController(DSConfiguration config, IRequestItemsServic [HttpPost] public IActionResult Create() { + // Data for this method + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + + bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -33,15 +39,14 @@ public IActionResult Create() RequestItemsService.EgName = EgName; return Redirect("/ds/mustAuthenticate"); } + // Step 1. List templates to see if ours exists already string templateName = "Example Signer and CC template"; - var session = RequestItemsService.Session; - var user = RequestItemsService.User; - var config = new Configuration(new ApiClient(session.BasePath + "/restapi")); - config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken); + var config = new Configuration(new ApiClient(basePath)); + config.AddDefaultHeader("Authorization", "Bearer " + accessToken); TemplatesApi templatesApi = new TemplatesApi(config); TemplatesApi.ListTemplatesOptions options = new TemplatesApi.ListTemplatesOptions(); options.searchText = "Example Signer and CC template"; - EnvelopeTemplateResults results = templatesApi.ListTemplates(RequestItemsService.Session.AccountId, options); + EnvelopeTemplateResults results = templatesApi.ListTemplates(accountId, options); string templateId; string resultsTemplateName; @@ -49,6 +54,7 @@ public IActionResult Create() if (int.Parse(results.ResultSetSize) > 0) { + // Found the template! Record its id EnvelopeTemplateResult template = results.EnvelopeTemplates[0]; templateId = template.TemplateId; resultsTemplateName = template.Name; @@ -56,13 +62,14 @@ public IActionResult Create() } else { + // No template! Create one! EnvelopeTemplate templateReqObject = MakeTemplate(templateName); - TemplateSummary template = templatesApi.CreateTemplate(RequestItemsService.Session.AccountId, templateReqObject); + TemplateSummary template = templatesApi.CreateTemplate(accountId, templateReqObject); templateId = template.TemplateId; resultsTemplateName = template.Name; createdNewTemplate = true; } - + // Save the templateId RequestItemsService.TemplateId = templateId; string msg = createdNewTemplate ? "The template has been created!" : @@ -74,6 +81,10 @@ public IActionResult Create() private EnvelopeTemplate MakeTemplate(string resultsTemplateName) { + // Data for this method + // resultsTemplateName + + // document 1 (pdf) has tag /sn1/ // // The template has two recipient roles. diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg009UseTemplateController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg009UseTemplateController.cs index 0e31dc94..20c95107 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg009UseTemplateController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg009UseTemplateController.cs @@ -23,6 +23,16 @@ public Eg009UseTemplateController(DSConfiguration config, IRequestItemsService r [HttpPost] public IActionResult Create(string signerEmail, string signerName, string ccEmail, string ccName) { + // Data for this method + // signerEmail + // signerName + // ccEmail + // ccName + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + var templateId = RequestItemsService.TemplateId; + bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -34,13 +44,11 @@ public IActionResult Create(string signerEmail, string signerName, string ccEmai RequestItemsService.EgName = EgName; return Redirect("/ds/mustAuthenticate"); } - var session = RequestItemsService.Session; - var user = RequestItemsService.User; - var config = new Configuration(new ApiClient(session.BasePath + "/restapi")); - config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken); + var config = new Configuration(new ApiClient(basePath)); + config.AddDefaultHeader("Authorization", "Bearer " + accessToken); EnvelopesApi envelopesApi = new EnvelopesApi(config); - EnvelopeDefinition envelope = MakeEnvelope(signerEmail, signerName, ccEmail, ccName, RequestItemsService.TemplateId); - EnvelopeSummary result = envelopesApi.CreateEnvelope(RequestItemsService.Session.AccountId, envelope); + EnvelopeDefinition envelope = MakeEnvelope(signerEmail, signerName, ccEmail, ccName, templateId); + EnvelopeSummary result = envelopesApi.CreateEnvelope(accountId, envelope); RequestItemsService.EnvelopeId = result.EnvelopeId; ViewBag.message = "The envelope has been created and sent!
Envelope ID " + result.EnvelopeId + "."; return View("example_done"); @@ -49,6 +57,13 @@ public IActionResult Create(string signerEmail, string signerName, string ccEmai private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, string ccEmail, string ccName, string templateId) { + // Data for this method + // signerEmail + // signerName + // ccEmail + // ccName + // templateId + EnvelopeDefinition env = new EnvelopeDefinition(); env.TemplateId = templateId; diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg010SendBinaryDocsController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg010SendBinaryDocsController.cs index dcd38f2f..ddee8e54 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg010SendBinaryDocsController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg010SendBinaryDocsController.cs @@ -26,6 +26,17 @@ public Eg010SendBinaryDocsController(DSConfiguration config, IRequestItemsServic [HttpPost] public IActionResult Create(string signerEmail, string signerName, string ccEmail, string ccName) { + // Data for this method + // signerEmail + // signerName + // ccEmail + // ccName + // Config.docDocx + // Config.docPdf + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -73,14 +84,14 @@ public IActionResult Create(string signerEmail, string signerName, string ccEmai byte[] boundary = Encoding.ASCII.GetBytes("multipartboundary_multipartboundary"); byte[] hyphens = Encoding.ASCII.GetBytes("--"); - string uri = RequestItemsService.Session.BasePath - + "/restapi/v2/accounts/" + RequestItemsService.Session.AccountId + "/envelopes"; + string uri = basePath + + "/v2/accounts/" + accountId + "/envelopes"; HttpWebRequest request = WebRequest.CreateHttp(uri); request.Method = "POST"; request.Accept = "application/json"; request.ContentType = "multipart/form-data; boundary=" + Encoding.ASCII.GetString(boundary); - request.Headers.Add("Authorization", "Bearer " + RequestItemsService.User.AccessToken); + request.Headers.Add("Authorization", "Bearer " + accessToken); using (var buffer = new BinaryWriter(request.GetRequestStream(), Encoding.ASCII)) { @@ -160,6 +171,13 @@ public IActionResult Create(string signerEmail, string signerName, string ccEmai private string document1(string signerEmail, string signerName, string ccEmail, string ccName) { + // Data for this method + // signerEmail + // signerName + // ccEmail + // ccName + + return " \n" + " \n" + " \n" + @@ -185,6 +203,13 @@ private string document1(string signerEmail, string signerName, string ccEmail, private object MakeEnvelope(string signerEmail, string signerName, string ccEmail, string ccName) { + // Data for this method + // signerEmail + // signerName + // ccEmail + // ccName + + // document 1 (html) has tag **signature_1** // document 2 (docx) has tag /sn1/ // document 3 (pdf) has tag /sn1/ @@ -221,22 +246,26 @@ private object MakeEnvelope(string signerEmail, string signerName, string ccEmai // 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(); - signer1.Email = signerEmail; - signer1.Name = signerName; - signer1.RecipientId = "1"; - signer1.RoutingOrder = "1"; + Signer signer1 = new Signer + { + Email = signerEmail, + Name = signerName, + RecipientId = "1", + RoutingOrder = "1" + }; // routingOrder (lower means earlier) determines the order of deliveries // to the recipients. Parallel routing order is supported by using the // same integer as the order for two or more recipients. // create a cc recipient to receive a copy of the documents, identified by name and email // We're setting the parameters via setters - CarbonCopy cc1 = new CarbonCopy(); - cc1.Email = ccEmail; - cc1.Name = ccName; - cc1.RoutingOrder = "2"; - cc1.RecipientId = "2"; + CarbonCopy cc1 = new CarbonCopy + { + Email = ccEmail, + Name = ccName, + RoutingOrder = "2", + RecipientId = "2" + }; // Create signHere fields (also known as tabs) on the documents, // We're using anchor (autoPlace) positioning // @@ -244,26 +273,34 @@ private object MakeEnvelope(string signerEmail, string signerName, string ccEmai // documents for matching anchor strings. So the // signHere2 tab will be used in both document 2 and 3 since they // use the same anchor string for their "signer 1" tabs. - SignHere signHere1 = new SignHere(); - signHere1.AnchorString = "**signature_1**"; - signHere1.AnchorYOffset = "10"; - signHere1.AnchorUnits = "pixels"; - signHere1.AnchorXOffset = "20"; - SignHere signHere2 = new SignHere(); - signHere2.AnchorString = "/sn1/"; - signHere2.AnchorYOffset = "10"; - signHere2.AnchorUnits = "pixels"; - signHere2.AnchorXOffset = "20"; + SignHere signHere1 = new SignHere + { + AnchorString = "**signature_1**", + AnchorYOffset = "10", + AnchorUnits = "pixels", + AnchorXOffset = "20" + }; + SignHere signHere2 = new SignHere + { + AnchorString = "/sn1/", + AnchorYOffset = "10", + AnchorUnits = "pixels", + AnchorXOffset = "20" + }; // Tabs are set per recipient / signer - Tabs signer1Tabs = new Tabs(); - signer1Tabs.SignHereTabs = new List { signHere1, signHere2 }; + Tabs signer1Tabs = new Tabs + { + SignHereTabs = new List { signHere1, signHere2 } + }; signer1.Tabs = signer1Tabs; // Add the recipients to the envelope object - Recipients recipients = new Recipients(); - recipients.Signers = new List { signer1 }; - recipients.CarbonCopies = new List { cc1 }; + Recipients recipients = new Recipients + { + Signers = new List { signer1 }, + CarbonCopies = new List { cc1 } + }; dynamic env = new diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg011EmbeddedSendingController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg011EmbeddedSendingController.cs index 85b02532..ece39e37 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg011EmbeddedSendingController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg011EmbeddedSendingController.cs @@ -26,6 +26,18 @@ public Eg011EmbeddedSendingController(DSConfiguration config, IRequestItemsServi [HttpPost] public IActionResult Create(string signerEmail, string signerName, string ccEmail, string ccName, string startingView) { + // Data for this method + // signerEmail + // signerName + // ccEmail + // ccName + // startingView + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + string dsReturnUrl = Config.AppUrl + "/dsReturn"; + + bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -37,11 +49,10 @@ public IActionResult Create(string signerEmail, string signerName, string ccEmai RequestItemsService.EgName = EgName; return Redirect("/ds/mustAuthenticate"); } - var session = RequestItemsService.Session; - var user = RequestItemsService.User; - var config = new Configuration(new ApiClient(session.BasePath + "/restapi")); - config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken); + var config = new Configuration(new ApiClient(basePath)); + config.AddDefaultHeader("Authorization", "Bearer " + accessToken); EnvelopesApi envelopesApi = new EnvelopesApi(config); + // Step 1. Make the envelope with "created" (draft) status // Using eg002 to create the envelope with "created" status RequestItemsService.Status = "created"; @@ -52,10 +63,11 @@ public IActionResult Create(string signerEmail, string signerName, string ccEmai // Step 2. create the sender view // Call the CreateSenderView API // Exceptions will be caught by the calling function - string dsReturnUrl = Config.AppUrl + "/ds-return"; - ReturnUrlRequest viewRequest = MakeSenderViewRequest(dsReturnUrl); - - ViewUrl result1 = envelopesApi.CreateSenderView(RequestItemsService.Session.AccountId, envelopeId, viewRequest); + ReturnUrlRequest viewRequest = new ReturnUrlRequest + { + ReturnUrl = dsReturnUrl + }; + ViewUrl result1 = envelopesApi.CreateSenderView(accountId, envelopeId, viewRequest); // Switch to Recipient and Documents view if requested by the user String url = result1.Url; Console.WriteLine("startingView: " + startingView); @@ -68,20 +80,5 @@ public IActionResult Create(string signerEmail, string signerName, string ccEmai return Redirect(url); } - - private ReturnUrlRequest MakeSenderViewRequest(string dsReturnUrl) - { - ReturnUrlRequest viewRequest = new ReturnUrlRequest(); - // 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"; - - return viewRequest; - } } } \ No newline at end of file diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg012EmbeddedConsoleController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg012EmbeddedConsoleController.cs index 338e91e7..592b30a6 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg012EmbeddedConsoleController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg012EmbeddedConsoleController.cs @@ -23,6 +23,17 @@ public Eg012EmbeddedConsoleController(DSConfiguration config, IRequestItemsServi [HttpPost] public IActionResult Create(string startingView) { + // Data for this method + // signerEmail + // signerName + // ccEmail + // ccName + // startingView + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + string dsReturnUrl = Config.AppUrl + "/dsReturn"; + bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -34,17 +45,15 @@ public IActionResult Create(string startingView) RequestItemsService.EgName = EgName; return Redirect("/ds/mustAuthenticate"); } - var session = RequestItemsService.Session; - var user = RequestItemsService.User; - var config = new Configuration(new ApiClient(session.BasePath + "/restapi")); - config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken); + var config = new Configuration(new ApiClient(basePath)); + config.AddDefaultHeader("Authorization", "Bearer " + accessToken); EnvelopesApi envelopesApi = new EnvelopesApi(config); - string dsReturnUrl = Config.AppUrl + "/ds-return"; ConsoleViewRequest viewRequest = MakeConsoleViewRequest(dsReturnUrl, startingView); + // Step 1. create the NDSE view // Call the CreateSenderView API // Exceptions will be caught by the calling function - ViewUrl results = envelopesApi.CreateConsoleView(RequestItemsService.Session.AccountId, viewRequest); + ViewUrl results = envelopesApi.CreateConsoleView(accountId, viewRequest); Console.WriteLine("NDSE view URL: " + results.Url); @@ -53,6 +62,11 @@ public IActionResult Create(string startingView) private ConsoleViewRequest MakeConsoleViewRequest(string dsReturnUrl, string startingView) { + // Data for this method + // dsReturnUrl + // startingView + string envelopeId = RequestItemsService.EnvelopeId; + ConsoleViewRequest viewRequest = new ConsoleViewRequest(); // Set the url where you want the recipient to go once they are done // with the NDSE. It is usually the case that the @@ -60,9 +74,9 @@ private ConsoleViewRequest MakeConsoleViewRequest(string dsReturnUrl, string sta // Assume that control will not be passed back to your app. viewRequest.ReturnUrl = dsReturnUrl; - if ("envelope".Equals(startingView) && RequestItemsService.EnvelopeId != null) + if ("envelope".Equals(startingView) && envelopeId != null) { - viewRequest.EnvelopeId = RequestItemsService.EnvelopeId; + viewRequest.EnvelopeId = envelopeId; } return viewRequest; diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg013AddDocToTemplateController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg013AddDocToTemplateController.cs index 691bdd7b..ca882b5d 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg013AddDocToTemplateController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg013AddDocToTemplateController.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text; -using System.Threading.Tasks; using DocuSign.eSign.Api; using DocuSign.eSign.Client; using DocuSign.eSign.Model; @@ -26,6 +24,19 @@ public Eg013AddDocToTemplateController(DSConfiguration config, IRequestItemsServ [HttpPost] public IActionResult Create(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 + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + string dsReturnUrl = Config.AppUrl + "/dsReturn"; + bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -37,69 +48,71 @@ public IActionResult Create(string signerEmail, string signerName, string ccEmai RequestItemsService.EgName = EgName; return Redirect("/ds/mustAuthenticate"); } - var session = RequestItemsService.Session; - var user = RequestItemsService.User; - var config = new Configuration(new ApiClient(session.BasePath + "/restapi")); - config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken); + var config = new Configuration(new ApiClient(basePath)); + config.AddDefaultHeader("Authorization", "Bearer " + accessToken); EnvelopesApi envelopesApi = new EnvelopesApi(config); - string dsReturnUrl = Config.AppUrl + "/dsReturn"; - string dsPingUrl = Config.AppUrl + "/"; + // 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(RequestItemsService.Session.AccountId, envelope); + 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, dsPingUrl); - ViewUrl results1 = envelopesApi.CreateRecipientView(RequestItemsService.Session.AccountId, envelopeId, viewRequest); + RecipientViewRequest viewRequest = MakeRecipientViewRequest(signerEmail, signerName, dsReturnUrl); + ViewUrl results1 = envelopesApi.CreateRecipientView(accountId, envelopeId, viewRequest); return Redirect(results1.Url); } private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string signerName, - string dsReturnUrl, string dsPingUrl) + string dsReturnUrl) { - 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; + // 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. - // 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 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 @@ -109,60 +122,80 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s // is used, not TemplateRole // // Create a signer recipient for the signer role of the server template - Signer signer1 = new Signer(); - signer1.Email = signerEmail; - signer1.Name = signerName; - signer1.RoleName = "signer"; - signer1.RecipientId = "1"; - // Adding clientUserId transforms the template recipient - // into an embedded recipient: - signer1.ClientUserId = signerClientId; + 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(); - cc1.Email = ccEmail; - cc1.Name = ccName; - cc1.RoleName = "cc"; - cc1.RecipientId = "2"; + CarbonCopy cc1 = new CarbonCopy + { + Email = ccEmail, + Name = ccName, + RoleName = "cc", + RecipientId = "2" + }; // Recipients object: - Recipients recipientsServerTemplate = new Recipients(); - recipientsServerTemplate.CarbonCopies = new List { cc1 }; - recipientsServerTemplate.Signers = new List { signer1 }; + Recipients recipientsServerTemplate = new Recipients + { + CarbonCopies = new List { cc1 }, + Signers = new List { signer1 } + }; // create a composite template for the Server Template - CompositeTemplate compTemplate1 = new CompositeTemplate(); - compTemplate1.CompositeTemplateId = "1"; - ServerTemplate serverTemplates = new ServerTemplate(); - serverTemplates.Sequence = "1"; - serverTemplates.TemplateId = RequestItemsService.TemplateId; + CompositeTemplate compTemplate1 = new CompositeTemplate + { + CompositeTemplateId = "1" + }; + ServerTemplate serverTemplates = new ServerTemplate + { + Sequence = "1", + TemplateId = RequestItemsService.TemplateId + }; compTemplate1.ServerTemplates = new List { serverTemplates }; // Add the roles via an inlineTemplate - InlineTemplate inlineTemplate = new InlineTemplate(); - inlineTemplate.Sequence = "1"; - inlineTemplate.Recipients = recipientsServerTemplate; + InlineTemplate inlineTemplate = new InlineTemplate + { + Sequence = "1", + Recipients = recipientsServerTemplate + }; compTemplate1.InlineTemplates = new List { inlineTemplate }; // The signer recipient for the added document with // a tab definition: - SignHere signHere1 = new SignHere(); - signHere1.AnchorString = "**signature_1**"; - signHere1.AnchorYOffset = "10"; - signHere1.AnchorUnits = "pixels"; - signHere1.AnchorXOffset = "20"; - - Tabs signer1Tabs = new Tabs(); - signer1Tabs.SignHereTabs = new List { signHere1 }; + SignHere signHere1 = new SignHere + { + AnchorString = "**signature_1**", + AnchorYOffset = "10", + AnchorUnits = "pixels", + AnchorXOffset = "20" + }; + + Tabs signer1Tabs = new Tabs + { + SignHereTabs = new List { signHere1 } + }; // Signer definition for the added document - Signer signer1AddedDoc = new Signer(); - signer1AddedDoc.Email = signerEmail; - signer1AddedDoc.Name = signerName; - signer1AddedDoc.ClientUserId = signerClientId; - signer1AddedDoc.RoleName = "signer"; - signer1AddedDoc.RecipientId = "1"; - signer1AddedDoc.Tabs = signer1Tabs; + 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(); - recipientsAddedDoc.CarbonCopies = new List { cc1 }; - recipientsAddedDoc.Signers = new List { signer1AddedDoc }; + Recipients recipientsAddedDoc = new Recipients + { + CarbonCopies = new List { cc1 }, + Signers = new List { signer1AddedDoc } + }; // create the HTML document Document doc1 = new Document(); @@ -173,18 +206,24 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s doc1.FileExtension = "html"; doc1.DocumentId = "1"; // create a composite template for the added document - CompositeTemplate compTemplate2 = new CompositeTemplate(); - compTemplate2.CompositeTemplateId = "2"; + CompositeTemplate compTemplate2 = new CompositeTemplate + { + CompositeTemplateId = "2" + }; // Add the recipients via an inlineTemplate - InlineTemplate inlineTemplate2 = new InlineTemplate(); - inlineTemplate2.Sequence = "2"; - inlineTemplate2.Recipients = recipientsAddedDoc; + InlineTemplate inlineTemplate2 = new InlineTemplate + { + Sequence = "2", + Recipients = recipientsAddedDoc + }; compTemplate2.InlineTemplates = new List { inlineTemplate2}; compTemplate2.Document = doc1; - EnvelopeDefinition env = new EnvelopeDefinition(); - env.Status = "sent"; - env.CompositeTemplates = new List { compTemplate1, compTemplate2}; + EnvelopeDefinition env = new EnvelopeDefinition + { + Status = "sent", + CompositeTemplates = new List { compTemplate1, compTemplate2 } + }; return env; } @@ -192,6 +231,14 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s private byte[] document1(string signerEmail, string signerName, string ccEmail, string ccName, string item, string quantity) { + // Data for this method + // signerEmail + // signerName + // ccEmail + // ccName + // item + // quantity + return Encoding.UTF8.GetBytes(" \n" + " \n" + " \n" + diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/Eg014CollectPaymentController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/Eg014CollectPaymentController.cs index c2bd7e51..f6fcca83 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/Eg014CollectPaymentController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/Eg014CollectPaymentController.cs @@ -25,6 +25,16 @@ public Eg014CollectPaymentController(DSConfiguration config, IRequestItemsServic [HttpPost] public IActionResult Create(string signerEmail, string signerName, string ccEmail, string ccName) { + // Data for this method + // signerEmail + // signerName + // ccEmail + // ccName + var accessToken = RequestItemsService.User.AccessToken; + var basePath = RequestItemsService.Session.BasePath + "/restapi"; + var accountId = RequestItemsService.Session.AccountId; + + bool tokenOk = CheckToken(3); if (!tokenOk) { @@ -36,16 +46,16 @@ public IActionResult Create(string signerEmail, string signerName, string ccEmai RequestItemsService.EgName = EgName; return Redirect("/ds/mustAuthenticate"); } - var session = RequestItemsService.Session; - var user = RequestItemsService.User; - var config = new Configuration(new ApiClient(session.BasePath + "/restapi")); - config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken); + 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); + // Step 2. call Envelopes::create API method // Exceptions will be caught by the calling function - EnvelopeSummary results = envelopesApi.CreateEnvelope(RequestItemsService.Session.AccountId, envelope); + EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelope); string envelopeId = results.EnvelopeId; Console.WriteLine("Envelope was created.EnvelopeId " + envelopeId); ViewBag.h1 = "Envelope sent"; @@ -55,6 +65,13 @@ public IActionResult Create(string signerEmail, string signerName, string ccEmai private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, string ccEmail, string ccName) { + // Data for this method + // signerEmail + // signerName + // ccEmail + // ccName + + // document 1 (html) has multiple tags: // /l1q/ and /l2q/ -- quantities: drop down // /l1e/ and /l2e/ -- extended: payment lines @@ -88,9 +105,6 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s // read file from a local directory // The read could raise an exception if the file is not available! string doc1HTML1 = System.IO.File.ReadAllText("order_form.html"); - //string doc1HTML1 = fs.readFileSync(path.resolve(demoDocsPath, doc1File), - // { encoding: 'utf8'}); - // Substitute values into the HTML // Substitute for: {signerName}, {signerEmail}, {ccName}, {ccEmail} var doc1HTML2 = doc1HTML1.Replace("{signerName}", signerName) @@ -98,19 +112,21 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s .Replace("{ccName}", ccName) .Replace("{ccEmail}", ccEmail); - // create the envelope definition - EnvelopeDefinition env = new EnvelopeDefinition(); - env.EmailSubject = "Please complete your order"; + EnvelopeDefinition env = new EnvelopeDefinition + { + EmailSubject = "Please complete your order" + }; // add the documents - Document doc1 = new Document(); string doc1b64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(doc1HTML2)); - - doc1.DocumentBase64 = doc1b64; - doc1.Name = "Order form"; // can be different from actual file name - doc1.FileExtension = "html"; // Source data format. Signed docs are always pdf. - doc1.DocumentId = "1"; // a label used to reference the doc + Document doc1 = new Document + { + DocumentBase64 = doc1b64, + Name = "Order form", // can be different from actual file name + FileExtension = "html", // Source data format. Signed docs are always pdf. + DocumentId = "1" // a label used to reference the doc + }; env.Documents = new List { doc1 }; // create a signer recipient to sign the document, identified by name and email @@ -128,12 +144,13 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s // create a cc recipient to receive a copy of the documents, identified by name and email // We're setting the parameters via setters - CarbonCopy cc1 = new CarbonCopy(); - cc1.Email = ccEmail; - cc1.Name = ccName; - cc1.RoutingOrder = "2"; - cc1.RecipientId = "2"; - + CarbonCopy cc1 = new CarbonCopy + { + Email = ccEmail, + Name = ccName, + RoutingOrder = "2", + RecipientId = "2" + }; // Create signHere fields (also known as tabs) on the documents, // We're using anchor (autoPlace) positioning @@ -144,62 +161,18 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s AnchorUnits = "pixels", AnchorXOffset = "20" }; - ListItem listItem0 = new ListItem - { - Text = "none", - Value = "0" - } - , listItem1 = new ListItem - { - Text = "1", - Value = "1" - } - , listItem2 = new ListItem - { - Text = "2", - Value = "2" - } - , listItem3 = new ListItem - { - Text = "3", - Value = "3" - } - , listItem4 = new ListItem - { - Text = "4", - Value = "4" - } - , listItem5 = new ListItem - { - Text = "5", - Value = "5" - } - , listItem6 = new ListItem - { - Text = "6", - Value = "6" - } - , listItem7 = new ListItem - { - Text = "7", - Value = "7" - } - , listItem8 = new ListItem - { - Text = "8", - Value = "8" - } - , listItem9 = new ListItem - { - Text = "9", - Value = "9" - } - , listItem10 = new ListItem - { - Text = "10", - Value = "10" - }; - + ListItem listItem0 = new ListItem { Text = "none", Value = "0" } + , listItem1 = new ListItem { Text = "1", Value = "1" } + , listItem2 = new ListItem { Text = "2", Value = "2" } + , listItem3 = new ListItem { Text = "3", Value = "3" } + , listItem4 = new ListItem { Text = "4", Value = "4" } + , listItem5 = new ListItem { Text = "5", Value = "5" } + , listItem6 = new ListItem { Text = "6", Value = "6" } + , listItem7 = new ListItem { Text = "7", Value = "7" } + , listItem8 = new ListItem { Text = "8", Value = "8" } + , listItem9 = new ListItem { Text = "9", Value = "9" } + , listItem10 = new ListItem { Text = "10", Value = "10" } + ; List listl1q = new List { Font = "helvetica", @@ -259,24 +232,24 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s Required = "true", Locked = "true", DisableAutoSize = "false", - } - // Formula for the total - , formulal3t = new FormulaTab - { - Font = "helvetica", - Bold = "true", - FontSize = "size12", - AnchorString = "/l3t/", - AnchorYOffset = "-8", - AnchorUnits = "pixels", - AnchorXOffset = "50", - TabLabel = "l3t", - Formula = $"[l1e] + [l2e]", - RoundDecimalPlaces = "0", - Required = "true", - Locked = "true", - DisableAutoSize = "false", - }; + }, + // Formula for the total + formulal3t = new FormulaTab + { + Font = "helvetica", + Bold = "true", + FontSize = "size12", + AnchorString = "/l3t/", + AnchorYOffset = "-8", + AnchorUnits = "pixels", + AnchorXOffset = "50", + TabLabel = "l3t", + Formula = $"[l1e] + [l2e]", + RoundDecimalPlaces = "0", + Required = "true", + Locked = "true", + DisableAutoSize = "false", + }; // Payment line items PaymentLineItem paymentLineIteml1 = new PaymentLineItem diff --git a/eg-03-csharp-auth-code-grant-core/Controllers/EgController.cs b/eg-03-csharp-auth-code-grant-core/Controllers/EgController.cs index 3b44c25d..eb37e27d 100644 --- a/eg-03-csharp-auth-code-grant-core/Controllers/EgController.cs +++ b/eg-03-csharp-auth-code-grant-core/Controllers/EgController.cs @@ -17,6 +17,7 @@ public EgController(DSConfiguration config, IRequestItemsService requestItemsSer ViewBag.csrfToken = ""; } + [HttpGet] public IActionResult Get() { // Check that the token is valid and will remain valid for awhile to enable the