|
| 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