Skip to content

This module for Prestashop allows you to restrict specific payment methods based on products in the cart.

License

Notifications You must be signed in to change notification settings

ettorestani/Restrict-Payment-Methods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Restrict Payment Methods for PrestaShop

Support via PayPal License: MIT PrestaShop PHP Version

A powerful PrestaShop module that allows you to restrict specific payment methods based on cart content (products, categories, or brands). Perfect for handling special payment restrictions for specific product types, categories, or manufacturers.

✨ Features

  • πŸ”’ Server-Side Payment Filtering - Secure restriction that cannot be bypassed by users
  • 🎯 Multiple Restriction Criteria - Filter by product ID, category ID, or brand/manufacturer ID
  • πŸ’¬ Custom User Messages - Display personalized messages explaining why certain payment methods are unavailable
  • πŸͺ Multi-Shop Support - Different rules for different shops in multi-shop environments
  • ⚑ Performance Optimized - Advanced caching system and optimized database queries (solves N+1 problem)
  • πŸ“Š Bulk Actions - Enable, disable, or delete multiple rules at once
  • πŸ” AJAX Search - User-friendly admin interface with instant search for products, categories, and brands
  • πŸ“ Activity Logging - Track when and why payment restrictions are applied
  • 🌍 Multi-Language Support - Full translation support with PrestaShop 8 XLIFF system
  • 🎨 Theme Compatible - Works with most PrestaShop themes (includes multiple fallbacks)

πŸš€ Why This Module?

Security First

Unlike basic JavaScript-only solutions, this module implements a double-layer protection system:

  • Primary Layer: Server-side filtering via paymentOptions hook (cannot be bypassed)
  • Secondary Layer: Client-side fallback for older themes + user-friendly messages

Performance Optimized

  • 1-hour caching system to minimize database queries
  • Bulk SQL queries eliminate the N+1 problem
  • Lazy loading of assets (only on checkout pages)
  • Database indexes on all search fields

Production Ready

  • Tested with PrestaShop 1.7.6+ and 8.x
  • Multi-shop and multi-language support
  • Automatic cache invalidation on rule changes
  • Complete logging system for debugging
  • Server-side validation to prevent invalid configurations

πŸ“¦ Installation

Method 1: Manual Installation

  1. Download the latest release from GitHub Releases
  2. Upload the restrictpayments folder to /modules directory of your PrestaShop installation
  3. Go to Modules > Module Manager in your PrestaShop back office
  4. Find "Restrict Payment Methods" and click Install

Method 2: Upload via Back Office

  1. Download the module ZIP file
  2. Go to Modules > Module Manager
  3. Click Upload a Module and select the ZIP file
  4. Click Configure after installation

πŸ”§ Configuration

Creating a New Rule

  1. Navigate to Payment > Restrict Payments in your PrestaShop back office
  2. Click Add New Rule
  3. Configure the rule:

Basic Information

  • Rule Name: Give your rule a descriptive name (supports multiple languages)
  • Custom Message (optional): Message displayed to customers when payment methods are restricted

Restriction Criteria (at least one required)

  • Product ID: Restrict payments when a specific product is in cart
  • Category ID: Restrict payments when products from a specific category are in cart
  • Brand ID: Restrict payments when products from a specific manufacturer/brand are in cart

Payment Methods

  • Select which payment methods to restrict when the criteria match
  • Multiple payment methods can be selected

Status

  • Enabled: Activate or deactivate the rule
  1. Click Save

Note: You must specify at least one criterion (product, category, or brand) and at least one payment method to restrict.

Using the Search Feature

Instead of manually entering IDs, use the built-in search buttons:

  • Select Product: Search products by name or reference
  • Select Category: Search categories by name
  • Select Brand: Search manufacturers/brands by name

πŸ’‘ Use Cases

Example 1: Restrict Cash on Delivery for Electronics

Rule: "No COD for Electronics"
Category ID: 3 (Electronics)
Restricted Methods: Cash on Delivery
Custom Message: "Cash on delivery is not available for electronic products."

Example 2: Restrict PayPal for Specific Brand

Rule: "No PayPal for Brand X"
Brand ID: 5
Restricted Methods: PayPal
Custom Message: "PayPal payments are not available for this brand."

Example 3: Restrict Multiple Methods for High-Value Products

Rule: "Premium Product Restrictions"
Product ID: 123
Restricted Methods: Cash on Delivery, Check Payment
Custom Message: "Only credit card and bank transfer are available for this product."

πŸͺ Multi-Shop Support

The module fully supports PrestaShop's multi-shop feature:

  • Create different restriction rules for different shops
  • Rules can be shop-specific or shared across shops
  • Each shop maintains its own rule cache for optimal performance

🌍 Multi-Language Support

  • Rule names are translatable for each language
  • Custom messages can be different for each language
  • Admin interface automatically adapts to the current language
  • Compatible with PrestaShop 8's modern XLIFF translation system

πŸ”„ Upgrade from Version 1.x

If you're upgrading from version 1.x to 2.0:

  • The module will automatically upgrade your database schema
  • All existing rules will be preserved
  • New features (custom messages, multi-shop support, server-side filtering) will be available immediately
  • Clear your browser cache after upgrading

