From a6e371e0faa50643fe8bf5994a22c00ec70c1b56 Mon Sep 17 00:00:00 2001 From: Petro Vakulenko Date: Fri, 22 May 2026 18:00:48 +0200 Subject: [PATCH] Synchronization of SampleApps between each other --- Makefile | 4 +- README.md | 4 +- .../SampleController.php | 95 +++++++++++-------- .../SampleController.php | 21 ++-- .../UploadEmbeddedSender/SampleController.php | 61 +++++++----- 5 files changed, 116 insertions(+), 69 deletions(-) diff --git a/Makefile b/Makefile index daa0e63..00880dc 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ setup-env: @echo "\nPlease configure your sample application with required information:"; \ read -p "signNow API host: " sn_api_host; \ read -p "signNow application's basic token: " sn_basic_token; \ - read -p "Your signer's email: " sn_signer_emal; \ + read -p "Your signer's email: " sn_signer_email; \ read -p "Your login to signNow account: " sn_user; \ read -p "Your password to signNow account: " sn_password; \ echo "\n" >> .env; \ @@ -34,6 +34,6 @@ setup-env: echo "SIGNNOW_API_BASIC_TOKEN=$$sn_basic_token" >> .env; \ echo "SIGNNOW_API_USERNAME=$$sn_user" >> .env; \ echo "SIGNNOW_API_PASSWORD=$$sn_password" >> .env; \ - echo "SIGNNOW_SIGNER_EMAIL=$$sn_signer_emal" >> .env; \ + echo "SIGNNOW_SIGNER_EMAIL=$$sn_signer_email" >> .env; \ echo "\n" >> .env; \ echo "Setup completed." diff --git a/README.md b/README.md index d2e3bef..2b5bb07 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![PHP Version](https://img.shields.io/badge/php->=8.2-blue)](https://php.net/) [![Laravel Version](https://img.shields.io/badge/laravel-10-cyan)](https://laravel.com/) -[![signNow PHP SDK](https://img.shields.io/badge/signNow_SDK-2.2-light)](https://github.com/signnow/SignNowPHPSDK) +[![signNow PHP SDK](https://img.shields.io/badge/signNow_SDK-3.x-light)](https://github.com/signnow/SignNowPHPSDK) [![Licence](https://img.shields.io/badge/license-MIT-green)](./LICENSE) ## About @@ -37,7 +37,7 @@ Configure the following variables to ensure the application’s proper functiona | SIGNNOW_API_PASSWORD | `*****` | Your signNow account password. | | SIGNNOW_SIGNER_EMAIL | `signer@mailer.com` | The email address of the person who is supposed to sign a document. | -View the entire configuration file, including standard Laravel variables, [here](./.env.example). +View the entire configuration file, including standard Laravel variables, [here](./.env.src). ## Get Started 1. Clone the repository diff --git a/samples/EmbeddedSenderWithFormAndFirstSigner/SampleController.php b/samples/EmbeddedSenderWithFormAndFirstSigner/SampleController.php index 67d4d9f..1819cb6 100644 --- a/samples/EmbeddedSenderWithFormAndFirstSigner/SampleController.php +++ b/samples/EmbeddedSenderWithFormAndFirstSigner/SampleController.php @@ -30,6 +30,7 @@ use SignNow\Api\DocumentGroup\Request\Data\Recipient\DocumentCollection as RecipientDocumentCollection; use SignNow\ApiClient; +use SignNow\Exception\SignNowApiException; use SignNow\Sdk; use Symfony\Component\HttpFoundation\Response; use SplFileInfo; @@ -60,10 +61,14 @@ public function handlePost(Request $request): Response { $action = $request->input('action'); - $sdk = new Sdk(); - $apiClient = $sdk->build() - ->authenticate() - ->getApiClient(); + try { + $sdk = new Sdk(); + $apiClient = $sdk->build() + ->authenticate() + ->getApiClient(); + } catch (SignNowApiException $e) { + return response()->json(['success' => false, 'message' => $e->getMessage()], 500); + } switch ($action) { case 'prepare_dg': @@ -88,37 +93,41 @@ private function prepareDocumentGroup(Request $request, ApiClient $apiClient): J return response()->json(['success' => false, 'message' => 'Name and email are required'], 400); } - // 1. Create Document Group from Template - $dgResponse = $this->createDocumentGroupFromTemplate($apiClient); - if (!$dgResponse['success']) { - return response()->json($dgResponse, 500); - } + try { + // 1. Create Document Group from Template + $dgResponse = $this->createDocumentGroupFromTemplate($apiClient); + if (!$dgResponse['success']) { + return response()->json($dgResponse, 500); + } - $documentGroupId = $dgResponse['document_group_id']; + $documentGroupId = $dgResponse['document_group_id']; - // 2. Update document fields with names - $updateFieldsResponse = $this->updateDocumentFields($apiClient, $documentGroupId, $name); - if (!$updateFieldsResponse['success']) { - return response()->json($updateFieldsResponse, 500); - } + // 2. Update document fields with names + $updateFieldsResponse = $this->updateDocumentFields($apiClient, $documentGroupId, $name); + if (!$updateFieldsResponse['success']) { + return response()->json($updateFieldsResponse, 500); + } - // 3. Add recipients to Document Group with different emails for different roles - $customerEmail = $email; // Email from form for "Customer to Sign" - $preparerEmail = config('signnow.api.user'); // Email from config for "Prepare Contract" - $addRecipientsResponse = $this->updateDocumentGroupRecipients( - $apiClient, - $documentGroupId, - $customerEmail, - $preparerEmail - ); - if (!$addRecipientsResponse['success']) { - return response()->json($addRecipientsResponse, 500); - } + // 3. Add recipients to Document Group with different emails for different roles + $customerEmail = $email; // Email from form for "Customer to Sign" + $preparerEmail = config('signnow.api.user'); // Email from config for "Prepare Contract" + $addRecipientsResponse = $this->updateDocumentGroupRecipients( + $apiClient, + $documentGroupId, + $customerEmail, + $preparerEmail + ); + if (!$addRecipientsResponse['success']) { + return response()->json($addRecipientsResponse, 500); + } - // 4. Create embedded sending link - $embeddedSendingResponse = $this->createEmbeddedSendingUrl($apiClient, $documentGroupId); - if (!$embeddedSendingResponse['success']) { - return response()->json($embeddedSendingResponse, 500); + // 4. Create embedded sending link + $embeddedSendingResponse = $this->createEmbeddedSendingUrl($apiClient, $documentGroupId); + if (!$embeddedSendingResponse['success']) { + return response()->json($embeddedSendingResponse, 500); + } + } catch (SignNowApiException $e) { + return response()->json(['success' => false, 'message' => $e->getMessage()], 500); } return response()->json([ @@ -132,10 +141,14 @@ private function createSigningUrl(Request $request, ApiClient $apiClient): JsonR { $documentGroupId = $request->input('document_group_id'); - // Create signing link with limited token - $signingLinkResponse = $this->createSigningLink($apiClient, $documentGroupId); - if (!$signingLinkResponse['success']) { - return response()->json($signingLinkResponse, 500); + try { + // Create signing link with limited token + $signingLinkResponse = $this->createSigningLink($apiClient, $documentGroupId); + if (!$signingLinkResponse['success']) { + return response()->json($signingLinkResponse, 500); + } + } catch (SignNowApiException $e) { + return response()->json(['success' => false, 'message' => $e->getMessage()], 500); } return response()->json([ @@ -149,7 +162,11 @@ private function createSigningUrl(Request $request, ApiClient $apiClient): JsonR private function getInviteStatus(Request $request, ApiClient $apiClient): JsonResponse { $documentGroupId = $request->input('document_group_id'); - $signers = $this->getDocumentGroupSignersStatus($apiClient, $documentGroupId); + try { + $signers = $this->getDocumentGroupSignersStatus($apiClient, $documentGroupId); + } catch (SignNowApiException $e) { + return response()->json(['success' => false, 'message' => $e->getMessage()], 500); + } return response()->json($signers); } @@ -157,7 +174,11 @@ private function downloadDocumentGroup(Request $request, ApiClient $apiClient): { $documentGroupId = $request->input('document_group_id'); - $file = $this->downloadDocumentGroupFile($apiClient, $documentGroupId); + try { + $file = $this->downloadDocumentGroupFile($apiClient, $documentGroupId); + } catch (SignNowApiException $e) { + return response()->json(['success' => false, 'message' => $e->getMessage()], 500); + } $content = file_get_contents($file->getRealPath()); unlink($file->getRealPath()); diff --git a/samples/EmbeddedSignerPatientIntakeForm/SampleController.php b/samples/EmbeddedSignerPatientIntakeForm/SampleController.php index a6353b3..95c172f 100644 --- a/samples/EmbeddedSignerPatientIntakeForm/SampleController.php +++ b/samples/EmbeddedSignerPatientIntakeForm/SampleController.php @@ -20,6 +20,7 @@ use SignNow\Api\EmbeddedInvite\Response\DocumentInviteLinkPost as DocumentInviteLinkPostResponse; use SignNow\Api\EmbeddedInvite\Response\DocumentInvitePost as DocumentInvitePostReponse; use SignNow\ApiClient; +use SignNow\Exception\SignNowApiException; use SignNow\Sdk; use SignNow\Api\Template\Response\CloneTemplatePost as CloneTemplatePostResponse; use SignNow\Api\Document\Response\DocumentDownloadGet as DocumentDownloadGetResponse; @@ -49,7 +50,11 @@ public function handleGet(Request $request): Response ] ); } else { - $link = $this->createEmbeddedInviteAndReturnSigningLink(self::TEMPLATE_ID); + try { + $link = $this->createEmbeddedInviteAndReturnSigningLink(self::TEMPLATE_ID); + } catch (SignNowApiException $e) { + return response()->json(['success' => false, 'message' => $e->getMessage()], 500); + } return new RedirectResponse($link); } @@ -65,12 +70,16 @@ public function handlePost(Request $request): Response { $request->get('document_id'); - $sdk = new Sdk(); - $apiClient = $sdk->build() - ->authenticate() - ->getApiClient(); + try { + $sdk = new Sdk(); + $apiClient = $sdk->build() + ->authenticate() + ->getApiClient(); - $file = $this->downloadDocument($apiClient, $request->get('document_id')); + $file = $this->downloadDocument($apiClient, $request->get('document_id')); + } catch (SignNowApiException $e) { + return response()->json(['success' => false, 'message' => $e->getMessage()], 500); + } return new Response($file, 200, [ 'Content-Type' => 'application/pdf', diff --git a/samples/UploadEmbeddedSender/SampleController.php b/samples/UploadEmbeddedSender/SampleController.php index 23ee745..01c986e 100644 --- a/samples/UploadEmbeddedSender/SampleController.php +++ b/samples/UploadEmbeddedSender/SampleController.php @@ -27,6 +27,7 @@ use SignNow\Api\DocumentGroup\Request\DocumentGroupRecipientsGet; use SignNow\Api\DocumentGroup\Response\DocumentGroupRecipientsGet as DocumentGroupRecipientsGetResponse; use SignNow\ApiClient; +use SignNow\Exception\SignNowApiException; use SignNow\Sdk; use Symfony\Component\HttpFoundation\Response; use SplFileInfo; @@ -48,10 +49,14 @@ public function handlePost(Request $request): Response { $action = $request->input('action'); - $sdk = new Sdk(); - $apiClient = $sdk->build() - ->authenticate() - ->getApiClient(); + try { + $sdk = new Sdk(); + $apiClient = $sdk->build() + ->authenticate() + ->getApiClient(); + } catch (SignNowApiException $e) { + return response()->json(['success' => false, 'message' => $e->getMessage()], 500); + } switch ($action) { case 'upload_and_create_dg': @@ -67,26 +72,30 @@ public function handlePost(Request $request): Response private function uploadAndCreateDocumentGroup(Request $request, ApiClient $apiClient): JsonResponse { - // 1. Upload PDF file to SignNow - $documentResponse = $this->uploadDocument($apiClient); - if (!$documentResponse['success']) { - return response()->json($documentResponse, 500); - } + try { + // 1. Upload PDF file to SignNow + $documentResponse = $this->uploadDocument($apiClient); + if (!$documentResponse['success']) { + return response()->json($documentResponse, 500); + } - $documentId = $documentResponse['document_id']; + $documentId = $documentResponse['document_id']; - // 2. Create Document Group from uploaded document - $documentGroupResponse = $this->createDocumentGroup($apiClient, $documentId); - if (!$documentGroupResponse['success']) { - return response()->json($documentGroupResponse, 500); - } + // 2. Create Document Group from uploaded document + $documentGroupResponse = $this->createDocumentGroup($apiClient, $documentId); + if (!$documentGroupResponse['success']) { + return response()->json($documentGroupResponse, 500); + } - $documentGroupId = $documentGroupResponse['document_group_id']; + $documentGroupId = $documentGroupResponse['document_group_id']; - // 3. Create embedded sending link - $embeddedSendingResponse = $this->createEmbeddedSendingUrl($apiClient, $documentGroupId); - if (!$embeddedSendingResponse['success']) { - return response()->json($embeddedSendingResponse, 500); + // 3. Create embedded sending link + $embeddedSendingResponse = $this->createEmbeddedSendingUrl($apiClient, $documentGroupId); + if (!$embeddedSendingResponse['success']) { + return response()->json($embeddedSendingResponse, 500); + } + } catch (SignNowApiException $e) { + return response()->json(['success' => false, 'message' => $e->getMessage()], 500); } return response()->json([ @@ -175,7 +184,11 @@ private function createEmbeddedSendingUrl(ApiClient $apiClient, string $document private function getInviteStatus(Request $request, ApiClient $apiClient): JsonResponse { $documentGroupId = $request->input('document_group_id'); - $signers = $this->getDocumentGroupSignersStatus($apiClient, $documentGroupId); + try { + $signers = $this->getDocumentGroupSignersStatus($apiClient, $documentGroupId); + } catch (SignNowApiException $e) { + return response()->json(['success' => false, 'message' => $e->getMessage()], 500); + } return response()->json($signers); } @@ -183,7 +196,11 @@ private function downloadDocumentGroup(Request $request, ApiClient $apiClient): { $documentGroupId = $request->input('document_group_id'); - $file = $this->downloadDocumentGroupFile($apiClient, $documentGroupId); + try { + $file = $this->downloadDocumentGroupFile($apiClient, $documentGroupId); + } catch (SignNowApiException $e) { + return response()->json(['success' => false, 'message' => $e->getMessage()], 500); + } $content = file_get_contents($file->getRealPath()); unlink($file->getRealPath());