Skip to content

Commit fb6014c

Browse files
author
Raileen Del Rosario
committed
2 parents 965adc6 + e8a28e3 commit fb6014c

File tree

11 files changed

+377
-3
lines changed

11 files changed

+377
-3
lines changed

ExamplesAPIType.cs

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public enum ExamplesApiType
4949
/// </summary>
5050
[Description("web")]
5151
WebForms = 6,
52+
53+
/// <summary>
54+
/// Notary API
55+
/// </summary>
56+
[Description("neg")]
57+
Notary = 7
5258
}
5359

5460
public static class ExamplesApiTypeExtensions

ExamplesApiTypeExtensions.cs

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public enum ExamplesApiType
5555
/// </summary>
5656
[Description("mae")]
5757
Maestro = 7,
58+
59+
/// <summary>
60+
/// Notary API
61+
/// </summary>
62+
[Description("neg")]
63+
Notary = 8,
5864
}
5965

6066
public static class ExamplesApiTypeExtensions

launcher-csharp/Common/RequestItemsService.cs

+4
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ public string IdentifyApiOfCodeExample(string eg)
289289
{
290290
currentApiType = ExamplesApiType.WebForms.ToString();
291291
}
292+
else if (eg.Contains(ExamplesApiType.Notary.ToKeywordString()))
293+
{
294+
currentApiType = ExamplesApiType.Notary.ToString();
295+
}
292296
else
293297
{
294298
currentApiType = ExamplesApiType.ESignature.ToString();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// <copyright file="Neg004SendWithThirdPartyNotaryController.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.Controllers
6+
{
7+
using DocuSign.CodeExamples.Common;
8+
using DocuSign.CodeExamples.Examples;
9+
using DocuSign.CodeExamples.Models;
10+
using Microsoft.AspNetCore.Mvc;
11+
12+
[Area("Notary")]
13+
[Route("neg004")]
14+
public class Neg004SendWithThirdPartyNotaryController : EgController
15+
{
16+
public Neg004SendWithThirdPartyNotaryController(DsConfiguration dsConfig,
17+
LauncherTexts launcherTexts,
18+
IRequestItemsService requestItemsService)
19+
: base(dsConfig, launcherTexts, requestItemsService)
20+
{
21+
this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.Notary);
22+
this.ViewBag.title = this.CodeExampleText.ExampleName;
23+
}
24+
25+
public override string EgName => "neg004";
26+
27+
[HttpPost]
28+
[SetViewBag]
29+
public IActionResult Create(string signerEmail, string signerName)
30+
{
31+
// Check the token with minimal buffer time.
32+
bool tokenOk = this.CheckToken(3);
33+
if (!tokenOk)
34+
{
35+
// We could store the parameters of the requested operation
36+
// so it could be restarted automatically.
37+
// But since it should be rare to have a token issue here,
38+
// we'll make the user re-enter the form data after
39+
// authentication.
40+
this.RequestItemsService.EgName = this.EgName;
41+
return this.Redirect("/ds/mustAuthenticate");
42+
}
43+
44+
var accessToken = this.RequestItemsService.User.AccessToken;
45+
var basePath = this.RequestItemsService.Session.BasePath + "/restapi";
46+
var accountId = this.RequestItemsService.Session.AccountId;
47+
var envStatus = this.RequestItemsService.Status;
48+
49+
// Call the Examples API method to create and send an notary envelope via email
50+
var envelopeId = SendWithThirdPartyNotary.SendWithNotary(signerEmail, signerName, accessToken, basePath, accountId, envStatus);
51+
52+
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
53+
this.ViewBag.message = string.Format(this.CodeExampleText.ResultsPageText, envelopeId);
54+
return this.View("example_done");
55+
}
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
// <copyright file="SendWithThirdPartyNotary.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.Examples
6+
{
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Text;
10+
using DocuSign.eSign.Api;
11+
using DocuSign.eSign.Client;
12+
using DocuSign.eSign.Model;
13+
14+
public static class SendWithThirdPartyNotary
15+
{
16+
public static string SendWithNotary(string signerEmail, string signerName, string accessToken, string basePath, string accountId, string envStatus)
17+
{
18+
//ds-snippet-start:Notary4Step2
19+
EnvelopeDefinition env = MakeEnvelope(signerEmail, signerName, envStatus);
20+
var docuSignClient = new DocuSignClient(basePath);
21+
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
22+
//ds-snippet-end:Notary4Step2
23+
24+
//ds-snippet-start:Notary4Step4
25+
var envelopesApi = new EnvelopesApi(docuSignClient);
26+
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, env);
27+
return results.EnvelopeId;
28+
//ds-snippet-end:Notary4Step4
29+
}
30+
31+
//ds-snippet-start:Notary4Step3
32+
private static EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, string envStatus)
33+
{
34+
var env = new EnvelopeDefinition
35+
{
36+
EmailSubject = "Please sign this document set",
37+
};
38+
39+
env.Documents = GetDocuments(signerEmail, signerName);
40+
41+
var signers = GetSigners(signerEmail, signerName);
42+
43+
var notaryRecipients = GetNotaryRecipients();
44+
45+
// Add the recipients to the envelope object
46+
var recipients = new Recipients
47+
{
48+
Signers = signers,
49+
Notaries = notaryRecipients,
50+
};
51+
env.Recipients = recipients;
52+
53+
// Request that the envelope be sent by setting |status| to "sent".
54+
// To request that the envelope be created as a draft, set to "created"
55+
env.Status = envStatus;
56+
57+
return env;
58+
}
59+
60+
private static List<Document> GetDocuments(string signerEmail, string signerName)
61+
{
62+
// Create document objects, one per document
63+
var doc1 = new Document();
64+
var b64 = Convert.ToBase64String(GetDocumentExample(signerEmail, signerName));
65+
doc1.DocumentBase64 = b64;
66+
doc1.Name = "Order acknowledgement"; // can be different from actual file name
67+
doc1.FileExtension = "html"; // Source data format. Signed docs are always pdf.
68+
doc1.DocumentId = "1"; // a label used to reference the doc
69+
70+
return new List<Document> { doc1 };
71+
}
72+
73+
private static byte[] GetDocumentExample(string signerEmail, string signerName)
74+
{
75+
return Encoding.UTF8.GetBytes(" <!DOCTYPE html>\n"
76+
+ " <html>\n"
77+
+ " <head>\n"
78+
+ " <meta charset=\"UTF-8\">\n"
79+
+ " </head>\n"
80+
+ " <body style=\"font-family:sans-serif;margin-left:2em;\">\n"
81+
+ " <h1 style=\"font-family: 'Trebuchet MS', Helvetica, sans-serif;\n"
82+
+ " color: darkblue;margin-bottom: 0;\">World Wide Corp</h1>\n"
83+
+ " <h2 style=\"font-family: 'Trebuchet MS', Helvetica, sans-serif;\n"
84+
+ " margin-top: 0px;margin-bottom: 3.5em;font-size: 1em;\n"
85+
+ " color: darkblue;\">Order Processing Division</h2>\n"
86+
+ " <h4>Ordered by "
87+
+ signerName
88+
+ "</h4>\n"
89+
+ " <p style=\"margin-top:0em; margin-bottom:0em;\">Email: "
90+
+ signerEmail
91+
+ "</p>\n"
92+
+ " <p style=\"margin-top:3em;\">\n"
93+
+ " Candy bonbon pastry jujubes lollipop wafer biscuit biscuit. Topping brownie sesame snaps sweet roll pie. Croissant danish biscuit soufflé caramels jujubes jelly. Dragée danish caramels lemon drops dragée. Gummi bears cupcake biscuit tiramisu sugar plum pastry. Dragée gummies applicake pudding liquorice. Donut jujubes oat cake jelly-o. Dessert bear claw chocolate cake gummies lollipop sugar plum ice cream gummies cheesecake.\n"
94+
+ " </p>\n"
95+
+ " <!-- Note the anchor tag for the signature field is in white. -->\n"
96+
+ " <h3 style=\"margin-top:3em;\">Agreed: <span style=\"color:white;\">**signature_1**/</span></h3>\n"
97+
+ " </body>\n"
98+
+ " </html>");
99+
}
100+
101+
private static List<Signer> GetSigners(string signerEmail, string signerName)
102+
{
103+
// create a signer recipient to sign the document, identified by name and email
104+
// We're setting the parameters via the object creation
105+
var signer1 = new Signer
106+
{
107+
ClientUserId = "1000",
108+
Email = signerEmail,
109+
Name = signerName,
110+
RecipientId = "2",
111+
RoutingOrder = "1",
112+
NotaryId = "1",
113+
};
114+
115+
// Create signHere fields (also known as tabs) on the documents,
116+
// We're using anchor (autoPlace) positioning
117+
//
118+
// The DocuSign platform searches throughout your envelope's
119+
// documents for matching anchor strings. So the
120+
// signHere2 tab will be used in both document 2 and 3 since they
121+
// use the same anchor string for their "signer 1" tabs.
122+
var signHere1 = new SignHere
123+
{
124+
DocumentId = "1",
125+
XPosition = "200",
126+
YPosition = "235",
127+
PageNumber = "1",
128+
};
129+
130+
var signHere2 = new SignHere
131+
{
132+
StampType = "stamp",
133+
DocumentId = "1",
134+
XPosition = "200",
135+
YPosition = "150",
136+
PageNumber = "1",
137+
};
138+
139+
// Tabs are set per recipient
140+
var signer1Tabs = new Tabs
141+
{
142+
SignHereTabs = new List<SignHere> { signHere1, signHere2 },
143+
};
144+
signer1.Tabs = signer1Tabs;
145+
146+
return new List<Signer> { signer1 };
147+
}
148+
149+
private static List<NotaryRecipient> GetNotaryRecipients()
150+
{
151+
var notarySealTabs = new NotarySeal
152+
{
153+
XPosition = "300",
154+
YPosition = "235",
155+
DocumentId = "1",
156+
PageNumber = "1",
157+
};
158+
159+
var notarySignHere = new SignHere
160+
{
161+
XPosition = "300",
162+
YPosition = "150",
163+
DocumentId = "1",
164+
PageNumber = "1",
165+
};
166+
167+
var notaryTabs = new Tabs
168+
{
169+
SignHereTabs = new List<SignHere> { notarySignHere },
170+
NotarySealTabs = new List<NotarySeal> { notarySealTabs },
171+
};
172+
173+
var notaryRecipient = new List<NotaryRecipient>
174+
{
175+
new NotaryRecipient
176+
{
177+
Email = string.Empty,
178+
Name = "Notary",
179+
RecipientId = "1",
180+
RoutingOrder = "1",
181+
Tabs = notaryTabs,
182+
NotaryType = "remote",
183+
NotarySourceType = "thirdparty",
184+
NotaryThirdPartyPartner = "onenotary",
185+
RecipientSignatureProviders = new List<RecipientSignatureProvider>
186+
{
187+
new RecipientSignatureProvider
188+
{
189+
SealDocumentsWithTabsOnly = "false",
190+
SignatureProviderName = "ds_authority_idv",
191+
SignatureProviderOptions = new RecipientSignatureProviderOptions(),
192+
},
193+
},
194+
},
195+
};
196+
197+
return notaryRecipient;
198+
}
199+
200+
//ds-snippet-end:Notary4Step3
201+
}
202+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
@{
2+
int formNumber = 0;
3+
int signerEmailInputNumber = 0;
4+
int signerNameInputNumber = 1;
5+
}
6+
7+
<h4>@Html.Raw(ViewBag.CodeExampleText.ExampleName)</h4>
8+
<p>
9+
@Html.Raw(ViewBag.CodeExampleText.ExampleDescription)
10+
</p>
11+
12+
@if (ViewBag.showDoc == true)
13+
{
14+
<p><a target='_blank' href='<%= documentation %>'>Documentation</a> about this example</p>
15+
}
16+
17+
<partial name="../../../Views/Shared/LinkToMethodView" model="ViewBag.CodeExampleText" />
18+
19+
<p>
20+
@Html.Raw(@String.Format(ViewBag.SupportingTexts.ViewSourceFile, "<a target='_blank' href=" + @ViewBag.source + ">SendWithThirdPartyNotary.cs</a>"))
21+
</p>
22+
23+
<form class="eg" action="" method="post" data-busy="form">
24+
<div class="form-group">
25+
<label for="signerEmail">
26+
@Html.Raw(ViewBag.CodeExampleText.Forms[formNumber].Inputs[signerEmailInputNumber].InputName)
27+
</label>
28+
<input type="email"
29+
class="form-control"
30+
id="signerEmail"
31+
name="signerEmail"
32+
aria-describedby="emailHelp"
33+
placeholder="@ViewBag.CodeExampleText.Forms[formNumber].Inputs[signerEmailInputNumber].InputPlaceholder"
34+
required
35+
value="@ViewBag.Locals.DsConfig.SignerEmail" />
36+
<small id="emailHelp" class="form-text text-muted">@Html.Raw(ViewBag.SupportingTexts.HelpingTexts.EmailWontBeShared)</small>
37+
</div>
38+
<div class="form-group">
39+
<label for="signerName">
40+
@Html.Raw(ViewBag.CodeExampleText.Forms[formNumber].Inputs[signerNameInputNumber].InputName)
41+
</label>
42+
<input type="text"
43+
class="form-control"
44+
id="signerName"
45+
placeholder="@ViewBag.CodeExampleText.Forms[formNumber].Inputs[signerNameInputNumber].InputPlaceholder"
46+
name="signerName"
47+
value="@ViewBag.Locals.DsConfig.SignerName"
48+
required />
49+
</div>
50+
<input type="hidden" name="_csrf" value="<%- csrfToken %>">
51+
<button type="submit" class="btn btn-primary">@Html.Raw(ViewBag.SupportingTexts.SubmitButton)</button>
52+
</form>

launcher-csharp/Startup.cs

+6
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public Startup(IConfiguration configuration)
9292
});
9393

