Skip to content

Commit a6df699

Browse files
Click api examples porting (#10)
* Add the click api examples * Update readme * remove redundant files and mek the code more readable * remove a redundant folder * content edits for Click PR * fix the click scopes routing * fix readme, add scope * fixes to PR comments * add verification is clickwrap id presented or not * remove self-descriptive comments * Change a readme click api text * refactor to point to Eg01 when no clickwrap is found * revert problems with combined readme Co-authored-by: Aaron Wilde <Aaron.Wilde@docusign.com>
1 parent 5b3a5eb commit a6df699

40 files changed

+974
-71
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,32 @@ The **refresh token** is not used in this example.
156156
1. **Create an external form fillable session.**
157157
[Source.](./launcher-csharp/Rooms/Controllers/Eg06CreateExternalFormFillSessionController.cs)
158158
This example create an external form that can be filled using DocuSign for a specific room in your DocuSign Rooms account.
159-
159+
160+
## Click API
161+
**Note:** to use the Click API, include click_manage and click_send scopes. Review the [Click API 101 Auth Guide](https://developers.docusign.com/docs/click-api/click101/auth) for more details.
162+
163+
164+
1. **Create Clickwraps.**
165+
[Source.](./launcher-csharp/Click/Controllers/Eg01CreateClickwrapController.cs)
166+
Creates a clickwrap.
167+
1. **Activate Clickwrap.**
168+
[Source.](./launcher-csharp/Click/Controllers/Eg02ActivateClickwrapController.cs)
169+
Activates a newly created clickwrap.
170+
1. **Test Clickwrap.**
171+
[Source.](./launcher-csharp/Click/Controllers/Eg03TestClickwrapController.cs)
172+
Tests a newly created clickwrap.
173+
1. **Clickwrap Embeding.**
174+
[Source.](./launcher-csharp/Click/Controllers/Eg04EmbedClickwrapController.cs)
175+
Embeds a clickwrap into a page.
176+
1. **Clickwrap Versioning.**
177+
[Source.](./launcher-csharp/Click/Controllers/Eg05CreateNewClickwrapVersionController.cs)
178+
Creates a new clickwrap version.
179+
1. **Retrieve Clickwraps.**
180+
[Source.](./launcher-csharp/Click/Controllers/Eg06RetrieveClickwrapsController.cs)
181+
Retrieves clickwraps.
182+
1. **Get Clickwrap Responses.**
183+
[Source.](./launcher-csharp/Click/Controllers/Eg07GetClickwrapResponsesController.cs)
184+
Retrieves a clickwrap responses.
160185

161186
## Installation
162187

Terms_of_service.docx

16.3 KB
Binary file not shown.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+

2+
using System;
3+
using System.Collections.Generic;
4+
using DocuSign.Click.Api;
5+
using DocuSign.Click.Client;
6+
using DocuSign.Click.Model;
7+
using DocuSign.CodeExamples.Common;
8+
using DocuSign.CodeExamples.Controllers;
9+
using DocuSign.CodeExamples.Models;
10+
using Microsoft.AspNetCore.Mvc;
11+
using Newtonsoft.Json;
12+
13+
namespace DocuSign.CodeExamples.Click.Controllers
14+
{
15+
[Area("Click")]
16+
[Route("[area]/Eg01")]
17+
public class Eg01CreateClickwrapController : EgController
18+
{
19+
public Eg01CreateClickwrapController(
20+
DSConfiguration dsConfig,
21+
IRequestItemsService requestItemsService)
22+
: base(dsConfig, requestItemsService)
23+
{
24+
}
25+
26+
public override string EgName => "Eg01";
27+
28+
[MustAuthenticate]
29+
[Route("Create")]
30+
[HttpPost]
31+
[ValidateAntiForgeryToken]
32+
public ActionResult Create(string name)
33+
{
34+
// Step 1. Obtain your OAuth token
35+
var accessToken = RequestItemsService.User.AccessToken;
36+
var basePath = $"{RequestItemsService.Session.BasePath}/clickapi"; // Base API path
37+
38+
// Step 2: Construct your API headers
39+
var apiClient = new ApiClient(basePath);
40+
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
41+
var clickAccountApi = new AccountsApi(apiClient);
42+
43+
var accountId = RequestItemsService.Session.AccountId;
44+
45+
try
46+
{
47+
// Step 3: Construct the request body for your clickwrap
48+
ClickwrapRequest clickwrapRequest = BuildClickwraprequest(name);
49+
50+
// Step 4: Call the Click API to create a clickwrap
51+
var clickWrap = clickAccountApi.CreateClickwrap(accountId, clickwrapRequest);
52+
53+
//Show results
54+
ViewBag.h1 = "The clickwrap was successfully created";
55+
ViewBag.message = $"The clickwrap was created! Clickwrap ID: {clickWrap.ClickwrapId}, Name: {clickWrap.ClickwrapName}.";
56+
ViewBag.Locals.Json = JsonConvert.SerializeObject(clickWrap, Formatting.Indented);
57+
58+
// Save for future use within the example launcher
59+
RequestItemsService.ClickwrapId = clickWrap.ClickwrapId;
60+
61+
return View("example_done");
62+
}
63+
catch (ApiException apiException)
64+
{
65+
ViewBag.errorCode = apiException.ErrorCode;
66+
ViewBag.errorMessage = apiException.Message;
67+
68+
return View("Error");
69+
}
70+
}
71+
72+
private static ClickwrapRequest BuildClickwraprequest(string name)
73+
{
74+
var clickwrapRequest = new ClickwrapRequest
75+
{
76+
DisplaySettings = new DisplaySettings()
77+
{
78+
ConsentButtonText = "I Agree",
79+
DisplayName = "Terms of Service",
80+
Downloadable = true,
81+
Format = "modal",
82+
MustRead = true,
83+
MustView = true,
84+
RequireAccept = true,
85+
DocumentDisplay = "document"
86+
},
87+
Documents = new List<Document>(){
88+
new Document()
89+
{
90+
DocumentBase64=Convert.ToBase64String(System.IO.File.ReadAllBytes("Terms_of_service.pdf")),
91+
DocumentName="Terms of Service",
92+
FileExtension="pdf",
93+
Order= 0
94+
}
95+
},
96+
Name = name,
97+
RequireReacceptance = true
98+
};
99+
100+
return clickwrapRequest;
101+
}
102+
}
103+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using DocuSign.Click.Api;
2+
using DocuSign.Click.Client;
3+
using DocuSign.Click.Model;
4+
using DocuSign.CodeExamples.Common;
5+
using DocuSign.CodeExamples.Controllers;
6+
using DocuSign.CodeExamples.Models;
7+
using Microsoft.AspNetCore.Mvc;
8+
using Newtonsoft.Json;
9+
10+
namespace DocuSign.CodeExamples.Click.Controllers
11+
{
12+
[Area("Click")]
13+
[Route("[area]/Eg02")]
14+
public class Eg02ActivateClickwrapController : EgController
15+
{
16+
public Eg02ActivateClickwrapController(
17+
DSConfiguration dsConfig,
18+
IRequestItemsService requestItemsService)
19+
: base(dsConfig, requestItemsService)
20+
{
21+
}
22+
23+
public override string EgName => "Eg02";
24+
25+
protected override void InitializeInternal()
26+
{
27+
ViewBag.ClickwrapId = RequestItemsService.ClickwrapId;
28+
ViewBag.AccountId = RequestItemsService.Session.AccountId;
29+
}
30+
31+
32+
[MustAuthenticate]
33+
[Route("Activate")]
34+
[HttpPost]
35+
[ValidateAntiForgeryToken]
36+
public ActionResult Activate()
37+
{
38+
// Step 1. Obtain your OAuth token
39+
var accessToken = RequestItemsService.User.AccessToken;
40+
var basePath = $"{RequestItemsService.Session.BasePath}/clickapi"; // Base API path
41+
42+
// Step 2: Construct your API headers
43+
var apiClient = new ApiClient(basePath);
44+
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
45+
var clickAccountApi = new AccountsApi(apiClient);
46+
47+
var accountId = RequestItemsService.Session.AccountId;
48+
49+
try
50+
{
51+
if (string.IsNullOrEmpty(RequestItemsService.ClickwrapId))
52+
{
53+
ViewBag.errorCode = 400;
54+
ViewBag.errorMessage = "Cannot find any clickwrap. Please first create a clickwrap using the first example.";
55+
56+
return View("Error");
57+
}
58+
59+
// Step 3: Construct the request body for your clickwrap
60+
ClickwrapRequest clickwrapRequest = BuildUpdateClickwrapVersionRequest();
61+
62+
var clickwrapId = RequestItemsService.ClickwrapId;
63+
var clickwrapVersion = "1"; //A newly created clickwrap has default version 1
64+
65+
// Step 4: Call the Click API to activate a clickwrap
66+
var clickWrap = clickAccountApi.UpdateClickwrapVersion(accountId, clickwrapId, clickwrapVersion, clickwrapRequest);
67+
68+
//Show results
69+
ViewBag.h1 = "The clickwrap was successfully activated";
70+
ViewBag.message = $"The clickwrap was activated! Clickwrap ID: {clickWrap.ClickwrapId}, Name: {clickWrap.ClickwrapName}.";
71+
ViewBag.Locals.Json = JsonConvert.SerializeObject(clickWrap, Formatting.Indented);
72+
73+
return View("example_done");
74+
}
75+
catch (ApiException apiException)
76+
{
77+
ViewBag.errorCode = apiException.ErrorCode;
78+
ViewBag.errorMessage = apiException.Message;
79+
80+
return View("Error");
81+
}
82+
}
83+
84+
private static ClickwrapRequest BuildUpdateClickwrapVersionRequest()
85+
{
86+
var clickwrapRequest = new ClickwrapRequest
87+
{
88+
Status = "active"
89+
};
90+
91+
return clickwrapRequest;
92+
}
93+
}
94+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using DocuSign.CodeExamples.Common;
2+
using DocuSign.CodeExamples.Controllers;
3+
using DocuSign.CodeExamples.Models;
4+
using Microsoft.AspNetCore.Mvc;
5+
6+
namespace DocuSign.CodeExamples.Click.Controllers
7+
{
8+
[Area("Click")]
9+
[Route("[area]/Eg03")]
10+
public class Eg03TestClickwrapController : EgController
11+
{
12+
public Eg03TestClickwrapController(
13+
DSConfiguration dsConfig,
14+
IRequestItemsService requestItemsService)
15+
: base(dsConfig, requestItemsService)
16+
{
17+
}
18+
19+
public override string EgName => "Eg03";
20+
21+
[MustAuthenticate]
22+
[HttpGet]
23+
public override IActionResult Get()
24+
{
25+
if (string.IsNullOrEmpty(RequestItemsService.ClickwrapId))
26+
{
27+
ViewBag.errorCode = 400;
28+
ViewBag.errorMessage = "Cannot find any clickwrap. Please first create a clickwrap using the first example.";
29+
30+
return View("Error");
31+
}
32+
33+
return base.Get();
34+
}
35+
36+
protected override void InitializeInternal()
37+
{
38+
ViewBag.ClickwrapId = RequestItemsService.ClickwrapId;
39+
ViewBag.AccountId = RequestItemsService.Session.AccountId;
40+
}
41+
}
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using DocuSign.CodeExamples.Common;
2+
using DocuSign.CodeExamples.Controllers;
3+
using DocuSign.CodeExamples.Models;
4+
using Microsoft.AspNetCore.Mvc;
5+
6+
namespace DocuSign.CodeExamples.Click.Controllers
7+
{
8+
[Area("Click")]
9+
[Route("[area]/Eg04")]
10+
public class Eg04EmbedClickwrapController : EgController
11+
{
12+
public Eg04EmbedClickwrapController(
13+
DSConfiguration dsConfig,
14+
IRequestItemsService requestItemsService)
15+
: base(dsConfig, requestItemsService)
16+
{
17+
}
18+
19+
public override string EgName => "Eg04";
20+
21+
[MustAuthenticate]
22+
[HttpGet]
23+
public override IActionResult Get()
24+
{
25+
if (string.IsNullOrEmpty(RequestItemsService.ClickwrapId))
26+
{
27+
ViewBag.errorCode = 400;
28+
ViewBag.errorMessage = "Cannot find any clickwrap. Please first create a clickwrap using the first example.";
29+
30+
return View("Error");
31+
}
32+
33+
return base.Get();
34+
}
35+
36+
protected override void InitializeInternal()
37+
{
38+
ViewBag.ClickwrapId = RequestItemsService.ClickwrapId;
39+
ViewBag.AccountId = RequestItemsService.Session.AccountId;
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)