🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Best Alternative of Laravel Spark with Stripe/Paddle

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.), maybe SubscriptionUsage 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 or spatie/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.

Putting It All Together (The Workflow):

  1. Define Plans/Features: Use your internal models (possibly assisted by webaune/laravel-subscriptions) to define subscription plans and their associated features in your database.
  2. User Subscribes:
    • User selects a plan in your UI.
    • Create a Subscription record in your database (using your internal models/package) with a status like pending or initiating.
    • 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.
  3. Handle Gateway Callbacks/Redirects: User returns to your site. Show a pending/success/failure message. The real confirmation often comes via webhook.
  4. 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 or elegantly/laravel-invoices), feeding it data from your internal Subscription and Plan models. Save/store the invoice.
      • Grant the user access to features based on the active subscription.
    • 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.
  5. Manage Subscription Changes (Cancel, Swap):
    • Provide UI for users to manage their subscriptions.
    • When a user cancels: Update the internal Subscription status (e.g., set ends_at to the end of the current paid period, mark as cancelling). Call the gateway API (via srmklive/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 or elegantly/laravel-invoices
  • PayPal: srmklive/paypal
  • Paytm: anandsiddharth/laravel-paytm-wallet (evaluate first) or official paytm/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”.

Subscribe
Notify of
guest


0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x