Skip to content

Conversation

@davidperezgar
Copy link
Contributor

@davidperezgar davidperezgar commented Dec 22, 2025

Fixes webhook ID extraction to correctly handle different ID formats returned by CRM APIs, including:

  • Plain numeric IDs: 22222
  • Pipe-separated IDs with text prefixes: Lead 32132|Deal 22222
  • Single IDs with text prefixes: Deal 22222, Oportunidad 23123

Changes Made

🔧 Core Fix (helpers-functions.php)

  • Fixed ID extraction logic in formscrm_send_webhook() function
  • Replaced hardcoded str_replace('Deal ', '', $entry_id) with regex-based extraction
  • Now uses preg_replace('/\D/', '', $entry_raw) to extract only numeric characters
  • Fixed bug: now correctly uses $entry_raw variable instead of undefined $entry_id
  • Cast extracted ID to integer for proper data typing

✅ Tests Added (test-helpers-functions.php)

  • Added comprehensive unit test test_webhook_id_extraction()
  • Covers 5 test scenarios:
    • Plain numeric ID
    • Pipe-separated with English prefix
    • Single ID with English prefix
    • Single ID with Spanish prefix
    • Multiple pipe-separated IDs
  • Validates both value correctness and integer type casting

📝 Documentation

  • Updated plugin version
  • Added changelog entry in readme.txt

Benefits

  • Language-agnostic: Works with any language prefix (English "Deal", Spanish "Oportunidad", etc.)
  • Format-agnostic: Handles pipe-separated or single IDs
  • Type-safe: Properly casts to integer
  • Bug fix: Uses correct variable name
  • Test coverage: Comprehensive unit tests ensure reliability

Test Plan

Run the new unit tests:

composer test-debug --filter test_webhook_id_extraction

All test cases pass successfully.

@davidperezgar davidperezgar merged commit bbeffff into trunk Dec 22, 2025
6 checks passed
@davidperezgar davidperezgar deleted the hotfix-webhook branch December 22, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants