Skip to content

Commit bbeffff

Browse files
Merge pull request #140 from closemarketing/hotfix-webhook
Fix webhook ID extraction to handle multiple formats
2 parents 56d4abe + 205cdf2 commit bbeffff

File tree

4 files changed

+81
-10
lines changed

4 files changed

+81
-10
lines changed

formscrm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: FormsCRM
44
* Plugin URI : https://close.technology/wordpress-plugins/formscrm/
55
* Description: Connects Forms with CRM, ERP and Email Marketing.
6-
* Version: 4.2.0
6+
* Version: 4.2.1
77
* Author: CloseTechnology
88
* Author URI: https://close.technology
99
* Text Domain: formscrm
@@ -23,7 +23,7 @@
2323

2424
defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
2525

26-
define( 'FORMSCRM_VERSION', '4.2.0' );
26+
define( 'FORMSCRM_VERSION', '4.2.1' );
2727
define( 'FORMSCRM_PLUGIN', __FILE__ );
2828
define( 'FORMSCRM_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
2929
define( 'FORMSCRM_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );

includes/formscrm-library/helpers-functions.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,19 +404,19 @@ function formscrm_send_webhook( $settings, $response ) {
404404
if ( ! $webhook_url ) {
405405
return;
406406
}
407-
$module = isset( $response['module'] ) ? $response['module'] : '';
408-
$ids = isset( $response['id'] ) ? $response['id'] : '';
409-
$ids = explode( '|', $ids );
410-
$entry_id = end( $ids );
411-
$entry_id = str_replace( 'Deal ', '', $entry_id );
407+
$module = isset( $response['module'] ) ? $response['module'] : '';
408+
$ids = isset( $response['id'] ) ? $response['id'] : '';
409+
$ids = explode( '|', $ids );
410+
$entry_raw = end( $ids );
411+
$entry_id = preg_replace( '/\D/', '', $entry_raw );
412412

413413
$body = array(
414414
'hook' => array(
415415
'event' => $module . '.saved',
416416
'target' => $webhook_url,
417417
),
418418
'data' => array(
419-
'id' => $entry_id,
419+
'id' => (int) $entry_id,
420420
),
421421
);
422422
$response = wp_remote_post(

readme.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Tags: gravityforms, wpforms, crm, vtiger, odoo
44
Donate link: https://close.marketing/go/donate/
55
Requires at least: 5.5
66
Tested up to: 6.9
7-
Stable tag: 4.2.0
8-
Version: 4.2.0
7+
Stable tag: 4.2.1
8+
Version: 4.2.1
99
License: GPL2
1010
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1111

@@ -130,6 +130,9 @@ WordPress installation and then activate the Plugin from Plugins page.
130130
[Official Repository GitHub](https://github.com/closemarketing/formscrm/)
131131

132132
== Changelog ==
133+
= 4.2.1 =
134+
* Hotfix: Error not sending correctly entry id in webhook.
135+
133136
= 4.2.0 =
134137
* Enhanced: New design for the settings page.
135138
* Dedicated menu for FormsCRM settings.

tests/Unit/test-helpers-functions.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,74 @@ public function test_webhook_post_no_url() {
9595
$this->assertNull( $response );
9696
}
9797

98+
/**
99+
* Test formscrm_send_webhook ID extraction from different formats.
100+
*
101+
* Test that the function correctly extracts numeric ID from:
102+
* - Plain number: '22222'
103+
* - Pipe-separated with text: 'Lead 32132|Deal 22222'
104+
* - Text prefix: 'Deal 22222'
105+
* - Spanish text prefix: 'Oportunidad 22222'
106+
*/
107+
public function test_webhook_id_extraction() {
108+
$settings = array( 'fc_crm_webhook' => 'https://webhook.com/test' );
109+
110+
// Test Case 1: Plain numeric ID.
111+
$response_api = array(
112+
'status' => 'ok',
113+
'message' => 'success',
114+
'module' => 'deal',
115+
'id' => '22222',
116+
);
117+
$response = formscrm_send_webhook( $settings, $response_api );
118+
$this->assertEquals( 22222, $response['request']['data']['id'] );
119+
$this->assertIsInt( $response['request']['data']['id'] );
120+
121+
// Test Case 2: Pipe-separated IDs with text prefix (Lead 32132|Deal 22222).
122+
$response_api = array(
123+
'status' => 'ok',
124+
'message' => 'success',
125+
'module' => 'deal',
126+
'id' => 'Lead 32132|Deal 22222',
127+
);
128+
$response = formscrm_send_webhook( $settings, $response_api );
129+
$this->assertEquals( 22222, $response['request']['data']['id'] );
130+
$this->assertIsInt( $response['request']['data']['id'] );
131+
132+
// Test Case 3: Single ID with text prefix (Deal 22222).
133+
$response_api = array(
134+
'status' => 'ok',
135+
'message' => 'success',
136+
'module' => 'deal',
137+
'id' => 'Deal 22222',
138+
);
139+
$response = formscrm_send_webhook( $settings, $response_api );
140+
$this->assertEquals( 22222, $response['request']['data']['id'] );
141+
$this->assertIsInt( $response['request']['data']['id'] );
142+
143+
// Test Case 4: Spanish text prefix (Oportunidad 22222).
144+
$response_api = array(
145+
'status' => 'ok',
146+
'message' => 'success',
147+
'module' => 'deal',
148+
'id' => 'Oportunidad 22222',
149+
);
150+
$response = formscrm_send_webhook( $settings, $response_api );
151+
$this->assertEquals( 22222, $response['request']['data']['id'] );
152+
$this->assertIsInt( $response['request']['data']['id'] );
153+
154+
// Test Case 5: Multiple pipe-separated with different numbers.
155+
$response_api = array(
156+
'status' => 'ok',
157+
'message' => 'success',
158+
'module' => 'deal',
159+
'id' => 'Contact 11111|Lead 99999|Deal 22222',
160+
);
161+
$response = formscrm_send_webhook( $settings, $response_api );
162+
$this->assertEquals( 22222, $response['request']['data']['id'] );
163+
$this->assertIsInt( $response['request']['data']['id'] );
164+
}
165+
98166
/**
99167
* Test formscrm_debug_message with WP_DEBUG enabled.
100168
*/

0 commit comments

Comments
 (0)