Skip to content

Commit ae583dc

Browse files
author
Just Chris
committed
feat: implement billing package with FedaPay and Mobile Money support
Complete billing system for West African markets including subscriptions, one-time payments, marketplace commissions, and seller payouts.
1 parent 9873a69 commit ae583dc

File tree

81 files changed

+8022
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+8022
-78
lines changed

CLAUDE.md

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,88 @@
22

33
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44

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-
95
## Commands
106

117
```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)
1312
composer test
1413

1514
# Run specific test suites
16-
composer test:unit # Pest tests (parallel)
15+
composer test:unit # Pest unit tests (parallel)
1716
composer test:types # PHPStan static analysis
1817
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
2020
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%)
2321

2422
# Run a single test file
25-
./vendor/bin/pest tests/ExampleTest.php
23+
./vendor/bin/pest tests/Unit/ExampleTest.php
2624

2725
# Run a single test by name
2826
./vendor/bin/pest --filter="test name here"
2927

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
3532
```
3633

3734
## Architecture
3835

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
4073

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`.
4775

48-
Tests use Orchestra Testbench with Pest. Base test case in `tests/TestCase.php` configures the package providers and factory resolution.
76+
## Code Style
4977

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
5183

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
5985

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

Comments
 (0)