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
90 changes: 54 additions & 36 deletions lib/EchoSign/Info/AbstractCreationInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,114 +4,132 @@

class AbstractCreationInfo
{


const SIGNATURE_FLOW_SENDER_SIGNATURE_NOT_REQUIRED = 'SENDER_SIGNATURE_NOT_REQUIRED';
const SIGNATURE_FLOW_SENDER_SIGNS_LAST = 'SENDER_SIGNS_LAST';
const SIGNATURE_FLOW_SENDER_SINGS_FIRST = 'SENDER_SIGNS_FIRST';

protected $name;
protected $file;
protected $file_infos;
protected $filename;
protected $locale;
protected $signature_flow;
protected $security_options;
protected $callback_info;
protected $merge_fields;
function __construct($name, FileInfo $file){

function __construct($name, FileInfo $file = null){
$this->name = $name;
$this->file = $file;
$this->file_infos = new FileInfos($file);
}

function setName($name){
$this->name = $name;
return $this;
}

function getName(){
return $this->name;
}

function setFile(FileInfo $file){
$this->file = $file;
$this->file_infos = new FileInfos($file);
return $this;
}

function getFile(){
return $this->file;
return $this->file_infos->getFile();
}


function addFile(FileInfo $file) {
$this->file_infos->addFile($file);
return $this;
}

function getFiles() {
return $this->file_infos;
}

function setFiles(FileInfos $files) {
$this->file_infos = $files;
return $this;
}

function setLocale($locale){
$this->locale = $locale;
return $this;
}

function getLocale(){
return $this->locale;
}

function setSignatureFlow($signature_flow){
$allowed = array('SENDER_SIGNATURE_NOT_REQUIRED', 'SENDER_SIGNS_LAST', 'SENDER_SIGNS_FIRST');

$allowed = array(self::SIGNATURE_FLOW_SENDER_SIGNATURE_NOT_REQUIRED, self::SIGNATURE_FLOW_SENDER_SIGNS_LAST, self::SIGNATURE_FLOW_SENDER_SINGS_FIRST);

if(!in_array($signature_flow, $allowed)){
throw new \InvalidArgumentException('signatureFlow must be one of: '.implode(', ', $allowed));
}

$this->signature_flow = $signature_flow;
return $this;
}

function getSignatureFlow(){
return $this->signature_flow;
}

function setSecurityOptions(SecurityOptions $security_options){
$this->security_options = $security_options;
return $this;
}

function getSecurityOptions(){
return $this->security_options;
}

function setCallbackInfo($callback_url){

if (!filter_var($callback_url, FILTER_VALIDATE_URL)) {
throw new \InvalidArgumentException("The callback url is invalid.");
}

if(!preg_match('#^(http://|https://)#', $callback_url)){
$callback_url = 'http://'.$callback_url;
}

$this->callback_info = $callback_url;
return $this;
}

function getCallbackInfo(){
return $this->callback_info;
}

function setMergeFields(MergeFieldInfo $merge_fields){
$this->merge_fields = $merge_fields;
return $this;
}

function getMergeFields(){
return $this->merge_fields;
}

function asArray(){

$properties = array(
'name' => $this->name,
'fileInfos' => $this->file->asArray(),
'fileInfos' => $this->file_infos->asArray(),
'locale' => $this->locale,
'signatureFlow' => $this->signature_flow
);

if(!empty($this->callback_info)) $properties['callbackInfo']['signedDocumentUrl'] = $this->callback_info;
if(!empty($this->security_options)) $properties = array_merge($properties, $this->security_options->asArray());
if(!empty($this->merge_fields)) $properties = array_merge($properties, $this->merge_fields->asArray());
if(!empty($this->merge_fields)) $properties = array_merge($properties, array('mergeFieldInfo' => array('mergeFields' => $this->merge_fields->asArray())));

return $properties;

}
}
}
77 changes: 40 additions & 37 deletions lib/EchoSign/Info/DocumentCreationInfo.php
Original file line number Diff line number Diff line change
@@ -1,132 +1,135 @@
<?php

namespace EchoSign\Info;

class DocumentCreationInfo extends AbstractCreationInfo
{


const SIGNATURE_TYPE_ESIGN = 'ESIGN';
const SIGNATURE_TYPE_WRITTEN = 'WRITTEN';

protected $recipients;
protected $ccs;
protected $message;
protected $signature_type;
protected $external_id;
protected $reminder_frequency;
protected $days_until_signing_deadline;

function setRecipients(RecipientInfo $recipients){
$this->recipients = $recipients;
return $this;
}

function getRecipients(){
return $this->recipients;
}

function setCCs(array $ccs){

foreach($ccs as $e){
if(!filter_var($e, FILTER_VALIDATE_EMAIL)) {
throw new \InvalidArgumentException($e. ' is not a valid email');
}
}

$this->ccs = $ccs;
return $this;
}

function getCCs(){
return $this->ccs;
}

function setMessage($message){
$this->message = $message;
return $this;
}

function getMessage(){
return $this->message;
}

function setSignatureType($signature_type){
$allowed = array('ESIGN', 'WRITTEN');

$allowed = array(self::SIGNATURE_TYPE_ESIGN, self::SIGNATURE_TYPE_WRITTEN);

if(!in_array($signature_type, $allowed)){
throw new \InvalidArgumentException('signatureType must be one of: '.implode(', ', $allowed));
}

$this->signature_type = $signature_type;
return $this;
}

function getSignatureType(){
return $this->signature_type;
}

function setExternalId($external_id){
$this->external_id = $external_id;
return $this;
}

function getExternalId(){
return $this->external_id;
}

function setReminderFrequency($reminder_frequency){

$allowed = array('DAILY_UNTIL_SIGNED', 'WEEKLY_UNTIL_SIGNED');

if(!in_array($reminder_frequency, $allowed)){
throw new \InvalidArgumentException('ReminderFrequency must be one of: '.implode(', ', $allowed));
}

$this->reminder_frequency = $reminder_frequency;
return $this;
}

function getReminderFrequency(){
return $this->reminder_frequency;
}

function setDaysUntilSigningDeadline($days){

if(!filter_var($days, FILTER_VALIDATE_INT)) {
throw new \InvalidArgumentException('DaysUntilSigningDeadline must be an integer');
}

$this->days_until_signing_deadline = $days;
return $this;
}

function getDaysUntilSigningDeadline(){
return $this->days_until_signing_deadline;
}

function asArray(){

$inherited = parent::asArray();

$properties = array(

'recipients' => $this->recipients->asArray(),
'ccs' => $this->ccs,
'message' => $this->message,
'signatureType' => $this->signature_type,
'reminderFrequency' => $this->reminder_frequency,
'daysUntilSigningDeadline' => $this->days_until_signing_deadline

);

$properties = array_merge($inherited, $properties);

foreach($properties as $k => $v){
if($v === null || $v === ''){
unset($properties[$k]);
}
}

return array('documentCreationInfo' => $properties);

}

}
Loading