9494
this.apiTypes.Add(ExamplesApiType.Maestro, new List<string> { "signature", "aow_manage" });
95+
96+
this.apiTypes.Add(ExamplesApiType.Notary, new List<string> { "signature", "organization_read", "notary_read", "notary_write" });
9597
}
9698

9799
public IConfiguration Configuration { get; }
@@ -288,6 +290,10 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
288290
endpoints.MapControllerRoute(
289291
name: "default",
290292
pattern: "{area=Admin}/{controller=Home}/{action=Index}/{id?}");
293+
294+
endpoints.MapControllerRoute(
295+
name: "default",
296+
pattern: "{area=Notary}/{controller=Home}/{action=Index}/{id?}");
291297
});
292298
}
293299

launcher-csharp/Views/Home/Index.cshtml

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@
4343
: ((ApIs) api).Name.ToLower() == ExamplesApiType.Monitor.ToString().ToLower() ? ExamplesApiType.Monitor.ToKeywordString()
4444
: ((ApIs) api).Name.ToLower() == ExamplesApiType.Rooms.ToString().ToLower() ? ExamplesApiType.Rooms.ToKeywordString()
4545
: ((ApIs) api).Name.ToLower() == ExamplesApiType.Connect.ToString().ToLower() ? ExamplesApiType.Connect.ToKeywordString()
46-
: ((ApIs)api).Name.ToLower() == ExamplesApiType.Maestro.ToString().ToLower() ? ExamplesApiType.Maestro.ToKeywordString()
46+
: ((ApIs) api).Name.ToLower() == ExamplesApiType.Maestro.ToString().ToLower() ? ExamplesApiType.Maestro.ToKeywordString()
4747
: ((ApIs) api).Name.ToLower() == ExamplesApiType.WebForms.ToString().ToLower() ? ExamplesApiType.WebForms.ToKeywordString()
48+
: ((ApIs) api).Name.ToLower() == ExamplesApiType.Notary.ToString().ToLower() ? ExamplesApiType.Notary.ToKeywordString()
4849
: ExamplesApiType.Admin.ToKeywordString();
4950

5051
@foreach(var exampleGroup in api.Groups)

launcher-csharp/launcher-csharp.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<ItemGroup>
3939
<PackageReference Include="DocuSign.Admin" Version="2.0.0-rc4" />
4040
<PackageReference Include="DocuSign.Click" Version="2.0.0-rc1" />
41-
<PackageReference Include="DocuSign.eSign.dll" Version="8.0.0-rc2" />
41+
<PackageReference Include="DocuSign.eSign.dll" Version="8.0.2" />
4242
<PackageReference Include="DocuSign.Monitor" Version="2.0.0-rc3" />
4343
<PackageReference Include="DocuSign.Rooms" Version="2.0.0-rc3" />
4444
<PackageReference Include="DocuSign.WebForms" Version="2.0.0-rc3" />

0 commit comments

Comments
 (0)