Download the PHP package derrickob/pricer without Composer
On this page you can find all versions of the php package derrickob/pricer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download derrickob/pricer
More information about derrickob/pricer
Files in derrickob/pricer
Package pricer
Short Description A PHP pricing calculator that does one thing perfectly: calculate prices with taxes, discounts, fees, and credits in the correct order.
License MIT
Homepage https://github.com/derrickobedgiu1/pricer
Informations about the package pricer
Pricer
A PHP pricing calculator that does one thing perfectly: calculate prices with taxes, discounts, fees, and credits in the correct order.
The Problem
You're building a store, SaaS, subscription service, or any app that charges money. You need to:
- Calculate totals with taxes and discounts in the right order
- Handle gift cards and credits before or after tax
- Charge subscription fees with proration when customers sign up mid-month
- Add processing fees or shipping costs without floating-point errors
- Know exactly how you arrived at the final price
- Keep your code that handles pricing calculations simple and readable
Pricer solves all this. It's a calculation engine that handles money correctly, applies components in the right order, and gives you a detailed breakdown of every step.
Installation
Requirements: PHP 8.1+, ext-bcmath, ext-intl
Laravel users: Run php artisan pricer:install after installation to publish the configuration.
Quick Start
That's it. Now let's see what Pricer can do for your business.
Table of Contents
- Real-World Use Cases
- E-commerce Checkout
- Restaurant Bills with Tips
- SaaS Subscription Billing
- Payment Processing Fees
- Gift Cards & Store Credit
- Bulk/Wholesale Pricing
- Multiple Tax Jurisdictions
- Tax Calculation Modes
- Core Concepts
- Complete API Reference
- Laravel Integration
- Advanced Features
Real-World Use Cases
1. E-commerce Checkout
Your Scenario: Customer buys a $150 item, applies a 10% discount code, adds shipping, pays sales tax, and you pass Stripe fees to them.
Why the order matters: Discount is applied first (reduces taxable amount), then shipping is added (shipping is taxable in most states), then tax is calculated on the new subtotal, and finally fees are added.
Get a detailed breakdown:
Output:
2. Restaurant Bills with Tips
Your Scenario: Dinner costs $85.50, customer pays 8% sales tax, and wants to tip 20% on the pre-tax amount (not the tax).
Alternative: Tip on post-tax amount (some customers prefer this):
Use Case: Point-of-sale systems, restaurant billing, delivery apps.
3. SaaS Subscription Billing
Your Scenario: Customer signs up for a $30/month plan on January 15th. You only charge them for the remaining 17 days until February 1st (fair billing).
First month prorated + next month regular:
Use Case: SaaS platforms, membership sites, recurring billing services.
Supported Billing Cycles:
BillingCycle::DAILYBillingCycle::WEEKLYBillingCycle::BI_WEEKLYBillingCycle::MONTHLYBillingCycle::QUARTERLYBillingCycle::SEMI_ANNUALLYBillingCycle::YEARLY
4. Payment Processing Fees
Your Scenario: You use Stripe (2.9% + $0.30 per transaction) and want to pass fees to customers.
Use Case: E-commerce platforms, marketplaces, donation platforms.
5. Gift Cards & Store Credit
Your Scenario: $150 order, customer has a $50 gift card. Should it apply before or after tax?
Option A: Credit AFTER tax (most common)
Option B: Credit BEFORE tax (less common)
Why this matters: Tax laws vary by jurisdiction. Some require tax on the full amount before credits, others allow credits to reduce the taxable amount. Pricer gives you control.
Use Case: Retail stores, e-commerce platforms, loyalty programs.
6. Bulk/Wholesale Pricing
Your Scenario: The more units a customer buys, the cheaper each unit becomes.
Fixed-amount tiers (e.g., $5 off per unit):
Use Case: Wholesale distributors, B2B platforms, quantity-based pricing.
7. Multiple Tax Jurisdictions
Your Scenario: Customer is in a location with state + city + county taxes (all stack).
Use Case: US sales tax, Canadian GST/PST, VAT in multiple countries.
8. Tax Calculation Modes: Non-Compounding vs Compounding
Your Scenario: Different jurisdictions calculate taxes differently. Some taxes are non-compounding (all calculate on the subtotal), while others are compounding (each tax includes previous taxes in its base).
Non-Compounding Taxes (Default)
Most jurisdictions use this: all taxes calculate on the same subtotal.
Compounding Taxes (Quebec, Some Jurisdictions)
Some jurisdictions apply tax on top of previous taxes.
Mixing Tax Modes
You can mix both modes in a single calculation:
Use Case: Multi-jurisdiction tax compliance, Canadian provinces, luxury/environmental taxes.
Core Concepts
1. Amount Types
Every component (discount, tax, fee, etc.) can be percentage-based or fixed amount:
Examples:
2. Component Priorities (Order of Calculation)
Components are applied in priority order (lower number = applied first):
| Component | Default Priority | Why This Order |
|---|---|---|
| Subscription | 1 | Adds base recurring amount first |
| Discount | 10 | Early (reduces taxable amount) |
| TieredPricing | 12 | Bulk discounts after regular discounts |
| Credit (BEFORE_TAX) | 15 | If credits reduce taxable amount |
| Shipping | 20 | Added before tax (shipping is often taxable) |
| Tax | 30 | Calculated on subtotal after discounts |
| Fee | 40 | Added after tax (e.g., credit card fees) |
| Credit (AFTER_TAX) | 50 | Most common - credits applied to final amount |
| Tip | 60 | Gratuity added last |
Why this matters: Order affects the final price.
Example:
Custom Priorities:
You can override priorities if needed:
3. Precision & Rounding
Pricer uses BCMath for all calculations (no floating-point errors):
Configuration:
Why this matters: Floating-point math in PHP gives you $100.00000000001. BCMath gives you exact $100.00.
4. Money Object
Pricer includes an immutable Money value object for safe calculations:
Complete API Reference
Starting a Calculation
PriceBuilder Methods
All methods return $this for chaining (except calculate()).
Discounts
Taxes
Fees
Shipping
Subscriptions
Credits & Gift Cards
Tips
Bulk/Tiered Pricing
Conditional Logic
Calculate & Retrieve Results
Laravel Integration
1. Installation
This publishes the configuration file to config/pricer.php.
2. Configuration
3. Facade
4. Helper Functions
5. Blade Directives
Advanced Features
1. Conditional Pricing Patterns
Free shipping over threshold:
VIP customer logic:
2. Multi-Currency Support
3. Validation
Pricer includes comprehensive validation:
4. Common Patterns
Invoice Generation
Subscription Billing
Error Handling
Pricer validates inputs and throws descriptive exceptions:
Testing Your Code
Roadmap & Feature Status
Out of Scope
These features are intentionally excluded to keep Pricer focused:
- Subscription State Management - Use Laravel Cashier, Stripe Billing, or similar
- Customer Management - Use your own customer database
- Payment Processing - Use Stripe, PayPal, etc.
- Recurring Billing Automation - Use scheduling systems
- Invoice Storage - Use your database or invoicing system
- Email Notifications - Use your notification system
- Dunning Management - Use payment gateway features
- Upgrade/Downgrade Logic - Application-level business logic
Why? Pricer is a pricing calculator, not a billing platform. It calculates what to charge, your app handles when, how, and to whom.
License
MIT License. See LICENSE for details.
Support
- Issues: GitHub Issues
- Email: [email protected]
Stop worrying about pricing logic. Use Pricer.
All versions of pricer with dependencies
ext-intl Version *
ext-bcmath Version *