WP Manifestindependent plugin directory
manifest / ecommerce / deal-pipeline

Kaplan E-Commerce & CRM Deal Flow Pipeline

Custom WordPress e-commerce checkout, CRM deal lifecycle, compliance validation, and Moodle provisioning simulation.

by IT Lead Web Development Candidate · github.com/shubhamsharma950/deal-pipeline · website

0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/shubhamsharma950/deal-pipeline/archive/refs/heads/main.zip

Readme

Kaplan E-Commerce Checkout Pipeline & CRM Deal Flow Plugin

Author: Shubham Sharma (Lead Web Architect)
Compatible Theme: WordPress Default Themes (including Twenty Twenty-Five)
Technology Stack: Object-Oriented PHP 8.2+ (PSR-12), WordPress Coding Standards (WPCS), Vanilla ES6 JavaScript (Fetch API).


Overview

A lightweight, object-oriented custom WordPress plugin and high-availability architecture connecting the WordPress storefront with Zoho CRM / Creator (deal lifecycle management) and Moodle LMS (automated student account provisioning).

Key Architectural Capabilities:

  • Zero Third-Party Plugin Bloat: Pure bespoke OOP PHP architecture designed without heavy dependencies like WooCommerce.
  • Full Deal Lifecycle Mapping: Maps cart actions to Zoho CRM "Quotation" stage, and transitions deals to "Closed Won" upon payment confirmation.
  • Server-Side Sanctions Compliance: Enforces international trade compliance against restricted jurisdictions (['CU', 'IR', 'KP', 'SY']).
  • Automated LMS Student Provisioning: Dispatches webhooks to Moodle REST API (core_user_create_users, enrol_manual_enrol_users) with 1-year subscription management.
  • High-Availability Cloud Design: Multi-AZ AWS architecture (ALB, Nginx/PHP-FPM, Aurora MySQL, ElastiCache Redis, S3/CloudFront) behind Cloudflare Enterprise Edge.
  • High-Performance Custom Tables: Normalized MySQL tables with composite B-Tree indexing designed for fast query execution (avoiding unindexed wp_postmeta joins).

Task 1: High-Availability Cloud & Integration Architecture

The detailed architectural whitepaper and diagrams are available in:

Key Architecture Highlights:

  1. Edge Tier (Cloudflare Enterprise): Global Anycast DNS, OWASP Top 10 WAF, Layer 7 DDoS mitigation, SSL/TLS 1.3 termination, and edge asset caching.
  2. Compute Tier (AWS Multi-AZ): AWS Dual-AZ Application Load Balancer (ALB) routing to an Auto-Scaling Group (ASG) of Nginx + PHP-FPM 8.2 web nodes in private subnets.
  3. Database Tier (Amazon Aurora MySQL): Multi-AZ cluster with 1 Primary Writer in AZ-a and 1 Read Replica in AZ-b with asynchronous replication and automated failover.
  4. Caching & Storage Tier: Amazon ElastiCache Redis Cluster for persistent object caching and session state; Amazon S3 + CloudFront CDN for media uploads; Amazon EFS for shared filesystem sync.
  5. 3-Tier Cross-System Integration:
    • WordPress <-> Zoho Creator: Product catalog & SKU bidirectional sync with HMAC-SHA256 signature verification.
    • WordPress -> Zoho CRM: Cart action triggers Deal creation in "Quotation" stage; payment confirmation transitions Deal to "Closed Won".
    • WordPress -> Moodle LMS: Completed checkout dispatches automated provisioning payload (core_user_create_users, enrol_manual_enrol_users) with student email, course ID, and 1-year subscription expiry date.
  6. Asynchronous Error & Retry Mechanism: Decoupled worker queue utilizing exponential backoff with jitter (1m, 5m, 15m, 1h) and Dead Letter Queue (DLQ) alerting via Amazon SNS / Slack.

Task 2: Custom WordPress Plugin Implementation

1. Object-Oriented Architecture (PSR-12 & WPCS)

