Skip to content

Commit 9c9a140

Browse files
AaronWDSdependabot[bot]InbarGazit
authored
Devdocs 9013: cfr part 11 (#93)
* Bump twig/twig from 3.3.8 to 3.4.3 in /Quick_ACG Bumps [twig/twig](https://github.com/twigphp/Twig) from 3.3.8 to 3.4.3. - [Release notes](https://github.com/twigphp/Twig/releases) - [Changelog](https://github.com/twigphp/Twig/blob/3.x/CHANGELOG) - [Commits](twigphp/Twig@v3.3.8...v3.4.3) --- updated-dependencies: - dependency-name: twig/twig dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * Bump twig/twig from 3.3.8 to 3.4.3 Bumps [twig/twig](https://github.com/twigphp/Twig) from 3.3.8 to 3.4.3. - [Release notes](https://github.com/twigphp/Twig/releases) - [Changelog](https://github.com/twigphp/Twig/blob/3.x/CHANGELOG) - [Commits](twigphp/Twig@v3.3.8...v3.4.3) --- updated-dependencies: - dependency-name: twig/twig dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * README.md updates * wire in cfr check for jwt * check in changes * checking files in * home page filtering * checking in work (still need to fix eg41) filtering appears to be working * checking in changes * finally got it working! * pr requested fixes * small bugfix Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Inbar Gazit <inbar.gazit@docusign.com>
1 parent 01dc803 commit 9c9a140

File tree

13 files changed

+508
-10
lines changed

13 files changed

+508
-10
lines changed

Quick_ACG/src/RouterService.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
use Example\Services\ManifestService;
77
use Example\Services\IRouterService;
88

9+
910
class RouterService implements IRouterService
1011
{
1112
private const CONTROLLER = [
12-
'eg001' => 'EG001EmbeddedSigning'
13+
'eg001' => 'EG001EmbeddedSigning',
14+
'eg041' => 'eSignature\EG041CFREmbeddedSigning'
1315
];
1416

1517
private const TEMPLATES = [
16-
'eg001' => 'esignature/quickEmbeddedSigning.html'
18+
'eg001' => 'esignature/quickEmbeddedSigning.html',
19+
'eg041' => 'esignature/eg041_cfr_embedded_signing.html',
1720
];
1821

1922
private const SESSION_VALUES = [
@@ -30,7 +33,8 @@ class RouterService implements IRouterService
3033
'envelope_documents',
3134
'template_id',
3235
'api_type',
33-
'auth_service'
36+
'auth_service',
37+
'cfr_enabled'
3438
];
3539

3640
public $authService;
@@ -53,7 +57,12 @@ public function __construct()
5357
*/
5458
public function router(): void
5559
{
56-
$page = $_GET['page'] ?? 'eg001';
60+
61+
$embedSwitch = 'eg001';
62+
if ($_SESSION['cfr_enabled'] == 'enabled'){
63+
$embedSwitch = 'eg041';
64+
}
65+
$page = $_GET['page'] ?? $embedSwitch;
5766

5867
switch ($page) {
5968
case 'select_api':
@@ -68,7 +77,9 @@ public function router(): void
6877
default:
6978
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED);
7079
$_SESSION['API_TEXT'] = ManifestService::loadManifestData(ManifestService::getLinkToManifestFile('eSignature'));
71-
$controller = '\Example\\' . $this->getController($page);
80+
$controller = '\Example\Controllers\Examples\\' . $this->getController($page);
81+
// var_dump($controller);
82+
// die;
7283
new $controller($page);
7384
break;
7485
}

src/Controllers/Examples/SelectAPI.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ class SelectAPI
1414
{
1515
public function controller()
1616
{
17+
18+
19+
/*
20+
we don't know if the api_type has been set,
21+
if it has never been set, this will trigger an
22+
error in the manifest, therefore, we'll set it
23+
to ESignature for the Manifest service to work.
24+
*/
25+
if(!isset($_SESSION['api_type'])){
26+
$_SESSION['api_type'] = "ESignature";
27+
}
28+
1729
$method = $_SERVER['REQUEST_METHOD'];
1830
if ($method == 'GET') {
1931
$this->getController();
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Example 001: Use embedded signing
4+
*/
5+
6+
namespace Example\Controllers\Examples\eSignature;
7+
8+
use Example\Controllers\eSignBaseController;
9+
use Example\Services\Examples\eSignature\CFREmbeddedSigningService;
10+
11+
class EG041CFREmbeddedSigning extends eSignBaseController
12+
{
13+
const EG = "eg041"; # reference (and url) for this example
14+
const FILE = __FILE__;
15+
private int $signer_client_id = 1000; # Used to indicate that the signer will use embedded
16+
# Signing. Represents the signer's userId within your application.
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+
# 1. Call the worker method
41+
# More data validation would be a good idea here
42+
# Strip anything other than characters listed
43+
$envelopeIdAndReturnUrl = CFREmbeddedSigningService::worker(
44+
$this->args,
45+
$this->clientService,
46+
self::DEMO_DOCS_PATH
47+
);
48+
49+
if ($envelopeIdAndReturnUrl) {
50+
# Redirect the user to the embedded signing
51+
# Don't use an iFrame!
52+
# State can be stored/recovered using the framework's session or a
53+
# query parameter on the returnUrl (see the make recipient_view_request method)
54+
header('Location: ' . $envelopeIdAndReturnUrl["redirect_url"]);
55+
exit;
56+
}
57+
}
58+
59+
/**
60+
* Get specific template arguments
61+
*
62+
* @return array
63+
*/
64+
public function getTemplateArgs(): array
65+
{
66+
$envelope_args = [
67+
'signer_email' => $this->checkInputValues($_POST['signer_email']),
68+
'signer_name' => $this->checkInputValues($_POST['signer_name']),
69+
'phone_number' => $_POST['phone_number'],
70+
'country_code' => $_POST['country_code'],
71+
'signer_client_id' => $this->signer_client_id,
72+
'ds_return_url' => $GLOBALS['app_url'] . 'index.php?page=ds_return'
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+
'envelope_args' => $envelope_args
79+
];
80+
}
81+
}

src/Controllers/eSignBaseController.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Example\Controllers;
44

5+
use DocuSign\eSign\Client\ApiException;
56
use Example\Services\RouterService;
67
use QuickACG\RouterService as QuickRouterService;
78
use Example\Services\SignatureClientService;
89
use Example\Services\IRouterService;
10+
use Example\Services\ManifestService;
911

1012
abstract class eSignBaseController extends BaseController
1113
{
@@ -119,11 +121,35 @@ function getController(
119121
'title' => $this->homePageTitle($eg),
120122
'show_doc' => false,
121123
'launcher_texts' => $_SESSION['API_TEXT']['Groups'],
122-
'common_texts' => $this->getCommonText()
124+
'common_texts' => $this->getCommonText(),
125+
'cfr_enabled' => $_SESSION['cfr_enabled']
123126
]
124127
);
125128
} else {
126129
if ($this->routerService->ds_token_ok()) {
130+
131+
$cfrStatus = $this->getPageText($eg)['CFREnabled'];
132+
// this example is not compatible with cfr
133+
134+
// var_dump($cfrStatus);
135+
// var_dump($_SESSION['cfr_enabled']);
136+
// die;
137+
if($_SESSION['cfr_enabled'] == "enabled" && $cfrStatus == "NonCFR"){
138+
139+
$GLOBALS['twig']->display("error_cfr.html",
140+
[
141+
'common_texts' => ManifestService::getCommonTexts()
142+
]);
143+
exit;
144+
145+
} elseif (!isset($_SESSION['cfr_enabled']) && $cfrStatus == "CFROnly") {
146+
$this->clientService->showErrorTemplate(new ApiException("This example requires a CFR Part 11 account"));
147+
exit;
148+
}
149+
150+
151+
152+
127153
$pause_envelope_ok = $_SESSION["pause_envelope_id"] ?? false;
128154
$envelope_id = $_SESSION['envelope_id'] ?? false;
129155
$template_id = $_SESSION['template_id'] ?? false;

src/Services/CodeGrantService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Example\Controllers\Auth\DocuSign;
66
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
7+
use Example\Services\utils;
8+
79

810
class CodeGrantService
911
{
@@ -66,6 +68,8 @@ function get_oauth_provider(): DocuSign
6668
);
6769
}
6870

71+
72+
6973
/**
7074
* DocuSign login handler
7175
* @param $redirectUrl
@@ -103,7 +107,11 @@ function authCallback($redirectUrl): void
103107
$_SESSION['ds_user_email'] = $user->getEmail();
104108

105109
$account_info = $user->getAccountInfo();
110+
106111
$base_uri_suffix = '/restapi';
112+
113+
$cfr = new utils();
114+
$_SESSION['cfr_enabled'] = $cfr->isCFR($_SESSION['ds_access_token'], $account_info["account_id"], $account_info["base_uri"] . $base_uri_suffix);
107115
$_SESSION['ds_account_id'] = $account_info["account_id"];
108116
$_SESSION['ds_account_name'] = $account_info["account_name"];
109117
$_SESSION['ds_base_path'] = $account_info["base_uri"] . $base_uri_suffix;

0 commit comments

Comments
 (0)