|
2 | 2 |
|
3 | 3 | This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
4 | 4 |
|
5 | | -## Project Overview |
6 | | - |
7 | | -Laravel billing package for the Ratoufa project. Built on PHP 8.4+ with Laravel 11/12 support using Spatie's Laravel Package Tools. |
8 | | - |
9 | 5 | ## Commands |
10 | 6 |
|
11 | 7 | ```bash |
12 | | -# Run all tests and checks |
| 8 | +# Install dependencies |
| 9 | +composer install |
| 10 | + |
| 11 | +# Run all tests (lint, type coverage, typos, unit tests, static analysis, refactoring checks) |
13 | 12 | composer test |
14 | 13 |
|
15 | 14 | # Run specific test suites |
16 | | -composer test:unit # Pest tests (parallel) |
| 15 | +composer test:unit # Pest unit tests (parallel) |
17 | 16 | composer test:types # PHPStan static analysis |
18 | 17 | composer test:lint # Pint code style check |
19 | | -composer test:typos # Peck typo checker |
| 18 | +composer test:type-coverage # Type coverage (100% required) |
| 19 | +composer test:typos # Peck typo detection |
20 | 20 | composer test:refactor # Rector dry-run |
21 | | -composer test:type-coverage # Type coverage (requires 100%) |
22 | | -composer test:unit:coverage # Unit test coverage (requires 100%) |
23 | 21 |
|
24 | 22 | # Run a single test file |
25 | | -./vendor/bin/pest tests/ExampleTest.php |
| 23 | +./vendor/bin/pest tests/Unit/ExampleTest.php |
26 | 24 |
|
27 | 25 | # Run a single test by name |
28 | 26 | ./vendor/bin/pest --filter="test name here" |
29 | 27 |
|
30 | | -# Fix code style and run refactoring |
31 | | -composer fix # Runs PHPStan, Rector, then Pint |
32 | | -composer lint # Pint auto-fix |
33 | | -composer refactor # Rector auto-fix |
34 | | -composer analyse # PHPStan only |
| 28 | +# Fix code style and run fixes |
| 29 | +composer lint # Fix code style with Pint |
| 30 | +composer refactor # Apply Rector refactoring |
| 31 | +composer fix # PHPStan + Rector + Pint combined |
35 | 32 | ``` |
36 | 33 |
|
37 | 34 | ## Architecture |
38 | 35 |
|
39 | | -This is a Laravel package using Spatie's `laravel-package-tools` for service provider configuration: |
| 36 | +This is a Laravel billing package for West African markets with FedaPay integration supporting Mobile Money payments. |
| 37 | + |
| 38 | +### Core Components |
| 39 | + |
| 40 | +- **BillingManager** (`src/BillingManager.php`) - Extends Laravel's Manager class, provides the main facade for all billing operations. Manages provider drivers and exposes methods like `charge()`, `createPaymentIntent()`, `getCheckoutUrl()`. |
| 41 | + |
| 42 | +- **BillingProvider Contract** (`src/Contracts/BillingProvider.php`) - Interface that all payment providers must implement. Defines methods for customer management, charges, refunds, subscriptions, and webhooks. |
| 43 | + |
| 44 | +- **AbstractProvider** (`src/Providers/AbstractProvider.php`) - Base class for payment providers with shared logic. |
| 45 | + |
| 46 | +- **FedaPayProvider** (`src/Providers/FedaPay/`) - Default implementation for FedaPay with Mobile Money support (MTN, Moov, Togocel). |
| 47 | + |
| 48 | +### Traits for Eloquent Models |
| 49 | + |
| 50 | +- **Billable** (`src/Concerns/Billable.php`) - Add to User model for subscription and payment capabilities: `subscriptions()`, `payments()`, `charge()`, `pay()`, `newSubscription()`. |
| 51 | + |
| 52 | +- **Commissionable** (`src/Concerns/Commissionable.php`) - Add to seller/organization models for marketplace features: commission tracking, payouts, transaction recording. |
| 53 | + |
| 54 | +### Data Transfer Objects |
| 55 | + |
| 56 | +Located in `src/Data/`: `CommissionData`, `CustomerData`, `PayoutData`, `PaymentIntentData`, `CheckoutData`. |
| 57 | + |
| 58 | +### Services |
| 59 | + |
| 60 | +- **SubscriptionBuilderService** - Fluent builder for creating subscriptions with trials, metadata. |
| 61 | +- **CommissionCalculator** / **CommissionService** - Calculate and record marketplace commissions. |
| 62 | +- **InstantPayoutService** - Process seller payouts. |
| 63 | + |
| 64 | +### Models |
| 65 | + |
| 66 | +- `Plan` - Subscription plans with pricing, intervals. |
| 67 | +- `Subscription` - User subscriptions with status, trial dates, grace periods. |
| 68 | +- `Payment` - Payment records. |
| 69 | +- `Transaction` - Marketplace sale transactions. |
| 70 | +- `Payout` - Seller payout records. |
| 71 | + |
| 72 | +### Enums |
40 | 73 |
|
41 | | -- `src/BillingServiceProvider.php` - Package configuration (config, views, migrations, commands) |
42 | | -- `src/Billing.php` - Main service class |
43 | | -- `src/Facades/Billing.php` - Facade for the Billing service |
44 | | -- `src/Commands/` - Artisan commands |
45 | | -- `config/billing.php` - Package configuration |
46 | | -- `database/migrations/` - Migration stubs (published with `--tag="laravel-billing-migrations"`) |
| 74 | +Located in `src/Enums/`: `PaymentStatusEnum`, `SubscriptionStatusEnum`, `PlanIntervalEnum`, `PayoutStatusEnum`, `PayoutMethodEnum`, `TransactionStatusEnum`. |
47 | 75 |
|
48 | | -Tests use Orchestra Testbench with Pest. Base test case in `tests/TestCase.php` configures the package providers and factory resolution. |
| 76 | +## Code Style |
49 | 77 |
|
50 | | -## Code Style Requirements |
| 78 | +- PHP 8.4+ with strict types (`declare(strict_types=1)`) |
| 79 | +- All classes must be `final` (enforced by Pint) |
| 80 | +- PHPStan level 5 with 100% type coverage required |
| 81 | +- Laravel Pint with strict rules (see `pint.json`): `final_class`, `strict_comparison`, `date_time_immutable`, `mb_str_functions` |
| 82 | +- Class element ordering enforced: traits, constants, properties, constructor, magic methods, public methods, protected methods, private methods |
51 | 83 |
|
52 | | -Enforced via Pint (`pint.json`): |
53 | | -- `declare(strict_types=1)` required |
54 | | -- Classes should be `final` |
55 | | -- Use `DateTimeImmutable` over `DateTime` |
56 | | -- Use `mb_str_*` functions |
57 | | -- Strict comparisons (`===`, `!==`) |
58 | | -- Specific class element ordering (traits, constants, properties, constructor, then methods by visibility) |
| 84 | +## Adding a New Provider |
59 | 85 |
|
60 | | -Architecture tests (`tests/ArchTest.php`) forbid: `dd`, `dump`, `ray` |
| 86 | +1. Create provider class extending `AbstractProvider` in `src/Providers/` |
| 87 | +2. Implement all methods from `BillingProvider` contract |
| 88 | +3. Optionally implement `MobileMoneyProvider` or `PayoutProvider` contracts |
| 89 | +4. Register driver in `BillingManager::createXxxDriver()` or via `extend()` in a service provider |
0 commit comments