Skip to content

Commit c8a2430

Browse files
authored
Merge pull request #170 from docusign/feature/added-notary-example
Added notary example
2 parents 2c98ab3 + cd03cdc commit c8a2430

11 files changed

+529
-79
lines changed

public/assets/search.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ let DS_SEARCH = (function () {
66
ROOMS: 'rooms',
77
ADMIN: 'admin',
88
CONNECT: 'connect',
9-
WEBFORMS: 'webforms'
9+
WEBFORMS: 'webforms',
10+
NOTARY: 'notary',
1011
};
1112

1213
let processJSONData = function () {
@@ -128,6 +129,8 @@ let DS_SEARCH = (function () {
128129
return "con";
129130
case API_TYPES.WEBFORMS:
130131
return "web";
132+
case API_TYPES.NOTARY:
133+
return "n";
131134
}
132135
}
133136

src/Controllers/Auth/DocuSign.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ public function getDefaultScopes(): array
126126
return [
127127
"signature webforms_read webforms_instance_read webforms_instance_write"
128128
];
129+
} elseif ($_SESSION['api_type'] == ApiTypes::NOTARY) {
130+
return [
131+
"signature"
132+
];
129133
} else {
130134
return [
131135
"signature"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace DocuSign\Controllers\Examples\Notary;
4+
5+
use DocuSign\Controllers\NotaryApiBaseController;
6+
use DocuSign\Services\Examples\Notary\SendWithThirdPartyNotaryService;
7+
use DocuSign\WebForms\Client\ApiException;
8+
use DocuSign\Services\ManifestService;
9+
10+
class Neg004SendWithThirdPartyNotary extends NotaryApiBaseController
11+
{
12+
const EG = "n004"; # reference (and URL) for this example
13+
const FILE = __FILE__;
14+
15+
/**
16+
* Create a new controller instance.
17+
*
18+
* @return void
19+
*/
20+
public function __construct()
21+
{
22+
parent::__construct();
23+
parent::controller();
24+
}
25+
26+
/**
27+
* Get specific template arguments
28+
*
29+
* @return array
30+
*/
31+
public function getTemplateArgs(): array
32+
{
33+
return [
34+
"signer_email" => $this->checkEmailInputValue($_POST["signer_email"]),
35+
"signer_name" => $this->checkInputValues($_POST["signer_name"]),
36+
"account_id" => $_SESSION["ds_account_id"],
37+
"base_path" => $_SESSION["ds_base_path"],
38+
"ds_access_token" => $_SESSION["ds_access_token"]
39+
];
40+
}
41+
42+
/**
43+
* 1. Check the token
44+
* 2. Call the worker method
45+
* 3. Return envelope id
46+
*
47+
* @return void
48+
* @throws ApiException
49+
* @throws \DocuSign\eSign\Client\ApiException
50+
*/
51+
protected function createController(): void
52+
{
53+
$this->checkDsToken();
54+
55+
$envelopeResponse = SendWithThirdPartyNotaryService::sendWithNotary(
56+
$this->args["signer_email"],
57+
$this->args["signer_email"],
58+
$this->clientService->getEnvelopeApi(),
59+
$this->args["account_id"],
60+
self::DEMO_DOCS_PATH
61+
);
62+
63+
64+
if ($envelopeResponse) {
65+
$this->clientService->showDoneTemplateFromManifest(
66+
$this->codeExampleText,
67+
null,
68+
ManifestService::replacePlaceholders(
69+
"{0}",
70+
$envelopeResponse["envelope_id"],
71+
$this->codeExampleText["ResultsPageText"]
72+
)
73+
);
74+
}
75+
}
76+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
3+
namespace DocuSign\Controllers;
4+
5+
use DocuSign\Services\SignatureClientService;
6+
use DocuSign\Services\RouterService;
7+
use DocuSign\Services\IRouterService;
8+
use DocuSign\Services\ApiTypes;
9+
use DocuSign\Services\ManifestService;
10+
11+
abstract class NotaryApiBaseController extends BaseController
12+
{
13+
private const MINIMUM_BUFFER_MIN = 3;
14+
protected SignatureClientService $clientService;
15+
protected IRouterService $routerService;
16+
protected array $args;
17+
18+
public function __construct()
19+
{
20+
$this->args = $this->getTemplateArgs();
21+
$this->clientService = new SignatureClientService($this->args);
22+
$this->routerService = new RouterService();
23+
if (defined("static::EG")) {
24+
$this->checkDsToken();
25+
}
26+
}
27+
28+
abstract protected function getTemplateArgs(): array;
29+
30+
/**
31+
* Base controller
32+
*
33+
* @param null $eg
34+
* @return void
35+
*/
36+
public function controller($eg = null): void
37+
{
38+
if (empty($eg)) {
39+
$eg = static::EG;
40+
$this->codeExampleText = $this->getPageText(static::EG);
41+
}
42+
43+
if ($this->isMethodGet()) {
44+
$this->getController(
45+
$eg,
46+
basename(static::FILE)
47+
);
48+
}
49+
50+
if ($this->isMethodPost()) {
51+
$this->createController();
52+
}
53+
}
54+
55+
/**
56+
* Show the example's form page
57+
*
58+
* @param $eg
59+
* @param $basename string|null
60+
* @param $brand_languages array|null
61+
* @param $brands array|null
62+
* @param $permission_profiles array|null
63+
* @param $groups array|null
64+
* @return void
65+
*/
66+
protected function getController(
67+
$eg,
68+
?string $basename
69+
): void {
70+
if ($this->isHomePage($eg)) {
71+
$GLOBALS['twig']->display(
72+
$eg . '.html',
73+
[
74+
'title' => $this->homePageTitle($eg),
75+
'show_doc' => false,
76+
'launcher_texts' => $_SESSION['API_TEXT']['APIs'],
77+
'api_texts' => $_SESSION['API_TEXT'],
78+
'common_texts' => $this->getCommonText(),
79+
]
80+
);
81+
} else {
82+
$currentAPI = ManifestService::getAPIByLink(static::EG);
83+
if ($this->routerService->dsTokenOk() && $currentAPI === $_SESSION['api_type']) {
84+
$displayOptions = [
85+
'title' => $this->routerService->getTitle($eg),
86+
'source_file' => $basename,
87+
'source_url' => $GLOBALS['DS_CONFIG']['github_example_url'] . "/Notary/". $basename,
88+
'documentation' => $GLOBALS['DS_CONFIG']['documentation'] . $eg,
89+
'show_doc' => $GLOBALS['DS_CONFIG']['documentation'],
90+
'signer_name' => $GLOBALS['DS_CONFIG']['signer_name'],
91+
'signer_email' => $GLOBALS['DS_CONFIG']['signer_email'],
92+
'code_example_text' => $this->codeExampleText,
93+
'common_texts' => $this->getCommonText()
94+
];
95+
96+
$GLOBALS['twig']->display($this->routerService->getTemplate($eg), $displayOptions);
97+
} else {
98+
$_SESSION['prefered_api_type'] = ApiTypes::NOTARY;
99+
$this->saveCurrentUrlToSession($eg);
100+
header('Location: ' . $GLOBALS['app_url'] . 'index.php?page=' . static::LOGIN_REDIRECT);
101+
exit;
102+
}
103+
}
104+
}
105+
106+
/**
107+
* Declaration for the base controller creator. Each creator should be described in specific Controller
108+
*/
109+
abstract protected function createController(): void;
110+
111+
/**
112+
* Check email input value using regular expression
113+
* @param $email
114+
* @return string
115+
*/
116+
protected function checkEmailInputValue($email): string
117+
{
118+
return preg_replace('/([^\w +\-\@\.\,])+/', '', $email);
119+
}
120+
121+
/**
122+
* Check input values using regular expressions
123+
* @param $value
124+
* @return string
125+
*/
126+
protected function checkInputValues($value): string
127+
{
128+
return preg_replace('/([^\w \-\@\.\,])+/', '', $value);
129+
}
130+
131+
/**
132+
* Check ds
133+
*/
134+
protected function checkDsToken(): void
135+
{
136+
$currentAPI = ManifestService::getAPIByLink(static::EG);
137+
138+
if (!$this->routerService->dsTokenOk(self::MINIMUM_BUFFER_MIN) || $currentAPI !== $_SESSION['api_type']) {
139+
$_SESSION['prefered_api_type'] = ApiTypes::NOTARY;
140+
$this->clientService->needToReAuth(static::EG);
141+
}
142+
}
143+
}

src/Services/ApiTypes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ abstract class ApiTypes
1010
const ROOMS = 'Rooms';
1111
const ESIGNATURE = 'eSignature';
1212
const CONNECT = 'Connect';
13+
const MAESTRO = 'Maestro';
1314
const WEBFORMS = 'WebForms';
15+
const NOTARY = 'Notary';
1416
}

0 commit comments

Comments
 (0)