firefly-iii/app/Services/Bunq/Object/Payment.php

146 lines
3.5 KiB
PHP
Raw Normal View History

2018-03-19 02:17:15 -05:00
<?php
/**
* Payment.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Services\Bunq\Object;
2018-03-24 12:55:02 -05:00
2018-03-19 02:17:15 -05:00
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
2018-03-19 02:17:15 -05:00
/**
* Class Payment
*/
class Payment extends BunqObject
{
2018-03-24 12:55:02 -05:00
/** @var LabelMonetaryAccount */
private $alias;
2018-03-19 02:17:15 -05:00
/** @var Amount */
private $amount;
2018-03-24 12:55:02 -05:00
/** @var array */
private $attachments = [];
/** @var LabelMonetaryAccount */
private $counterParty;
/** @var Carbon */
private $created;
2018-03-19 02:17:15 -05:00
/** @var string */
private $description;
2018-03-24 12:55:02 -05:00
/** @var int */
private $id;
2018-03-19 02:17:15 -05:00
/** @var string */
private $merchantReference;
2018-03-24 12:55:02 -05:00
/** @var int */
private $monetaryAccountId;
2018-03-19 02:17:15 -05:00
/** @var string */
private $subType;
2018-03-24 12:55:02 -05:00
/** @var string */
private $type;
/** @var Carbon */
private $updated;
2018-03-19 02:17:15 -05:00
/**
* Payment constructor.
*
* @param array $data
2018-03-29 12:01:47 -05:00
*
2018-03-19 02:17:15 -05:00
*/
public function __construct(array $data)
{
2018-03-24 12:55:02 -05:00
$this->id = $data['id'];
$this->created = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['created']);
$this->updated = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['updated']);
$this->monetaryAccountId = (int)$data['monetary_account_id'];
$this->amount = new Amount($data['amount']);
$this->description = $data['description'];
$this->type = $data['type'];
$this->merchantReference = $data['merchant_reference'];
$this->alias = new LabelMonetaryAccount($data['alias']);
$this->counterParty = new LabelMonetaryAccount($data['counterparty_alias']);
$this->subType = $data['sub_type'];
}
2018-03-19 02:17:15 -05:00
2018-03-24 12:55:02 -05:00
/**
* @return Amount
*/
public function getAmount(): Amount
{
return $this->amount;
}
/**
* @return LabelMonetaryAccount|null
*/
public function getCounterParty(): ?LabelMonetaryAccount
{
return $this->counterParty;
}
/**
* @return Carbon
*/
public function getCreated(): Carbon
{
return $this->created;
}
/**
* @return string
*/
public function getDescription(): string
{
return $this->description;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @return string
*/
public function getSubType(): string
{
return $this->subType;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @return array
2018-04-27 23:23:13 -05:00
* @throws FireflyException
2018-03-24 12:55:02 -05:00
*/
public function toArray(): array
{
throw new FireflyException(sprintf('Cannot convert %s to array.', \get_class($this)));
2018-03-19 02:17:15 -05:00
}
}