πŸ› οΈ Developer Information

Architecture

Hooks Used

  • paymentOptions - Server-side payment filtering (main security layer)
  • displayPaymentTop - Client-side fallback + user messages
  • actionFrontControllerSetMedia - Load frontend assets (checkout only)
  • displayBackOfficeHeader - Load admin assets

Database Schema

  • ps_restrict_payments_rule - Main rules table
  • ps_restrict_payments_rule_lang - Multi-language support
  • ps_restrict_payments_rule_shop - Multi-shop associations

Cache Management

The module automatically clears its cache when:

  • A rule is created, updated, or deleted
  • The module is uninstalled
  • Manual: Call $module->clearCache() from code

Performance Features

  • Caching: Rules cached with 1-hour TTL
  • Bulk Queries: Product categories fetched in single JOIN query
  • Lazy Loading: Assets loaded only on checkout pages
  • Indexed Database: All search fields properly indexed

File Structure

restrictpayments/
β”œβ”€β”€ restrictpayments.php              # Main module class
β”œβ”€β”€ classes/
β”‚   └── RestrictPaymentsRule.php      # Model with multishop/multilang
β”œβ”€β”€ controllers/admin/
β”‚   └── AdminRestrictPaymentsController.php  # Admin interface
β”œβ”€β”€ sql/
β”‚   β”œβ”€β”€ install.php                   # Database installation
β”‚   └── uninstall.php                 # Database cleanup
β”œβ”€β”€ upgrade/
β”‚   └── upgrade-2.0.0.php             # Upgrade scripts
β”œβ”€β”€ views/
β”‚   β”œβ”€β”€ js/                           # JavaScript files
β”‚   β”œβ”€β”€ css/                          # Stylesheets
β”‚   └── templates/                    # Smarty templates
└── translations/                     # XLIFF translation files

πŸ› Troubleshooting

Payment methods still appear

  1. Verify the rule is enabled (green toggle in the list)
  2. Check that product/category/brand IDs are correct
  3. Clear PrestaShop cache: Advanced Parameters > Performance > Clear Cache
  4. Check logs: Advanced Parameters > Logs

Custom message not showing

  1. Ensure you entered a custom message for the current language
  2. Verify your theme uses the displayPaymentTop hook
  3. Check browser console for JavaScript errors

Multi-shop rules not working

  1. Ensure multi-shop is enabled in PrestaShop settings
  2. Verify the rule is associated with the correct shop
  3. Clear cache for the specific shop context

Performance issues

  1. Check if caching is working (enable debug mode to see cache hits)
  2. Verify database indexes exist (re-run module installation if needed)
  3. Consider reducing the number of active rules if you have many

πŸ“‹ Requirements

  • PrestaShop: 1.7.6.0 or higher (including 8.x)
  • PHP: 7.1+ (7.2+ recommended for PrestaShop 8)
  • MySQL: 5.6+ or MariaDB 10.0+
  • PHP Extensions: mbstring, gd, curl, xml, zip

πŸ“„ License

This module is released under the MIT License. See LICENSE file for details.

You are free to:

  • βœ… Use commercially
  • βœ… Modify
  • βœ… Distribute
  • βœ… Private use

⚠️ Disclaimer

This module is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement.

Important:

  • βœ… Always test in a development/staging environment before production
  • βœ… Create a complete backup of your store before installation
  • βœ… Verify compatibility with your PrestaShop version and other modules
  • ❌ The author is not responsible for any damage, data loss, or issues caused by using this module

Use at your own risk. For production environments, consider using professional installation services.

πŸ› Bug Reports & Feature Requests

Found a bug or have a feature request? Please open an issue on GitHub Issues.

When reporting bugs, please include:

  • PrestaShop version
  • PHP version
  • Module version
  • Steps to reproduce
  • Error messages (if any)

πŸ“ Changelog

See CHANGELOG.md for a detailed version history.

πŸ’™ Support This Project

This module is completely free and always will be.

If you're using it in your business and it's saving you development time, please consider supporting its development:

Support via PayPal

Even a small contribution helps me:

  • βœ… Keep the module updated with new PrestaShop versions
  • βœ… Fix bugs faster
  • βœ… Add new features based on community feedback
  • βœ… Provide better documentation and support

Thank you for your support! πŸ™

πŸ’Ό Professional Services

Need help with your PrestaShop store? I offer professional services:

  • 🎨 Module Customization - Tailored modifications to fit your specific needs
  • πŸ›’ Complete PrestaShop E-commerce Development - From setup to launch
  • ⚑ Performance Optimization - Speed up your store and improve conversions
  • πŸ”§ Custom Module Development - Build exactly what your business needs
  • πŸ†˜ Support & Maintenance - Keep your store running smoothly

Contact Me:


Made with ❀️ by Ettore Stani

If this module helped you, please consider leaving a ⭐ on GitHub!

About

This module for Prestashop allows you to restrict specific payment methods based on products in the cart.

Resources

License

Stars

Watchers

Forks

Packages

No packages published