diff --git a/README.md b/README.md index 9822e95..1f08950 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,22 @@ if($result->success()){ } ``` + +It is also possible to send multiple files. The files will be merged into one file on our server. +Both files must be of the same type (pdf or image) + +```php +$result = Paynl\Alliance\Document::upload(array( + 'documentId' => 'D-1234-5678', + 'path' => array('/path/to/the/file', 'path/to/the/second/file'), + 'filename' => 'rekeningAfschrift.pdf' // optional, when you leave this blank, the filename from the path will be used + )); + +if($result->success()){ +} + +``` + ##### 5. Getting the list of available categories You must select the correct category for the services you add for the merchant. The available paymentmethods differ for each category (for example, a wine giftcard is only valid for category wines) diff --git a/samples/uploadDocument.php b/samples/uploadDocument.php index 0177695..9e260a8 100644 --- a/samples/uploadDocument.php +++ b/samples/uploadDocument.php @@ -3,9 +3,9 @@ require_once 'config.php'; try { $result = Paynl\Alliance\Document::upload(array( - 'documentId' => 'D-1234-5678', - 'path' => '/path/to/the/file', - 'filename' => 'rekeningAfschrift.pdf' // optional, when you leave this blank, the filename from the path will be used + 'documentId' => 'D-3527-0371', + 'path' => array('C:\Users\andy\Documents\test.png'),// you can just send a path, or an array of paths, the documents will be merged on our server + 'filename' => 'rekeningAfschrift.png' // optional, when you leave this blank, the filename from the path will be used )); var_dump($result->success()); diff --git a/src/Api/AddDocument.php b/src/Api/AddDocument.php index db5eea3..88c501e 100644 --- a/src/Api/AddDocument.php +++ b/src/Api/AddDocument.php @@ -26,7 +26,7 @@ class AddDocument extends Api */ private $_filename; /** - * @var string base64 encoded content of the document + * @var string[] base64 encoded content of the document */ private $_content; @@ -49,9 +49,9 @@ public function setFilename($filename) /** * @param string $content */ - public function setContent($content) + public function addContent($content) { - $this->_content = $content; + $this->_content[] = $content; } protected function getData() @@ -66,10 +66,14 @@ protected function getData() } $this->data['documentId'] = $this->_documentId; - if (!isset($this->_content)) { + if (!isset($this->_content) && !empty($this->_content)) { throw new Required('content'); } - $this->data['documentFile'] = $this->_content; + if(count($this->_content) == 1){ + $this->data['documentFile'] = $this->_content[0]; + } else { + $this->data['documentFile'] = $this->_content; + } return parent::getData(); } diff --git a/src/Document.php b/src/Document.php index 2f1a5f4..5d935f1 100644 --- a/src/Document.php +++ b/src/Document.php @@ -15,16 +15,29 @@ class Document { + private static function addFile($path, Api\AddDocument $api){ + if (!file_exists($path)) { + throw new Error('path is invalid, file does not exist'); + } + $content = file_get_contents($path); + $api->addContent(base64_encode($content)); + } + public static function upload($options) { $api = new Api\AddDocument(); if (isset($options['path'])) { - if (!file_exists($options['path'])) { - throw new Error('path is invalid, file does not exist'); + if(is_string($options['path'])){ + self::addFile($options['path'], $api); + } elseif(is_array($options['path'])){ + foreach($options['path'] as $path){ + self::addFile($path, $api); + } + } else { + throw new Error('path is invalid'); } - $content = file_get_contents($options['path']); - $api->setContent(base64_encode($content)); + } else { throw new Required('path'); } @@ -33,7 +46,11 @@ public static function upload($options) $api->setFilename($options['filename']); } else { // We should use the filename from the path - $pathinfo = pathinfo($options['path']); + $path = $options['path']; + if(is_array($path)){ + $path = $path[0]; + } + $pathinfo = pathinfo($path); $api->setFilename($pathinfo['basename']); }