You want the control centre of your subscription logic (plans, user status, features, invoicing rules) to be inside your core Laravel application, using PayPal and Paytm purely as external payment processors.
This is a valid approach, often chosen for greater flexibility or when dealing with payment gateways not supported by tools like Cashier/Spark. However, it does mean you’ll be responsible for building more of the logic yourself.
Laravel Spark is not suitable for this, as its primary value comes from its tight integration with Cashier (Stripe/Paddle) and handling much of the billing logic via those providers.
Here’s a suggested approach using Laravel libraries to speed up development while keeping core logic in-house:
1. Core Subscription Management (In-House Logic)
- Goal: Manage plans, features, user subscription status, trial periods, and renewals within your application’s database and logic.
- Approach: You’ll need Eloquent models for
Plan
,Feature
,Subscription
(linking User to Plan, storing status, trial end, next billing date, etc.), maybeSubscriptionUsage
for metered billing. - Libraries to Help:
webaune/laravel-subscriptions
: This package looks like a strong candidate. Its description explicitly states “Payments are out of scope for this package”. It focuses on providing the database structure (migrations) and Eloquent models/traits for managing plans, features, and subscriptions within your Laravel application itself. This aligns perfectly with your goal of keeping the core logic internal.- Custom Build: You can always build these models and the associated logic (checking
isActive()
,isOnTrial()
,canUseFeature()
, handling renewals) yourself using standard Laravel practices.webaune/laravel-subscriptions
just gives you a head start.
2. Invoice Generation (In-House Logic)
- Goal: Generate PDF invoices based on your internal subscription data when a payment is confirmed or a billing cycle renews. Store or allow download of these PDFs.
- Approach: Use a dedicated Laravel PDF generation package combined with your internal subscription data.
- Libraries to Help:
laraveldaily/laravel-invoices
: A popular and robust package specifically for creating customizable PDF invoices. You feed it data (buyer info, items, prices, taxes from your models), and it generates the PDF.elegantly/laravel-invoices
: A newer, well-regarded alternative that also focuses on generating PDFs from Eloquent data and includes database storage for invoice records.- Base PDF Packages: You could use lower-level packages like
barryvdh/laravel-dompdf
orspatie/laravel-pdf
and create the HTML invoice template yourself, but the dedicated invoice packages provide more structure.
3. PayPal Integration (Payment Processing Only)
- Goal: Initiate payments (one-time or recurring setup), securely handle redirects/callbacks, and listen for webhook notifications (e.g.,
PAYMENT.SALE.COMPLETED
,BILLING.SUBSCRIPTION.ACTIVATED
,PAYMENT.CAPTURE.COMPLETED
). - Approach: Use a reliable PayPal SDK wrapper for Laravel.
- Libraries to Help:
srmklive/paypal
: This is a widely used and generally well-maintained package for integrating PayPal into Laravel. It simplifies interacting with the PayPal REST API (getting tokens, creating orders, capturing payments, setting up subscriptions) and handling IPN/Webhooks compared to using the raw PayPal PHP SDK directly. This is likely your best option for accelerating PayPal integration.
4. Paytm Integration (Payment Processing Only)
- Goal: Initiate payments (supporting methods like UPI, cards, NetBanking, including recurring mandates like UPI Autopay/eNACH), handle callbacks, and process webhook notifications.
- Approach: Use the official Paytm SDK or a trusted Laravel wrapper.
- Libraries to Help:
- Official
paytm/paytm-pg
SDK: Use the official SDK provided by Paytm. This gives you the most direct control but requires more manual setup within your Laravel app. anandsiddharth/laravel-paytm-wallet
: This third-party package was specifically mentioned in a tutorial regarding Paytm subscriptions in Laravel. You’ll need to assess its current maintenance status and compatibility with the latest Laravel versions and Paytm APIs. If it’s up-to-date, it could save significant time. Evaluate this first.
- Official
Putting It All Together (The Workflow):
- Define Plans/Features: Use your internal models (possibly assisted by
webaune/laravel-subscriptions
) to define subscription plans and their associated features in your database. - User Subscribes:
- User selects a plan in your UI.
- Create a
Subscription
record in your database (using your internal models/package) with a status likepending
orinitiating
. - Based on the user’s chosen gateway (PayPal/Paytm), call the appropriate package (
srmklive/paypal
or Paytm package) to initiate the payment/subscription setup on the gateway’s side. - Redirect the user to PayPal/Paytm to authorize the payment/mandate.
- Handle Gateway Callbacks/Redirects: User returns to your site. Show a pending/success/failure message. The real confirmation often comes via webhook.
- Handle Gateway Webhooks:
- Create dedicated webhook controllers/routes for PayPal and Paytm.
- Verify the incoming webhook authenticity.
- When a successful payment/activation webhook arrives:
- Find the corresponding internal
Subscription
record. - Update its status to
active
. - Set the
trial_ends_at
,starts_at
,ends_at
(next billing date) based on the plan and payment confirmation. - Store relevant gateway subscription IDs (e.g., PayPal Subscription ID) on your internal
Subscription
model for reference (e.g., for cancellations). - Trigger invoice generation using your chosen invoicing package (
laraveldaily/laravel-invoices
orelegantly/laravel-invoices
), feeding it data from your internalSubscription
andPlan
models. Save/store the invoice. - Grant the user access to features based on the active subscription.
- Find the corresponding internal
- When a renewal payment webhook arrives, update the
ends_at
date and generate a new invoice. - Handle failure/cancellation webhooks by updating the internal
Subscription
status accordingly (e.g.,past_due
,cancelled
) and potentially revoking feature access after any grace period.
- Manage Subscription Changes (Cancel, Swap):
- Provide UI for users to manage their subscriptions.
- When a user cancels: Update the internal
Subscription
status (e.g., setends_at
to the end of the current paid period, mark ascancelling
). Call the gateway API (viasrmklive/paypal
or Paytm package) to cancel the recurring payment on their end. - Swapping plans involves more complex logic: potentially cancelling the old gateway subscription, creating a new one, calculating proration (if needed – this logic would be yours to implement), and updating the internal
Subscription
record.
Summary of Suggested Libraries:
- Core Subscriptions:
webaune/laravel-subscriptions
(or custom Eloquent models) - Invoicing:
laraveldaily/laravel-invoices
orelegantly/laravel-invoices
- PayPal:
srmklive/paypal
- Paytm:
anandsiddharth/laravel-paytm-wallet
(evaluate first) or officialpaytm/paytm-pg
SDK
This approach gives you the desired control over the core logic while leveraging specialized packages to handle the complex and time-consuming parts of PDF generation and payment gateway API interactions. It requires more development effort than Spark but precisely meets your requirement of keeping the subscription business logic “in-house”.
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND