Installation:
composer require tomatophp/filament-payments
Publish the package assets and config:
php artisan vendor:publish --provider="TomatoPHP\FilamentPayments\FilamentPaymentsServiceProvider" --tag="filament-payments-config"
php artisan vendor:publish --provider="TomatoPHP\FilamentPayments\FilamentPaymentsServiceProvider" --tag="filament-payments-migrations"
Run migrations:
php artisan migrate
Register the plugin in app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\TomatoPHP\FilamentPayments\FilamentPaymentsPlugin::make(),
]);
}
First Use Case:
Gateway Configuration:
config/filament-payments.php or via the Payment Gates admin panel.'gates' => [
'stripe' => [
'driver' => 'stripe',
'key' => env('STRIPE_KEY'),
'secret' => env('STRIPE_SECRET'),
'currency' => 'usd',
],
],
TomatoPHP\FilamentPayments\Gateways\Gateway facade to dynamically fetch gateways:
$gateway = \TomatoPHP\FilamentPayments\Facades\Gateway::find('stripe');
Creating Payments:
use TomatoPHP\FilamentPayments\Actions\CreatePaymentAction;
public static function getActions(): array
{
return [
CreatePaymentAction::make()
->gateway('stripe')
->amount(9.99)
->name('Upgrade to Pro'),
];
}
$payment = \TomatoPHP\FilamentPayments\Facades\Payment::create([
'gateway_id' => 1,
'amount' => 9.99,
'currency' => 'usd',
'metadata' => ['user_id' => auth()->id()],
]);
Webhook Handling:
use TomatoPHP\FilamentPayments\Webhooks\StripeWebhookController;
Route::post('/filament-payments/webhooks/stripe', [StripeWebhookController::class, 'handle']);
app/Http/Controllers/WebhookController.php:
public function handle(Request $request)
{
return \TomatoPHP\FilamentPayments\Facades\Webhook::handle($request);
}
Subscription Management:
TomatoPHP\FilamentPayments\Subscriptions\Subscription model to manage recurring payments:
$subscription = \TomatoPHP\FilamentPayments\Facades\Subscription::create([
'gateway_id' => 1,
'user_id' => auth()->id(),
'plan' => 'premium',
]);
Custom Fields: Extend the Payment model to add custom fields (e.g., invoice_number):
use TomatoPHP\FilamentPayments\Models\Payment;
class CustomPayment extends Payment
{
protected $casts = [
'invoice_number' => 'string',
];
}
Update the config to use your custom model:
'models' => [
'payment' => \App\Models\CustomPayment::class,
],
Localization: Override labels and messages in resources/lang/en/payments.php:
return [
'actions' => [
'create_payment' => 'Make Payment',
],
];
Testing: Use test modes for gateways (e.g., Stripe test keys) and mock webhooks:
$gateway = \TomatoPHP\FilamentPayments\Facades\Gateway::find('stripe-test');
Webhook Verification:
Webhook::handle() method with the verify option:
\TomatoPHP\FilamentPayments\Facades\Webhook::handle($request, verify: true);
STRIPE_WEBHOOK_SECRET is set in .env.Gateway-Specific Quirks:
sandbox: true in config).STRIPE_KEY and STRIPE_SECRET are correctly set. For subscriptions, use TomatoPHP\FilamentPayments\Subscriptions\Subscription methods like create() or cancel().TomatoPHP\FilamentPayments\Contracts\Gateway interface for third-party integrations.Migration Conflicts:
Payment or Gateway tables, run php artisan vendor:publish --tag="filament-payments-migrations" again to update the published migrations.Permission Issues:
view payments, create payments, or manage gates permissions in Filament. Add roles via:
public static function getPages(): array
{
return [
\TomatoPHP\FilamentPayments\Resources\PaymentResource::class,
\TomatoPHP\FilamentPayments\Resources\GatewayResource::class,
];
}
Logs: Enable debug mode in config/filament-payments.php:
'debug' => env('APP_DEBUG', false),
Check logs in storage/logs/laravel.log for gateway errors.
Webhook Testing: Use tools like Stripe CLI or Ngrok to test webhooks locally:
stripe listen --forward-to localhost:8000/filament-payments/webhooks/stripe
Custom Actions:
Extend CreatePaymentAction to add pre/post-payment logic:
use TomatoPHP\FilamentPayments\Actions\Concerns\InteractsWithPayments;
class CustomPaymentAction extends CreatePaymentAction
{
use InteractsWithPayments;
protected function afterPaymentCreated(Payment $payment)
{
// Send email, update user role, etc.
}
}
Gateway Drivers:
Create custom drivers by implementing the Gateway contract:
namespace App\Gateways;
use TomatoPHP\FilamentPayments\Contracts\Gateway;
class CustomGateway implements Gateway
{
public function createPayment(array $data): array
{
// Custom logic
}
// Implement other required methods
}
Register the driver in the config:
'gateways' => [
'custom' => [
'driver' => \App\Gateways\CustomGateway::class,
],
],
Resource Customization:
Override the default resources by binding them in AppServiceProvider:
public function boot()
{
$this->app->bind(
\TomatoPHP\FilamentPayments\Resources\PaymentResource::class,
\App\Resources\CustomPaymentResource::class
);
}
How can I help you explore Laravel packages today?