2019-03-27 05:50:13 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
namespace App\Transformers;
|
2019-03-27 05:50:13 +01:00
|
|
|
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Payment;
|
2019-04-03 02:09:22 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-03-27 05:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @SWG\Definition(definition="Payment", required={"invoice_id"}, @SWG\Xml(name="Payment"))
|
|
|
|
*/
|
|
|
|
class PaymentTransformer extends EntityTransformer
|
|
|
|
{
|
2019-04-03 02:09:22 +02:00
|
|
|
use MakesHash;
|
2019-03-27 05:50:13 +01:00
|
|
|
/**
|
|
|
|
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
|
|
|
|
* @SWG\Property(property="amount", type="number", format="float", example=10, readOnly=true)
|
|
|
|
* @SWG\Property(property="transaction_reference", type="string", example="Transaction Reference")
|
|
|
|
* @SWG\Property(property="payment_date", type="string", format="date", example="2018-01-01")
|
|
|
|
* @SWG\Property(property="updated_at", type="integer", example=1451160233, readOnly=true)
|
|
|
|
* @SWG\Property(property="archived_at", type="integer", example=1451160233, readOnly=true)
|
|
|
|
* @SWG\Property(property="is_deleted", type="boolean", example=false, readOnly=true)
|
|
|
|
* @SWG\Property(property="invoice_id", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="invoice_number", type="string", example="Invoice Number")
|
|
|
|
* @SWG\Property(property="private_notes", type="string", example="Notes")
|
|
|
|
* @SWG\Property(property="exchange_rate", type="number", format="float", example=10)
|
|
|
|
* @SWG\Property(property="exchange_currency_id", type="integer", example=1)
|
|
|
|
*/
|
2019-03-28 03:36:36 +01:00
|
|
|
|
|
|
|
protected $serializer;
|
|
|
|
|
2019-03-27 05:50:13 +01:00
|
|
|
protected $defaultIncludes = [];
|
|
|
|
|
|
|
|
protected $availableIncludes = [
|
|
|
|
'client',
|
|
|
|
'invoice',
|
|
|
|
];
|
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
public function __construct($serializer = null)
|
2019-03-27 05:50:13 +01:00
|
|
|
{
|
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
$this->serializer = $serializer;
|
|
|
|
|
2019-03-27 05:50:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function includeInvoice(Payment $payment)
|
|
|
|
{
|
2019-03-28 03:36:36 +01:00
|
|
|
$transformer = new InvoiceTransformer($this->serializer);
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
return $this->includeItem($payment->invoice, $transformer, Invoice::class);
|
2019-03-27 05:50:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function includeClient(Payment $payment)
|
|
|
|
{
|
2019-03-28 03:36:36 +01:00
|
|
|
$transformer = new ClientTransformer($this->serializer);
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
return $this->includeItem($payment->client, $transformer, Client::class);
|
2019-03-27 05:50:13 +01:00
|
|
|
}
|
2019-03-28 03:36:36 +01:00
|
|
|
//todo incomplete
|
2019-03-27 05:50:13 +01:00
|
|
|
public function transform(Payment $payment)
|
|
|
|
{
|
2019-03-28 03:36:36 +01:00
|
|
|
return [
|
2019-04-03 02:09:22 +02:00
|
|
|
'id' => $this->encodePrimaryKey($payment->id),
|
2019-03-27 05:50:13 +01:00
|
|
|
'amount' => (float) $payment->amount,
|
2019-04-20 00:47:10 +02:00
|
|
|
/*
|
2019-03-27 05:50:13 +01:00
|
|
|
'transaction_reference' => $payment->transaction_reference ?: '',
|
|
|
|
'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 ?: 0),
|
|
|
|
'invoice_id' => (int) ($this->invoice ? $this->invoice->public_id : $payment->invoice->public_id),
|
|
|
|
'invoice_number' => $this->invoice ? $this->invoice->invoice_number : $payment->invoice->invoice_number,
|
|
|
|
'private_notes' => $payment->private_notes ?: '',
|
|
|
|
'exchange_rate' => (float) $payment->exchange_rate,
|
|
|
|
'exchange_currency_id' => (int) $payment->exchange_currency_id,
|
|
|
|
'refunded' => (float) $payment->refunded,
|
2019-04-20 00:47:10 +02:00
|
|
|
'payment_status_id' => (int) $payment->payment_status_id,
|
|
|
|
*/
|
|
|
|
];
|
2019-03-27 05:50:13 +01:00
|
|
|
}
|
|
|
|
}
|