2019-10-25 11:49:38 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-10-25 11:49:38 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-10-25 11:49:38 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-10-25 11:49:38 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Transformers;
|
|
|
|
|
|
|
|
use App\Models\ClientGatewayToken;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
2020-10-28 11:10:49 +01:00
|
|
|
use stdClass;
|
2019-10-25 11:49:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ClientGatewayTokenTransformer.
|
|
|
|
*/
|
|
|
|
class ClientGatewayTokenTransformer extends EntityTransformer
|
|
|
|
{
|
|
|
|
use MakesHash;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-10-25 11:49:38 +02:00
|
|
|
/**
|
|
|
|
* @param ClientGatewayToken $cgt
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(ClientGatewayToken $cgt)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => $this->encodePrimaryKey($cgt->id),
|
2020-09-06 11:38:10 +02:00
|
|
|
'token' => (string) $cgt->token ?: '',
|
2019-10-25 11:49:38 +02:00
|
|
|
'gateway_customer_reference' => $cgt->gateway_customer_reference ?: '',
|
2020-09-06 11:38:10 +02:00
|
|
|
'gateway_type_id' => (string) $cgt->gateway_type_id ?: '',
|
|
|
|
'company_gateway_id' => (string) $this->encodePrimaryKey($cgt->company_gateway_id) ?: '',
|
2019-10-25 11:49:38 +02:00
|
|
|
'is_default' => (bool) $cgt->is_default,
|
2020-10-09 08:55:03 +02:00
|
|
|
'meta' => $this->typeCastMeta($cgt->meta),
|
2020-09-06 11:38:10 +02:00
|
|
|
'created_at' => (int) $cgt->created_at,
|
|
|
|
'updated_at' => (int) $cgt->updated_at,
|
|
|
|
'archived_at' => (int) $cgt->deleted_at,
|
2020-08-12 00:17:32 +02:00
|
|
|
'is_deleted' => (bool) $cgt->is_deleted,
|
2019-10-25 11:49:38 +02:00
|
|
|
];
|
|
|
|
}
|
2020-10-09 08:55:03 +02:00
|
|
|
|
|
|
|
private function typeCastMeta($meta)
|
|
|
|
{
|
2020-10-28 11:10:49 +01:00
|
|
|
$casted = new stdClass;
|
2020-10-09 08:55:03 +02:00
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
if (property_exists($meta, 'exp_month')) {
|
2022-06-21 11:57:17 +02:00
|
|
|
$casted->exp_month = (string) $meta->exp_month;
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-10-09 08:55:03 +02:00
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
if (property_exists($meta, 'exp_year')) {
|
2022-06-21 11:57:17 +02:00
|
|
|
$casted->exp_year = (string) $meta->exp_year;
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-10-09 08:55:03 +02:00
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
if (property_exists($meta, 'brand')) {
|
2022-06-21 11:57:17 +02:00
|
|
|
$casted->brand = (string) $meta->brand;
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-10-09 08:55:03 +02:00
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
if (property_exists($meta, 'last4')) {
|
2022-06-21 11:57:17 +02:00
|
|
|
$casted->last4 = (string) $meta->last4;
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-10-09 08:55:03 +02:00
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
if (property_exists($meta, 'type')) {
|
2022-06-21 11:57:17 +02:00
|
|
|
$casted->type = (int) $meta->type;
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-10-09 08:55:03 +02:00
|
|
|
|
|
|
|
return $casted;
|
|
|
|
}
|
2019-10-25 11:49:38 +02:00
|
|
|
}
|