1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Transformers/SubscriptionTransformer.php

75 lines
3.0 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 05:20:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Transformers;
use App\Models\Subscription;
use App\Utils\Traits\MakesHash;
class SubscriptionTransformer extends EntityTransformer
{
use MakesHash;
/**
* @var array
*/
protected $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
];
public function transform(Subscription $subscription): array
{
$company = $subscription->company;
return [
'id' => $this->encodePrimaryKey($subscription->id),
'user_id' => $this->encodePrimaryKey($subscription->user_id),
2021-03-26 21:28:56 +01:00
'group_id' => $this->encodePrimaryKey($subscription->group_id),
2021-03-29 04:14:55 +02:00
'product_ids' => (string)$subscription->product_ids,
2021-04-01 11:33:50 +02:00
'name' => (string)$subscription->name,
2021-03-29 04:14:55 +02:00
'recurring_product_ids' => (string)$subscription->recurring_product_ids,
'assigned_user_id' => $this->encodePrimaryKey($subscription->assigned_user_id),
'company_id' => $this->encodePrimaryKey($subscription->company_id),
2021-03-26 21:28:56 +01:00
'price' => (float) $subscription->price,
2021-03-31 23:28:51 +02:00
'promo_price' => (float) $subscription->promo_price,
'frequency_id' => (string)$subscription->frequency_id,
'auto_bill' => (string)$subscription->auto_bill,
'promo_code' => (string)$subscription->promo_code,
'promo_discount' => (float)$subscription->promo_discount,
'is_amount_discount' => (bool)$subscription->is_amount_discount,
'allow_cancellation' => (bool)$subscription->allow_cancellation,
2021-03-31 02:07:54 +02:00
'per_seat_enabled' => (bool)$subscription->per_seat_enabled,
'max_seats_limit' => (int)$subscription->max_seats_limit,
'trial_enabled' => (bool)$subscription->trial_enabled,
'trial_duration' => (int)$subscription->trial_duration,
'allow_query_overrides' => (bool)$subscription->allow_query_overrides,
'allow_plan_changes' => (bool)$subscription->allow_plan_changes,
'refund_period' => (int)$subscription->refund_period,
2021-04-01 11:56:50 +02:00
'webhook_configuration' => $subscription->webhook_configuration ?: [],
2021-05-15 06:50:07 +02:00
'purchase_page' => (string)$company->domain() . "/client/subscriptions/{$subscription->hashed_id}/purchase",
//'purchase_page' => (string)route('client.subscription.purchase', $subscription->hashed_id),
2021-04-02 00:09:01 +02:00
'currency_id' => (string) $subscription->currency_id,
'is_deleted' => (bool)$subscription->is_deleted,
'created_at' => (int)$subscription->created_at,
'updated_at' => (int)$subscription->updated_at,
'archived_at' => (int)$subscription->deleted_at,
2021-04-05 00:37:01 +02:00
'plan_map' => '', //@deprecated 03/04/2021
];
}
}