Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- AJAX status checking for improved customer experience during verification
- Quick start guide for checkout integration
- Implementation summary documentation
- Clean redirects to KYC verification page instead of throwing exceptions
- Contextual alerts with URL parameters for better user feedback
- French translation for alert messages

### Changed
- Updated README.md to reference integration guide
- Enhanced hook documentation with detailed parameter information
- Updated order validation hook to actionValidateOrderBefore with version-specific handling for PrestaShop 8 and 9 compatibility

## [1.1.2] - 2025-09-17

Expand Down
89 changes: 84 additions & 5 deletions INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The KYC Secure Upload module leverages the following PrestaShop hooks for checko
| Hook Name | Type | Trigger Point | Purpose | Parameters |
|-----------|------|---------------|---------|------------|
| `actionCheckoutRender` | Action | Before checkout page renders | Inject KYC step into checkout process | `['checkoutProcess']` |
| `actionValidateOrder` | Action | Before order confirmation | Block order if KYC not approved | `['cart', 'order', 'customer']` |
| `actionValidateOrderBefore` | Action | Before order validation | Block order if KYC not approved | `['cart', 'customer', 'currency', 'id_order_state', 'payment_method']` |
| `displayBeforeCarrier` | Display | Before carrier selection | Show KYC warning/requirements | `[]` |
| `displayCustomerAccount` | Display | Customer account page | Display KYC verification link | `[]` |
| `actionFrontControllerSetMedia` | Action | Page asset loading | Load KYC-related CSS/JS | `[]` |
Expand All @@ -50,7 +50,7 @@ There are several approaches to integrate KYC verification with third-party chec

### 1. Pre-Order Validation Hook (Recommended)

Use the `actionValidateOrder` hook to block order creation if KYC is not approved.
Use the `actionValidateOrderBefore` hook to block order creation if KYC is not approved.

**Pros:**
- ✅ Works with any checkout module
Expand Down Expand Up @@ -83,6 +83,85 @@ Inject JavaScript that validates KYC status before order submission.
**Cons:**
- ⚠️ Can be bypassed (always use server-side validation too)

## PrestaShop 8.x Compatibility Matrix (Important)

The **KYC Secure Upload** module provides a PrestaShop-9–style `actionValidateOrderBefore` hook on **PrestaShop 8.x** through an **optional `PaymentModule` override shim**.

This allows blocking order creation *server-side* **only if the checkout module uses `PaymentModule::validateOrder()`**.

Because many checkout modules modify or replace the core order-validation flow, compatibility must be assessed per module.

> **TODO (maintainers):** Before completing this matrix, identify whether each checkout/payment module calls
> `PaymentModule::validateOrder()` → (Hard-block possible),
> OR bypasses it → (Requires module-specific integration).

---

### Compatibility Levels
- **A — Fully Compatible**
Uses core `PaymentModule::validateOrder()` → PS8 hard-block works.
- **B — Partially Compatible**
Uses some core hooks but may bypass parts of validation → soft-block + payment gating recommended.
- **C — Requires Integration**
Custom flow / AJAX confirm controller → override shim has no effect.
- **D — Unknown / Not Tested**

### Risk Levels
- **Low**: Standard checkout flow
- **Medium**: OPC with custom rendering but calls `validateOrder()`
- **High**: OPC creates orders via custom controllers / endpoints

---

## Checkout Module Compatibility Matrix

| Checkout Module | Vendor | PS8 Compatibility | Enforcement Level | Risk | Notes |
|-----------------|--------|------------------|-------------------|-------|-------|
| **Default Checkout** | PrestaShop | **A** | Hard-block + Payment Gating | Low | Fully standard; recommended baseline. |
| **Prestahero One Page Checkout** | PrestaHero | **B / C (verify)** | Soft-block; may need integration | Medium/High | Some versions skip standard hooks; confirm if `validateOrder()` is used. |
| **Knowband SuperCheckout** | Knowband | **C (likely)** | Soft-block; integration recommended | High | Known to bypass multiple core hooks; confirm their "confirm order" controller. |
| **One Page Checkout PS** | PresTeamShop | **B / C (verify)** | Soft-block | Medium | Hybrid OPC; may or may not trigger core validation. |
| **Revolut / Stripe / PayPal modules** | Payments | **A** | Hard-block | Low | Most payment modules call `validateOrder()` normally. |
| **Custom Checkout Modules** | Varies | **D** | Varies | High | Must check call chain manually. |

