feat: implement comprehensive multi-provider payment processing system
- Add unified payment provider architecture with contract-based design - Implement 6 payment providers: Stripe, Lemon Squeezy, Polar, Oxapay, Crypto, Activation Keys - Create subscription management with lifecycle handling (create, cancel, pause, resume, update) - Add coupon system with usage tracking and trial extensions - Build Filament admin resources for payment providers, subscriptions, coupons, and trials - Implement payment orchestration service with provider registry and configuration management - Add comprehensive payment logging and webhook handling for all providers - Create customer analytics dashboard with revenue, churn, and lifetime value metrics - Add subscription migration service for provider switching - Include extensive test coverage for all payment functionality
This commit is contained in:
107
database/factories/CouponFactory.php
Normal file
107
database/factories/CouponFactory.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Coupon>
|
||||
*/
|
||||
class CouponFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$type = fake()->randomElement(['percentage', 'fixed']);
|
||||
$value = $type === 'percentage'
|
||||
? fake()->numberBetween(5, 50)
|
||||
: fake()->randomFloat(2, 5, 100);
|
||||
|
||||
return [
|
||||
'code' => strtoupper(fake()->lexify('??????')),
|
||||
'name' => fake()->words(3, true),
|
||||
'description' => fake()->sentence(),
|
||||
'type' => $type,
|
||||
'value' => $value,
|
||||
'minimum_amount' => fake()->optional(0.7)->randomFloat(2, 10, 500),
|
||||
'max_uses' => fake()->optional(0.6)->numberBetween(10, 1000),
|
||||
'uses_count' => 0,
|
||||
'max_uses_per_user' => fake()->optional(0.5)->numberBetween(1, 5),
|
||||
'starts_at' => fake()->optional(0.3)->dateTimeBetween('-1 week', 'now'),
|
||||
'expires_at' => fake()->optional(0.8)->dateTimeBetween('now', '+6 months'),
|
||||
'is_active' => true,
|
||||
'metadata' => fake()->optional(0.2)->randomElements([
|
||||
'created_by_admin' => fake()->boolean(),
|
||||
'campaign' => fake()->word(),
|
||||
'region' => fake()->countryCode(),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a percentage-based coupon
|
||||
*/
|
||||
public function percentage(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'type' => 'percentage',
|
||||
'value' => fake()->numberBetween(5, 50),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fixed amount coupon
|
||||
*/
|
||||
public function fixed(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'type' => 'fixed',
|
||||
'value' => fake()->randomFloat(2, 5, 100),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an expired coupon
|
||||
*/
|
||||
public function expired(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'expires_at' => fake()->dateTimeBetween('-1 month', '-1 day'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inactive coupon
|
||||
*/
|
||||
public function inactive(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_active' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a coupon with usage limits
|
||||
*/
|
||||
public function withUsageLimit(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'max_uses' => fake()->numberBetween(10, 100),
|
||||
'max_uses_per_user' => fake()->numberBetween(1, 3),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a coupon with minimum amount requirement
|
||||
*/
|
||||
public function withMinimumAmount(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'minimum_amount' => fake()->randomFloat(2, 25, 200),
|
||||
]);
|
||||
}
|
||||
}
|
||||
32
database/factories/CouponUsageFactory.php
Normal file
32
database/factories/CouponUsageFactory.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\CouponUsage>
|
||||
*/
|
||||
class CouponUsageFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'coupon_id' => Coupon::factory(),
|
||||
'user_id' => \App\Models\User::factory(),
|
||||
'subscription_id' => \App\Models\Subscription::factory(),
|
||||
'discount_amount' => fake()->randomFloat(2, 5, 50),
|
||||
'currency' => 'USD',
|
||||
'used_at' => fake()->dateTimeBetween('-3 months', 'now'),
|
||||
'metadata' => fake()->optional(0.2)->randomElements([
|
||||
'ip_address' => fake()->ipv4(),
|
||||
'user_agent' => fake()->userAgent(),
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
23
database/factories/PaymentProviderFactory.php
Normal file
23
database/factories/PaymentProviderFactory.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PaymentProvider>
|
||||
*/
|
||||
class PaymentProviderFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
53
database/factories/SubscriptionChangeFactory.php
Normal file
53
database/factories/SubscriptionChangeFactory.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SubscriptionChange>
|
||||
*/
|
||||
class SubscriptionChangeFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$changeType = fake()->randomElement([
|
||||
'plan_change', 'cancellation', 'pause', 'resume', 'migration', 'provider_change',
|
||||
]);
|
||||
|
||||
return [
|
||||
'subscription_id' => \App\Models\Subscription::factory(),
|
||||
'user_id' => \App\Models\User::factory(),
|
||||
'change_type' => $changeType,
|
||||
'change_description' => fake()->sentence(),
|
||||
'old_values' => fake()->optional(0.7)->randomElement([
|
||||
['plan_id' => fake()->numberBetween(1, 5), 'price' => fake()->randomFloat(2, 10, 100)],
|
||||
['status' => 'active', 'provider' => 'stripe'],
|
||||
]),
|
||||
'new_values' => fake()->optional(0.7)->randomElement([
|
||||
['plan_id' => fake()->numberBetween(1, 5), 'price' => fake()->randomFloat(2, 10, 100)],
|
||||
['status' => 'cancelled', 'provider' => 'lemon_squeezy'],
|
||||
]),
|
||||
'reason' => fake()->optional(0.6)->randomElement([
|
||||
'Customer request',
|
||||
'Payment failure',
|
||||
'Plan upgrade',
|
||||
'Service downgrade',
|
||||
'Technical migration',
|
||||
]),
|
||||
'effective_at' => fake()->dateTimeBetween('-1 month', 'now'),
|
||||
'processed_at' => fake()->optional(0.8)->dateTimeBetween('-1 month', 'now'),
|
||||
'is_processed' => fake()->boolean(80),
|
||||
'metadata' => fake()->optional(0.2)->randomElements([
|
||||
'processed_by' => fake()->name(),
|
||||
'system_generated' => fake()->boolean(),
|
||||
'batch_id' => fake()->uuid(),
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
45
database/factories/TrialExtensionFactory.php
Normal file
45
database/factories/TrialExtensionFactory.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\TrialExtension>
|
||||
*/
|
||||
class TrialExtensionFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$originalEnd = fake()->dateTimeBetween('now', '+14 days');
|
||||
$extensionDays = fake()->numberBetween(1, 30);
|
||||
$newEnd = (new \DateTime($originalEnd->format('Y-m-d')))->modify("+{$extensionDays} days");
|
||||
|
||||
return [
|
||||
'subscription_id' => \App\Models\Subscription::factory(),
|
||||
'user_id' => \App\Models\User::factory(),
|
||||
'extension_days' => $extensionDays,
|
||||
'reason' => fake()->optional(0.7)->randomElement([
|
||||
'Customer request',
|
||||
'Technical issues',
|
||||
'Service outage compensation',
|
||||
'Goodwill gesture',
|
||||
'Payment processing delay',
|
||||
]),
|
||||
'extension_type' => fake()->randomElement(['manual', 'automatic', 'compensation']),
|
||||
'original_trial_ends_at' => $originalEnd,
|
||||
'new_trial_ends_at' => $newEnd,
|
||||
'granted_at' => fake()->dateTimeBetween('-1 week', 'now'),
|
||||
'granted_by_admin_id' => \App\Models\User::factory(),
|
||||
'metadata' => fake()->optional(0.2)->randomElements([
|
||||
'notes' => fake()->sentence(),
|
||||
'approval_ticket' => fake()->numerify('TCK-#####'),
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user