The plugin is structured cleanly into dedicated modules:

  • includes/Core/Plugin.php: Core singleton container orchestrating routes, services, and hooks.
  • includes/Database/Schema.php: DDL manager creating high-performance custom tables:
    • wp_kaplan_deals: Stores normalized deals, amounts, country codes, compliance flags, and Moodle sync statuses.
    • wp_kaplan_deal_logs: Granular audit log storing full outbound/inbound JSON payloads, timestamps, IP addresses, and HTTP status codes.
    • wp_kaplan_retry_queue: Manages asynchronous retries with exponential backoff schedules.
  • includes/Database/DealRepository.php: Data access layer using $wpdb->prepare(), composite B-Tree index queries, and statistics aggregations.
  • includes/Services/CatalogService.php: Authoritative product catalog enforcing server-side price validation with transient caching.
  • includes/Services/SanctionComplianceService.php: Server-side compliance validator enforcing OFAC restrictions (['CU', 'IR', 'KP', 'SY']).
  • includes/Services/ZohoCrmSimulator.php: Generates Zoho CRM API v2 request/response payloads for "Quotation" and "Closed Won" stages with checkout_token generation.
  • includes/Services/MoodleLmsSimulator.php: Dispatches two-step Moodle REST Web Services payloads (core_user_create_users + enrol_manual_enrol_users) with simulated mock tokens.
  • includes/Services/RetryQueueService.php: Implements exponential backoff calculation with full jitter and UTC timestamps:
    $$\text{Delay} = \min(\text{MaxDelay}, \text{Base} \times 2^{\text{attempt}-1}) + \text{Jitter}$$
  • includes/Api/CheckoutRestController.php: REST API endpoints under /wp-json/kaplan-crm/v1/ with strict nonce verification (X-WP-Nonce), admin authorization checks, server price validation, and cryptographic checkout_token session verification.
  • includes/Frontend/CheckoutRenderer.php: Renders [kaplan_checkout] shortcode and conditionally enqueues styles/scripts strictly on checkout pages.
  • includes/Admin/AdminDashboard.php: IT Lead Admin Dashboard for real-time deal monitoring and payload inspection.

2. Functional Capabilities & Security

  • Cart to CRM "Quotation" Deal Mapping: User course selection generates a Deal Reference (KAP-XXXXX) along with a secure checkout_token and creates an outbound JSON payload to Zoho CRM set to "Quotation".
  • Server-Side Price Validation: Product ID is verified against an authoritative server catalog; client-submitted prices and names are never trusted.
  • Deal Ownership & Session Security: Verifies cryptographic checkout_token, customer email, and course ID before allowing transition to "Closed Won".
  • Sanctioned Country Compliance Check: Tests billing country against restricted ISO codes ['CU', 'IR', 'KP', 'SY'] (Cuba, Iran, North Korea, Syria). Blocks transactions before payment, logs a SANCTION_BLOCKED audit entry, and returns a sanitized HTTP 403 response.
  • Checkout Completion & Moodle LMS Webhook: Captures payment, transitions Zoho Deal to "Closed Won", and dispatches simulated Moodle LMS provisioning payloads (core_user_create_users and enrol_manual_enrol_users) with +365 days subscription expiry date.
  • Asynchronous Retry Engine: Captures simulated 429 rate limit or 504 gateway timeout failures and schedules automatic retries with exponential backoff and Dead Letter Queue (DLQ) escalation upon 5 failed attempts.
  • Security Hardening: All input fields sanitized with sanitize_text_field and sanitize_email; output escaped with esc_html and esc_attr; REST API endpoints protected with WordPress Nonces and administrator capability checks.

Task 3: Web Performance, Security & Database Tuning

The complete writeup is available in docs/TASK3_PERFORMANCE_SECURITY.md.

1. Database Optimization Scenario (Custom Table vs. Slow meta_query)

  • Before (wp_postmeta): Requires 3 INNER JOIN operations on unindexed meta_value columns, resulting in full table scans (ALL) and high query latency under load.
  • After (wp_kaplan_deals): Uses dedicated columns with composite B-Tree index KEY idx_user_stage_comp_date (user_email, deal_stage, compliance_status, created_at). Designed for sub-10ms query execution and eliminates filesort.

2. Production Web Server Hardening

  • Nginx Configuration: Strict headers (Content-Security-Policy, X-Frame-Options: SAMEORIGIN, X-Content-Type-Options: nosniff, Strict-Transport-Security), blocking direct PHP execution in /wp-content/uploads/, blocking .git, .env, wp-config.php, and disabling xmlrpc.php.
  • Apache Configuration: Production .htaccess equivalent rules provided without invalid <Directory> directives.

