Skip to content

Commit 267e248

Browse files
committed
2 parents ed1289b + 2284a5b commit 267e248

26 files changed

+2183
-209
lines changed

azure-pipelines.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,28 @@ steps:
8787

8888
- script: dir $(Build.SourcesDirectory)/code-examples-php-private
8989

90+
- script: |
91+
echo "Checking for running Docker containers..."
92+
containers=$(docker ps -q)
93+
if [ ! -z "$containers" ]; then
94+
echo "Stopping running Docker containers..."
95+
docker stop $(docker ps -q)
96+
else
97+
echo "No Docker containers are running."
98+
fi
99+
displayName: "check for running containers"
100+
101+
- script: |
102+
echo "Checking for running Docker containers..."
103+
containers=$(docker ps -q)
104+
if [ ! -z "$containers" ]; then
105+
echo "Stopping running Docker containers..."
106+
docker stop $(docker ps -q)
107+
else
108+
echo "No Docker containers are running."
109+
fi
110+
displayName: "check for running containers"
111+
90112
- script: |
91113
echo "kill and remove any running containers"
92114
docker rm -f $(docker ps -a -q)

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@
2121
"docusign/rooms-client": "^2.1.0",
2222
"docusign/monitor-client": "^1.1.0",
2323
"docusign/webforms-client": "^1.0.0",
24+
"docusign/maestro-client": "dev-1.0.0-rc1-v1.0.0-1.0.3",
2425
"twig/twig": "^3.5.1",
2526
"league/oauth2-client": "^2.6.1",
2627
"ext-json": "*",
2728
"guzzlehttp/guzzle": "7.5.0",
28-
"firebase/php-jwt": "5.5.1",
29+
"firebase/php-jwt": "6.0.0",
2930
"mashape/unirest-php": "3.0.4",
3031
"squizlabs/php_codesniffer": "*",
3132
"phpunit/phpunit": "^9.5"
3233
},
3334
"require-dev": {
3435
"squizlabs/php_codesniffer": "*"
3536
}
36-
}
37+
}

composer.lock

