Skip to content

Commit 9d97cdd

Browse files
committed
Merge branch 'master' into feature/add-linter-to-CI-CD
2 parents 2628033 + a1c277b commit 9d97cdd

File tree

16 files changed

+765
-104
lines changed

16 files changed

+765
-104
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"description": "DocuSign PHP launcher",
1717
"require": {
18-
"docusign/admin-client": "^1.3.0-rc",
18+
"docusign/admin-client": "^1.4.1",
1919
"docusign/click-client": "^1.3.0-rc",
2020
"docusign/esign-client": "^6.15.0-rc",
2121
"docusign/rooms-client": "^2.1.0",

composer.lock

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

src/Controllers/Auth/DocuSign.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ public function getDefaultScopes(): array
117117
];
118118
} elseif ($_SESSION['api_type'] == ApiTypes::ADMIN) {
119119
return [
120-
"signature user_write group_read organization_read permission_read user_read "
121-
. "account_read domain_read identity_provider_read user_data_redact"
120+
"signature user_write group_read organization_read permission_read user_read"
121+
. " account_read domain_read identity_provider_read user_data_redact asset_group_account_read"
122+
. " asset_group_account_clone_write asset_group_account_clone_read"
122123
];
123124
} else {
124125
return [
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
namespace Example\Controllers\Examples\Admin;
4+
5+
use DocuSign\Admin\Client\ApiException;
6+
use Example\Controllers\AdminApiBaseController;
7+
use Example\Services\Examples\Admin\CloneAccountService;
8+
9+
class EG012CloneAccount extends AdminApiBaseController
10+
{
11+
public const EG = 'aeg012'; # reference (and url) for this example
12+
public const FILE = __FILE__;
13+
14+
/**
15+
* Create a new controller instance
16+
*
17+
* @return void
18+
*/
19+
public function __construct()
20+
{
21+
parent::__construct();
22+
23+
$this->checkDsToken();
24+
25+
try {
26+
$this->orgId = $this->clientService->getOrgAdminId();
27+
$provisionAssetGroupApi = $this->clientService->provisionAssetGroupApi();
28+
29+
$assetGroupAccountsResponse = CloneAccountService::getAccounts($provisionAssetGroupApi, $this->orgId);
30+
parent::controller(['groups' => $assetGroupAccountsResponse['asset_group_accounts']]);
31+
} catch (ApiException $e) {
32+
$this->clientService->showErrorTemplate($e);
33+
}
34+
}
35+
36+
/**
37+
* 1. Check the token
38+
* 2. Call the worker method
39+
*
40+
* @return void
41+
*/
42+
public function createController(): void
43+
{
44+
$this->checkDsToken();
45+
46+
try {
47+
$this->orgId = $this->clientService->getOrgAdminId();
48+
$provisionAssetGroupApi = $this->clientService->provisionAssetGroupApi();
49+
50+
$assetGroupAccountClone = CloneAccountService::cloneAccount(
51+
$provisionAssetGroupApi,
52+
$this->orgId,
53+
$this->args['source_account_id'],
54+
$this->args['target_account_name'],
55+
$this->args['target_account_first_name'],
56+
$this->args['target_account_last_name'],
57+
$this->args['target_account_email']
58+
);
59+
60+
$this->clientService->showDoneTemplateFromManifest(
61+
$this->codeExampleText,
62+
json_encode($assetGroupAccountClone->__toString())
63+
);
64+
} catch (ApiException $e) {
65+
$this->clientService->showErrorTemplate($e);
66+
}
67+
}
68+
69+
/**
70+
* Get specific template arguments
71+
*
72+
* @return array
73+
*/
74+
public function getTemplateArgs(): array
75+
{
76+
return [
77+
'account_id' => $_SESSION['ds_account_id'],
78+
'ds_access_token' => $_SESSION['ds_access_token'],
79+
'source_account_id' => $this->checkInputValues($_POST['source_account_id']),
80+
'target_account_name' => $this->checkInputValues($_POST['target_account_name']),
81+
'target_account_first_name' => $this->checkInputValues($_POST['target_account_first_name']),
82+
'target_account_last_name' => $this->checkInputValues($_POST['target_account_last_name']),
83+
'target_account_email' => $this->checkInputValues($_POST['target_account_email']),
84+
];
85+
}
86+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Example 044: Used to generate an envelope and allow user to sign
4+
* it directly from the app without having to open an email.
5+
*/
6+
7+
namespace Example\Controllers\Examples\eSignature;
8+
9+
use Example\Controllers\eSignBaseController;
10+
use Example\Services\Examples\eSignature\FocusedViewService;
11+
12+
class EG044FocusedView extends eSignBaseController
13+
{
14+
const EG = 'eg044'; # reference (and url) for this example
15+
const FILE = __FILE__;
16+
const EMBED = 'esignature/embed';
17+
private int $signer_client_id = 1000;
18+
19+
/**
20+
* Create a new controller instance.
21+
*
22+
* @return void
23+
*/
24+
public function __construct()
25+
{
26+
parent::__construct();
27+
parent::controller();
28+
}
29+
30+
/**
31+
* Check the token
32+
* Call the worker method
33+
* Redirect the user to the signing
34+
*
35+
* @return void
36+
*/
37+
public function createController(): void
38+
{
39+
$this->checkDsToken();
40+
$pdf_doc = $GLOBALS['DS_CONFIG']['doc_pdf'];
41+
$envelope_id_and_url = FocusedViewService::worker(
42+
$this->args,
43+
$this->clientService,
44+
self::DEMO_DOCS_PATH,
45+
$pdf_doc
46+
);
47+
48+
if ($envelope_id_and_url) {
49+
$GLOBALS['twig']->display(
50+
self::EMBED . '.html',
51+
[
52+
'common_texts' => $this->getCommonText(),
53+
'integration_key' => $GLOBALS['DS_CONFIG']['ds_client_id'],
54+
'envelope_id' => $envelope_id_and_url['envelope_id'],
55+
'url' => $envelope_id_and_url['redirect_url']
56+
]
57+
);
58+
exit;
59+
}
60+
}
61+
62+
/**
63+
* Get specific template arguments
64+
*
65+
* @return array
66+
*/
67+
public function getTemplateArgs(): array
68+
{
69+
$envelope_args = [
70+
'signer_email' => $this->checkInputValues($_POST['signer_email']),
71+
'signer_name' => $this->checkInputValues($_POST['signer_name']),
72+
'signer_client_id' => $this->signer_client_id,
73+
'ds_return_url' => $GLOBALS['app_url'] . 'index.php?page=ds_return'
74+
];
75+
return [
76+
'account_id' => $_SESSION['ds_account_id'],
77+
'base_path' => $_SESSION['ds_base_path'],
78+
'ds_access_token' => $_SESSION['ds_access_token'],
79+
'envelope_args' => $envelope_args
80+
];
81+
}
82+
}

src/Services/AdminApiClientService.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use DocuSign\Admin\Api\BulkImportsApi;
1010
use DocuSign\Admin\Api\DSGroupsApi;
1111
use DocuSign\Admin\Api\ProductPermissionProfilesApi;
12+
use DocuSign\Admin\Api\ProvisionAssetGroupApi;
1213
use DocuSign\Admin\Client\ApiClient;
1314
use DocuSign\Admin\Api\UsersApi;
1415
use DocuSign\Admin\Configuration;
@@ -81,6 +82,14 @@ public function permProfilesApi(): ProductPermissionProfilesApi
8182
return new ProductPermissionProfilesApi($this->apiClient);
8283
}
8384

85+
/**
86+
* Get provision asset group api
87+
*/
88+
public function provisionAssetGroupApi(): ProvisionAssetGroupApi
89+
{
90+
return new ProvisionAssetGroupApi($this->apiClient);
91+
}
92+
8493
/**
8594
* Get Org Admin Id
8695
*
@@ -92,9 +101,7 @@ public function getOrgAdminId(): String
92101
$AccountsApi = new AccountsApi($this->apiClient);
93102
$orgs = $AccountsApi->getOrganizations();
94103
if ($orgs["organizations"] == null) {
95-
throw new ApiException("You must create an organization for this account to use"
96-
. " the DocuSign Admin API. For details, see <a target='_blank' href='"
97-
. "https://support.docusign.com/guides/org-admin-guide'> this support article.</a>", 1);
104+
throw new ApiException("You must create an organization for this account to use the DocuSign Admin API. For details, see <a target='_blank' href='https://support.docusign.com/guides/org-admin-guide'> this support article.</a>", 1);
98105
} else {
99106
return $orgs["organizations"][0]["id"];
100107
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace Example\Services\Examples\Admin;
4+
5+
use DocuSign\Admin\Api\ProvisionAssetGroupApi;
6+
use DocuSign\Admin\Api\ProvisionAssetGroupApi\GetAssetGroupAccountsOptions;
7+
use DocuSign\Admin\Client\ApiException;
8+
use DocuSign\Admin\Model\AssetGroupAccountClone;
9+
use DocuSign\Admin\Model\AssetGroupAccountCloneSourceAccount;
10+
use DocuSign\Admin\Model\AssetGroupAccountCloneTargetAccount;
11+
use DocuSign\Admin\Model\AssetGroupAccountCloneTargetAccountAdmin;
12+
use DocuSign\Admin\Model\AssetGroupAccountsResponse;
13+
14+
class CloneAccountService
15+
{
16+
/**
17+
* Get all accounts in asset groups for the organization.
18+
* @param ProvisionAssetGroupApi $provisionAssetGroupApi
19+
* @param string $organizationId
20+
* @return AssetGroupAccountsResponse
21+
* @throws ApiException
22+
*/
23+
public static function getAccounts(
24+
ProvisionAssetGroupApi $provisionAssetGroupApi,
25+
string $organizationId
26+
): AssetGroupAccountsResponse {
27+
#ds-snippet-start:Admin12Step3
28+
$options = new GetAssetGroupAccountsOptions();
29+
$options->setCompliant(true);
30+
31+
return $provisionAssetGroupApi->getAssetGroupAccounts($organizationId, $options);
32+
#ds-snippet-end:Admin12Step3
33+
}
34+
35+
/**
36+
* Clones an existing DocuSign account to a new DocuSign account
37+
* @param ProvisionAssetGroupApi $provisionAssetGroupApi
38+
* @param string $organizationId
39+
* @param string $sourceAccountId
40+
* @param string $targetAccountName
41+
* @param string $targetAccountFirstName
42+
* @param string $targetAccountLastName
43+
* @param string $targetAccountEmail
44+
* @return AssetGroupAccountClone
45+
* @throws ApiException
46+
*/
47+
public static function cloneAccount(
48+
ProvisionAssetGroupApi $provisionAssetGroupApi,
49+
string $organizationId,
50+
string $sourceAccountId,
51+
string $targetAccountName,
52+
string $targetAccountFirstName,
53+
string $targetAccountLastName,
54+
string $targetAccountEmail
55+
): AssetGroupAccountClone {
56+
#ds-snippet-start:Admin12Step4
57+
$countryCode = "US";
58+
59+
$accountData = new AssetGroupAccountClone([
60+
'source_account' => new AssetGroupAccountCloneSourceAccount(
61+
[
62+
'id' => $sourceAccountId,
63+
]
64+
),
65+
'target_account' => new AssetGroupAccountCloneTargetAccount(
66+
[
67+
'name' => $targetAccountName,
68+
'country_code' => $countryCode,
69+
'admin' => new AssetGroupAccountCloneTargetAccountAdmin(
70+
[
71+
'first_name' => $targetAccountFirstName,
72+
'last_name' => $targetAccountLastName,
73+
'email' => $targetAccountEmail,
74+
]
75+
),
76+
]
77+
),
78+
]);
79+
#ds-snippet-end:Admin12Step4
80+
81+
#ds-snippet-start:Admin12Step5
82+
return $provisionAssetGroupApi->cloneAssetGroupAccount($organizationId, $accountData);
83+
#ds-snippet-end:Admin12Step5
84+
}
85+
}

0 commit comments

Comments
 (0)