User Guide

Subscribe & Save for Magento 2

Version 1.0.0

Add recurring billing and subscription functionality to your Magento store with Stripe integration, customizable themes, and full customer self-service.

1. Introduction

Jscriptz Subscriptions adds Subscribe & Save functionality to your Magento 2 store, enabling customers to purchase products on a recurring basis. The module integrates seamlessly with Stripe for payment processing and provides a complete customer self-service portal.

Key Features

Recurring Billing

Automatic billing at configurable intervals (weekly, monthly, etc.) powered by Stripe Subscriptions.

Flexible Plans

Create multiple subscription plans with different frequencies, discounts, and trial periods.

Customer Self-Service

Customers can pause, resume, skip, cancel, and manage their subscriptions from their account.

Visual Themes

6 pre-built themes with full customization options for the Subscribe & Save widget.

Email Notifications

7 customizable email templates for subscription lifecycle events.

GraphQL API

Full GraphQL support for headless implementations and custom frontends.

Requirements

  • Magento 2.4.x (Open Source or Commerce)
  • PHP 8.1 or higher
  • Stripe_Payments module (for payment processing)
  • Jscriptz_Checkout module (optional, for enhanced checkout integration)
  • Stripe account with Subscriptions enabled

2. Installation

Prerequisites

  • Magento 2.4.4 or higher
  • PHP 8.1 or higher
  • Composer 2.x
  • Stripe account (for payment processing)
  • Valid Jscriptz license (purchased from mage.jscriptz.com)

Step 1: Get Your Composer Access Token

After purchasing the extension, log in to your Jscriptz account to get your Composer authentication token:

  1. Go to mage.jscriptz.com/customer/account
  2. Click on GitHub Access in the left sidebar
  3. Click Generate New Token if you don't have one
  4. Copy your access token (valid for 50 minutes)

Step 2: Configure Composer Authentication

Create or update your auth.json file in your Magento root directory:

{
    "http-basic": {
        "packages.jscriptz.com": {
            "username": "YOUR_LICENSE_KEY",
            "password": "YOUR_ACCESS_TOKEN"
        }
    }
}

Replace YOUR_LICENSE_KEY with your license key from the My Licenses page, and YOUR_ACCESS_TOKEN with the token from Step 1.

Step 3: Install via Composer

# Add the Jscriptz repository (first time only)
composer config repositories.jscriptz composer https://packages.jscriptz.com

# Install the Subscriptions module
composer require jscriptz/module-subscriptions

Step 4: Run Magento Setup

# Enable the module
bin/magento module:enable Jscriptz_Subscriptions

# Run setup upgrade
bin/magento setup:upgrade

# Compile DI (production mode)
bin/magento setup:di:compile

# Deploy static content (production mode)
bin/magento setup:static-content:deploy -f

# Clear cache
bin/magento cache:flush

Step 5: Activate Your License

After installation, activate your license in the Magento admin:

  1. Go to Stores → Configuration → Jscriptz → Subscriptions
  2. Expand the License section
  3. Enter your License Key from your Jscriptz License Account
  4. Click Save Config
  5. Click Verify License to confirm activation
Success! A green "Active" badge confirms your license is valid. Next, configure your Stripe API keys in the Stripe Integration section.

3. Admin Configuration

Admin Path: Stores > Configuration > Jscriptz > Subscriptions

3.1 General Settings

Setting Description Default
Enable Subscriptions Master toggle to enable/disable all subscription functionality No

3.2 Display Settings

Setting Description Options
Display Position Where subscription options appear on the product/cart page Below Product, Above Qty, Below Qty, Inline, Below Everything
Visual Theme Theme style for the Subscribe & Save widget Piggy, Modern, Minimal, Rocket, Garden, Vines
Theme Customization Advanced customization for backgrounds, borders, typography, and animations Visual editor
Show Savings Amount Display how much the customer saves with a subscription Yes/No
Price Location Where to display the subscription discount price Inline, Override Item Price

3.3 Customer Options

Setting Description Default
Allow Customers to Pause Allow customers to temporarily pause their subscriptions Yes
Allow Customers to Skip Allow customers to skip the next billing cycle Yes
Maximum Skips Allowed Limit how many times a customer can skip (0 = unlimited) 0
Billing Reminder Days Days before billing to send reminder email 3

3.4 Stripe Integration

Setting Description
Stripe Webhook Signing Secret Webhook signing secret from Stripe Dashboard for secure webhook verification
Status Sync Schedule How often to sync subscription status with Stripe
Webhook URL: https://yourdomain.com/jscriptz_subscriptions/webhook/stripeSubscription

Configure this URL in your Stripe Dashboard under Webhooks > Add Endpoint.

4. Subscription Plans

Admin Path: Marketing > Subscriptions > Subscription Plans

