Skip to content

Commit

Permalink
Added multiple files upload for documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Pieters committed Mar 8, 2016
1 parent 4ac90ef commit d5059a4
Showing 4 changed files with 50 additions and 13 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 3 additions & 3 deletions samples/uploadDocument.php
Original file line number Diff line number Diff line change
@@ -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());
14 changes: 9 additions & 5 deletions src/Api/AddDocument.php
Original file line number Diff line number Diff line change
@@ -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();
}
27 changes: 22 additions & 5 deletions src/Document.php
Original file line number Diff line number Diff line change
@@ -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']);

}

0 comments on commit d5059a4

Please sign in to comment.