Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.

Commit 9649c0e

Browse files
authored
Merge pull request #60 from jyoung488/Update-Template-Files
Update template files
2 parents 3ce95f0 + be6c44b commit 9649c0e

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

library/HelloSign/Client.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Client
6767
const TEMPLATE_CREATE_EMBEDDED_DRAFT = "template/create_embedded_draft";
6868
const TEMPLATE_DELETE_PATH = "template/delete";
6969
const TEMPLATE_FILES_PATH = "template/files";
70+
const TEMPLATE_UPDATE_FILES_PATH = "template/update_files";
7071

7172
const TEAM_PATH = "team";
7273
const TEAM_CREATE_PATH = "team/create";
@@ -390,6 +391,24 @@ public function getTemplateFiles($template_id, $dest_path = null, $type = 'pdf')
390391
return $response;
391392
}
392393

394+
/**
395+
* Creates a new template using the overlay of current template_id
396+
*
397+
* @param string $template_id
398+
* @param string $file
399+
* @return string
400+
*/
401+
402+
public function updateTemplateFiles($template_id, $request)
403+
{
404+
$params = $request->toParams();
405+
$response = $this->rest->post(
406+
static::TEMPLATE_UPDATE_FILES_PATH . '/' . $template_id,
407+
$params
408+
);
409+
return new Template($response);
410+
}
411+
393412
/**
394413
* Creates a new Signature Request based on the template provided
395414
*

library/HelloSign/Template.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,4 +393,27 @@ public function toEmbeddedDraftParams()
393393

394394
return $params;
395395
}
396+
397+
public function toParams()
398+
{
399+
$fields_to_include = array(
400+
'template_id',
401+
'test_mode',
402+
'client_id',
403+
'file',
404+
'file_url',
405+
'subject',
406+
'message'
407+
);
408+
409+
$params = $this->toArray();
410+
411+
foreach ($params as $key => $value) {
412+
if (!in_array($key, $fields_to_include)) {
413+
unset($params[$key]);
414+
}
415+
}
416+
417+
return $params;
418+
}
396419
}

library/HelloSign/Test/TemplateTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,25 @@ public function testGetTemplateFiles()
196196

197197
return $response;
198198
}
199+
200+
201+
/**
202+
* @group updateFile
203+
*/
204+
public function testUpdateTemplateFiles()
205+
{
206+
$templates = $this->client->getTemplates();
207+
$template_id = '01e0af3105fc7d880280ceb446bbc386b71a6981';
208+
209+
$request = new \HelloSign\Template();
210+
$request->enableTestMode();
211+
$request->setClientId($client_id);
212+
$request->addFile(__DIR__ . '/nda.docx');
213+
$request->setMessage('PHP SDK Test Update File Message');
214+
$request->setSubject('PHP SDK Test Update File Subject');
215+
216+
$response = $this->client->updateTemplateFiles($template_id, $request);
217+
$this->assertTrue(is_string($response->getId()));
218+
return $response;
219+
}
199220
}

0 commit comments

Comments
 (0)