Skip to content

Commit 62ad6b7

Browse files
committed
added notary example
1 parent 2c98ab3 commit 62ad6b7

File tree

11 files changed

+520
-84
lines changed

11 files changed

+520
-84
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: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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+
if (empty($eg)) {
38+
$eg = static::EG;
39+
$this->codeExampleText = $this->getPageText(static::EG);
40+
}
41+
42+
if ($this->isMethodGet()) {
43+
$this->getController(
44+
$eg,
45+
basename(static::FILE)
46+
);
47+
}
48+
49+
if ($this->isMethodPost()) {
50+
$this->createController();
51+
}
52+
}
53+
54+
/**
55+
* Show the example's form page
56+
*
57+
* @param $eg
58+
* @param $basename string|null
59+
* @param $brand_languages array|null
60+
* @param $brands array|null
61+
* @param $permission_profiles array|null
62+
* @param $groups array|null
63+
* @return void
64+
*/
65+
protected function getController(
66+
$eg,
67+
?string $basename
68+
): void {
69+
if ($this->isHomePage($eg)) {
70+
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+
85+
$displayOptions = [
86+
'title' => $this->routerService->getTitle($eg),
87+
'source_file' => $basename,
88+
'source_url' => $GLOBALS['DS_CONFIG']['github_example_url'] . "/Notary/". $basename,
89+
'documentation' => $GLOBALS['DS_CONFIG']['documentation'] . $eg,
90+
'show_doc' => $GLOBALS['DS_CONFIG']['documentation'],
91+
'signer_name' => $GLOBALS['DS_CONFIG']['signer_name'],
92+
'signer_email' => $GLOBALS['DS_CONFIG']['signer_email'],
93+
'code_example_text' => $this->codeExampleText,
94+
'common_texts' => $this->getCommonText()
95+
];
96+
97+
$GLOBALS['twig']->display($this->routerService->getTemplate($eg), $displayOptions);
98+
} else {
99+
$_SESSION['prefered_api_type'] = ApiTypes::NOTARY;
100+
$this->saveCurrentUrlToSession($eg);
101+
header('Location: ' . $GLOBALS['app_url'] . 'index.php?page=' . static::LOGIN_REDIRECT);
102+
exit;
103+
}
104+
}
105+
}
106+
107+
/**
108+
* Declaration for the base controller creator. Each creator should be described in specific Controller
109+
*/
110+
abstract protected function createController(): void;
111+
112+
/**
113+
* Check email input value using regular expression
114+
* @param $email
115+
* @return string
116+
*/
117+
protected function checkEmailInputValue($email): string
118+
{
119+
return preg_replace('/([^\w +\-\@\.\,])+/', '', $email);
120+
}
121+
122+
/**
123+
* Check input values using regular expressions
124+
* @param $value
125+
* @return string
126+
*/
127+
protected function checkInputValues($value): string
128+
{
129+
return preg_replace('/([^\w \-\@\.\,])+/', '', $value);
130+
}
131+
132+
/**
133+
* Check ds
134+
*/
135+
protected function checkDsToken(): void
136+
{
137+
$currentAPI = ManifestService::getAPIByLink(static::EG);
138+
139+
if (!$this->routerService->dsTokenOk(self::MINIMUM_BUFFER_MIN) || $currentAPI !== $_SESSION['api_type']) {
140+
$_SESSION['prefered_api_type'] = ApiTypes::NOTARY;
141+
$this->clientService->needToReAuth(static::EG);
142+
}
143+
}
144+
}

