Download the PHP package banulakwin/laravel-pricing without Composer
On this page you can find all versions of the php package banulakwin/laravel-pricing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download banulakwin/laravel-pricing
More information about banulakwin/laravel-pricing
Files in banulakwin/laravel-pricing
Package laravel-pricing
Short Description Rule-based Laravel pricing engine with configurable coupon, tax, and shipping rules.
License MIT
Homepage https://github.com/banulalakwindu/laravel-pricing
Informations about the package laravel-pricing
Laravel Pricing (banulakwin/laravel-pricing)
Portable Laravel package: a small rule-based pricing engine with config toggles, injectable coupon validation, and defaults for coupon (percent), tax, and flat shipping.
Requirements
- PHP
^8.2 - Laravel
^11.0|^12.0|^13.0
Installation
Registration is automatic via Composer extra.laravel.providers:
Banulakwin\Pricing\PricingServiceProvider
Optional facade alias: Pricing → Banulakwin\Pricing\Facades\Pricing.
Publish configuration (optional):
Publish migrations (optional):
Configuration
| Config key | Purpose |
|---|---|
pricing.rules |
Booleans: coupon, tax, shipping (your app branches when building the engine). |
pricing.user_model |
Class string for the user model, used for coupon user restrictions and first-time validation. |
pricing.user_orders_relation |
Method name on the user model (e.g., orders) to verify first_time_only coupon eligibility. |
pricing.user_orders_scope |
Optional scope name (e.g., captured) applied to the orders query. Set to null to use the relation as-is. |
pricing.tax.rate |
Default tax rate for TaxRule (overridable in constructor). |
pricing.shipping.flat |
Default flat shipping for ShippingRule (overridable in constructor). |
pricing.auto_rules |
Optional list of rule class names to resolve with app($class) and attach to the engine. |
Environment: PRICING_TAX_RATE, PRICING_SHIPPING_FLAT (see config/pricing.php).
Usage
Basic Pricing
Line Item Format
Conditional Rule Registration
Architecture
Engine Flow
calculate()buildsPriceContext, setssubtotal/ initialtotalfrom line items (price×qty).- Each registered rule mutates
discount,tax,shipping, andtotalin order.
Rule order matters — compose rules explicitly in your app.
Contracts
Banulakwin\Pricing\Contracts\PriceRule—apply(PriceContext $context): voidBanulakwin\Pricing\Contracts\RuleValidator—validate(PriceContext $context, array $data): bool(optional forCouponRule)
Coupon Types
Global Coupon
Applies to all items in the cart (empty items relation).
Targeted Coupon
Applies only to specific items via coupon_items pivot table.
User-Restricted Coupon
Only redeemable by specific users via coupon_users pivot table.
First-Time Only Coupon
Validates that the user has no prior orders via the configured user_orders_relation. Guest users are allowed through during preview — server-side checkout re-validates once authenticated.
Once Per User Coupon
Prevents a user from redeeming the same coupon code more than once. Checks past orders for the coupon code via the configured user_orders_relation. Guest users are allowed through during preview — server-side checkout re-validates once authenticated.
Configurable Order Scope
When validating first_time_only or once_per_user, an optional scope can be applied to the orders query via pricing.user_orders_scope (e.g., captured to only count paid orders). Leave it null to use the relation as-is, or define your relation to return only the orders you want counted.
Testing
Changelog
See CHANGELOG.md for details.
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/your-feature) - Run
composer qualityto ensure tests and style pass - Commit and push
- Open a pull request
Package layout (reference)
License
MIT — see LICENSE for details.
All versions of laravel-pricing with dependencies
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0