Subscription plans define the billing frequency, discounts, and trial periods available to customers.

4.1 Creating Plans

  1. Navigate to Marketing > Subscriptions > Subscription Plans
  2. Click Add New Plan
  3. Fill in the plan details (see configuration below)
  4. Save the plan

4.2 Plan Configuration

Field Description Required
Plan Code Unique identifier for the plan (e.g., monthly_10off) Yes
Name Display name shown to customers (e.g., "Monthly Delivery") Yes
Description Optional description for admin reference No
Billing Frequency How often the subscription bills (weekly, monthly, etc.) Yes
Billing Interval Number of frequency units (e.g., 2 for "every 2 weeks") Yes
Discount Type Percentage or fixed amount discount No
Discount Value Discount amount (e.g., 10 for 10% or $10) No
Is Enabled Whether the plan is available for use Yes
Sort Order Display order when multiple plans are available No

4.3 Frequency Options

Frequency Description
weekly Bills every week (interval = 1) or every N weeks
biweekly Bills every 2 weeks
monthly Bills every month (interval = 1) or every N months
bimonthly Bills every 2 months
quarterly Bills every 3 months
semiannual Bills every 6 months
annual Bills once per year

4.4 Trials & Discounts

Field Description
Trial Enabled Enable a trial period before regular billing starts
Trial Days Number of days for the trial period
Trial Price Price during trial (null or 0 = free trial)
Min Cycles Minimum billing cycles before cancellation is allowed
Max Cycles Maximum billing cycles (null = unlimited)
Example Plans:
  • Monthly 10% Off: billing_frequency=monthly, interval=1, discount_type=percent, discount_value=10
  • Every 2 Weeks: billing_frequency=weekly, interval=2
  • Quarterly with Trial: billing_frequency=quarterly, trial_enabled=true, trial_days=14

5. Product Configuration

Admin Path: Catalog > Products > [Edit Product] > Subscriptions Tab

Enable subscriptions on a per-product basis and assign available plans.

Enabling Subscriptions for a Product

  1. Edit the product in Catalog > Products
  2. Navigate to the Subscriptions tab
  3. Set Enable Subscription to Yes
  4. Select the available Subscription Plans for this product
  5. Optionally configure product-specific discount overrides
  6. Save the product

Product Subscription Fields

Field Description
Enable Subscription Allow this product to be purchased as a subscription
Available Plans Select which subscription plans are available for this product
Override Discount Type Product-specific discount type (overrides plan default)
Override Discount Value Product-specific discount value (overrides plan default)
Note: If no plans are assigned to a product, the subscription option will not appear on the frontend even if subscriptions are enabled for the product.

6. Visual Themes

The Subscribe & Save widget supports 6 pre-built visual themes, each with full customization options.

6.1 Available Themes

Theme Description Style
Piggy Playful design with piggy bank icon Fun, savings-focused
Modern Clean, contemporary design Professional, minimal
Minimal Ultra-simple appearance Subtle, unobtrusive
Rocket Dynamic design with rocket imagery Energetic, action-oriented
Garden Nature-inspired botanical design Organic, eco-friendly
Vines Elegant vine patterns Sophisticated, natural

6.2 Theme Customization

Each theme can be customized using the visual editor in admin configuration:

Background Options

  • Type: Gradient, Solid, or Transparent
  • Solid Color: Hex color value
  • Gradient Type: Linear or Radial
  • Gradient Angle: Direction in degrees
  • Gradient Stops: Color positions

Border Options

  • Style: None, Solid, Dashed, Dotted, Gradient, Glow
  • Width: Border thickness in pixels
  • Color: Border color
  • Radius: Corner roundness

Typography Options

  • Font Color: Main text color
  • Accent Color: Highlight color for "Save" text and prices
  • Font Size: Base font size

Animation Options

  • Icon Animation: Bounce, Pulse, Wiggle, or None
  • Hover Animation: Scale, Glow, Lift, or None

Layout Options

  • Scale: Widget size (50%-150%)
  • Show Icon: Display theme icon
  • Show Discount Badge: Display discount percentage badge
  • Show Original Price: Show crossed-out original price
  • Show Frequency Dropdown: Display frequency selector

Toggle Options

  • Type: Switch, Checkbox, or Radio
  • Background Color: Active state color
  • Border Radius: Toggle corner roundness

7. Customer Experience

7.1 Product Page Widget

When a product has subscriptions enabled, customers see the Subscribe & Save widget on the product page (and optionally in the cart).

Widget Elements

  • One-Time Purchase: Radio button for single purchase
  • Subscribe & Save: Radio button to enable subscription
  • Frequency Selector: Dropdown to choose delivery frequency
  • Discount Display: Shows savings amount (e.g., "Save 10%")
  • Price Comparison: Original price vs. subscription price