src/Services/ApiTypes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ abstract class ApiTypes
1111
const ESIGNATURE = 'eSignature';
1212
const CONNECT = 'Connect';
1313
const WEBFORMS = 'WebForms';
14+
const NOTARY = 'Notary';
1415
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
3+
namespace DocuSign\Services\Examples\Notary;
4+
5+
use DocuSign\eSign\Model\Document;
6+
use DocuSign\eSign\Model\Recipients;
7+
use DocuSign\eSign\Model\Signer;
8+
use DocuSign\eSign\Model\SignHere;
9+
use DocuSign\eSign\Model\Tabs;
10+
use DocuSign\eSign\Model\EnvelopeDefinition;
11+
use DocuSign\eSign\Model\NotaryRecipient;
12+
use DocuSign\eSign\Model\NotarySeal;
13+
use DocuSign\eSign\Model\RecipientSignatureProvider;
14+
use DocuSign\eSign\Model\RecipientSignatureProviderOptions;
15+
16+
class SendWithThirdPartyNotaryService
17+
{
18+
public static function sendWithNotary($signerEmail, $signerName, $envelopesApi, $accountId, $demoPath) {
19+
$env = SendWithThirdPartyNotaryService::makeEnvelope($signerEmail, $signerName, $demoPath);
20+
21+
$results = $envelopesApi->createEnvelope($accountId, $env);
22+
return $results;
23+
}
24+
25+
static function makeEnvelope($signerEmail, $signerName, $demoPath) {
26+
$env = new EnvelopeDefinition();
27+
$env->setEmailSubject("Please sign this document set");
28+
29+
$env->setDocuments(SendWithThirdPartyNotaryService::getDocuments($signerEmail, $signerName, $demoPath));
30+
31+
$recipients = new Recipients();
32+
$recipients->setSigners(SendWithThirdPartyNotaryService::getSigners($signerEmail, $signerName));
33+
$recipients->setNotaries(SendWithThirdPartyNotaryService::getNotaryRecipients());
34+
35+
$env->setRecipients($recipients);
36+
$env->setStatus("sent");
37+
38+
return $env;
39+
}
40+
41+
static function getDocuments($signerEmail, $signerName,$demoPath) {
42+
43+
44+
$doc1 = new Document();
45+
$b64 = base64_encode(SendWithThirdPartyNotaryService::getDocumentExample($signerEmail, $signerName, $demoPath));
46+
$doc1->setDocumentBase64($b64);
47+
$doc1->setName("Order acknowledgement");
48+
$doc1->setFileExtension("html");
49+
$doc1->setDocumentId("1");
50+
51+
return [$doc1];
52+
}
53+
54+
static function getDocumentExample($signerEmail, $signerName, $demoPath): string {
55+
$htmlMarkupFileName = "order_form.html";
56+
$htmlMarkup = file_get_contents($demoPath . $htmlMarkupFileName);
57+
$htmlWithData = str_replace(
58+
[
59+
"{signer_name}",
60+
"{signer_email}"
61+
],
62+
[
63+
$signerName,
64+
$signerEmail
65+
],
66+
$htmlMarkup
67+
);
68+
return $htmlWithData;
69+
}
70+
71+
static function getSigners($signerEmail, $signerName) {
72+
$signer = new Signer();
73+
$signer->setClientUserId("1000");
74+
$signer->setEmail($signerEmail);
75+
$signer->setName($signerName);
76+
$signer->setRecipientId("2");
77+
$signer->setRoutingOrder("1");
78+
$signer->setNotaryId("1");
79+
80+
$signHere = new SignHere();
81+
$signHere->setDocumentId("1");
82+
$signHere->setXPosition("200");
83+
$signHere->setYPosition("235");
84+
$signHere->setPageNumber("1");
85+
86+
$signHereWithStamp = new SignHere();
87+
$signHereWithStamp->setDocumentId("1");
88+
$signHereWithStamp->setXPosition("200");
89+
$signHereWithStamp->setYPosition("150");
90+
$signHereWithStamp->setPageNumber("1");
91+
$signHereWithStamp->setStampType("stamp");
92+
93+
$tabs = new Tabs();
94+
$tabs->setSignHereTabs([$signHere, $signHereWithStamp]);
95+
$signer->setTabs($tabs);
96+
97+
return [$signer];
98+
}
99+
100+
static function getNotaryRecipients(): array {
101+
$notarySeal = new NotarySeal();
102+
$notarySeal->setXPosition("300");
103+
$notarySeal->setYPosition("235");
104+
$notarySeal->setDocumentId("1");
105+
$notarySeal->setPageNumber("1");
106+
107+
$signHere = new SignHere();
108+
$signHere->setDocumentId("1");
109+
$signHere->setXPosition("300");
110+
$signHere->setYPosition("150");
111+
$signHere->setPageNumber("1");
112+
113+
$tabs = new Tabs();
114+
$tabs->setSignHereTabs([$signHere]);
115+
$tabs->setNotarySealTabs([$notarySeal]);
116+
117+
$notaryRecipient = new NotaryRecipient();
118+
$notaryRecipient->setEmail("");
119+
$notaryRecipient->setName("Notary");
120+
$notaryRecipient->setRecipientId("1");
121+
$notaryRecipient->setRoutingOrder("1");
122+
$notaryRecipient->setNotaryType("remote");
123+
$notaryRecipient->setNotarySourceType("thirdparty");
124+
$notaryRecipient->setNotaryThirdPartyPartner("onenotary");
125+
$notaryRecipient->setTabs($tabs);
126+
127+
$signatureProvider = new RecipientSignatureProvider();
128+
$signatureProvider->setSignatureProviderName("ds_authority_idv");
129+
$signatureProvider->setSignatureProviderOptions(new RecipientSignatureProviderOptions());
130+
131+
$notaryRecipient->setRecipientSignatureProviders([$signatureProvider]);
132+
133+
return [$notaryRecipient];
134+
}
135+
}

0 commit comments

Comments
 (0)