Skip to content

Commit

Permalink
[Billing] Add tier component
Browse files Browse the repository at this point in the history
  • Loading branch information
that-guy-iain committed Aug 15, 2024
1 parent 8fb5727 commit 4ea6fbc
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ doctrine:
Parthenon\Billing\Entity\ReceiptInterface: App\Entity\Receipt
Parthenon\Billing\Entity\ReceiptLineInterface: App\Entity\ReceiptLine
Parthenon\Billing\Entity\PriceInterface: App\Entity\Price
Parthenon\Billing\Entity\TierComponentInterface: App\Entity\TierComponent
Parthenon\Billing\Entity\SubscriptionInterface: App\Entity\Subscription
Parthenon\Billing\Entity\SubscriptionPlanInterface: App\Entity\SubscriptionPlan
Parthenon\MultiTenancy\Entity\TenantInterface: App\Entity\Tenant
Expand Down
30 changes: 30 additions & 0 deletions src/Entity/TierComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/*
* Copyright (C) 2020-2024 Iain Cambridge
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity()]
#[ORM\Table('tier_component')]
class TierComponent extends \Parthenon\Billing\Entity\TierComponent
{
}
9 changes: 9 additions & 0 deletions src/Parthenon/Billing/Entity/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@

use Brick\Money\Currency;
use Brick\Money\Money;
use Doctrine\Common\Collections\Collection;
use Parthenon\Athena\Entity\CrudEntityInterface;
use Parthenon\Athena\Entity\DeletableInterface;
use Parthenon\Billing\Enum\PriceType;
use Parthenon\Billing\Enum\UsageType;

class Price implements CrudEntityInterface, DeletableInterface, PriceInterface
{
Expand Down Expand Up @@ -53,6 +56,12 @@ class Price implements CrudEntityInterface, DeletableInterface, PriceInterface

private ?\DateTimeInterface $deletedAt = null;

private array|Collection $tierComponents = [];

private PriceType $type;

private ?UsageType $usageType = null;

public function getId()
{
return $this->id;
Expand Down
97 changes: 97 additions & 0 deletions src/Parthenon/Billing/Entity/TierComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

declare(strict_types=1);

/*
* Copyright (C) 2020-2024 Iain Cambridge
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

namespace Parthenon\Billing\Entity;

class TierComponent implements TierComponentInterface
{
private $id;

private int $firstUnit;

private ?int $lastUnit;

private int $unitPrice;

private int $flatFee;

private Price $price;

public function getId()
{
return $this->id;
}

public function setId($id): void
{
$this->id = $id;
}

public function getFirstUnit(): int
{
return $this->firstUnit;
}

public function setFirstUnit(int $firstUnit): void
{
$this->firstUnit = $firstUnit;
}

public function getLastUnit(): ?int
{
return $this->lastUnit;
}

public function setLastUnit(?int $lastUnit): void
{
$this->lastUnit = $lastUnit;
}

public function getUnitPrice(): int
{
return $this->unitPrice;
}

public function setUnitPrice(int $unitPrice): void
{
$this->unitPrice = $unitPrice;
}

public function getFlatFee(): int
{
return $this->flatFee;
}

public function setFlatFee(int $flatFee): void
{
$this->flatFee = $flatFee;
}

public function getPrice(): Price
{
return $this->price;
}

public function setPrice(Price $price): void
{
$this->price = $price;
}
}
45 changes: 45 additions & 0 deletions src/Parthenon/Billing/Entity/TierComponentInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/*
* Copyright (C) 2020-2024 Iain Cambridge
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

namespace Parthenon\Billing\Entity;

interface TierComponentInterface
{
public function getId();

public function setId($id): void;

public function getFirstUnit(): int;

public function setFirstUnit(int $firstUnit): void;

public function getLastUnit(): ?int;

public function setLastUnit(?int $lastUnit): void;

public function getUnitPrice(): int;

public function setUnitPrice(int $unitPrice): void;

public function getFlatFee(): int;

public function setFlatFee(int $flatFee): void;
}
29 changes: 29 additions & 0 deletions src/Parthenon/Billing/Enum/PriceSchedule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

/*
* Copyright (C) 2020-2024 Iain Cambridge
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

namespace Parthenon\Billing\Enum;

enum PriceSchedule: string
{
case WEEKLY = 'week';
case MONTHLY = 'month';
case YEARLY = 'year';
}
32 changes: 32 additions & 0 deletions src/Parthenon/Billing/Enum/PriceType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/*
* Copyright (C) 2020-2024 Iain Cambridge
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

namespace Parthenon\Billing\Enum;

enum PriceType: string
{
case RECURRING = 'recurring';
case ONE_OFF = 'one-off';
case PACKAGE = 'package';
case UNIT = 'per_unit';
case TIERED_VOLUME = 'tiered_volume';
case TIERED_GRADUATED = 'tiered_graduated';
}
30 changes: 30 additions & 0 deletions src/Parthenon/Billing/Enum/UsageType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/*
* Copyright (C) 2020-2024 Iain Cambridge
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

namespace Parthenon\Billing\Enum;

enum UsageType: string
{
case PACKAGE = 'package';
case UNIT = 'per_unit';
case TIERED_VOLUME = 'tiered_volume';
case TIERED_GRADUATED = 'tiered_graduated';
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
<field name="currency" column="currency" type="string" nullable="false" />
<field name="recurring" column="recurring" type="boolean" nullable="true" />
<field name="public" column="public" type="boolean" nullable="true" />
<field name="type" column="type" type="string" nullable="false" enum-type="Parthenon\Billing\Enum\PriceType" />
<field name="usageType" column="usage_type" type="string" nullable="true" enum-type="Parthenon\Billing\Enum\UsageType" />
<field name="includingTax" column="including_tax" type="boolean" nullable="true" />
<field name="isDeleted" column="is_deleted" type="boolean" nullable="true" />
<field name="schedule" column="schedule" type="string" nullable="true" />
<field name="externalReference" column="external_reference" type="string" nullable="true" />
<field name="paymentProviderDetailsUrl" column="payment_provider_details_url" type="string" nullable="true" />
<many-to-one field="product" target-entity="Parthenon\Billing\Entity\ProductInterface" />
<one-to-many field="tierComponent" target-entity="Parthenon\Billing\Entity\TierComponentInterface" mapped-by="price" />
<field name="createdAt" column="created_at" type="datetime" nullable="false" />
<field name="deletedAt" column="deleted_at" type="datetime" nullable="true" />
</mapped-superclass>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<mapped-superclass name="Parthenon\Billing\Entity\Price">
<id name="id" type="uuid" column="id">
<generator strategy="CUSTOM" />
<custom-id-generator class="Ramsey\Uuid\Doctrine\UuidGenerator" />
</id>

<field name="firstUnit" column="first_unit" type="integer" nullable="false" />
<field name="lastUnit" column="last_unit" type="integer" nullable="true" />
<field name="unitPrice" column="unit_price" type="integer" nullable="false" />
<field name="flatFee" column="flat_fee" type="integer" nullable="false" />

<many-to-one field="price" target-entity="Parthenon\Billing\Entity\PriceInterface" />
</mapped-superclass>
</doctrine-mapping>

0 comments on commit 4ea6fbc

Please sign in to comment.