- How do I switch between Paystack and PayPal in Laravel Billing Core?
- Switching gateways is as simple as updating the `BILLING_DEFAULT_DRIVER` in your `.env` file. The package uses a driver-based architecture, so no code changes are needed—just reconfigure the API keys for the new gateway. Ensure the new gateway’s webhook endpoint is properly set up to avoid missed events.
- Does Laravel Billing Core support Stripe or other payment gateways?
- Currently, the package supports Paystack and PayPal out of the box. However, you can easily extend it by creating a custom driver that implements the `GatewayDriver` interface. The package provides clear documentation on how to build and register new drivers for other gateways like Stripe or Flutterwave.
- How do I handle subscription plan swaps (upgrades/downgrades) with proration?
- The package includes a fluent API for plan swaps via `swapPlan()`. Proration is handled automatically by the underlying gateway (Paystack/PayPal), but you may need to configure proration settings in your gateway’s dashboard. Always test swaps during trials or billing periods to ensure correct charge adjustments.
- What happens if a user’s payment fails during a subscription? How is dunning managed?
- The package listens for `invoice.payment_failed` webhooks and automatically marks the subscription as `past_due`. You can customize dunning behavior by extending the `invoice.payment_failed` event listener or overriding the `handleFailedPayment` method in your service provider. Failed payments trigger retries based on your gateway’s retry logic.
- Can I use Laravel Billing Core with Laravel 9 or 10? Are there breaking changes?
- The package is built for Laravel 8+ and should work with Laravel 9/10 without issues, assuming you’re using modern PHP (8.0+). However, always check the package’s `composer.json` for Laravel version constraints. If you encounter compatibility issues, refer to the GitHub issues or consider forking the package for custom adjustments.
- How do I generate invoices or receipts for users after a payment?
- The package integrates with Laravel’s mail system to send receipts and invoices. After a successful payment, the `PaymentSucceeded` event is fired, which you can listen to and attach a custom email template. Ensure your mail driver (e.g., SMTP) is configured in `.env` to send emails reliably.
- What’s the best way to test webhooks and dunning logic locally?
- Use your gateway’s sandbox mode (e.g., PayPal Sandbox or Paystack Test API) to simulate webhooks. For dunning, manually trigger a failed payment via the gateway’s test dashboard and verify the `past_due` status updates in your database. Tools like Laravel’s `queue:work` can help process webhooks in real-time during testing.
- How do I customize the subscription lifecycle events (e.g., cancel-at-period-end)?
- The package fires events like `SubscriptionCancelled`, `SubscriptionStarted`, and `SubscriptionSwapped`. You can listen to these events in your `EventServiceProvider` or create custom listeners to trigger notifications, analytics, or workflows. Override the default behavior by binding your event handlers in the `register` method.
- Will Laravel Billing Core work with my existing database schema for billing?
- The package publishes migrations for `plans`, `subscriptions`, and `transactions` tables. If you already have billing tables, you’ll need to merge schemas carefully to avoid conflicts. Consider using a database migration tool like Laravel Schema Builder to extend existing tables or manually adjust the published migrations.
- What are the performance considerations for high-volume subscriptions (e.g., 10,000+ users)?
- The package relies on Laravel’s queue system for async webhook processing, which helps with scalability. Monitor queue workers to avoid delays, and ensure your database is optimized for high write loads (e.g., indexing `subscriptions` table on `user_id` and `status`). Gateways like PayPal/Paystack may have API rate limits, so implement caching or batch processing for bulk operations.