2015-11-27 13:55:28 +01:00
|
|
|
<?php namespace App\Ninja\Transformers;
|
|
|
|
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Payment;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Client;
|
|
|
|
use League\Fractal;
|
|
|
|
use App\Ninja\Transformers\InvoiceTransformer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @SWG\Definition(definition="Payment", required={"invoice_id"}, @SWG\Xml(name="Payment"))
|
|
|
|
*/
|
|
|
|
|
|
|
|
class PaymentTransformer extends EntityTransformer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
|
|
|
|
* @SWG\Property(property="amount", type="float", example=10, readOnly=true)
|
|
|
|
* @SWG\Property(property="invoice_id", type="integer", example=1)
|
|
|
|
*/
|
2016-01-05 13:51:27 +01:00
|
|
|
protected $defaultIncludes = [];
|
2015-11-27 13:55:28 +01:00
|
|
|
|
2016-02-16 16:30:09 +01:00
|
|
|
protected $availableIncludes = [
|
|
|
|
'client',
|
|
|
|
'invoice',
|
|
|
|
];
|
|
|
|
|
2015-11-27 13:55:28 +01:00
|
|
|
|
|
|
|
public function __construct(Account $account)
|
|
|
|
{
|
|
|
|
parent::__construct($account);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function includeInvoice(Payment $payment)
|
|
|
|
{
|
|
|
|
$transformer = new InvoiceTransformer($this->account, $this->serializer);
|
|
|
|
return $this->includeItem($payment->invoice, $transformer, 'invoice');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function includeClient(Payment $payment)
|
|
|
|
{
|
|
|
|
$transformer = new ClientTransformer($this->account, $this->serializer);
|
|
|
|
return $this->includeItem($payment->client, $transformer, 'client');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function transform(Payment $payment)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => (int) $payment->public_id,
|
|
|
|
'amount' => (float) $payment->amount,
|
|
|
|
'account_key' => $this->account->account_key,
|
|
|
|
'user_id' => (int) $payment->user->public_id + 1,
|
|
|
|
'transaction_reference' => $payment->transaction_reference,
|
2016-01-05 13:51:27 +01:00
|
|
|
'payment_date' => $payment->payment_date,
|
|
|
|
'updated_at' => $this->getTimestamp($payment->updated_at),
|
|
|
|
'archived_at' => $this->getTimestamp($payment->deleted_at),
|
|
|
|
'is_deleted' => (bool) $payment->is_deleted,
|
|
|
|
'payment_type_id' => (int) $payment->payment_type_id,
|
2015-11-27 13:55:28 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|