1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Transformers/PaymentTransformer.php

78 lines
2.3 KiB
PHP
Raw Normal View History

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
class PaymentTransformer extends EntityTransformer
{
2019-04-03 02:09:22 +02:00
use MakesHash;
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),
'user_id' => $this->encodePrimaryKey($payment->user_id),
'assigned_user_id' => $this->encodePrimaryKey($payment->assigned_user_id),
2019-03-27 05:50:13 +01:00
'amount' => (float) $payment->amount,
'transaction_reference' => $payment->transaction_reference ?: '',
'payment_date' => $payment->payment_date ?: '',
2019-10-03 02:17:29 +02:00
'updated_at' => $payment->updated_at,
'archived_at' => $payment->deleted_at,
2019-03-27 05:50:13 +01:00
'is_deleted' => (bool) $payment->is_deleted,
2019-10-02 10:50:54 +02:00
'payment_type_id' => (string) $payment->payment_type_id ?: '',
'invitation_id' => (string) $payment->invitation_id ?: '',
/*
2019-03-27 05:50:13 +01:00
'private_notes' => $payment->private_notes ?: '',
'exchange_rate' => (float) $payment->exchange_rate,
'exchange_currency_id' => (int) $payment->exchange_currency_id,
'refunded' => (float) $payment->refunded,
2019-10-02 10:50:54 +02:00
'payment_status_id' => (string) $payment->payment_status_id,
*/
2019-04-20 00:47:10 +02:00
];
2019-03-27 05:50:13 +01:00
}
}