|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Example\Controllers\Examples\Click; |
| 4 | + |
| 5 | +use DocuSign\Click\Client\ApiException; |
| 6 | +use Example\Controllers\ClickApiBaseController; |
| 7 | +use Example\Services\Examples\Click\EmbedClickwrapService; |
| 8 | + |
| 9 | +class EG006EmbedClickwrap extends ClickApiBaseController |
| 10 | +{ |
| 11 | + const EG = 'ceg006'; # reference (and URL) for this example |
| 12 | + const FILE = __FILE__; |
| 13 | + |
| 14 | + /** |
| 15 | + * 1. Get available clickwraps |
| 16 | + * 2. Create a new controller instance. |
| 17 | + * |
| 18 | + * @return void |
| 19 | + */ |
| 20 | + public function __construct() |
| 21 | + { |
| 22 | + parent::__construct(); |
| 23 | + # Get available clickwraps |
| 24 | + $clickwraps = EmbedClickwrapService::getClickwraps( |
| 25 | + $this->routerService, |
| 26 | + $this->clientService, |
| 27 | + $this->args, |
| 28 | + $this::EG |
| 29 | + ); |
| 30 | + |
| 31 | + parent::controller(['clickwraps' => $clickwraps[0], 'inactives'=>$clickwraps[1]]); |
| 32 | + } |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + /** |
| 37 | + * 1. Check the token |
| 38 | + * 2. Call the worker method |
| 39 | + * 3. Display clickwrap responses data |
| 40 | + * |
| 41 | + * @return void |
| 42 | + */ |
| 43 | + function createController(): void |
| 44 | + { |
| 45 | + $this->checkDsToken(); |
| 46 | + $clickwrapResponse = EmbedClickwrapService::createAgreeementUrl($this->args, $this->clientService); |
| 47 | + $htmlString = "<p id='agreementStatus'>NOT AGREED</p><div id='ds-terms-of-service'></div><script src='https://stage.docusign.net/clickapi/sdk/latest/docusign-click.js'></script><script>docuSignClick.Clickwrap.render({agreementUrl: '" . $clickwrapResponse . "',onAgreed: function () {document.getElementById('agreementStatus').innerHTML = 'AGREED';}}, '#ds-terms-of-service');</script>"; |
| 48 | + if ($clickwrapResponse) { |
| 49 | + |
| 50 | + if($clickwrapResponse === 'Already Agreed'){ |
| 51 | + $e = new ApiException("The email address was already used to agree to this elastic template. Provide a different email address if you want to view the agreement and agree to it.",990); |
| 52 | + $this->clientService->showErrorTemplate($e); |
| 53 | + exit; |
| 54 | + } |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + $this->clientService->showDoneTemplateFromManifest( |
| 59 | + $this->codeExampleText, |
| 60 | + null, |
| 61 | + $this->codeExampleText["ResultsPageText"]."<p>Agreement URL received back from API call: <code>".$clickwrapResponse."</code></p>".$htmlString |
| 62 | + ); |
| 63 | + |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + public function getTemplateArgs(): array |
| 68 | + { |
| 69 | + return [ |
| 70 | + 'account_id' => $_SESSION['ds_account_id'], |
| 71 | + 'ds_access_token' => $_SESSION['ds_access_token'], |
| 72 | + 'clickwrap_id' => $this->checkInputValues($_POST['clickwrap_id']), |
| 73 | + 'full_name' => $this->checkInputValues($_POST['fullName']), |
| 74 | + 'email_address' => $this->checkInputValues(($_POST['emailAddress'])), |
| 75 | + 'company' => $this->checkInputValues($_POST['company']), |
| 76 | + 'job_title' => $this->checkInputValues($_POST['jobTitle']), |
| 77 | + 'date' => $this->checkInputValues($_POST['date']) |
| 78 | + ]; |
| 79 | + } |
| 80 | +} |
0 commit comments