> ⚠ **Warning:**
> On PrestaShop 8.x, the hard-block mechanism **only works** with checkout modules that call
> `PaymentModule::validateOrder()`.
> Modules that bypass this method require **specific integration** (controller override or validation hook in their flow).

---

## How to Verify a Module's Compatibility (Quick Test)

1. **Search the module for:**
```
validateOrder(
```
If found → Likely **A** (hard-block possible).

2. If not found, search for:
```
placeOrder(
createOrder(
OrderController(
ajaxValidate
```
→ Likely **C** (custom confirm flow → override shim won't execute).

3. Test by enabling KYC hard-block and attempting checkout:
- If hook fires → module is compatible.
- If order is created anyway → requires integration.

---

## Summary

- **PS9 → native hard-block** (no overrides)
- **PS8 → optional override shim** adds `actionValidateOrderBefore`
- Works with modules using **standard core validation**
- Custom OPC modules may require **module-specific integration**
- Always enable **payment gating** for consistent UX

---

## Custom Validation Integration
Expand Down Expand Up @@ -217,7 +296,7 @@ The KYC module provides extension points for third-party modules:
#### Issue: Customer can complete order without KYC approval

**Possible causes:**
1. `actionValidateOrder` hook not registered
1. `actionValidateOrderBefore` hook not registered
2. KYC required categories not configured
3. Service error not properly handled

Expand Down Expand Up @@ -314,6 +393,6 @@ Found an issue or want to improve this guide?

---

**Last Updated:** 2025-01-28
**Module Version:** 1.1.2+
**Last Updated:** 2026-02-01
**Module Version:** 1.1.3
Comment thread
vachmara marked this conversation as resolved.
Resolved
**Tested with:** PrestaShop 8.1.x, 8.2.x
1 change: 1 addition & 0 deletions controllers/front/verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function initContent()
'verification' => $verification,
'documents' => $documents,
'token' => sha1($context->customer->secure_key),
'kyc_required_alert' => (bool) Tools::getValue('kyc_required'),
]);

$this->context->smarty->tpl_vars['page']->value['body_classes']['page-customer-account'] = true;
Expand Down
74 changes: 74 additions & 0 deletions override/classes/PaymentModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
Comment thread
vachmara marked this conversation as resolved.
Resolved

