PHPackages                             tourze/credit-resource-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. tourze/credit-resource-bundle

ActiveSymfony-bundle[Payment Processing](/categories/payments)

tourze/credit-resource-bundle
=============================

Credit resource management bundle providing resource pricing and automatic billing functionality for Symfony applications

0.0.1(11mo ago)00MITPHPPHP ^8.1CI failing

Since Jun 3Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/credit-resource-bundle)[ Packagist](https://packagist.org/packages/tourze/credit-resource-bundle)[ RSS](/packages/tourze-credit-resource-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (32)Versions (2)Used By (0)

credit-resource-bundle
======================

[](#credit-resource-bundle)

[English](README.md) | [中文](README.zh-CN.md)

\[[![Latest Version](https://camo.githubusercontent.com/9d6ed9e9669644e965ebb40d135793e094026e26d3b18c985e83271b5c2b1239/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f6372656469742d7265736f757263652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/9d6ed9e9669644e965ebb40d135793e094026e26d3b18c985e83271b5c2b1239/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f6372656469742d7265736f757263652d62756e646c652e7376673f7374796c653d666c61742d737175617265)\] () [!\[Build Status\](https://img.shields.io/github/actions/workflow/status/tourze/php-monorepo/tests.yml ?branch=master&amp;style=flat-square)](https://github.com/tourze/php-monorepo/actions)\[[![Code Coverage](https://camo.githubusercontent.com/6ce0146325478eb7cebae4cc6139b2af2c161735dd0e3c6ff6802f2c5a708179/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/6ce0146325478eb7cebae4cc6139b2af2c161735dd0e3c6ff6802f2c5a708179/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f3f7374796c653d666c61742d737175617265)\] () \[[![PHP Version](https://camo.githubusercontent.com/966e912427eef54192c557b01d62a08f7c30f97a51e99aef91886674aa5e1e63/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f6372656469742d7265736f757263652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/966e912427eef54192c557b01d62a08f7c30f97a51e99aef91886674aa5e1e63/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f6372656469742d7265736f757263652d62756e646c652e7376673f7374796c653d666c61742d737175617265)\] () \[[![License](https://camo.githubusercontent.com/ab6540858ad697c071e5dd74022eb83f499642b0206d9f602be4d1e6f97b8474/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f6372656469742d7265736f757263652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/ab6540858ad697c071e5dd74022eb83f499642b0206d9f602be4d1e6f97b8474/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f6372656469742d7265736f757263652d62756e646c652e7376673f7374796c653d666c61742d737175617265)\] ()

Credit resource management bundle providing resource pricing and automatic billing functionality for Symfony applications. Supports flexible billing strategies with asynchronous bill processing via message queue.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
- [Advanced Usage](#advanced-usage)
- [Security](#security)
- [Contributing](#contributing)
- [License](#license)
- [Authors](#authors)
- [Changelog](#changelog)

Features
--------

[](#features)

- Resource pricing management with multiple billing strategies
- Automatic billing functionality with customizable rules
- Flexible billing cycles (hourly, daily, monthly, yearly)
- Tiered pricing support for complex billing scenarios
- Asynchronous bill processing via message queue
- Free quota and price ceiling/floor controls
- Integration with Symfony Messenger for scalable processing

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- Symfony &gt;= 7.3
- Doctrine ORM &gt;= 3.0

Installation
------------

[](#installation)

```
composer require tourze/credit-resource-bundle
```

Quick Start
-----------

[](#quick-start)

### 1. Register Bundle

[](#1-register-bundle)

Register the bundle in your Symfony application:

```
// config/bundles.php
return [
    // ...
    CreditResourceBundle\CreditResourceBundle::class => ['all' => true],
];
```

### 2. Configure Database

[](#2-configure-database)

Run database migrations to create the required table structures:

```
php bin/console doctrine:migrations:migrate
```

### 3. Create Resource Price Configuration

[](#3-create-resource-price-configuration)

```
use CreditResourceBundle\Entity\ResourcePrice;
use CreditResourceBundle\Enum\FeeCycle;

$resourcePrice = new ResourcePrice();
$resourcePrice->setTitle('VPN Usage');
$resourcePrice->setResource('App\Entity\VpnSession');
$resourcePrice->setCycle(FeeCycle::NEW_BY_HOUR);
$resourcePrice->setPrice('0.01');
$resourcePrice->setValid(true);

$entityManager->persist($resourcePrice);
$entityManager->flush();
```

### 4. Generate Bills

[](#4-generate-bills)

```
# Manual billing execution
php bin/console billing:create-resource-bill

# Or configure as cron job (runs at 1st minute of every hour)
# 1 * * * * php /path/to/project/bin/console billing:create-resource-bill
```

Configuration
-------------

[](#configuration)

### Billing Strategies

[](#billing-strategies)

The bundle supports multiple billing strategies:

#### Fixed Price Strategy

[](#fixed-price-strategy)

```
// Simple fixed price per unit
$resourcePrice->setBillingStrategy(null); // Uses default fixed strategy
$resourcePrice->setPrice('1.00'); // $1 per unit
```

#### Tiered Price Strategy

[](#tiered-price-strategy)

```
$resourcePrice->setBillingStrategy(TieredPriceStrategy::class);
$resourcePrice->setPriceRules([
    ['min' => 0, 'max' => 100, 'price' => '1.00'],     // First 100 units: $1 each
    ['min' => 100, 'max' => 1000, 'price' => '0.80'],  // Next 900 units: $0.80 each
    ['min' => 1000, 'max' => PHP_INT_MAX, 'price' => '0.50'] // 1000+: $0.50 each
]);
```

### Billing Cycles

[](#billing-cycles)

Configure different billing cycles based on your needs:

```
// Calculate new items added in the current hour
$resourcePrice->setCycle(FeeCycle::NEW_BY_HOUR);

// Calculate total items accumulated by end of day
$resourcePrice->setCycle(FeeCycle::TOTAL_BY_DAY);
```

### Price Controls

[](#price-controls)

```
// Set free quota (first 100 units free)
$resourcePrice->setFreeQuota(100);

// Set minimum charge (at least $5 even if usage is low)
$resourcePrice->setBottomPrice('5.00');

// Set maximum charge (never more than $100)
$resourcePrice->setTopPrice('100.00');
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Resource Usage Providers

[](#custom-resource-usage-providers)

Implement the `ResourceUsageProviderInterface` to define custom usage calculation:

```
use CreditResourceBundle\Interface\ResourceUsageProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;

class CustomUsageProvider implements ResourceUsageProviderInterface
{
    public function supports(string $resourceType): bool
    {
        return $resourceType === 'custom_resource';
    }

    public function getUsage(
        UserInterface $user,
        string $resourceType,
        \DateTimeInterface $start,
        \DateTimeInterface $end
    ): int {
        // Custom usage calculation logic
        return $this->calculateCustomUsage($user, $start, $end);
    }

    public function getUsageDetails(
        UserInterface $user,
        string $resourceType,
        \DateTimeInterface $start,
        \DateTimeInterface $end
    ): array {
        // Return detailed usage information
        return [];
    }

    public function getPriority(): int
    {
        return 0;
    }
}
```

### Custom Billing Strategies

[](#custom-billing-strategies)

Create custom billing strategies for complex pricing rules:

```
use CreditResourceBundle\Interface\BillingStrategyInterface;
use CreditResourceBundle\Entity\ResourcePrice;

class VolumeDiscountStrategy implements BillingStrategyInterface
{
    public function calculate(ResourcePrice $price, int $usage, array $context = []): string
    {
        $basePrice = bcmul($price->getPrice(), (string) $usage, 5);

        // Apply volume discount
        if ($usage > 1000) {
            $discount = bcmul($basePrice, '0.10', 5); // 10% discount
            return bcsub($basePrice, $discount, 5);
        }

        return $basePrice;
    }

    public function supports(ResourcePrice $price): bool
    {
        return true;
    }

    public function getName(): string
    {
        return 'volume_discount';
    }

    public function getDescription(): string
    {
        return 'Volume discount strategy with 10% discount for usage over 1000 units';
    }

    public function validateConfiguration(ResourcePrice $price): array
    {
        return [];
    }

    public function getPriority(): int
    {
        return 0;
    }
}
```

Security
--------

[](#security)

When using this bundle in production:

- Ensure proper access controls on admin interfaces
- Validate all pricing configurations before deployment
- Monitor billing logs for anomalies
- Use database transactions for critical billing operations
- Implement proper error handling and alerting

Contributing
------------

[](#contributing)

Issues and Pull Requests are welcome. Please ensure:

1. Code follows PSR-12 coding standards
2. All tests must pass (`./vendor/bin/phpunit`)
3. PHPStan analysis passes (`./vendor/bin/phpstan analyse`)
4. New features require corresponding tests
5. Update relevant documentation

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

Authors
-------

[](#authors)

- Tourze Team

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for version history.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance64

Regular maintenance activity

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

341d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-credit-resource-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-credit-resource-bundle/health.svg)](https://phpackages.com/packages/tourze-credit-resource-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M650](/packages/sylius-sylius)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
