Skip to content

Commit 370328c

Browse files
authored
Merge pull request #20 from docusign/eSignature-controllers-update
Add examples folder. Update controllers to use methods from example folder classes
2 parents 708fbb2 + 81651c8 commit 370328c

File tree

70 files changed

+4248
-3411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4248
-3411
lines changed
Lines changed: 10 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using DocuSign.eSign.Api;
4-
using DocuSign.eSign.Client;
5-
using DocuSign.eSign.Model;
6-
using DocuSign.CodeExamples.Controllers;
1+
using DocuSign.CodeExamples.Controllers;
72
using DocuSign.CodeExamples.Models;
83
using Microsoft.AspNetCore.Mvc;
4+
using eSignature.Examples;
95

106
namespace DocuSign.CodeExamples.Views
117
{
@@ -24,161 +20,6 @@ public Eg001EmbeddedSigningController(DSConfiguration config, IRequestItemsServi
2420
ViewBag.title = "Embedded Signing Ceremony";
2521
}
2622

27-
// ***DS.snippet.0.start
28-
private string DoWork(string signerEmail, string signerName,
29-
string accessToken, string basePath, string accountId)
30-
{
31-
// Data for this method
32-
// signerEmail
33-
// signerName
34-
// accessToken
35-
// basePath
36-
// accountId
37-
38-
// dsPingUrl -- class global
39-
// signerClientId -- class global
40-
// dsReturnUrl -- class global
41-
42-
// Step 1. Create the envelope definition
43-
EnvelopeDefinition envelope = MakeEnvelope(signerEmail, signerName);
44-
45-
// Step 2. Call DocuSign to create the envelope
46-
var apiClient = new ApiClient(basePath);
47-
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
48-
var envelopesApi = new EnvelopesApi(apiClient);
49-
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelope);
50-
string envelopeId = results.EnvelopeId;
51-
52-
// Save for future use within the example launcher
53-
RequestItemsService.EnvelopeId = envelopeId;
54-
55-
// Step 3. create the recipient view, the Signing Ceremony
56-
RecipientViewRequest viewRequest = MakeRecipientViewRequest(signerEmail, signerName);
57-
// call the CreateRecipientView API
58-
ViewUrl results1 = envelopesApi.CreateRecipientView(accountId, envelopeId, viewRequest);
59-
60-
// Step 4. Redirect the user to the Signing Ceremony
61-
// Don't use an iFrame!
62-
// State can be stored/recovered using the framework's session or a
63-
// query parameter on the returnUrl (see the makeRecipientViewRequest method)
64-
string redirectUrl = results1.Url;
65-
return redirectUrl;
66-
}
67-
68-
private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string signerName)
69-
{
70-
// Data for this method
71-
// signerEmail
72-
// signerName
73-
// dsPingUrl -- class global
74-
// signerClientId -- class global
75-
// dsReturnUrl -- class global
76-
77-
78-
RecipientViewRequest viewRequest = new RecipientViewRequest();
79-
// Set the url where you want the recipient to go once they are done signing
80-
// should typically be a callback route somewhere in your app.
81-
// The query parameter is included as an example of how
82-
// to save/recover state information during the redirect to
83-
// the DocuSign signing ceremony. It's usually better to use
84-
// the session mechanism of your web framework. Query parameters
85-
// can be changed/spoofed very easily.
86-
viewRequest.ReturnUrl = dsReturnUrl + "?state=123";
87-
88-
// How has your app authenticated the user? In addition to your app's
89-
// authentication, you can include authenticate steps from DocuSign.
90-
// Eg, SMS authentication
91-
viewRequest.AuthenticationMethod = "none";
92-
93-
// Recipient information must match embedded recipient info
94-
// we used to create the envelope.
95-
viewRequest.Email = signerEmail;
96-
viewRequest.UserName = signerName;
97-
viewRequest.ClientUserId = signerClientId;
98-
99-
// DocuSign recommends that you redirect to DocuSign for the
100-
// Signing Ceremony. There are multiple ways to save state.
101-
// To maintain your application's session, use the pingUrl
102-
// parameter. It causes the DocuSign Signing Ceremony web page
103-
// (not the DocuSign server) to send pings via AJAX to your
104-
// app,
105-
viewRequest.PingFrequency = "600"; // seconds
106-
// NOTE: The pings will only be sent if the pingUrl is an https address
107-
viewRequest.PingUrl = dsPingUrl; // optional setting
108-
109-
return viewRequest;
110-
}
111-
112-
private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName)
113-
{
114-
// Data for this method
115-
// signerEmail
116-
// signerName
117-
// signerClientId -- class global
118-
// Config.docPdf
119-
120-
121-
byte[] buffer = System.IO.File.ReadAllBytes(Config.docPdf);
122-
123-
EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();
124-
envelopeDefinition.EmailSubject = "Please sign this document";
125-
Document doc1 = new Document();
126-
127-
String doc1b64 = Convert.ToBase64String(buffer);
128-
129-
doc1.DocumentBase64 = doc1b64;
130-
doc1.Name = "Lorem Ipsum"; // can be different from actual file name
131-
doc1.FileExtension = "pdf";
132-
doc1.DocumentId = "3";
133-
134-
// The order in the docs array determines the order in the envelope
135-
envelopeDefinition.Documents = new List<Document> { doc1 };
136-
137-
// Create a signer recipient to sign the document, identified by name and email
138-
// We set the clientUserId to enable embedded signing for the recipient
139-
// We're setting the parameters via the object creation
140-
Signer signer1 = new Signer {
141-
Email = signerEmail,
142-
Name = signerName,
143-
ClientUserId = signerClientId,
144-
RecipientId = "1"
145-
};
146-
147-
// Create signHere fields (also known as tabs) on the documents,
148-
// We're using anchor (autoPlace) positioning
149-
//
150-
// The DocuSign platform seaches throughout your envelope's
151-
// documents for matching anchor strings.
152-
SignHere signHere1 = new SignHere
153-
{
154-
AnchorString = "/sn1/",
155-
AnchorUnits = "pixels",
156-
AnchorXOffset = "10",
157-
AnchorYOffset = "20"
158-
};
159-
// Tabs are set per recipient / signer
160-
Tabs signer1Tabs = new Tabs
161-
{
162-
SignHereTabs = new List<SignHere> { signHere1 }
163-
};
164-
signer1.Tabs = signer1Tabs;
165-
166-
// Add the recipient to the envelope object
167-
Recipients recipients = new Recipients
168-
{
169-
Signers = new List<Signer> { signer1 }
170-
};
171-
envelopeDefinition.Recipients = recipients;
172-
173-
// Request that the envelope be sent by setting |status| to "sent".
174-
// To request that the envelope be created as a draft, set to "created"
175-
envelopeDefinition.Status = "sent";
176-
177-
return envelopeDefinition;
178-
}
179-
// ***DS.snippet.0.end
180-
181-
18223
public override string EgName => "eg001";
18324

18425
[HttpPost]
@@ -207,9 +48,15 @@ public IActionResult Create(string signerEmail, string signerName)
20748
return Redirect("/ds/mustAuthenticate");
20849
}
20950

210-
string redirectUrl = DoWork(signerEmail, signerName, accessToken, basePath, accountId);
51+
// Call the method from Examples API to send envelope and generate url for embedded signing
52+
var result = EmbeddedSigningCeremony.SendEnvelopeForEmbeddedSigning(signerEmail,
53+
signerName, signerClientId, accessToken, basePath, accountId, Config.docPdf, dsReturnUrl, dsPingUrl);
54+
55+
// Save for future use within the example launcher
56+
RequestItemsService.EnvelopeId = result.Item1;
57+
21158
// Redirect the user to the Signing Ceremony
212-
return Redirect(redirectUrl);
59+
return Redirect(result.Item2);
21360
}
21461
}
21562
}

0 commit comments

Comments
 (0)