Quick implementation checklist
- Quick implementation checklist
- Treat the callback as a trust boundary
- Build a dedicated PrestaShop endpoint
- Authenticate the provider before mutation
- Bind the event to the right merchant, cart, and customer
- Validate transaction state, amount, and currency
- Make replay handling atomic and idempotent
- Create or transition the order once
- Return retry-safe responses
- Log, reconcile, and test hostile paths
- FAQ
- Sources
For each PrestaShop payment module callback:
- Require HTTPS.
- Use a dedicated module endpoint.
- Preserve the raw request body when the provider signs raw bytes.
- Enforce method and content-type rules.
- Limit body size and processing time.
- Verify the provider’s signature or token exactly as documented.
- Verify a signed timestamp only when the provider supplies one.
- Reject stale signed events using the provider’s documented tolerance.
- Allowlist supported event types.
- Confirm live/test environment and merchant account.
- Extract provider event ID and transaction ID.
- Resolve the intended cart/order using a server-issued reference.
- Verify cart ownership/secure key before order creation.
- Compare external amount and currency.
- Confirm the payment module is active and valid for the context.
- Deduplicate event ID atomically.
- Prevent concurrent creation for the same cart or transaction.
- Call
validateOrder()only when its invariants are satisfied. - Apply each payment transition once.
- Return success only for accepted or already-applied events.
- Return provider-appropriate retryable or terminal failures.
- Store redacted evidence and reconcile with the provider.
- Test valid, invalid, duplicate, concurrent, reordered, and delayed events.
The PrestaShop payment module callback must not trust a customer return URL, a cart ID, an amount, or a status merely because it arrived in an HTTP request.
Treat the callback as a trust boundary
A payment flow normally has separate actors:
| Path | Sender | Purpose |
|---|---|---|
| Checkout request | Shopper/store | Start payment |
| Browser return | Shopper browser | Restore customer UX |
| Callback/webhook | Provider server | Deliver payment state |
| Reconciliation query | Store to provider | Recover or confirm state |
The browser can close, refresh, replay history, or alter unsigned parameters.
The provider can retry a callback because:
- Your endpoint timed out.
- Your response was lost.
- Your endpoint returned an error.
- Delivery is at least once.
- Events arrived out of order.
Design for:
- Authentication
- Input validation
- Deduplication
- Concurrency
- Reordering
- Partial failure
- Reconciliation
Do not place payment truth in the shopper’s session alone.
Build a dedicated PrestaShop endpoint
PrestaShop front-controller documentation explains how modules expose front-office controllers and can require SSL.
Use a dedicated module front controller or the module architecture required by the provider integration.
Endpoint controls
Define:
- Allowed method, normally the provider’s documented method
- Allowed content type
- Maximum body size
- Short network timeout
- HTTPS
- No full-page cache
- No browser redirect requirement
- No CSRF assumption designed for a logged-in shopper
- Provider-specific authentication
A callback is often intentionally reachable without a customer session. That does not make it unauthenticated: authenticity comes from the provider’s documented signature, token, mTLS, or equivalent control.
Keep the browser return separate
The browser return can:
- Show a pending page.
- Poll a safe order-status endpoint.
- Direct the customer to order history.
- Display a reference.
It should not:
- Trust an unsigned
paid=true. - Capture again.
- Create another order.
- Reveal callback validation details.
- Leak a cart secure key.
Preserve the raw body
Some providers sign the exact raw payload.
Middleware can break verification by:
- Parsing and reserializing JSON
- Changing whitespace
- Normalizing line endings
- Converting character encoding
- Reading a stream twice
Stripe’s webhook documentation is one provider example that requires the raw request body for signature verification. Use the selected provider’s rule.
Authenticate the provider before mutation
Perform authentication before creating an order, updating state, sending email, or granting access.
Use the documented verifier
Prefer:
- Provider SDK verifier
- Documented HMAC/public-key routine
- Constant-time comparison for MAC values
- Rotatable secret/key lookup
Do not invent:
- Header names
- Hash algorithm
- String-to-sign
- JSON canonicalization
- Timestamp tolerance
Signed timestamp and replay window
If the provider includes a timestamp in the signed material:
- Parse it strictly.
- Verify it as part of the signature.
- Apply the provider’s recommended tolerance.
- Use a calibrated server clock.
- Do not replace event deduplication with a timestamp window.
Stripe’s signature guidance explains one implementation where a signed timestamp helps mitigate replay. This is not a universal format.
Secret rotation
Support the provider’s actual rotation model:
- Current secret
- Temporary previous secret when documented
- Key ID/version where supplied
- Explicit retirement time
- Audit of which verifier accepted the event
Never log the secret or expected signature.
IP allowlisting is supplemental
An IP list can reduce noise where the provider publishes stable ranges. It does not replace:
- Signature verification
- Amount/currency checks
- Event deduplication
- Transaction reconciliation
Proxies and provider infrastructure can change network evidence.
Invalid authentication
For invalid signatures/tokens:
- Make no payment or order mutation.
- Log a redacted reason and request correlation ID.
- Return the provider-appropriate terminal response.
- Alert on spikes.
Do not return a detailed cryptographic error to the caller.
Bind the event to the right merchant, cart, and customer
Authentication proves who signed the event. It does not prove the event belongs to this cart, shop, environment, or amount.
Allowlist event types
Accept only the event types implemented by the module.
Map provider states explicitly:
- Created
- Pending/processing
- Authorized
- Captured/paid
- Failed
- Canceled
- Reversed
- Refunded
- Disputed
Names and semantics vary by provider.
Unknown event types should not create a paid order.
Verify environment and merchant
Compare:
- Live versus sandbox
- Merchant/account ID
- Application ID
- Endpoint secret/key ID
- Shop or multishop context
A valid event for another merchant account is still wrong for this module instance.
Use a server-issued correlation value
Correlate using:
- Provider transaction/payment ID
- Provider event ID
- Module-generated merchant reference
- PrestaShop cart ID stored in provider metadata
- Server-side mapping record
Do not resolve by:
- Email alone
- Browser cookie alone
- Customer-supplied order reference alone
Verify cart ownership
PrestaShop payment-module documentation warns that before creating the order, a module must make sure another customer cannot validate a cart that is not theirs.
Verify:
- Cart exists.
- Cart belongs to the expected customer/guest context.
- Secure key or equivalent server-side correlation matches.
- Cart has not already produced the intended order.
- Shop/context is correct.
- Module is available for the currency/context.
Do not accept a secure_key merely because it is present in the payload; compare it to trusted server-side state.
Validate transaction state, amount, and currency
Query provider truth where needed
A callback may contain enough signed data, or the provider may require an authenticated API fetch.
Use provider truth to confirm:
- Transaction exists.
- State is eligible for the intended transition.
- Amount
- Currency
- Merchant
- Environment
- Order reference
- Authorization versus capture
- Partial payment/refund
Amount must come from the external payment system
PrestaShop’s payment-module documentation explicitly says the amount supplied to validateOrder() should come from the external payment system, not simply from Cart->getOrderTotal().
That does not mean ignoring the cart.
Compare:
- External amount
- Expected cart/order amount
- Currency
- Tax/shipping/discount result
- Rounding and exponent rules
- Partial-capture policy
On mismatch:
- Do not silently mark paid.
- Preserve evidence.
- Move to a reviewed state if the provider/module design supports it.
- Reconcile before fulfillment.
Use decimal/minor-unit-safe comparison
Avoid binary floating-point equality for money.
Use:
- Provider minor units when supplied
- Currency exponent rules
- Decimal/money type
- Explicit rounding policy
Never assume every currency has two decimal places.
Semantic validation
OWASP Input Validation guidance recommends syntactic and semantic validation.
Validate:
- Required fields
- Type and length
- Character set/format
- Enum allowlists
- Identifier shape
- Positive/allowed money range
- Valid currency
- Business transition
Schema-valid JSON can still request an invalid payment transition.
Make replay handling atomic and idempotent
Signature verification does not stop an authenticated event from being delivered twice.
Choose stable keys
Store:
- Provider account
- Environment
- Event ID
- Event type
- Transaction/payment ID
- Cart/order ID
- Payload hash, excluding secrets
- First-seen and processed timestamps
- Processing result
- Applied transition/version
Use a unique database constraint for the provider/account/event ID when the provider guarantees event-ID uniqueness in that scope.
Exact duplicate
If the same authenticated event was already applied:
- Do not call
validateOrder()again. - Do not create another payment/order.
- Do not send duplicate email.
- Return the provider’s accepted response.
- Record the duplicate delivery.
Stripe, for example, advises tracking event IDs to identify duplicate deliveries.
Same ID, different payload
Treat this as an anomaly:
- Do not overwrite the accepted record.
- Do not apply the mutation.
- Preserve both hashes safely.
- Alert and investigate.
Same transaction, different event
Providers can emit multiple legitimate events for one transaction.
The transition engine must decide whether each event:
- Advances state
- Confirms current state
- Is stale
- Conflicts
- Requires review
Do not deduplicate solely by transaction ID if event types legitimately differ.
Concurrency
Two valid retries can arrive at the same time.
Protect the critical section with:
- Unique constraints
- Transactional event claim
- Row/version lock
- Compare-and-set state transition
Use the minimum lock scope needed for:
- Claim event.
- Re-read cart/order/payment state.
- Apply one transition.
- Persist evidence.
- Commit.
External API calls inside a long database transaction can increase contention. Fetch/verify provider state before the short mutation transaction when the threat model and provider flow allow it.
Create or transition the order once
Before validateOrder()
Confirm:
- Authenticated event
- Supported event/state
- Correct merchant/environment
- Correct cart/customer/secure key
- External amount and currency
- No existing intended order
- No conflicting processed event
- Module/context available
Then call the supported PrestaShop payment-module API.
Do not:
- Insert order rows directly.
- Call
validateOrder()on every retry. - Use the browser return as the callback.
- Pass an unverified request amount.
Order lifecycle
PrestaShop’s order-lifecycle documentation explains the cart-to-order lifecycle.
Map provider events to explicit module/order behavior:
| Provider result | Typical module decision |
|---|---|
| Created/pending | Keep pending; no paid fulfillment |
| Authorized | Use configured authorization state |
| Captured/paid | Apply paid state once |
| Failed/canceled | Apply failure/cancel behavior where appropriate |
| Refunded/reversed | Reconcile before applying refund/reversal state |
| Unknown/conflicting | Hold for reconciliation |
“Typical” is not a universal status mapping. Use module configuration and store policy.
OrderState
PrestaShop OrderState domain documentation describes the order-state domain used to manage states.
State changes can trigger:
- Invoice behavior
- Stock behavior
- Download/fulfillment
- Accounting effects
Do not change state solely to make the back office look correct.
Existing order
If the order already exists:
- Match it to the cart/transaction.
- Verify current state.
- Apply only a valid forward/reconciliation transition.
- Avoid another
validateOrder(). - Avoid duplicate payment records.
Use supported PrestaShop/module APIs, not direct SQL.
Return retry-safe responses
Define a response matrix from provider documentation.
Accepted
Return the provider’s expected success when:
- Event is authenticated.
- Event is accepted and persisted/applied.
- Exact duplicate was already applied successfully.
Terminal rejection
Use the provider-appropriate non-retry response for:
- Invalid authentication
- Unsupported event
- Wrong merchant/environment
- Malformed request
- Permanent business mismatch
Some providers retry all non-success responses; confirm behavior.
Transient failure
Use a retryable failure when:
- Database unavailable
- Lock timeout
- Temporary provider lookup failure
- Internal processing exception
Do not return success before durable event claim/application unless the design deliberately queues the authenticated event durably.
Fast acknowledgement
If work exceeds provider timeout:
- Authenticate.
- Validate minimum envelope.
- Claim/store event durably.
- Return success.
- Process asynchronously.
The queue consumer must use the same idempotency and state rules.
Safe response body
Return a minimal body.
Do not reveal:
- Signature calculation
- Secret/key ID internals
- Customer data
- Cart secure key
- Provider payload
- Stack trace
Log, reconcile, and test hostile paths
Structured evidence
Log:
- Internal request ID
- Provider/account/environment
- Event ID/type
- Transaction ID, redacted where needed
- Cart/order ID
- Signature result category, not secret
- Amount/currency comparison
- Deduplication result
- Previous/new state
- Response class
- Latency
Do not log:
- Secrets
- Full authorization headers
- Card data
- CVV
- Customer password
- Raw unredacted payload by default
Reconciliation
Run a scheduled comparison for:
- Provider paid but no PrestaShop order
- PrestaShop paid but provider not paid
- Amount/currency mismatch
- Duplicate transaction
- Callback permanently failed
- Event received but not applied
- Order stuck pending
PatSaTECH’s webhook monitoring guide covers event-delivery evidence. Adapt it to the PrestaShop module and provider.
Test matrix
Authentication
- Valid current secret/key
- Valid previous key during approved overlap
- Invalid signature
- Missing signature
- Altered body
- Wrong endpoint secret
- Old signed timestamp
- Future timestamp outside tolerance
Identity
- Wrong merchant
- Wrong environment
- Unknown cart
- Wrong customer/secure key
- Cart already ordered
- Wrong shop context
Money
- Exact amount/currency
- Amount mismatch
- Currency mismatch
- Zero/negative
- High value
- Three-decimal or zero-decimal currency
- Partial authorization/capture
Replay and order
- Exact duplicate
- Concurrent duplicate
- Same event ID/different payload
- Same transaction/different events
- Events out of order
- Delayed event after cancellation
- Refund before local paid state
Failure
- Database outage
- Lock timeout
- Queue outage
- Provider API timeout
- Email failure after order commit
- Response lost after commit
Assertions
- One event claim
- One order per intended cart/payment
- One valid payment transition
- Correct amount/currency
- Correct order state
- No duplicate email/stock/fulfillment
- Retry-safe response
- Redacted evidence
Use the actual provider sandbox and module version.
For product-specific setup context, see NMI Collect.js for PrestaShop. For architecture decisions, see payment gateway plugin versus custom integration.
FAQ
Can the customer return URL create the paid order?
Only if the provider/module contract authenticates and validates that return as payment evidence. A browser redirect alone is not proof.
Is signature verification enough?
No. Also verify merchant/environment, event type, transaction state, cart ownership, amount, currency, idempotency, and allowed state transition.
Should I calculate the validateOrder() amount from the cart?
PrestaShop says the amount passed to validateOrder() should come from the external payment system. Compare it with trusted cart expectations and reconcile mismatches.
How should duplicate callbacks respond?
If the same authenticated event already completed successfully, do no mutation and return the provider’s expected accepted response.
Should every callback return HTTP 200?
No. Define accepted, terminal, and retryable outcomes from the provider contract. Returning success for an unprocessed transient failure can lose payment state.
Can I use IP allowlisting instead of a signature?
No. Treat network allowlisting as supplemental when the provider supports it.
What if two callbacks arrive at once?
Use atomic event claiming, unique constraints, and a short transactional state transition so only one applies.
Can I directly update PrestaShop order tables?
Avoid direct SQL. Use supported PrestaShop/module APIs so order history and side effects remain consistent.
How do I safely replay a callback?
Use the provider’s supported redelivery tool where available. Never fabricate a payload or bypass authentication. The callback must remain idempotent.
Sources
Primary sources accessed September 20, 2026:
- PrestaShop 9 — Payment modules
- PrestaShop 9 — Front controllers
- PrestaShop 9 — Orders lifecycle
- PrestaShop 9 — OrderState domain
- Stripe — Receive events in a webhook endpoint
- Stripe — Resolve webhook signature verification errors
- OWASP — Input Validation Cheat Sheet
- OWASP — Web Service Security Cheat Sheet
This article provides general implementation guidance. Provider signatures, event formats, retry rules, timestamp tolerances, payment states, and PrestaShop module behavior vary; follow current provider and PrestaShop documentation and test in a sandbox.













