mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Billing subscriptions: Factory, repository & transformer
This commit is contained in:
parent
2de12ea973
commit
ea5117ecbe
17
app/Factory/BillingSubscriptionFactory.php
Normal file
17
app/Factory/BillingSubscriptionFactory.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace App\Factory;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Models\BillingSubscription;
|
||||||
|
|
||||||
|
class BillingSubscriptionFactory
|
||||||
|
{
|
||||||
|
public static function create(int $company_id, int $user_id): BillingSubscription
|
||||||
|
{
|
||||||
|
$billing_subscription = new BillingSubscription();
|
||||||
|
|
||||||
|
return $billing_subscription;
|
||||||
|
}
|
||||||
|
}
|
28
app/Repositories/BillingSubscriptionRepository.php
Normal file
28
app/Repositories/BillingSubscriptionRepository.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Repositories;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Models\BillingSubscription;
|
||||||
|
|
||||||
|
class BillingSubscriptionRepository extends BaseRepository
|
||||||
|
{
|
||||||
|
public function save($data, BillingSubscription $billing_subscription): ?BillingSubscription
|
||||||
|
{
|
||||||
|
$billing_subscription
|
||||||
|
->fill($data)
|
||||||
|
->save();
|
||||||
|
|
||||||
|
return $billing_subscription;
|
||||||
|
}
|
||||||
|
}
|
70
app/Transformers/BillingSubscriptionTransformer.php
Normal file
70
app/Transformers/BillingSubscriptionTransformer.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Transformers;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Models\BillingSubscription;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
|
||||||
|
class BillingSubscriptionTransformer extends EntityTransformer
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $defaultIncludes = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $availableIncludes = [
|
||||||
|
'products',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function transform(BillingSubscription $billing_subscription): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->encodePrimaryKey($billing_subscription->id),
|
||||||
|
'user_id' => $this->encodePrimaryKey($billing_subscription->user_id),
|
||||||
|
'product_id' => $this->encodePrimaryKey($billing_subscription->product_id),
|
||||||
|
'assigned_user_id' => $this->encodePrimaryKey($billing_subscription->assigned_user_id),
|
||||||
|
'company_id' => $this->encodePrimaryKey($billing_subscription->company_id),
|
||||||
|
'is_recurring' => (bool)$billing_subscription->is_recurring,
|
||||||
|
'frequency_id' => (string)$billing_subscription->frequency_id,
|
||||||
|
'auto_bill' => (string)$billing_subscription->auto_bill,
|
||||||
|
'promo_code' => (string)$billing_subscription->promo_code,
|
||||||
|
'promo_discount' => (string)$billing_subscription->promo_discount,
|
||||||
|
'is_amount_discount' => (bool)$billing_subscription->is_amount_discount,
|
||||||
|
'allow_cancellation' => (bool)$billing_subscription->allow_cancellation,
|
||||||
|
'per_set_enabled' => (bool)$billing_subscription->per_set_enabled,
|
||||||
|
'min_seats_limit' => (int)$billing_subscription->min_seats_limit,
|
||||||
|
'max_seats_limit' => (int)$billing_subscription->max_seats_limit,
|
||||||
|
'trial_enabled' => (bool)$billing_subscription->trial_enabled,
|
||||||
|
'trial_duration' => (string)$billing_subscription->trial_duration,
|
||||||
|
'allow_query_overrides' => (bool)$billing_subscription->allow_query_overrides,
|
||||||
|
'allow_plan_changes' => (bool)$billing_subscription->allow_plan_changes,
|
||||||
|
'plan_map' => (string)$billing_subscription->plan_map,
|
||||||
|
'refund_period' => (string)$billing_subscription->refund_period,
|
||||||
|
'webhook_configuration' => (string)$billing_subscription->webhook_configuration,
|
||||||
|
'is_deleted' => (bool)$billing_subscription->is_deleted,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function includeProducts(BillingSubscription $billing_subscription): \League\Fractal\Resource\Item
|
||||||
|
{
|
||||||
|
$transformer = new ProductTransformer($this->serializer);
|
||||||
|
|
||||||
|
return $this->includeItem($billing_subscription->product, $transformer, Product::class);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user