1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Transformers/CompanyGatewayTransformer.php

89 lines
2.9 KiB
PHP
Raw Normal View History

<?php
/**
* 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
*/
namespace App\Transformers;
use App\Models\CompanyGateway;
2019-10-17 13:49:09 +02:00
use App\Transformers\GatewayTransformer;
use App\Utils\Traits\MakesHash;
/**
* Class CompanyGatewayTransformer.
*/
class CompanyGatewayTransformer extends EntityTransformer
{
use MakesHash;
/**
* @var array
*/
protected $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
2019-10-17 13:49:09 +02:00
'gateway'
];
/**
* @param CompanyGateway $company_gateway
*
* @return array
*/
public function transform(CompanyGateway $company_gateway)
{
return [
'id' => (string)$this->encodePrimaryKey($company_gateway->id),
'gateway_key' => (string)$company_gateway->gateway_key ?: '',
'accepted_credit_cards' => (int)$company_gateway->accepted_credit_cards,
'require_cvv' => (bool)$company_gateway->require_cvv,
2019-10-17 13:49:09 +02:00
'show_billing_address' => (bool)$company_gateway->show_billing_address,
'show_shipping_address' => (bool)$company_gateway->show_shipping_address,
'update_details' => (bool)$company_gateway->update_details,
2019-10-03 12:59:19 +02:00
'config' => (string) $company_gateway->getConfigTransformed(),
//'priority' => (int)$company_gateway->priority,
'fees_and_limits' => $this->mapFeesAndLimits($company_gateway),
'updated_at' => $company_gateway->updated_at,
'deleted_at' => $company_gateway->deleted_at,
];
}
2019-10-17 13:49:09 +02:00
public function includeGateway(CompanyGateway $company_gateway)
{
$transformer = new GatewayTransformer($this->serializer);
return $this->includeItem($company_gateway->gateway, $transformer, Gateway::class);
}
private function mapFeesAndLimits($company_gateway)
{
$cg = new \stdClass;
$cg->min_limit = (float)$company_gateway->min_limit ?: null;
$cg->max_limit = (float)$company_gateway->max_limit ?: null;
$cg->fee_amount = (float) $company_gateway->fee_amount ?: null;
$cg->fee_percent = (float)$company_gateway->fee_percent ?: null;
$cg->fee_tax_name1 = (string)$company_gateway->fee_tax_name1 ?: '';
$cg->fee_tax_name2 = (string) $company_gateway->fee_tax_name2 ?: '';
$cg->fee_tax_name3 = (string) $company_gateway->fee_tax_name3 ?: '';
$cg->fee_tax_rate1 = (float) $company_gateway->fee_tax_rate1;
$cg->fee_tax_rate2 = (float)$company_gateway->fee_tax_rate2;
$cg->fee_tax_rate3 = (float)$company_gateway->fee_tax_rate3;
$cg->fee_cap = (float)$company_gateway->fee_cap ?: null;
$cg->adjust_fee_percent = (bool)$company_gateway->adjust_fee_percent;
return $cg;
}
}