Skip to content

PayPal Configuration

This guide will help you correctly configure PayPal integration in the Filament Tenancy package.

  1. Prerequisites
  2. Initial Configuration
  3. Migrations
  4. Configuration from Filament
  5. Webhook Configuration in PayPal
  6. Environment Variables
  7. Service Usage
  8. Supported Events and Webhooks
  9. Troubleshooting
  10. Usage Examples

Before starting, make sure you have:

  • A PayPal Business account (not personal)
  • Access to the PayPal Developer Dashboard
  • Laravel with the filament-tenancy package installed
  • Database configured and migrations executed

  1. Go to PayPal Developer Dashboard
  2. Sign in with your PayPal Business account
  3. Navigate to My Apps & Credentials
  4. Click Create App
  5. Complete the form:
    • App Name: Your application name (e.g., “My Application”)
    • Merchant: Select your business account
    • Features: Select the features you need
  6. Click Create App

After creating the application, you’ll see two sets of credentials:

  • Sandbox Credentials: For testing
  • Live Credentials: For production

Each set includes:

  • Client ID: Public identifier for your application
  • Client Secret: Secret key (keep it secure)

The necessary migrations are already included in the package. Run migrations if you haven’t already:

Terminal window
php artisan migrate

The relevant migrations for PayPal are:

  • 2024_01_01_000017_create_paypal_settings_table.php - Creates PayPal configuration table
  • 2024_01_01_000015_add_paypal_fields_to_subscriptions_table.php - Adds PayPal fields to subscriptions

  1. Access the Filament administration panel (Landlord Panel)
  2. In the sidebar menu, look for PayPal Settings in the Administration group
  3. Click to open the configuration page
  • Activate the Is Enabled toggle to enable PayPal
  • Once activated, other fields will be displayed

Mode:

  • Sandbox: For testing and development
  • Live: For production

Client ID:

  • Enter the Client ID obtained from PayPal Developer Dashboard
  • For testing, use Sandbox Client ID
  • For production, use Live Client ID

Client Secret:

  • Enter the corresponding Client Secret
  • This field is hidden for security (password type)

Currency:

  • ISO 4217 currency code (e.g., USD, EUR, MXN)
  • Default: USD

Webhook Secret:

  • Obtained after configuring the webhook in PayPal (see next section)
  • Used to verify authenticity of PayPal notifications

Return URL:

  • URL where PayPal redirects after successful payment
  • Default: /paypal/success
  • You can customize it according to your needs

Cancel URL:

  • URL where PayPal redirects if user cancels payment
  • Default: /paypal/cancel
  • You can customize it according to your needs

Although configuration is mainly done from Filament, you can also use environment variables as backup:

# PayPal Configuration
PAYPAL_MODE=sandbox
PAYPAL_CLIENT_ID=your_client_id_here
PAYPAL_CLIENT_SECRET=your_client_secret_here
PAYPAL_CURRENCY=USD
PAYPAL_WEBHOOK_SECRET=your_webhook_secret_here
PAYPAL_RETURN_URL=/paypal/success
PAYPAL_CANCEL_URL=/paypal/cancel

Note: Configuration from Filament takes priority over environment variables. Environment variables are only used if PayPal is not enabled in the database or if there’s an error loading the configuration.


use AngelitoSystems\FilamentTenancy\Support\PayPalService;
use AngelitoSystems\FilamentTenancy\Models\Subscription;
$paypalService = app(PayPalService::class);
$subscription = Subscription::find(1);
// Create one-time payment order
$order = $paypalService->createOrder($subscription);
if ($order) {
// Get approval URL
$approveUrl = collect($order['links'])->firstWhere('rel', 'approve')['href'];
// Redirect user to PayPal
return redirect($approveUrl);
}
use AngelitoSystems\FilamentTenancy\Support\PayPalService;
use AngelitoSystems\FilamentTenancy\Models\Subscription;
$paypalService = app(PayPalService::class);
$subscription = Subscription::find(1);
// Create recurring subscription in PayPal
$paypalSubscription = $paypalService->createSubscription($subscription);
if ($paypalSubscription) {
// Get approval URL
$approveUrl = collect($paypalSubscription['links'])->firstWhere('rel', 'approve')['href'];
// Redirect user to PayPal
return redirect($approveUrl);
}

The system automatically handles the following PayPal events:

  • PAYMENT.CAPTURE.COMPLETED:

    • Activates subscription
    • Creates invoice
    • Calculates commissions if there’s an associated seller
  • PAYMENT.CAPTURE.DENIED:

    • Marks subscription as pending
    • Records failure reason
  • PAYMENT.CAPTURE.REFUNDED:

    • Marks subscription as pending
    • Records refund
  • BILLING.SUBSCRIPTION.CREATED:

    • Records subscription creation in PayPal
  • BILLING.SUBSCRIPTION.ACTIVATED:

    • Activates subscription in system
    • Creates initial invoice
    • Calculates commissions
  • BILLING.SUBSCRIPTION.CANCELLED:

    • Cancels subscription in system
    • Records cancellation reason
  • BILLING.SUBSCRIPTION.EXPIRED:

    • Marks subscription as expired
  • BILLING.SUBSCRIPTION.PAYMENT.FAILED:

    • Marks subscription as pending
    • Records payment failure
  • BILLING.SUBSCRIPTION.UPDATED:

    • Updates subscription status

Error: “PayPal: Service is not enabled”

Section titled “Error: “PayPal: Service is not enabled””

Cause: PayPal is not enabled in configuration.

Solution:

  1. Go to Filament > PayPal Settings
  2. Activate the “Is Enabled” toggle
  3. Save changes

Error: “PayPal: Failed to get access token”

Section titled “Error: “PayPal: Failed to get access token””

Cause: Incorrect credentials or connection issues.

Solutions:

  1. Verify that Client ID and Client Secret are correct
  2. Make sure you’re using the correct credentials (Sandbox vs Live)
  3. Check your internet connection
  4. Use the “Test Connection” button in Filament to diagnose

Error: “PayPal: Webhook signature verification failed”

Section titled “Error: “PayPal: Webhook signature verification failed””

Cause: Webhook Secret is not configured correctly.

Solutions:

  1. Verify that Webhook Secret in Filament matches PayPal Webhook ID
  2. Make sure webhook is configured in PayPal Dashboard
  3. Verify that webhook URL is publicly accessible

  1. Never expose your credentials:

    • Don’t include them in source code
    • Use environment variables or Filament configuration
  2. Use HTTPS in production:

    • PayPal requires HTTPS for webhooks in production
    • Make sure you have a valid SSL certificate
  3. Verify webhooks:

    • The system automatically verifies webhook signatures
    • Never disable this verification
  4. Keep credentials updated:

    • If you change credentials in PayPal, update them in Filament too
    • Clear cache after changing credentials

With this configuration, your application should be ready to process payments and subscriptions through PayPal. Remember:

  • Use Sandbox for testing and development
  • Switch to Live only when ready for production
  • Configure webhooks correctly to receive notifications
  • Review logs regularly to detect issues

Good luck with your PayPal integration!