1+ <?php
2+ /**
3+ * Example 001: Use embedded signing
4+ */
5+
6+ namespace Example \Controllers \Examples \eSignature ;
7+
8+ use Example \Controllers \eSignBaseController ;
9+ use Example \Services \Examples \eSignature \CFREmbeddedSigningService ;
10+
11+ class EG041CFREmbeddedSigning extends eSignBaseController
12+ {
13+ const EG = "eg041 " ; # reference (and url) for this example
14+ const FILE = __FILE__ ;
15+ private int $ signer_client_id = 1000 ; # Used to indicate that the signer will use embedded
16+ # Signing. Represents the signer's userId within your application.
17+
18+ /**
19+ * Create a new controller instance.
20+ *
21+ * @return void
22+ */
23+ public function __construct ()
24+ {
25+ parent ::__construct ();
26+ parent ::controller ();
27+ }
28+
29+ /**
30+ * 1. Check the token
31+ * 2. Call the worker method
32+ * 3. Redirect the user to the signing
33+ *
34+ * @return void
35+ */
36+ public function createController (): void
37+ {
38+ $ this ->checkDsToken ();
39+
40+ # 1. Call the worker method
41+ # More data validation would be a good idea here
42+ # Strip anything other than characters listed
43+ $ envelopeIdAndReturnUrl = CFREmbeddedSigningService::worker (
44+ $ this ->args ,
45+ $ this ->clientService ,
46+ self ::DEMO_DOCS_PATH
47+ );
48+
49+ if ($ envelopeIdAndReturnUrl ) {
50+ # Redirect the user to the embedded signing
51+ # Don't use an iFrame!
52+ # State can be stored/recovered using the framework's session or a
53+ # query parameter on the returnUrl (see the make recipient_view_request method)
54+ header ('Location: ' . $ envelopeIdAndReturnUrl ["redirect_url " ]);
55+ exit ;
56+ }
57+ }
58+
59+ /**
60+ * Get specific template arguments
61+ *
62+ * @return array
63+ */
64+ public function getTemplateArgs (): array
65+ {
66+ $ envelope_args = [
67+ 'signer_email ' => $ this ->checkInputValues ($ _POST ['signer_email ' ]),
68+ 'signer_name ' => $ this ->checkInputValues ($ _POST ['signer_name ' ]),
69+ 'phone_number ' => $ _POST ['phone_number ' ],
70+ 'country_code ' => $ _POST ['country_code ' ],
71+ 'signer_client_id ' => $ this ->signer_client_id ,
72+ 'ds_return_url ' => $ GLOBALS ['app_url ' ] . 'index.php?page=ds_return '
73+ ];
74+ return [
75+ 'account_id ' => $ _SESSION ['ds_account_id ' ],
76+ 'base_path ' => $ _SESSION ['ds_base_path ' ],
77+ 'ds_access_token ' => $ _SESSION ['ds_access_token ' ],
78+ 'envelope_args ' => $ envelope_args
79+ ];
80+ }
81+ }
0 commit comments