/**
* MIT License
* Copyright (c) 2025 Valentin Chmara
*
* @author Valentin Chmara
* @copyright Valentin Chmara
* @license MIT
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class PaymentModule extends PaymentModuleCore
{
/**
* Validate an order in database
* Function called from a payment module.
*
* @param int $id_cart
* @param int $id_order_state
* @param float $amount_paid Amount really paid by customer (in the default currency)
* @param string $payment_method Payment method (eg. 'Credit card')
* @param string|null $message Message to attach to order
* @param array $extra_vars
* @param int|null $currency_special
* @param bool $dont_touch_amount
* @param string|bool $secure_key
* @param Shop $shop
* @param string|null $order_reference if this parameter is not provided, a random order reference will be generated
*
* @return bool
*
* @throws PrestaShopException
*/
public function validateOrder(
$id_cart,
$id_order_state,
$amount_paid,
$payment_method = 'Unknown',
$message = null,
$extra_vars = [],
$currency_special = null,
$dont_touch_amount = false,
$secure_key = false,
?Shop $shop = null,
?string $order_reference = null,
Comment thread
vachmara marked this conversation as resolved.
Resolved
) {
// Only for Prestashop 8: execute the pre-order validation hook
if (version_compare(_PS_VERSION_, '9.0.0', '<')) {
Hook::exec('actionValidateOrderBefore', [
'cart' => $this->context->cart,
'customer' => $this->context->customer,
'currency' => $this->context->currency,
'id_order_state' => &$id_order_state,
'payment_method' => $payment_method,
]);
}
Comment thread
vachmara marked this conversation as resolved.
Resolved

return parent::validateOrder(
$id_cart,
$id_order_state,
$amount_paid,
$payment_method,
$message,
$extra_vars,
$currency_special,
$dont_touch_amount,
$secure_key,
$shop,
$order_reference
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}
Comment thread
vachmara marked this conversation as resolved.
Resolved
19 changes: 19 additions & 0 deletions override/classes/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* MIT License
* Copyright (c) 2025 Valentin Chmara
*
* @author Valentin Chmara
* @copyright Valentin Chmara
* @license MIT
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
52 changes: 19 additions & 33 deletions pskyc.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function install()

return parent::install()
&& $this->registerHook('actionCheckoutRender')
&& $this->registerHook('actionValidateOrder')
&& $this->registerHook('actionValidateOrderBefore')
&& $this->registerHook('displayBeforeCarrier')
Comment thread
vachmara marked this conversation as resolved.
Resolved
&& $this->registerHook('actionFrontControllerSetMedia')
&& $this->registerHook('displayAdminCustomers')
Expand Down Expand Up @@ -201,6 +201,7 @@ public function getContent()

// Assign template variables
$this->context->smarty->assign([
'module_version' => $this->version,
'module_dir' => $this->_path,
'form_html' => $this->renderForm(),
'errors' => $errors,
Expand Down Expand Up @@ -696,32 +697,24 @@ public function hookActionDeleteGDPRCustomer($customer)
/**
* Hook executed before order validation
*
* Critical hook for third-party checkout modules (e.g., Prestahero)
* Blocks order creation if KYC verification is required but not approved
* In PrestaShop 8, this behavior is injected via a PaymentModule override.
* In future PrestaShop versions where a native "validate order before" hook is available,
* this method can be wired to that native hook.
* Blocks order creation if KYC verification is required but not approved.
*
* @param array $params Contains ['cart', 'order', 'customer']
*
* @return bool True to allow order, false to block
* @param array $params Contains ['cart', 'customer']
*/
public function hookActionValidateOrder($params)
public function hookActionValidateOrderBefore($params)
{
if (!isset($params['cart']) || !isset($params['customer'])) {
return true;
}

$cart = $params['cart'];
$customer = $params['customer'];
$cart = $params['cart'] ?? null;
$customer = $params['customer'] ?? null;

// Check if customer is a guest - allow guest checkout
if (!$customer->id || $customer->is_guest) {
return true;
if (!$cart || !$customer || !$customer->id || $customer->is_guest) {
return;
}

// Check if KYC is required for cart products
$kycRequired = $this->isKycRequiredForCart($cart);

if (!$kycRequired) {
return true;
if (!$this->isKycRequiredForCart($cart)) {
return;
}

// Get customer's verification status
Expand All @@ -734,25 +727,18 @@ public function hookActionValidateOrder($params)
return true;
Comment thread
vachmara marked this conversation as resolved.
Resolved
}

// KYC required but not approved - block order
// KYC required but not approved - redirect to verification page
// Log the event for debugging
PrestaShopLogger::addLog(
'KYC: Order blocked for customer ' . $customer->id . ' - verification required',
'KYC: Order blocked for customer ' . $customer->id . ' - verification required, redirecting to KYC page',
1,
null,
'Pskyc'
);

// Set error message in context
if (isset($this->context->controller)) {
$this->context->controller->errors[] = $this->trans(
'Identity verification is required before placing an order. Please complete the verification process.',
[],
'Modules.Pskyc.Shop'
);
}

return false;
// Redirect to KYC verification page
$kycUrl = $this->context->link->getModuleLink($this->name, 'verify', ['kyc_required' => 1], true);
Tools::redirect($kycUrl);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/PsKyc/Mock/ModuleFrontController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?php

/**
* MIT License
* Copyright (c) 2025 Valentin Chmara
*
* @author Valentin Chmara
* @copyright Valentin Chmara
* @license MIT
*/
class ModuleFrontController
{
public $ajax = false;
Expand Down
9 changes: 9 additions & 0 deletions tests/PsKyc/controllers/front/CronControllerFrontTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/**
* MIT License
* Copyright (c) 2025 Valentin Chmara
*
* @author Valentin Chmara
* @copyright Valentin Chmara
* @license MIT
*/

namespace Tests\PsKyc\Controller;

use Mockery;
Expand Down
9 changes: 9 additions & 0 deletions tests/PsKyc/controllers/front/VerifyControllerFrontTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/**
* MIT License
* Copyright (c) 2025 Valentin Chmara
*
* @author Valentin Chmara
* @copyright Valentin Chmara
* @license MIT
*/

namespace Tests\PsKyc\Controller;

use Mockery;
Expand Down
5 changes: 5 additions & 0 deletions translations/fr-FR/ModulesPskycAdmin.fr-FR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@
<target>Enregistrer les statuts des documents</target>
<note>Line: </note>
</trans-unit>
<trans-unit id="fbbddb052fd200e7d05593f6918e3ab3">
<source>Customer Note</source>
<target>Note client</target>
<note>Line: </note>
</trans-unit>
<trans-unit id="7cab5b2f456f909f541ec77334ba294d">
<source>Admin Notes</source>
<target>Notes administrateur</target>
Expand Down
Loading