Files
zemailnator/app/Filament/Resources/PaymentProviders/Schemas/PaymentProviderForm.php
idevakk d767c6cf59 feat(plans): enhance plan management with dynamic providers, improved UI, and bug fixes
Dynamic Provider Integration:
  - Replace hardcoded provider arrays with database-driven payment_providers lookup
  - Display provider status (Active/Inactive) in selection dropdowns
  - Add provider_variant_id and provider_product_id input fields to plan configuration
  - Update EditPlan and SubscriptionForm with dynamic provider selection
  - Add empty state handling with helpful guidance when no providers exist

  UI/UX Improvements:
  - Format billing_cycle_days to readable text (Daily, Weekly, Monthly, Quarterly, Annually)
  - Add color-coded badges for billing cycle frequency
  - Fix plan_providers and plan_feature_limits count display with eager loading
  - Implement intelligent color coding for count indicators
  - Add visual status indicators for provider availability

  Database Compatibility:
  - Fix SQLite strftime() compatibility across all dashboard widgets
  - Fix CAST AS REAL syntax in ChurnAnalysis widget
  - Add database-agnostic date and cast expression methods
  - Support MySQL, SQLite, PostgreSQL, and SQL Server

  Bug Fixes:
  - Fix null reference error in SubscriptionForm provider_data access
  - Add null safety checks for new subscription creation
  - Optimize queries with withCount() to prevent N+1 issues

  Performance Optimizations:
  - Add eager loading with withCount() for relationship counts
  - Optimize plan provider and feature limit queries
  - Prevent N+1 query issues in resource tables

  BREAKING CHANGE: Plan provider configuration now uses dynamic provider options
  from payment_providers table instead of hardcoded list.
2025-12-02 09:47:51 -08:00

107 lines
4.5 KiB
PHP

<?php
namespace App\Filament\Resources\PaymentProviders\Schemas;
use Filament\Forms\Components\KeyValue;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
class PaymentProviderForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Section::make('Basic Information')
->schema([
Grid::make(2)
->schema([
TextInput::make('name')
->label('Provider Name')
->required()
->unique(ignoreRecord: true)
->helperText('Internal identifier for the provider'),
TextInput::make('display_name')
->label('Display Name')
->required()
->helperText('Name shown to users'),
]),
Textarea::make('description')
->label('Description')
->rows(3)
->helperText('Brief description of the payment provider')
->columnSpanFull(),
]),
Section::make('Capabilities')
->schema([
Grid::make(3)
->schema([
Toggle::make('is_active')
->label('Active')
->default(true)
->helperText('Enable this provider for use'),
Toggle::make('supports_recurring')
->label('Supports Recurring')
->default(false)
->helperText('Can handle subscription payments'),
Toggle::make('supports_one_time')
->label('Supports One-Time')
->default(true)
->helperText('Can handle single payments'),
]),
Grid::make(2)
->schema([
TextInput::make('priority')
->label('Priority')
->numeric()
->default(0)
->helperText('Higher priority = shown first'),
Toggle::make('is_fallback')
->label('Fallback Provider')
->default(false)
->helperText('Default provider when others fail'),
]),
]),
Section::make('Configuration')
->schema([
KeyValue::make('configuration')
->label('Provider Configuration')
->addActionLabel('Add configuration')
->keyLabel('Key')
->valueLabel('Value')
->helperText('API keys and other provider-specific settings')
->columnSpanFull(),
KeyValue::make('supported_currencies')
->label('Supported Currencies')
->addActionLabel('Add currency')
->keyLabel('Currency Code')
->valueLabel('Display Name')
->default(['USD' => 'US Dollar'])
->helperText('Currencies this provider supports')
->columnSpanFull(),
KeyValue::make('fee_structure')
->label('Fee Structure')
->addActionLabel('Add fee setting')
->keyLabel('Fee Type')
->valueLabel('Value')
->helperText('Example: fixed_fee, percentage_fee')
->columnSpanFull(),
]),
]);
}
}