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