7.2 My Subscriptions Dashboard

Frontend Path: My Account > My Subscriptions

Logged-in customers can view and manage all their subscriptions from their account dashboard.

Dashboard Features

  • List of all active, paused, and cancelled subscriptions
  • Subscription details (products, frequency, next billing date)
  • Subscription increment ID (e.g., SUB-000001)
  • Status indicators (Active, Paused, Cancelled, etc.)
  • Action buttons for each subscription

7.3 Customer Actions

Action Description Configurable
View Details View complete subscription information Always available
Change Frequency Switch to a different billing frequency/plan Always available
Skip Next Delivery Skip the next billing cycle Allow Skip setting
Pause Subscription Temporarily pause billing (can set resume date) Allow Pause setting
Resume Subscription Resume a paused subscription Always available
Update Payment Change the payment method on file Always available
Cancel Subscription Cancel (immediately or at period end) Always available

Subscription Statuses

Status Description
Pending Subscription created but not yet active
Active Subscription is billing normally
Paused Subscription is temporarily paused
Cancelled Subscription has been cancelled
Expired Subscription reached max cycles or end date
Failed Payment failed (requires attention)

8. GraphQL API

The module provides a complete GraphQL API for headless implementations and custom frontends.

8.1 Queries

subscriptionThemeConfig

Get the subscription theme configuration including customizations.

{
  subscriptionThemeConfig {
    enabled
    theme
    display_position
    show_savings
    price_location
    custom_css
    customization {
      background { type solid_color gradient_type }
      border { style width color radius }
      typography { font_color accent_color font_size }
      animations { icon_enabled icon_type hover_enabled hover_type }
      layout { scale show_icon show_discount_badge }
      toggle { type bg_color border_radius }
    }
  }
}

customer.subscriptions

Get the logged-in customer's subscriptions.

{
  customer {
    subscriptions(status: "active") {
      subscription_id
      increment_id
      status
      status_label
      plan { name billing_frequency discount_value }
      items { name sku qty subscription_price { value currency } }
      next_billing_date
      recurring_amount { value currency }
      can_pause
      can_skip
      can_cancel
    }
  }
}

8.2 Mutations

Mutation Description Parameters
setCartItemSubscription Enable/disable subscription for a cart item cart_id, cart_item_id, enabled, plan_id
cancelSubscription Cancel a subscription subscription_id, reason, at_period_end
pauseSubscription Pause a subscription subscription_id, resume_date
resumeSubscription Resume a paused subscription subscription_id
skipSubscriptionCycle Skip the next billing cycle subscription_id
updateSubscriptionFrequency Change the subscription plan/frequency subscription_id, plan_id
updateSubscriptionPaymentMethod Update the payment method subscription_id, payment_method_id
createStripeSetupIntent Create Stripe SetupIntent for saving payment cart_id

Example: Set Cart Item Subscription

mutation {
  setCartItemSubscription(
    cart_id: "abc123"
    cart_item_id: 5
    enabled: true
    plan_id: 1
  ) {
    success
    message
    cart {
      items {
        id
        subscription {
          enabled
          plan { name discount_value }
          subscription_price { value currency }
        }
      }
    }
  }
}

Example: Cancel Subscription

mutation {
  cancelSubscription(
    subscription_id: 123
    reason: "No longer needed"
    at_period_end: true
  ) {
    success
    message
    subscription {
      status
      end_date
    }
  }
}

8.3 Types

CartItemInterface Extensions

Cart items include subscription data:

  • subscription_options - Available subscription plans for the product
  • subscription - Current subscription configuration for the item

Key Types

Type Description
SubscriptionPlan Plan configuration (id, name, frequency, discount)
CustomerSubscription Full subscription details including status, items, billing info
SubscriptionItem Line item within a subscription
CartItemSubscription Subscription state for a cart item
CartItemSubscriptionOptions Available subscription options for a product
SubscriptionThemeConfig Theme settings and customizations
SubscriptionActionOutput Result of subscription action mutations

9. Email Templates

The module includes 7 email templates for subscription lifecycle events. All templates can be customized in Marketing > Email Templates.

Template ID Label Trigger
jscriptz_subscriptions_created Subscription Created New subscription is created after order
jscriptz_subscriptions_billing_reminder Billing Reminder X days before next billing (configurable)
jscriptz_subscriptions_payment_success Payment Success Renewal payment processed successfully
jscriptz_subscriptions_payment_failed Payment Failed Renewal payment failed
jscriptz_subscriptions_paused Subscription Paused Customer pauses their subscription
jscriptz_subscriptions_resumed Subscription Resumed Customer resumes their subscription
jscriptz_subscriptions_cancelled Subscription Cancelled Customer cancels their subscription

