|
| 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\InPersonSigner; |
| 10 | +use DocuSign\eSign\Model\SignHere; |
| 11 | +use DocuSign\eSign\Model\Tabs; |
| 12 | +use Example\Services\SignatureClientService; |
| 13 | + |
| 14 | +class InPersonSigningService |
| 15 | +{ |
| 16 | + /** |
| 17 | + * Do the work of the example |
| 18 | + * 1. Create the envelope request object |
| 19 | + * 2. Send the envelope |
| 20 | + * 3. Create the Recipient View request object |
| 21 | + * 4. Obtain the recipient_view_url for the embedded signing |
| 22 | + * @return string |
| 23 | + */ |
| 24 | + public static function worker( |
| 25 | + string $accountId, |
| 26 | + string $hostName, |
| 27 | + SignatureClientService $clientService, |
| 28 | + string $demoPath |
| 29 | + ): string { |
| 30 | + $envelopeDefinition = InPersonSigningService::_prepareEnvelope($hostName, $demoPath); |
| 31 | + $envelopeApi = $clientService->getEnvelopeApi(); |
| 32 | + |
| 33 | + try { |
| 34 | + $envelopeSummary = $envelopeApi->createEnvelope($accountId, $envelopeDefinition); |
| 35 | + } catch (ApiException $e) { |
| 36 | + $clientService->showErrorTemplate($e); |
| 37 | + exit; |
| 38 | + } |
| 39 | + |
| 40 | + $authentication_method = 'None'; |
| 41 | + |
| 42 | + $envelopeArguments = [ |
| 43 | + 'signer_email' => $GLOBALS['DS_CONFIG']['signer_email'], |
| 44 | + 'signer_name' => $GLOBALS['DS_CONFIG']['signer_name'], |
| 45 | + 'ds_return_url' => $GLOBALS['app_url'] . 'index.php?page=ds_return' |
| 46 | + ]; |
| 47 | + |
| 48 | + $recipientViewRequest = $clientService->getRecipientViewRequest( |
| 49 | + $authentication_method, |
| 50 | + $envelopeArguments |
| 51 | + ); |
| 52 | + |
| 53 | + $viewUrl = $clientService->getRecipientView($accountId, $envelopeSummary->getEnvelopeId(), $recipientViewRequest); |
| 54 | + |
| 55 | + return $viewUrl['url']; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Creates envelope definition |
| 60 | + * Parameters for the envelope: signer_email, signer_name, signer_client_id |
| 61 | + * |
| 62 | + * @param $args array |
| 63 | + * @return EnvelopeDefinition -- returns an envelope definition |
| 64 | + */ |
| 65 | + private static function _prepareEnvelope(string $hostName, string $demoPath): EnvelopeDefinition |
| 66 | + { |
| 67 | + $file_content_in_bytes = file_get_contents($demoPath . $GLOBALS['DS_CONFIG']['doc_pdf']); |
| 68 | + $document = new Document( |
| 69 | + [ |
| 70 | + 'document_base64' => base64_encode($file_content_in_bytes), |
| 71 | + 'name' => 'Lorem Ipsum', |
| 72 | + 'file_extension' => 'pdf', |
| 73 | + 'document_id' => '1' |
| 74 | + ] |
| 75 | + ); |
| 76 | + |
| 77 | + $inPersonSigner = new InPersonSigner( |
| 78 | + [ |
| 79 | + 'host_email' => $GLOBALS['DS_CONFIG']['signer_email'], |
| 80 | + 'host_name' => $GLOBALS['DS_CONFIG']['signer_name'], |
| 81 | + 'signer_name' => $hostName, |
| 82 | + 'recipient_id' => "1", |
| 83 | + 'routing_order' => "1" |
| 84 | + ] |
| 85 | + ); |
| 86 | + |
| 87 | + $sign_here = new SignHere( |
| 88 | + [ |
| 89 | + 'anchor_string' => '/sn1/', |
| 90 | + 'anchor_units' => 'pixels', |
| 91 | + 'anchor_y_offset' => '10', |
| 92 | + 'anchor_x_offset' => '20' |
| 93 | + ] |
| 94 | + ); |
| 95 | + |
| 96 | + $inPersonSigner->settabs(new Tabs(['sign_here_tabs' => [$sign_here]])); |
| 97 | + |
| 98 | + return new EnvelopeDefinition( |
| 99 | + [ |
| 100 | + 'email_subject' => "Please host this in-person signing session", |
| 101 | + 'documents' => [$document], |
| 102 | + 'recipients' => new Recipients(['in_person_signers' => [$inPersonSigner]]), |
| 103 | + 'status' => "sent" |
| 104 | + ] |
| 105 | + ); |
| 106 | + } |
| 107 | +} |
0 commit comments