Skip to content

Commit f675db6

Browse files
annahiletaAaronWDSmeihDS
authored
Added the set document visibility code example (#83)
* added the in-person signing code example * added the set document visibility code example * fixed issue with mixed type for php 7 * used IRouterService interface * hide the installed vendor directory in ACG installs * remove the example numbers from view * remove individual ex. numbers from each template file Co-authored-by: Aaron JacksonWilde <Aaron.Wilde@docusign.com> Co-authored-by: meihDS <70775251+meihDS@users.noreply.github.com>
1 parent 322b217 commit f675db6

File tree

87 files changed

+950
-271
lines changed

Some content is hidden

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

87 files changed

+950
-271
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ debug.log
4444
public/demo_documents/ExportedUserData.csv
4545
JWTConsoleApp/vendor/*
4646
JWTConsoleApp/ds_config_jwt_mini.php
47+
Quick_ACG/vendor/*

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ RUN rm -rf /var/www && mkdir -p /var/www/html
44
WORKDIR /var/www/html
55

66

7-
8-
97
FROM php:8.1.6RC1-fpm-alpine3.15
108

119
# Install dev dependencies

Quick_ACG/src/RouterService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace QuickACG;
44

55
use Example\Services\CodeGrantService;
6+
use Example\Services\IRouterService;
67

7-
class RouterService
8+
class RouterService implements IRouterService
89
{
910
private const CONTROLLER = [
1011
'eg001' => 'EG001EmbeddedSigning'

ds_config_example.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'target_account_id' => false, // Set if you want a specific DocuSign AccountId, If false, the user's default account will be used.
2222
'demo_doc_path' => 'demo_documents',
2323
'doc_docx' => 'World_Wide_Corp_Battle_Plan_Trafalgar.docx',
24+
'doc_html' => 'doc_1.html',
2425
'doc_pdf' => 'World_Wide_Corp_lorem.pdf',
2526
'doc_txt' => 'Check_If_Approved.txt',
2627
// Payment gateway information is optional

public/demo_documents/doc_1.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
</head>
6+
<body style="font-family:sans-serif;margin-left:2em;">
7+
<h1 style="font-family: 'Trebuchet MS', Helvetica, sans-serif;
8+
color: darkblue;margin-bottom: 0;">World Wide Corp</h1>
9+
<h2 style="font-family: 'Trebuchet MS', Helvetica, sans-serif;
10+
margin-top: 0px;margin-bottom: 3.5em;font-size: 1em;
11+
color: darkblue;">Order Processing Division</h2>
12+
<h4>Ordered by {USER_FULLNAME}</h4>
13+
<p style="margin-top:0em; margin-bottom:0em;">Email: {USER_EMAIL}</p>
14+
<p style="margin-top:3em;">
15+
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.
16+
</p>
17+
<!-- Note the anchor tag for the signature field is in white. -->
18+
<h3 style="margin-top:3em;">Agreed: <span style="color:white;">**signature_1**/</span></h3>
19+
</body>
20+
</html>

src/Controllers/Examples/Home.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
use QuickACG\RouterService as QuickRouterService;
1212
use Example\Controllers\eSignBaseController;
1313
use Example\Services\RouterService;
14+
use Example\Services\IRouterService;
1415

1516
class Home extends eSignBaseController
1617
{
1718
const FILE = __FILE__;
1819
/** RouterService */
19-
protected mixed $routerService;
20+
protected IRouterService $routerService;
2021
private string $eg; # Reference (and URL) for this example
2122

2223
/**
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
/**
4+
* Example 039: In person signing.
5+
*/
6+
7+
namespace Example\Controllers\Examples\eSignature;
8+
9+
use Example\Controllers\eSignBaseController;
10+
use Example\Services\Examples\eSignature\InPersonSigningService;
11+
use DocuSign\eSign\Client\ApiException;
12+
13+
class EG039InPersonSigning extends eSignBaseController
14+
{
15+
const EG = 'eg039';
16+
const FILE = __FILE__;
17+
18+
/**
19+
* Create a new controller instance.
20+
*
21+
* @return void
22+
*/
23+
public function __construct()
24+
{
25+
parent::__construct();
26+
parent::controller();
27+
}
28+
29+
/**
30+
* 1. Check the token
31+
* 2. Call the worker method
32+
* 3. Redirect the user to the signing
33+
*
34+
* @return void
35+
*/
36+
public function createController(): void
37+
{
38+
$this->checkDsToken();
39+
40+
// Perhaps these can help with a use case?
41+
// $hostEmail = $this->clientService->getAuthenticatedUserEmail($this->args["ds_access_token"]);
42+
// $hostName = $this->clientService->getAuthenticatedUserName($this->args["ds_access_token"]);
43+
try {
44+
$returnUrl = InPersonSigningService::worker(
45+
$this->args["account_id"],
46+
$this->args["signer_name"],
47+
$this->clientService,
48+
self::DEMO_DOCS_PATH
49+
);
50+
51+
if ($returnUrl) {
52+
header('Location: ' . $returnUrl);
53+
exit;
54+
}
55+
} catch (ApiException $e) {
56+
$this->clientService->showErrorTemplate($e);
57+
}
58+
}
59+
60+
/**
61+
* Get specific template arguments
62+
* @return array
63+
*/
64+
public function getTemplateArgs(): array
65+
{
66+
return [
67+
'account_id' => $_SESSION['ds_account_id'],
68+
'base_path' => $_SESSION['ds_base_path'],
69+
'ds_access_token' => $_SESSION['ds_access_token'],
70+
'signer_name' => $this->checkInputValues($_POST['signer_name']),
71+
'ds_return_url' => $GLOBALS['app_url'] . 'index.php?page=ds_return'
72+
];
73+
}
74+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
/**
4+
* Example 040: Set document visibility.
5+
*/
6+
7+
namespace Example\Controllers\Examples\eSignature;
8+
9+
use Example\Controllers\eSignBaseController;
10+
use Example\Services\Examples\eSignature\SetDocumentsVisibilityService;
11+
use DocuSign\eSign\Client\ApiException;
12+
13+
class EG040SetDocumentsVisibility extends eSignBaseController
14+
{
15+
const EG = 'eg040'; # reference (and URL) for this example
16+
const FILE = __FILE__;
17+
18+
/**
19+
* Create a new controller instance.
20+
*
21+
* @return void
22+
*/
23+
public function __construct()
24+
{
25+
parent::__construct();
26+
parent::controller();
27+
}
28+
29+
/**
30+
* 1. Check the token
31+
* 2. Call the worker method
32+
* 3. Redirect the user to the signing
33+
*
34+
* @return void
35+
*/
36+
public function createController(): void
37+
{
38+
$this->checkDsToken();
39+
40+
try {
41+
$envelopeId = SetDocumentsVisibilityService::worker(
42+
$this->args['signer_1_email'],
43+
$this->args['signer_1_name'],
44+
$this->args['signer_2_email'],
45+
$this->args['signer_2_name'],
46+
$this->args['cc_email'],
47+
$this->args['cc_name'],
48+
$GLOBALS['DS_CONFIG']['doc_pdf'],
49+
$GLOBALS['DS_CONFIG']['doc_docx'],
50+
$GLOBALS['DS_CONFIG']['doc_html'],
51+
$this->args['account_id'],
52+
$this->clientService,
53+
self::DEMO_DOCS_PATH
54+
);
55+
56+
if ($envelopeId) {
57+
$this->clientService->showDoneTemplate(
58+
"Set document visibility for envelope recipients",
59+
"Set document visibility for envelope recipients",
60+
"The envelope has been created and sent!<br/> Envelope ID {$envelopeId}."
61+
);
62+
}
63+
} catch (ApiException $e) {
64+
$this->clientService->showErrorTemplate($e);
65+
}
66+
}
67+
68+
/**
69+
* Get specific template arguments
70+
* @return array
71+
*/
72+
public function getTemplateArgs(): array
73+
{
74+
return [
75+
'account_id' => $_SESSION['ds_account_id'],
76+
'base_path' => $_SESSION['ds_base_path'],
77+
'ds_access_token' => $_SESSION['ds_access_token'],
78+
'signer_1_email' => $this->checkEmailInputValue($_POST['signer_1_email']),
79+
'signer_1_name' => $this->checkInputValues($_POST['signer_1_name']),
80+
'signer_2_email' => $this->checkInputValues($_POST['signer_2_email']),
81+
'signer_2_name' => $this->checkInputValues($_POST['signer_2_name']),
82+
'cc_email' => $this->checkEmailInputValue($_POST['cc_email']),
83+
'cc_name' => $this->checkInputValues($_POST['cc_name']),
84+
];
85+
}
86+
}

src/Controllers/eSignBaseController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Example\Services\RouterService;
66
use QuickACG\RouterService as QuickRouterService;
77
use Example\Services\SignatureClientService;
8+
use Example\Services\IRouterService;
89

910
abstract class eSignBaseController extends BaseController
1011
{
@@ -37,7 +38,7 @@ abstract class eSignBaseController extends BaseController
3738
"vaultingMode" => "none"
3839
];
3940
protected SignatureClientService $clientService;
40-
protected mixed $routerService;
41+
protected IRouterService $routerService;
4142
protected array $args;
4243

4344
# DCM-3905 The SDK helper method for setting the SigningUIVersion is temporarily unavailable at this time.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
namespace Example\Services\Examples\eSignature;
4+
5+
use DocuSign\eSign\Client\ApiException;
6+
use DocuSign\eSign\Model\Document;
7+
use DocuSign\eSign\Model\EnvelopeDefinition;
8+
use DocuSign\eSign\Model\Recipients;
9+
use DocuSign\eSign\Model\InPersonSigner;
10+
use DocuSign\eSign\Model\SignHere;
11+
use DocuSign\eSign\Model\Tabs;
12+
use Example\Services\SignatureClientService;
13+
14+
class InPersonSigningService
15+
{
16+
/**
17+
* Do the work of the example
18+
* 1. Create the envelope request object
19+
* 2. Send the envelope
20+
* 3. Create the Recipient View request object
21+
* 4. Obtain the recipient_view_url for the embedded signing
22+
* @return string
23+
*/
24+
public static function worker(
25+
string $accountId,
26+
string $hostName,
27+
SignatureClientService $clientService,
28+
string $demoPath
29+
): string {
30+
$envelopeDefinition = InPersonSigningService::_prepareEnvelope($hostName, $demoPath);
31+
$envelopeApi = $clientService->getEnvelopeApi();
32+
33+
try {
34+
$envelopeSummary = $envelopeApi->createEnvelope($accountId, $envelopeDefinition);
35+
} catch (ApiException $e) {
36+
$clientService->showErrorTemplate($e);
37+
exit;
38+
}
39+
40+
$authentication_method = 'None';
41+
42+
$envelopeArguments = [
43+
'signer_email' => $GLOBALS['DS_CONFIG']['signer_email'],
44+
'signer_name' => $GLOBALS['DS_CONFIG']['signer_name'],
45+
'ds_return_url' => $GLOBALS['app_url'] . 'index.php?page=ds_return'
46+
];
47+
48+
$recipientViewRequest = $clientService->getRecipientViewRequest(
49+
$authentication_method,
50+
$envelopeArguments
51+
);
52+
53+
$viewUrl = $clientService->getRecipientView($accountId, $envelopeSummary->getEnvelopeId(), $recipientViewRequest);
54+
55+
return $viewUrl['url'];
56+
}
57+
58+
/**
59+
* Creates envelope definition
60+
* Parameters for the envelope: signer_email, signer_name, signer_client_id
61+
*
62+
* @param $args array
63+
* @return EnvelopeDefinition -- returns an envelope definition
64+
*/
65+
private static function _prepareEnvelope(string $hostName, string $demoPath): EnvelopeDefinition
66+
{
67+
$file_content_in_bytes = file_get_contents($demoPath . $GLOBALS['DS_CONFIG']['doc_pdf']);
68+
$document = new Document(
69+
[
70+
'document_base64' => base64_encode($file_content_in_bytes),
71+
'name' => 'Lorem Ipsum',
72+
'file_extension' => 'pdf',
73+
'document_id' => '1'
74+
]
75+
);
76+
77+
$inPersonSigner = new InPersonSigner(
78+
[
79+
'host_email' => $GLOBALS['DS_CONFIG']['signer_email'],
80+
'host_name' => $GLOBALS['DS_CONFIG']['signer_name'],
81+
'signer_name' => $hostName,
82+
'recipient_id' => "1",
83+
'routing_order' => "1"
84+
]
85+
);
86+
87+
$sign_here = new SignHere(
88+
[
89+
'anchor_string' => '/sn1/',
90+
'anchor_units' => 'pixels',
91+
'anchor_y_offset' => '10',
92+
'anchor_x_offset' => '20'
93+
]
94+
);
95+
96+
$inPersonSigner->settabs(new Tabs(['sign_here_tabs' => [$sign_here]]));
97+
98+
return new EnvelopeDefinition(
99+
[
100+
'email_subject' => "Please host this in-person signing session",
101+
'documents' => [$document],
102+
'recipients' => new Recipients(['in_person_signers' => [$inPersonSigner]]),
103+
'status' => "sent"
104+
]
105+
);
106+
}
107+
}

0 commit comments

Comments
 (0)