Customizing Email Templates

  1. Go to Marketing > Email Templates
  2. Click Add New Template
  3. Load the default template from the dropdown
  4. Customize the content
  5. Save and assign in Stores > Configuration > Jscriptz > Subscriptions

Available Template Variables

  • {{var subscription.increment_id}} - Subscription ID
  • {{var subscription.status}} - Current status
  • {{var subscription.next_billing_date}} - Next billing date
  • {{var subscription.recurring_amount}} - Recurring amount
  • {{var customer.name}} - Customer name
  • {{var plan.name}} - Plan name
  • {{var items}} - Subscription items collection

10. Stripe Integration

Subscriptions are powered by Stripe Subscriptions for secure, reliable recurring billing.

Setup Requirements

  1. Install and configure the Stripe_Payments module
  2. Enable Stripe in Magento payment configuration
  3. Create a webhook endpoint in Stripe Dashboard
  4. Configure the webhook signing secret in module settings

Webhook Configuration

Webhook URL: https://yourdomain.com/jscriptz_subscriptions/webhook/stripeSubscription

Required Webhook Events

  • customer.subscription.created
  • customer.subscription.updated
  • customer.subscription.deleted
  • invoice.paid
  • invoice.payment_failed
  • invoice.upcoming

Stripe Data Sync

The module syncs the following data with Stripe:

Magento Data Stripe Object
Subscription Plan Stripe Price + Product
Customer Subscription Stripe Subscription
Payment Method Stripe PaymentMethod
Renewal Order Stripe Invoice
Important: The webhook signing secret is required for secure webhook verification. Without it, webhooks will be rejected and subscription status will not sync properly.

11. Cron Jobs

The module includes 3 scheduled cron jobs for automated subscription management.

Job Name Schedule Description
jscriptz_subscriptions_sync_status Every 6 hours
0 */6 * * *
Syncs subscription status with Stripe. Catches any missed webhook events and ensures data consistency.
jscriptz_subscriptions_send_billing_reminders Daily at 9 AM
0 9 * * *
Sends billing reminder emails to customers X days before their next billing date.
jscriptz_subscriptions_cleanup_expired Daily at 3 AM
0 3 * * *
Cleans up expired subscriptions and performs database maintenance.

Manual Execution

Cron jobs can be run manually using:

bin/magento cron:run --group=default

Or run a specific job:

bin/magento indexer:reindex jscriptz_subscriptions_sync_status

12. Database Schema

The module creates 6 custom tables and extends 2 core Magento tables.

Custom Tables

Table Description Key Fields
jscriptz_subscription_plan Subscription plan configurations plan_id, plan_code, name, billing_frequency, discount_type, discount_value, trial_enabled
jscriptz_subscription_product Product-Plan associations product_id, plan_id, override_discount_type, override_discount_value
jscriptz_subscription Active customer subscriptions subscription_id, increment_id, customer_id, plan_id, stripe_subscription_id, status, next_billing_date
jscriptz_subscription_item Subscription line items item_id, subscription_id, product_id, sku, name, qty, subscription_price
jscriptz_subscription_order Subscription renewal order history subscription_id, order_id, billing_cycle, stripe_invoice_id
jscriptz_subscription_theme Theme customizations per store theme_id, store_id, theme_code, customization, custom_css

Extended Core Tables

Table Added Fields
quote_item is_subscription, subscription_plan_id, subscription_discount_amount, subscription_original_price
sales_order_item is_subscription, subscription_plan_id, subscription_discount_amount, subscription_original_price, subscription_id

13. Troubleshooting

Common Issues

Subscription widget not appearing

  • Verify subscriptions are enabled in configuration
  • Check that the product has subscriptions enabled
  • Confirm at least one plan is assigned to the product
  • Clear cache: bin/magento cache:clean

Webhooks not processing

  • Verify the webhook URL is correct in Stripe Dashboard
  • Check that the webhook signing secret is configured
  • Review var/log/system.log for webhook errors
  • Test webhook delivery from Stripe Dashboard

Subscription status not syncing

  • Verify cron is running: bin/magento cron:run
  • Check Stripe API credentials are correct
  • Review var/log/exception.log for errors
  • Manually run sync: bin/magento cron:run --group=default

Payment method update failing

  • Ensure Stripe.js is loading on the frontend
  • Check browser console for JavaScript errors
  • Verify the SetupIntent is being created successfully

Debug Logging

Enable debug logging for detailed troubleshooting:

# View subscription-related logs
tail -f var/log/system.log | grep -i subscription

# View all errors
tail -f var/log/exception.log

Cache Management

After configuration changes, clear relevant caches:

# Clear all caches
bin/magento cache:clean

# Clear specific caches
bin/magento cache:clean config full_page

Support

For additional support:

  • Check the module's GitHub repository for known issues
  • Review Stripe documentation for API-related issues
  • Contact Jscriptz support with detailed error logs