Download the PHP package smskin/laravel-billing without Composer
On this page you can find all versions of the php package smskin/laravel-billing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download smskin/laravel-billing
More information about smskin/laravel-billing
Files in smskin/laravel-billing
Package laravel-billing
Short Description Billing module for laravel projects
License MIT
Homepage https://github.com/smskin/laravel-billing
Informations about the package laravel-billing
Billing Module for Laravel Projects
Description
This module supports both synchronous and asynchronous interaction with billing.
Concept
Any object can participate in billing. To do this, simply implement the Billingable interface and include the BillingableTrait. The billing system doesn't care if it's an object in the database or just a class with statically declared properties.
Applications:
- Billingable objects as users (transferring funds from one user to another)
- Billingable objects as accounts in the accounting system (e.g., user's own and credit accounts)
- Billingable objects as part of a business process (e.g., Customer -> Task -> Performer)
Installation
This will create:
- a configuration file at
- a database migration file at
If necessary, you can change the table name for storing billing operations in the configuration file ().
Basic Usage
To start using billing, you need to create an object that implements the Billingable interface. For convenience, a Trait is prepared, which implements part of the interface methods - BillingableTrait.
Now you can create an instance of the User1 object and get its balance in the system:
Balance = sum of incoming operations - sum of outgoing operations
Module Features
- getBalances - bulk retrieval of balances for multiple entities (performed in a single database operation)
- increaseBalance - increase entity balance (synchronous)
- increaseBalanceAsync - increase entity balance (asynchronous)
- decreaseBalance - decrease entity balance (synchronous)
- decreaseBalanceAsync - decrease entity balance (asynchronous)
- transfer - transfer funds from one entity's balance to another entity's balance (synchronous)
- transferAsync - transfer funds from one entity's balance to another entity's balance (asynchronous)
- transferToMultipleRecipients - transfer funds from one entity's balance to multiple entities' balances (synchronous)
- transferToMultipleRecipientsAsync - transfer funds from one entity's balance to multiple entities' balances (asynchronous)
- createOperationsReport - report on billing operations
getBalances
Sometimes it's necessary to retrieve the balances of multiple entities simultaneously.
increaseBalance
This method is necessary to replenish the entity's balance from outside the system.
In synchronous execution, you may receive one of the Exceptions:
- NotUniqueOperationId - a non-unique operation ID was passed
- AmountMustBeMoreThan0 - the operation amount must be > 0
In asynchronous execution, one of the events will be sent to the EventBus:
- EBalanceIncreaseCompleted
- EBalanceIncreaseFailed
Both events will pass the input attributes, and the EBalanceIncreaseFailed event will pass an instance of Exception.
decreaseBalance
This method is necessary to withdraw funds from the entity's balance in the system.
In synchronous execution, you may receive one of the Exceptions:
- MutexException - error locking the sender entity of the payment (parallel operation)
- NotUniqueOperationId - a non-unique operation ID was passed
- AmountMustBeMoreThan0 - the operation amount must be > 0
- InsufficientBalance - insufficient funds on the balance
In asynchronous execution, a restart is provided after 5 seconds when MutexException is received.
In asynchronous execution, one of the events will be sent to the EventBus:
- EDecreaseBalanceCompleted
- EDecreaseBalanceFailed
Both events will pass the input attributes, and the EDecreaseBalanceFailed event will pass an instance of Exception.
transfer
This method is used to transfer funds from one entity's balance to another entity's balance.
In synchronous execution, you may receive one of the Exceptions:
- MutexException - error locking the sender entity of the payment (parallel operation)
- NotUniqueOperationId - a non-unique operation ID was passed
- AmountMustBeMoreThan0 - the operation amount must be > 0
- InsufficientBalance - insufficient funds on the balance
- RecipientIsSender - sender and recipient are the same entity
In asynchronous execution, a restart is provided after 5 seconds when MutexException is received.
In asynchronous execution, one of the events will be sent to the EventBus:
- ETransferCompleted
- ETransferFailed
Both events will pass the input attributes, and the ETransferFailed event will pass an instance of Exception.
transferToMultipleRecipients
This method is used to transfer funds to multiple recipient entities.
In synchronous execution, you may receive one of the Exceptions:
- MutexException - error locking the sender entity of the payment (parallel operation)
- NotUniqueOperationId - a non-unique operation ID was passed
- AmountMustBeMoreThan0 - the operation amount must be > 0
- InsufficientBalance - insufficient funds on the balance
- RecipientIsSender - sender and recipient are the same entity
In asynchronous execution, a restart is provided after 5 seconds when MutexException is received.
In asynchronous execution, one of the events will be sent to the EventBus:
- EBulkTransferCompleted
- EBulkTransferFailed
Both events will pass the input attributes, and the EBulkTransferFailed event will pass an instance of Exception.
createOperationsReport
Method for generating a balance report. Under development.
All versions of laravel-billing with dependencies
laravel/framework Version ^8 || ^9 || ^10 || ^11 || ^12
smskin/laravel-support Version ^3.0