Skip to content

Commit b7b1eb8

Browse files
authored
Merge branch 'master' into feature/added-PKCE-support
Signed-off-by: Raileen Del Rosario <43893067+raileendr@users.noreply.github.com>
2 parents 45f44c4 + 0e59d84 commit b7b1eb8

File tree

8 files changed

+265
-3
lines changed

8 files changed

+265
-3
lines changed

composer.lock

Lines changed: 1 addition & 0 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ public function getDefaultScopes(): array
119119
return [
120120
"signature user_write group_read organization_read permission_read user_read"
121121
. " 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"
122+
. " asset_group_account_clone_write asset_group_account_clone_read "
123+
. "organization_sub_account_write organization_sub_account_read"
123124
];
124125
} elseif ($_SESSION['api_type'] == ApiTypes::MAESTRO) {
125126
return [
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
namespace DocuSign\Controllers\Examples\Admin;
4+
5+
use DocuSign\Admin\Client\ApiException;
6+
use DocuSign\Controllers\AdminApiBaseController;
7+
use DocuSign\Services\Examples\Admin\CreateAccountService;
8+
9+
class EG013CreateAccount extends AdminApiBaseController
10+
{
11+
public const EG = 'aeg013'; # 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+
parent::controller();
24+
}
25+
26+
/**
27+
* 1. Check the token
28+
* 2. Call the worker method
29+
*
30+
* @return void
31+
*/
32+
public function createController(): void
33+
{
34+
$this->checkDsToken();
35+
36+
try {
37+
$orgId = $this->clientService->getOrgAdminId();
38+
$provisionAssetGroupApi = $this->clientService->provisionAssetGroupApi();
39+
40+
$planItem = CreateAccountService::getFirstPlanItem(
41+
$provisionAssetGroupApi,
42+
$orgId
43+
);
44+
45+
if (!is_null($planItem)) {
46+
$createdAccount = CreateAccountService::createAccountBySubscription(
47+
$provisionAssetGroupApi,
48+
$orgId,
49+
$this->args['email'],
50+
$this->args['firstName'],
51+
$this->args['lastName'],
52+
$planItem['subscription_id'],
53+
$planItem['plan_id']
54+
);
55+
56+
$this->clientService->showDoneTemplateFromManifest(
57+
$this->codeExampleText,
58+
json_encode($createdAccount->__toString())
59+
);
60+
}
61+
} catch (ApiException $e) {
62+
$this->clientService->showErrorTemplate($e);
63+
}
64+
}
65+
66+
/**
67+
* Get specific template arguments
68+
*
69+
* @return array
70+
*/
71+
public function getTemplateArgs(): array
72+
{
73+
return [
74+
'account_id' => $_SESSION['ds_account_id'],
75+
'ds_access_token' => $_SESSION['ds_access_token'],
76+
'email' => $this->checkInputValues($_POST['email']),
77+
'firstName' => $this->checkInputValues($_POST['firstName']),
78+
'lastName' => $this->checkInputValues($_POST['lastName']),
79+
];
80+
}
81+
}

src/Controllers/Examples/WebForms/EG001CreateAndEmbedForm.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use DocuSign\Controllers\WebFormsApiBaseController;
66
use DocuSign\Services\Examples\WebForms\CreateAndEmbedFormService;
77
use DocuSign\WebForms\Client\ApiException;
8+
use DocuSign\Services\ManifestService;
89

910
class EG001CreateAndEmbedForm extends WebFormsApiBaseController
1011
{
@@ -124,7 +125,11 @@ public function askToCreateWebForm(): void
124125
[
125126
'common_texts' => $this->getCommonText(),
126127
'code_example_text' => $this->codeExampleText,
127-
'description' => $this->codeExampleText["AdditionalPage"][1]["ResultsPageText"],
128+
'description' => ManifestService::replacePlaceholders(
129+
"{0}",
130+
"public/demo_documents",
131+
$this->codeExampleText["AdditionalPage"][1]["ResultsPageText"]
132+
),
128133
]
129134
);
130135

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace DocuSign\Services\Examples\Admin;
4+
5+
use DocuSign\Admin\Api\ProvisionAssetGroupApi;
6+
use DocuSign\Admin\Model\OrganizationSubscriptionResponse;
7+
use DocuSign\Admin\Model\SubAccountCreateRequest;
8+
use DocuSign\Admin\Model\SubAccountCreateRequestSubAccountCreationSubscription;
9+
use DocuSign\Admin\Model\SubAccountCreateRequestSubAccountCreationTargetAccountAdmin;
10+
use DocuSign\Admin\Model\SubAccountCreateRequestSubAccountCreationTargetAccountDetails;
11+
use DocuSign\Admin\Model\SubscriptionProvisionModelAssetGroupWorkResult;
12+
13+
class CreateAccountService
14+
{
15+
private const DEFAULT_ACCOUNT_NAME = 'CreatedThroughAPI';
16+
private const DEFAULT_COUNTRY_CODE = 'US';
17+
18+
#ds-snippet-start:Admin13Step3
19+
public static function getFirstPlanItem(
20+
ProvisionAssetGroupApi $provisionAssetGroupApi,
21+
string $orgId
22+
): ?OrganizationSubscriptionResponse {
23+
$planItems = $provisionAssetGroupApi->getOrganizationPlanItems($orgId);
24+
return $planItems[0] ?? null;
25+
}
26+
#ds-snippet-end:Admin13Step3
27+
28+
public static function createAccountBySubscription(
29+
ProvisionAssetGroupApi $provisionAssetGroupApi,
30+
string $orgId,
31+
string $email,
32+
string $firstName,
33+
string $lastName,
34+
string $subscriptionId,
35+
string $planId
36+
): SubscriptionProvisionModelAssetGroupWorkResult {
37+
$subAccountRequest = self::buildSubAccountRequest(
38+
$email,
39+
$firstName,
40+
$lastName,
41+
$subscriptionId,
42+
$planId
43+
);
44+
45+
#ds-snippet-start:Admin13Step5
46+
return $provisionAssetGroupApi->createAssetGroupAccount($orgId, $subAccountRequest);
47+
#ds-snippet-end:Admin13Step5
48+
}
49+
50+
#ds-snippet-start:Admin13Step4
51+
private static function buildSubAccountRequest(
52+
string $email,
53+
string $firstName,
54+
string $lastName,
55+
string $subscriptionId,
56+
string $planId
57+
): SubAccountCreateRequest {
58+
$uuidList = [];
59+
60+
$subscriptionDetails = new SubAccountCreateRequestSubAccountCreationSubscription();
61+
$subscriptionDetails->setId($subscriptionId);
62+
$subscriptionDetails->setPlanId($planId);
63+
$subscriptionDetails->setModules($uuidList);
64+
65+
$targetAccount = new SubAccountCreateRequestSubAccountCreationTargetAccountDetails();
66+
$targetAccount->setName(self::DEFAULT_ACCOUNT_NAME);
67+
$targetAccount->setCountryCode(self::DEFAULT_COUNTRY_CODE);
68+
69+
$admin = new SubAccountCreateRequestSubAccountCreationTargetAccountAdmin();
70+
$admin->setEmail($email);
71+
$admin->setFirstName($firstName);
72+
$admin->setLastName($lastName);
73+
$admin->setLocale(SubAccountCreateRequestSubAccountCreationTargetAccountAdmin::LOCALE_EN);
74+
75+
$targetAccount->setAdmin($admin);
76+
77+
$subAccountRequest = new SubAccountCreateRequest();
78+
$subAccountRequest->setSubscriptionDetails($subscriptionDetails);
79+
$subAccountRequest->setTargetAccount($targetAccount);
80+
81+
return $subAccountRequest;
82+
}
83+
#ds-snippet-end:Admin13Step4
84+
}

src/Services/RouterService.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class RouterService implements IRouterService
8888
'aeg010' => 'Admin\EG010DeleteUserDataFromOrganization',
8989
'aeg011' => 'Admin\EG011DeleteUserDataFromAccount',
9090
'aeg012' => 'Admin\EG012CloneAccount',
91+
'aeg013' => 'Admin\EG013CreateAccount',
9192
'con001' => 'Connect\Eg001ValidateUsingHmac',
9293
'mae001' => 'Maestro\Eg001TriggerWorkflow',
9394
'mae002' => 'Maestro\Eg002CancelWorkflow',
@@ -173,6 +174,8 @@ class RouterService implements IRouterService
173174
'aeg009' => 'admin/eg009_delete_user_product_permission_profile.html',
174175
'aeg010' => 'admin/eg010_delete_user_data_from_organization.html',
175176
'aeg011' => 'admin/eg011_delete_user_data_from_account.html',
177+
'aeg012' => 'admin/eg012_clone_account.html',
178+
'aeg013' => 'admin/eg013_create_account.html',
176179
'con001' => 'connect/eg001_validate_using_hmac.html',
177180
'mae001' => 'maestro/eg001_trigger_workflow.html',
178181
'mae002' => 'maestro/eg002_cancel_workflow.html',
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{% extends "base.html" %}
2+
{% block content %}
3+
4+
{% set formNumber = 0 %}
5+
{% set emailInputNumber = 0 %}
6+
{% set firstNameInputNumber = 1 %}
7+
{% set lastNameInputNumber = 2 %}
8+
9+
<h4>{{ code_example_text['ExampleName'] | raw }}</h4>
10+
11+
<p>{{ code_example_text["ExampleDescription"] | raw }}</p>
12+
13+
14+
{% if show_doc %}
15+
<p><a target='_blank' href='{{ documentation | raw }}'>Documentation</a> about this example.</p>
16+
{% endif %}
17+
18+
<p>
19+
{% if code_example_text["LinksToAPIMethod"] | length == 1 %}
20+
<span>{{ common_texts["APIMethodUsed"] | raw }}</span>
21+
{% else %}
22+
<span>{{ common_texts["APIMethodUsedPlural"] | raw }}</span>
23+
{% endif %}
24+
25+
{% for i in 0..(code_example_text["LinksToAPIMethod"] | length - 1) %}
26+
<a target='_blank' href="{{ example['LinksToAPIMethod'][i]['Path'] }}">
27+
{{ code_example_text['LinksToAPIMethod'][i]['PathName'] | raw}}
28+
</a>
29+
30+
{% if i + 1 == code_example_text["LinksToAPIMethod"] | length - 1 %}
31+
<span>and</span>
32+
{% elseif i + 1 != code_example_text["LinksToAPIMethod"] | length %}
33+
<span>,</span>
34+
{% endif %}
35+
{% endfor %}
36+
</p>
37+
38+
<p>
39+
{{ common_texts["ViewSourceFile"]|replace({ ("{0}"): ("<a target='_blank' href='%s'>%s</a>"|format(source_url, source_file)) })| raw }}
40+
</p>
41+
42+
<form class="eg" action="" method="post">
43+
<div class="form-group">
44+
<label for="email">
45+
{{ code_example_text['Forms'][formNumber]['Inputs'][emailInputNumber]['InputName'] | raw }}
46+
</label>
47+
48+
<input type="email"
49+
class="form-control"
50+
id="email"
51+
name="email"
52+
aria-describedby="emailHelp"
53+
placeholder="{{code_example_text['Forms'][formNumber]['Inputs'][emailInputNumber]['InputPlaceholder']}}"
54+
required>
55+
</div>
56+
57+
<div class="form-group">
58+
<label for="firstName">
59+
{{ code_example_text['Forms'][formNumber]['Inputs'][firstNameInputNumber]['InputName'] | raw }}
60+
</label>
61+
62+
<input type="text"
63+
class="form-control"
64+
id="firstName"
65+
placeholder="{{code_example_text['Forms'][formNumber]['Inputs'][firstNameInputNumber]['InputPlaceholder']}}"
66+
name="firstName"
67+
required />
68+
</div>
69+
70+
<div class="form-group">
71+
<label for="lastName">
72+
{{ code_example_text['Forms'][formNumber]['Inputs'][lastNameInputNumber]['InputName'] | raw }}
73+
</label>
74+
75+
<input type="text"
76+
class="form-control"
77+
id="lastName"
78+
placeholder="{{code_example_text['Forms'][formNumber]['Inputs'][lastNameInputNumber]['InputPlaceholder']}}"
79+
name="lastName"
80+
required />
81+
</div>
82+
83+
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
84+
<button type="submit" class="btn btn-primary">{{ common_texts["SubmitButton"] | raw }}</button>
85+
</form>
86+
87+
{% endblock %}

tests/JWTLoginMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function jwtAuthenticationMethod(string $apiType, TestConfig $test
3434
} elseif ($apiType == ApiTypes::ADMIN) {
3535
$scopes = "signature user_write group_read organization_read permission_read user_read "
3636
. "account_read domain_read identity_provider_read user_data_redact"
37-
. "asset_group_account_read asset_group_account_clone_write asset_group_account_clone_read";
37+
. "asset_group_account_read asset_group_account_clone_write asset_group_account_clone_read organization_sub_account_write organization_sub_account_read";
3838
} elseif ($apiType == ApiTypes::MAESTRO) {
3939
$scopes = "signature aow_manage";
4040
} elseif ($apiType == ApiTypes::WEBFORMS) {

0 commit comments

Comments
 (0)