Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DataExports endpoints #137

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class Client
* @var Endpoints\Insurance
*/
public $insurance;

/**
* @var Endpoints\DataExports
*/
public $dataExports;
/*************************/

/**
Expand Down Expand Up @@ -150,6 +155,7 @@ private function initEndpoints()
$this->shareOfCheckout = new Endpoints\ShareOfCheckout($this->context);
$this->webhooks = new Endpoints\Webhooks($this->context);
$this->insurance = new Endpoints\Insurance($this->context);
$this->dataExports = new Endpoints\DataExports($this->context);
}

private function initUserAgent()
Expand Down
89 changes: 89 additions & 0 deletions src/Endpoints/DataExports.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Copyright (c) 2018 Alma / Nabla SAS
*
* THE MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @author Alma / Nabla SAS <[email protected]>
* @copyright Copyright (c) 2018 Alma / Nabla SAS
* @license https://opensource.org/licenses/MIT The MIT License
*
*/

namespace Alma\API\Endpoints;

use Alma\API\Entities\DataExport;
use Alma\API\ParamsError;
use Alma\API\RequestError;

class DataExports extends Base
{
const DATA_EXPORTS_PATH = '/v1/data-exports';

/**
* @param $data
* @return DataExport
* @throws ParamsError
* @throws RequestError
*/
public function create($data)
{
$res = $this->request(self::DATA_EXPORTS_PATH)->setRequestBody($data)->post();

if ($res->isError()) {
throw new RequestError($res->errorMessage, null, $res);
}

return new DataExport($res->json);
}

/**
* @param $data
* @return DataExport
* @throws ParamsError
* @throws RequestError
*/
public function fetch($reportId)
{
$res = $this->request(self::DATA_EXPORTS_PATH . '/' . $reportId)->get();

if ($res->isError()) {
throw new RequestError($res->errorMessage, null, $res);
}

return new DataExport($res->json);
}

/**
* @param $reportId
* @param $format
*
* @return mixed
* @throws RequestError
*/
public function download($reportId, $format)
{
$res = $this->request(self::DATA_EXPORTS_PATH . '/' . $reportId)
->setQueryParams(['format' => $format])
->get();

if ($res->isError()) {
throw new RequestError($res->errorMessage, null, $res);
}

return $res->data;
}
}
68 changes: 68 additions & 0 deletions src/Entities/DataExport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright (c) 2018 Alma / Nabla SAS.
*
* THE MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @author Alma / Nabla SAS <[email protected]>
* @copyright Copyright (c) 2018 Alma / Nabla SAS
* @license https://opensource.org/licenses/MIT The MIT License
*/

namespace Alma\API\Entities;

class DataExport extends Base
{
public $complete;

public $created;

public $end;

public $holder_id;

public $id;

public $include_child_accounts;

public $merchant;

public $receivable_export_type;

public $start;

public $type;

public $updated;

public $url_csv;

public $url_pdf;

public $url_xlsx;

public $url_xml;

public $url_zip;

/**
* @param array $attributes
*/
public function __construct($attributes)
{
parent::__construct($attributes);
}
}
2 changes: 2 additions & 0 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ class Response
{
public $responseCode;
public $json;
public $data;
public $errorMessage;

public function __construct($curlHandle, $curlResult)
{
$this->responseCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
$this->json = json_decode($curlResult, true);
$this->data = $curlResult;

if ($this->isError()) {
if ($this->json && array_key_exists('message', $this->json)) {
Expand Down