Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ 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; \
echo "SIGNNOW_API_HOST=$$sn_api_host" >> .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."
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
95 changes: 58 additions & 37 deletions samples/EmbeddedSenderWithFormAndFirstSigner/SampleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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':
Expand All @@ -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([
Expand All @@ -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([
Expand All @@ -149,15 +162,23 @@ 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);
}

private function downloadDocumentGroup(Request $request, ApiClient $apiClient): Response
{
$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());
Expand Down
21 changes: 15 additions & 6 deletions samples/EmbeddedSignerPatientIntakeForm/SampleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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',
Expand Down
61 changes: 39 additions & 22 deletions samples/UploadEmbeddedSender/SampleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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':
Expand All @@ -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([
Expand Down Expand Up @@ -175,15 +184,23 @@ 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);
}

private function downloadDocumentGroup(Request $request, ApiClient $apiClient): Response
{
$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());
Expand Down