2019-12-16 12:34:38 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-12-16 12:34:38 +01:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Transformers;
|
|
|
|
|
2020-01-07 01:13:47 +01:00
|
|
|
use App\Models\Credit;
|
2019-12-16 12:34:38 +01:00
|
|
|
use App\Models\Payment;
|
|
|
|
use App\Models\Paymentable;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
|
|
|
|
class PaymentableTransformer extends EntityTransformer
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
|
|
|
|
protected $serializer;
|
|
|
|
|
|
|
|
protected $defaultIncludes = [];
|
|
|
|
|
|
|
|
protected $availableIncludes = [];
|
|
|
|
|
|
|
|
public function __construct($serializer = null)
|
|
|
|
{
|
|
|
|
$this->serializer = $serializer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function transform(Paymentable $paymentable)
|
|
|
|
{
|
2020-01-07 01:13:47 +01:00
|
|
|
$entity_key = 'invoice_id';
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if ($paymentable->paymentable_type == Credit::class) {
|
2020-01-07 01:13:47 +01:00
|
|
|
$entity_key = 'credit_id';
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-01-07 01:13:47 +01:00
|
|
|
|
2019-12-16 12:34:38 +01:00
|
|
|
return [
|
|
|
|
'id' => $this->encodePrimaryKey($paymentable->id),
|
2020-01-07 01:13:47 +01:00
|
|
|
$entity_key => $this->encodePrimaryKey($paymentable->paymentable_id),
|
2020-01-04 03:27:51 +01:00
|
|
|
'amount' => (float)$paymentable->amount,
|
2020-01-19 02:19:10 +01:00
|
|
|
'refunded' => (float)$paymentable->refunded,
|
2020-01-07 01:13:47 +01:00
|
|
|
'created_at' => (int) $paymentable->created_at,
|
|
|
|
'updated_at' => (int) $paymentable->updated_at,
|
2019-12-16 12:34:38 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|