Lines changed: 293 additions & 207 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/search.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ let DS_SEARCH = (function () {
66
ROOMS: 'rooms',
77
ADMIN: 'admin',
88
CONNECT: 'connect',
9+
MAESTRO: 'maestro',
910
WEBFORMS: 'webforms'
1011
};
1112

@@ -126,6 +127,8 @@ let DS_SEARCH = (function () {
126127
return "eg";
127128
case API_TYPES.CONNECT:
128129
return "con";
130+
case API_TYPES.MAESTRO:
131+
return "mae";
129132
case API_TYPES.WEBFORMS:
130133
return "web";
131134
}

public/demo_documents/doc_1.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
color: darkblue;">Order Processing Division</h2>
1212
<h4>Ordered by {USER_FULLNAME}</h4>
1313
<p style="margin-top:0em; margin-bottom:0em;">Email: {USER_EMAIL}</p>
14+
<p style="margin-top:0em; margin-bottom:0em;">Copy to: {CC_NAME}, {CC_EMAIL}</p>
1415
<p style="margin-top:3em;">
1516
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.
1617
</p>

src/Controllers/Auth/DocuSign.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public function getDefaultScopes(): array
121121
. " account_read domain_read identity_provider_read user_data_redact asset_group_account_read"
122122
. " asset_group_account_clone_write asset_group_account_clone_read"
123123
];
124+
} elseif ($_SESSION['api_type'] == ApiTypes::MAESTRO) {
125+
return [
126+
"signature aow_manage"
127+
];
124128
} elseif ($_SESSION['api_type'] == ApiTypes::WEBFORMS) {
125129
return [
126130
"signature webforms_read webforms_instance_read webforms_instance_write"
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<?php
2+
3+
namespace DocuSign\Controllers\Examples\Maestro;
4+
5+
use DocuSign\Controllers\MaestroApiBaseController;
6+
use DocuSign\Maestro\Client\ApiException;
7+
use DocuSign\Services\Examples\Maestro\TriggerMaestroWorkflowService;
8+
use DocuSign\Services\ManifestService;
9+
use DocuSign\Maestro\Model\TriggerWorkflowViaPostResponse;
10+
11+
class Eg001TriggerWorkflow extends MaestroApiBaseController
12+
{
13+
const EG = 'mae001'; # reference (and url) for this example
14+
15+
const FILE = __FILE__;
16+
17+
/**
18+
* Create a new controller instance
19+
*
20+
* @return void
21+
* @throws ApiException
22+
*/
23+
public function __construct()
24+
{
25+
parent::__construct();
26+
$this->checkDsToken();
27+
$this->codeExampleText = $this->getPageText(static::EG);
28+
$workflowName = 'Example workflow - send invite to signer';
29+
$accountId = $this->args['account_id'];
30+
$workflowManagementApi = $this->clientService->workflowManagementApi();
31+
32+
try {
33+
$workflowDefinitions = TriggerMaestroWorkflowService::getWorkflowDefinitions(
34+
$workflowManagementApi,
35+
$accountId
36+
);
37+
38+
$this->selectNewestWorkflowByName($workflowDefinitions, $workflowName);
39+
} catch (ApiException $e) {
40+
if ($e->getCode() == 403) {
41+
$this->contactSupportToEnableFeature($e);
42+
}
43+
}
44+
45+
if ($_COOKIE["template_id"] != null && $_SESSION["workflow_id"] === null) {
46+
try {
47+
$createdWorkflowDefinition = TriggerMaestroWorkflowService::createWorkflow(
48+
$workflowManagementApi,
49+
$accountId,
50+
$_COOKIE["template_id"]
51+
);
52+
53+
$_SESSION["workflow_id"] = $createdWorkflowDefinition->getWorkflowDefinitionId();
54+
55+
$publishWorkflowUrl = TriggerMaestroWorkflowService::publishWorkflow(
56+
$workflowManagementApi,
57+
$accountId,
58+
$_SESSION["workflow_id"]
59+
);
60+
61+
$_SESSION["workflow_published"] = true;
62+
$this->openPublishWorkflowPage($publishWorkflowUrl);
63+
} catch (ApiException $e) {
64+
if ($e->getCode() == 403) {
65+
$this->contactSupportToEnableFeature($e);
66+
}
67+
}
68+
}
69+
70+
if ($_SESSION['workflow_published']) {
71+
$publishWorkflowUrl = TriggerMaestroWorkflowService::publishWorkflow(
72+
$workflowManagementApi,
73+
$accountId,
74+
$_SESSION["workflow_id"]
75+
);
76+
77+
if ($publishWorkflowUrl == null) {
78+
$_SESSION["workflow_published"] = false;
79+
} else {
80+
$this->openPublishWorkflowPage($publishWorkflowUrl);
81+
}
82+
}
83+
84+
parent::controller();
85+
}
86+
87+
/**
88+
* Check the access token and call the worker method
89+
* @return void
90+
* @throws ApiException
91+
*/
92+
public function createController(): void
93+
{
94+
$this->getTemplateArgs();
95+
96+
$workflowId = $_SESSION["workflow_id"];
97+
$workflowManagementApi = $this->clientService->workflowManagementApi();
98+
99+
$trigger = new TriggerWorkflowViaPostResponse();
100+
try {
101+
$workflowDefinition = TriggerMaestroWorkflowService::getWorkflowDefinition(
102+
$workflowManagementApi,
103+
$this->args['account_id'],
104+
$workflowId
105+
);
106+
107+
$triggerUrl = $workflowDefinition->getTriggerUrl();
108+
109+
$queryParams = parse_url($triggerUrl, PHP_URL_QUERY);
110+
parse_str($queryParams, $params);
111+
112+
$mtid = $params['mtid'];
113+
$mtsec = $params['mtsec'];
114+
115+
$triggerApi = $this->clientService->workflowTriggerApi();
116+
117+
$trigger = TriggerMaestroWorkflowService::triggerWorkflow(
118+
$triggerApi,
119+
$this->args['account_id'],
120+
$this->args['envelope_args']['instance_name'],
121+
$this->args['envelope_args']['signer_name'],
122+
$this->args['envelope_args']['signer_email'],
123+
$this->args['envelope_args']['cc_name'],
124+
$this->args['envelope_args']['cc_email'],
125+
$mtid,
126+
$mtsec
127+
);
128+
$_SESSION['instance_id'] = $trigger->getInstanceId();
129+
} catch (ApiException $e) {
130+
if ($e->getCode() == 403) {
131+
$this->contactSupportToEnableFeature($e);
132+
}
133+
}
134+
$this->clientService->showDoneTemplateFromManifest(
135+
$this->codeExampleText,
136+
json_encode($trigger->__toString())
137+
);
138+
}
139+
140+
/**
141+
* Get specific template arguments
142+
* @return array
143+
*/
144+
public function getTemplateArgs(): array
145+
{
146+
$envelope_args = [
147+
'instance_name' => $_POST['instance_name'],
148+
'signer_email' => $_POST['signer_email'],
149+
'signer_name' => $_POST['signer_name'],
150+
'cc_email' => $_POST['cc_email'],
151+
'cc_name' => $_POST['cc_name'],
152+
];
153+
return [
154+
'account_id' => $_SESSION['ds_account_id'],
155+
'base_path' => $_SESSION['ds_base_path'],
156+
'ds_access_token' => $_SESSION['ds_access_token'],
157+
'envelope_args' => $envelope_args
158+
];
159+
}
160+
161+
private function contactSupportToEnableFeature($e)
162+
{
163+
$GLOBALS['twig']->display('error.html', [
164+
'error_code' => $e->getCode(),
165+
'error_message' => ManifestService::replacePlaceholders(
166+
'{0}',
167+
'Maestro',
168+
ManifestService::getCommonTexts()['ContactSupportToEnableFeature']
169+
),
170+
'common_texts' => ManifestService::getCommonTexts()
171+
]);
172+
exit;
173+
}
174+
175+
private function selectNewestWorkflowByName($workflowDefinitions, $workflowName)
176+
{
177+
if ($workflowDefinitions['count'] > 0) {
178+
$filteredWorkflows = array_filter(
179+
$workflowDefinitions['value'],
180+
function ($workflow) use ($workflowName) {
181+
return $workflow['name'] === $workflowName;
182+
}
183+
);
184+
185+
usort($filteredWorkflows, function ($wf1, $wf2) {
186+
return strtotime($wf2['lastUpdatedDate']) - strtotime($wf1['lastUpdatedDate']);
187+
});
188+
189+
$workflow = reset($filteredWorkflows);
190+
191+
if ($workflow) {
192+
$_SESSION["workflow_id"] = $workflow['id'];
193+
}
194+
}
195+
}
196+
197+
private function openPublishWorkflowPage($publishWorkflowUrl)
198+
{
199+
$GLOBALS['twig']->display("maestro/eg001_publish_workflow.html", [
200+
'title' => $this->routerService->getTitle(static::EG),
201+
'consent_url' => ManifestService::replacePlaceholders(
202+
'{0}',
203+
$publishWorkflowUrl,
204+
$this->codeExampleText['AdditionalPage'][0]['ResultsPageText']
205+
),
206+
'code_example_text' => $this->codeExampleText,
207+
'common_texts' => $this->getCommonText()
208+
]);
209+
exit();
210+
}
211+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace DocuSign\Controllers\Examples\Maestro;
4+
5+
use DocuSign\Controllers\MaestroApiBaseController;
6+
use DocuSign\Maestro\Client\ApiException;
7+
use DocuSign\Services\Examples\Maestro\CancelMaestroWorkflowService;
8+
use DocuSign\Services\ManifestService;
9+
10+
class Eg002CancelWorkflow extends MaestroApiBaseController
11+
{
12+
const EG = 'mae002'; # reference (and url) for this example
13+
14+
const FILE = __FILE__;
15+
16+
/**
17+
* Create a new controller instance.
18+
*
19+
* @return void
20+
*/
21+
public function __construct()
22+
{
23+
parent::__construct();
24+
parent::controller();
25+
}
26+
27+
/**
28+
* Check the access token and call the worker method
29+
* @return void
30+
* @throws \DocuSign\Maestro\Client\ApiException
31+
*/
32+
public function createController(): void
33+
{
34+
$accountId = $_SESSION['ds_account_id'];
35+
$instanceId = $_SESSION['instance_id'];
36+
$workflowId = $_SESSION["workflow_id"];
37+
$workflowInstanceApi = $this->clientService->workflowInstanceManagementApi();
38+
39+
try {
40+
$isRedirectNeeded = CancelMaestroWorkflowService::getWorkflowInstanceAndCheckItsStatus(
41+
$workflowInstanceApi,
42+
$accountId,
43+
$workflowId,
44+
$instanceId
45+
);
46+
47+
if (!$isRedirectNeeded) {
48+
header('Location: ' . $GLOBALS['app_url'] . 'index.php?page=mae001');
49+
}
50+
51+
$result = CancelMaestroWorkflowService::cancelWorkflowInstance(
52+
$workflowInstanceApi,
53+
$accountId,
54+
$instanceId
55+
);
56+
} catch (ApiException $e) {
57+
if ($e->getCode() == 403) {
58+
$GLOBALS['twig']->display('error.html', [
59+
'error_code' => $e->getCode(),
60+
'error_message' => ManifestService::replacePlaceholders(
61+
'{0}',
62+
'Maestro',
63+
ManifestService::getCommonTexts()['ContactSupportToEnableFeature']
64+
),
65+
'common_texts' => ManifestService::getCommonTexts()
66+
]);
67+
exit;
68+
}
69+
}
70+
71+
$this->clientService->showDoneTemplateFromManifest(
72+
$this->codeExampleText,
73+
json_encode($result->__toString()),
74+
ManifestService::replacePlaceholders('{0}', $instanceId, $this->codeExampleText['ResultsPageText'])
75+
);
76+
}
77+
78+
/**
79+
* Get specific template arguments
80+
* @return array
81+
*/
82+
public function getTemplateArgs(): array
83+
{
84+
return [
85+
'account_id' => $_SESSION['ds_account_id'],
86+
'base_path' => $_SESSION['ds_base_path'],
87+
'ds_access_token' => $_SESSION['ds_access_token'],
88+
];
89+
}
90+
}

0 commit comments

Comments
 (0)