Skip to content

Commit 74e51df

Browse files
annahiletaAaronWDS
andauthored
Added focused view code example (#129)
* added focused view code example * removed double-quotes * removed extra console log --------- Signed-off-by: Aaron Wilde <[email protected]> Co-authored-by: Aaron Wilde <[email protected]>
1 parent e28b2ed commit 74e51df

File tree

5 files changed

+417
-78
lines changed

5 files changed

+417
-78
lines changed
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+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
namespace Example\Services\Examples\eSignature;
4+
5+
use DocuSign\eSign\Client\ApiException;
6+
use DocuSign\eSign\Model\Document;
7+
use DocuSign\eSign\Model\EnvelopeDefinition;
8+
use DocuSign\eSign\Model\Recipients;
9+
use DocuSign\eSign\Model\Signer;
10+
use DocuSign\eSign\Model\SignHere;
11+
use DocuSign\eSign\Model\Tabs;
12+
use Example\Services\SignatureClientService;
13+
14+
class FocusedViewService
15+
{
16+
public static function worker(array $args, SignatureClientService $client_service, string $demo_path, string $pdf_file): array
17+
{
18+
//ds-snippet-start:eSign44Step3
19+
$envelope_definition = FocusedViewService::makeEnvelope($args['envelope_args'], $demo_path, $pdf_file);
20+
$envelope_api = $client_service->getEnvelopeApi();
21+
22+
try {
23+
$envelope_summary = $envelope_api->createEnvelope($args['account_id'], $envelope_definition);
24+
} catch (ApiException $e) {
25+
$client_service->showErrorTemplate($e);
26+
exit;
27+
}
28+
$envelope_id = $envelope_summary->getEnvelopeId();
29+
//ds-snippet-end:eSign44Step3
30+
31+
//ds-snippet-start:eSign44Step4
32+
$authentication_method = 'None';
33+
34+
$recipient_view_request = $client_service->getRecipientViewRequest(
35+
$authentication_method,
36+
$args['envelope_args']
37+
);
38+
39+
$recipient_view_request->setFrameAncestors(['http://localhost:8080/public', 'https://apps-d.docusign.com']);
40+
$recipient_view_request->setMessageOrigins(['https://apps-d.docusign.com']);
41+
//ds-snippet-end:eSign44Step4
42+
43+
//ds-snippet-start:eSign44Step5
44+
$view_url = $client_service->getRecipientView($args['account_id'], $envelope_id, $recipient_view_request);
45+
46+
return ['envelope_id' => $envelope_id, 'redirect_url' => $view_url['url']];
47+
//ds-snippet-end:eSign44Step5
48+
}
49+
50+
//ds-snippet-start:eSign44Step2
51+
public static function makeEnvelope(array $args, string $demo_path, string $pdf_file): EnvelopeDefinition
52+
{
53+
$content_bytes = file_get_contents($demo_path . $pdf_file);
54+
$base64_file_content = base64_encode($content_bytes);
55+
56+
$document = new Document(
57+
[
58+
'document_base64' => $base64_file_content,
59+
'name' => 'Example document',
60+
'file_extension' => 'pdf',
61+
'document_id' => 1
62+
]
63+
);
64+
65+
$signer = new Signer(
66+
[
67+
'email' => $args['signer_email'],
68+
'name' => $args['signer_name'],
69+
'recipient_id' => '1',
70+
'routing_order' => '1',
71+
'client_user_id' => $args['signer_client_id']
72+
]
73+
);
74+
75+
$sign_here = new SignHere(
76+
[
77+
'anchor_string' => '/sn1/',
78+
'anchor_units' => 'pixels',
79+
'anchor_y_offset' => '10',
80+
'anchor_x_offset' => '20'
81+
]
82+
);
83+
84+
$signer->settabs(new Tabs(['sign_here_tabs' => [$sign_here]]));
85+
86+
return new EnvelopeDefinition(
87+
[
88+
'email_subject' => 'Please sign this document sent from the PHP SDK',
89+
'documents' => [$document],
90+
'recipients' => new Recipients(['signers' => [$signer]]),
91+
'status' => 'sent'
92+
]
93+
);
94+
}
95+
//ds-snippet-end:eSign44Step2
96+
}

0 commit comments

Comments
 (0)