Skip to content

Commit ea9f29e

Browse files
committed
initial draft of the example
1 parent bc45ad8 commit ea9f29e

File tree

14 files changed

+391
-1
lines changed

14 files changed

+391
-1
lines changed

ExamplesApiTypeExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public enum ExamplesApiType
6161
/// </summary>
6262
[Description("neg")]
6363
Notary = 8,
64+
65+
/// <summary>
66+
/// Connected Fields
67+
/// </summary>")]
68+
[Description("cf")]
69+
ConnectedFields = 9,
6470
}
6571

6672
public static class ExamplesApiTypeExtensions

launcher-csharp/Common/RequestItemsService.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ public string IdentifyApiOfCodeExample(string eg)
293293
{
294294
currentApiType = ExamplesApiType.Notary.ToString();
295295
}
296+
else if (eg.Contains(ExamplesApiType.ConnectedFields.ToKeywordString()))
297+
{
298+
currentApiType = ExamplesApiType.ConnectedFields.ToString();
299+
}
296300
else
297301
{
298302
currentApiType = ExamplesApiType.ESignature.ToString();
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// <copyright file="Eg001SetConnectedFieldsController.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.Controllers
6+
{
7+
using System;
8+
using System.Linq;
9+
using DocuSign.CodeExamples.Common;
10+
using DocuSign.CodeExamples.ConnectedFields.Models;
11+
using DocuSign.CodeExamples.Examples;
12+
using DocuSign.CodeExamples.Models;
13+
using Microsoft.AspNetCore.Mvc;
14+
using Microsoft.IdentityModel.Tokens;
15+
16+
[Area("ConnectedFields")]
17+
[Route("cf001")]
18+
public class Eg001SetConnectedFieldsController : EgController
19+
{
20+
public Eg001SetConnectedFieldsController(DsConfiguration dsConfig,
21+
LauncherTexts launcherTexts,
22+
IRequestItemsService requestItemsService)
23+
: base(dsConfig, launcherTexts, requestItemsService)
24+
{
25+
this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.ConnectedFields);
26+
this.ViewBag.title = this.CodeExampleText.ExampleName;
27+
}
28+
29+
public override string EgName => "cf001";
30+
31+
[MustAuthenticate]
32+
[HttpGet]
33+
public override IActionResult Get()
34+
{
35+
IActionResult actionResult = base.Get();
36+
if (this.RequestItemsService.EgName == this.EgName)
37+
{
38+
return actionResult;
39+
}
40+
41+
Guid? organizationId = this.RequestItemsService.OrganizationId;
42+
string accessToken = this.RequestItemsService.User.AccessToken;
43+
44+
ExtensionApps extensionApps = SetConnectedFields.GetConnectedFieldsAsync(accessToken, this.RequestItemsService.User.AccountId).Result;
45+
46+
var filteredExtensionApps = extensionApps.Applications.FindAll(extension => !extension.Tabs.Where(tabs => tabs.ExtensionData.ActionContract.Contains("Verify") == true).IsNullOrEmpty());
47+
48+
this.ViewBag.ExtensionApps = filteredExtensionApps;
49+
return this.View(this.EgName, this);
50+
}
51+
52+
[HttpPost]
53+
[SetViewBag]
54+
public IActionResult Create(string signerEmail, string signerName, string extensionName)
55+
{
56+
bool tokenOk = this.CheckToken(3);
57+
if (!tokenOk)
58+
{
59+
this.RequestItemsService.EgName = this.EgName;
60+
return this.Redirect("/ds/mustAuthenticate");
61+
}
62+
63+
var accessToken = this.RequestItemsService.User.AccessToken;
64+
var basePath = this.RequestItemsService.Session.BasePath + "/restapi";
65+
var accountId = this.RequestItemsService.Session.AccountId;
66+
67+
var envelopeId = SetConnectedFields.SendEnvelopeViaEmail(
68+
signerEmail,
69+
signerName,
70+
null, // pass extension here
71+
accessToken,
72+
basePath,
73+
accountId,
74+
this.Config.DocPdf);
75+
76+
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
77+
this.ViewBag.message = string.Format(this.CodeExampleText.ResultsPageText, envelopeId);
78+
return this.View("example_done");
79+
}
80+
}
81+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// <copyright file="SetConnectedFields.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.Linq;
10+
using System.Net.Http;
11+
using System.Net.Http.Headers;
12+
using System.Text;
13+
using System.Text.Json;
14+
using System.Threading.Tasks;
15+
using DocuSign.CodeExamples.ConnectedFields.Models;
16+
using DocuSign.eSign.Api;
17+
using DocuSign.eSign.Client;
18+
using DocuSign.eSign.Model;
19+
using static System.Net.Mime.MediaTypeNames;
20+
21+
public static class SetConnectedFields
22+
{
23+
private static readonly HttpClient Client = new HttpClient();
24+
25+
public static async Task<ExtensionApps> GetConnectedFieldsAsync(string accessToken, string accountId)
26+
{
27+
string baseUrl = "https://api-d.docusign.com/v1";
28+
string requestUrl = $"{baseUrl}/accounts/{accountId}/connected-fields/tab-groups";
29+
30+
using (var request = new HttpRequestMessage(HttpMethod.Get, requestUrl))
31+
{
32+
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
33+
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
34+
request.Headers.Add("Content-Type", "application/json");
35+
36+
HttpResponseMessage response = await Client.SendAsync(request);
37+
string responseBody = await response.Content.ReadAsStringAsync();
38+
39+
return JsonSerializer.Deserialize<ExtensionApps>(responseBody);
40+
}
41+
}
42+
43+
public static string SendEnvelopeViaEmail(string signerEmail, string signerName, ExtensionApp extension, string basePath, string accessToken, string accountId, string docPdf)
44+
{
45+
EnvelopeDefinition env = MakeEnvelope(signerEmail, signerName, extension, docPdf);
46+
var docuSignClient = new DocuSignClient(basePath);
47+
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
48+
49+
EnvelopesApi envelopesApi = new EnvelopesApi(docuSignClient);
50+
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, env);
51+
return results.EnvelopeId;
52+
}
53+
54+
public static EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, ExtensionApp extension, string docPdf)
55+
{
56+
EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();
57+
envelopeDefinition.EmailSubject = "Please sign this document set";
58+
envelopeDefinition.Status = "sent";
59+
60+
string docPdfBytes = Convert.ToBase64String(System.IO.File.ReadAllBytes(docPdf));
61+
62+
Document document = new Document
63+
{
64+
DocumentBase64 = docPdfBytes,
65+
Name = "Lorem Ipsum",
66+
FileExtension = "pdf",
67+
DocumentId = "1",
68+
};
69+
70+
envelopeDefinition.Documents = new List<Document> { document };
71+
72+
Signer signer = new Signer
73+
{
74+
Email = signerEmail,
75+
Name = signerName,
76+
RecipientId = "1",
77+
RoutingOrder = "1",
78+
Tabs = new eSign.Model.Tabs
79+
{
80+
SignHereTabs = new List<SignHere>
81+
{
82+
new SignHere
83+
{
84+
AnchorString = "/sn1/",
85+
AnchorUnits = "pixels",
86+
AnchorYOffset = "10",
87+
AnchorXOffset = "20",
88+
},
89+
},
90+
TextTabs = new List<eSign.Model.Text>
91+
{
92+
new eSign.Model.Text
93+
{
94+
RequireInitialOnSharedChange = "false",
95+
RequireAll = "false",
96+
Name = extension.Tabs.First().ExtensionData.ApplicationName,
97+
Required = "false",
98+
Locked = "false",
99+
DisableAutoSize = "false",
100+
MaxLength = "4000",
101+
TabLabel = extension.Tabs.First().TabLabel,
102+
Font = "lucidaconsole",
103+
FontColor = "black",
104+
FontSize = "size9",
105+
DocumentId = "1",
106+
RecipientId = "1",
107+
PageNumber = "1",
108+
XPosition = "273",
109+
YPosition = "191",
110+
Width = "84",
111+
Height = "22",
112+
TemplateRequired = "false",
113+
TabType = "text",
114+
//add extension code here
115+
},
116+
},
117+
},
118+
};
119+
120+
return envelopeDefinition;
121+
}
122+
}
123+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// <copyright file="ConnectionInstances.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.ConnectedFields.Models
6+
{
7+
using Newtonsoft.Json;
8+
9+
public class ConnectionInstances
10+
{
11+
[JsonProperty("connectionKey")]
12+
public string ConnectionKey { get; set; }
13+
14+
[JsonProperty("connectionValue")]
15+
public string ConnectionValue { get; set; }
16+
}
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// <copyright file="ExtensionApp.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.ConnectedFields.Models
6+
{
7+
using System.Collections.Generic;
8+
using Newtonsoft.Json;
9+
10+
public class ExtensionApp
11+
{
12+
[JsonProperty("appId")]
13+
public string AppId { get; set; }
14+
15+
[JsonProperty("tabs")]
16+
public List<Tabs> Tabs { get; set; }
17+
}
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// <copyright file="ExtensionApps.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.ConnectedFields.Models
6+
{
7+
using System.Collections.Generic;
8+
using Newtonsoft.Json;
9+
10+
public class ExtensionApps
11+
{
12+
public List<ExtensionApp> Applications { get; set; }
13+
}
14+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// <copyright file="ExtensionData.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.ConnectedFields.Models
6+
{
7+
using Newtonsoft.Json;
8+
9+
public class ExtensionData
10+
{
11+
[JsonProperty("extensionGroupId")]
12+
public ExtensionData ExtensionGroupId { get; set; }
13+
14+
[JsonProperty("actionInputKey")]
15+
public string ActionInputKey { get; set; }
16+
17+
[JsonProperty("publisherName")]
18+
public string PublisherName { get; set; }
19+
20+
[JsonProperty("applicationName")]
21+
public string ApplicationName { get; set; }
22+
23+
[JsonProperty("actionContract")]
24+
public string ActionContract { get; set; }
25+
26+
[JsonProperty("extensionName")]
27+
public string ExtensionName { get; set; }
28+
29+
[JsonProperty("actionName")]
30+
public string ActionName { get; set; }
31+
32+
[JsonProperty("extensionContract")]
33+
public string ExtensionContract { get; set; }
34+
35+
[JsonProperty("extensionPolicy")]
36+
public string ExtensionPolicy { get; set; }
37+
38+
[JsonProperty("requiredForExtension")]
39+
public bool RequiredForExtension { get; set; }
40+
41+
[JsonProperty("connectionInstances")]
42+
public ConnectionInstances ConnectionInstances { get; set; }
43+
}
44+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// <copyright file="Tabs.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.ConnectedFields.Models
6+
{
7+
using Newtonsoft.Json;
8+
9+
public class Tabs
10+
{
11+
[JsonProperty("extensionData")]
12+
public ExtensionData ExtensionData { get; set; }
13+
14+
[JsonProperty("tabType")]
15+
public string TabType { get; set; }
16+
17+
[JsonProperty("tabLabel")]
18+
public string TabLabel { get; set; }
19+
}
20+
}

0 commit comments

Comments
 (0)