3. Core Web Vitals Optimization (Target Sub-1.2s Checkout)

  1. Conditional Asset Loading: Zero plugin CSS/JS is loaded on homepage, archives, or blog posts.
  2. Script Deferral: script_loader_tag filter injects defer on frontend JS bundles.
  3. Transient Catalog Caching: Course catalog cached safely in WordPress transients.

Local Installation & Verification Steps

Prerequisites

  • PHP 8.2+
  • WordPress 6.0+ with Twenty Twenty-Five theme active.

Step-by-Step Setup:

  1. Ensure the plugin folder kaplan-deal-pipeline is located in wp-content/plugins/.
  2. Activate the plugin via WP Admin (Plugins → Installed Plugins → Activate "Kaplan E-Commerce & CRM Deal Flow Pipeline") or via CLI.
  3. Upon activation, the plugin automatically:
    • Creates the custom database tables (wp_kaplan_deals, wp_kaplan_deal_logs, wp_kaplan_retry_queue).
    • Provisions a sample storefront checkout page at http://localhost/kaplan/checkout/ with the shortcode [kaplan_checkout].

Interactive IT Lead Admin Dashboard

Log in to WP Admin and navigate to Kaplan CRM Pipeline (wp-admin/admin.php?page=kaplan-deal-pipeline).

Features available in the control center:

  1. KPI Metrics Cards: Real-time counts of Total Deals, Quotations, Closed Won Deals, Sanction Blocks, and Revenue.
  2. Live Deal Table: Indexed list of all deals, customer details, country codes, stages, and Moodle sync statuses.
  3. Outbound API Payload Inspector: Single-click modal to inspect raw request and response JSON payloads sent to Zoho CRM and Moodle LMS.
  4. Asynchronous Retry Queue: View queued API failures, error messages, attempt counts, and trigger single-click manual retries.
  5. Simulate Zoho 429 Rate Limit Button: Demonstrates automatic queueing and exponential backoff resilience.

Directory Structure

wp-content/plugins/kaplan-deal-pipeline/
├── kaplan-deal-pipeline.php            # Main plugin bootstrap and activation hooks
├── composer.json                       # PSR-4 package definition
├── README.md                           # Comprehensive documentation
├── includes/
│   ├── Autoloader.php                  # PSR-4 autoloader
│   ├── Core/
│   │   ├── Plugin.php                  # Core container & lifecycle orchestrator
│   │   ├── Activator.php               # DB installer & demo page provisioner
│   │   └── Deactivator.php             # Cron uninstaller & cleanup
│   ├── Database/
│   │   ├── Schema.php                  # Custom table schema definitions
│   │   └── DealRepository.php          # Database repository with prepared statements
│   ├── Services/
│   │   ├── SanctionComplianceService.php # Server-side sanction compliance validator
│   │   ├── ZohoCrmSimulator.php        # Zoho CRM Deal API v2 simulator
│   │   ├── MoodleLmsSimulator.php      # Moodle LMS User Provisioning simulator
│   │   └── RetryQueueService.php       # Exponential backoff retry engine
│   ├── Api/
│   │   └── CheckoutRestController.php  # WP REST API routes (kaplan-crm/v1)
│   ├── Frontend/
│   │   └── CheckoutRenderer.php        # Shortcode renderer & conditional assets
│   └── Admin/
│       └── AdminDashboard.php          # IT Lead Admin Dashboard controller
├── assets/
│   ├── css/
│   │   ├── checkout.css                # Polished checkout UI for Twenty Twenty-Five
│   │   └── admin.css                   # Admin dashboard styles
│   └── js/
│       ├── checkout.js                 # Vanilla ES6 async/await Fetch API module
│       └── admin.js                    # Admin dashboard interactive modal & retry triggers
└── docs/
    ├── TASK1_ARCHITECTURE_PLAN.md      # AWS/Cloudflare/Zoho/Moodle architecture
    ├── TASK3_PERFORMANCE_SECURITY.md   # DB tuning, Nginx hardening & CWV guide
    ├── architecture-diagram.drawio     # Draw.io XML diagram
    └── architecture-diagram.svg        # Standalone vector SVG diagram

Read the full README on GitHub →