@@ -141,7 +141,7 @@ public function createCase($finalData, $actionsData)
141141 $ apiEndpoint = $ this ->_apiDomain . '/services/data/v37.0/sobjects/Case ' ;
142142
143143 foreach ($ actionsData as $ key => $ value ) {
144- if (! empty ($ value )) {
144+ if (isset ($ value )) {
145145 $ finalData [$ key ] = $ value ;
146146 }
147147 }
@@ -158,12 +158,15 @@ public function execute($integrationDetails, $fieldValues, $fieldMap, $actions)
158158 $ finalData = $ this ->generateReqDataFromFieldMap ($ fieldValues , $ fieldMap );
159159 $ response = $ this ->insertContact ($ finalData , $ update );
160160
161- $ responseType = empty ($ response ) || (\is_object ($ response ) && isset ($ response ->id )) ? 'success ' : 'error ' ;
161+ $ responseType = ! \is_null ($ response ) || (\is_object ($ response ) && isset ($ response ->id )) ? 'success ' : 'error ' ;
162162 $ typeName = !$ update || (\is_object ($ response ) && isset ($ response ->id )) ? 'Contact-create ' : 'Contact-update ' ;
163- $ message = $ responseType === 'success ' ? wp_json_encode (wp_sprintf (__ ('Created contact id is : %s ' , 'bit-integrations ' ), $ response ->id )) : wp_json_encode ($ response );
163+
164+ $ message = wp_json_encode ($ response );
164165
165166 if ($ responseType === 'success ' && $ update ) {
166167 $ message = __ ('Contact Updated Successfully ' , 'bit-integrations ' );
168+ } elseif ($ responseType === 'success ' ) {
169+ $ message = wp_json_encode (wp_sprintf (__ ('Created contact id is : %s ' , 'bit-integrations ' ), $ response ->id ));
167170 }
168171
169172 LogHandler::save ($ this ->_integrationID , wp_json_encode (['type ' => 'Contact ' , 'type_name ' => $ typeName ]), $ responseType , $ message );
@@ -182,10 +185,10 @@ public function execute($integrationDetails, $fieldValues, $fieldMap, $actions)
182185 } elseif ($ actionName === 'account-create ' ) {
183186 $ finalData = $ this ->generateReqDataFromFieldMap ($ fieldValues , $ fieldMap );
184187
185- if (! empty ($ actions ->selectedAccType )) {
188+ if (isset ($ actions ->selectedAccType )) {
186189 $ finalData ['Type ' ] = $ actions ->selectedAccType ;
187190 }
188- if (! empty ($ actions ->selectedOwnership )) {
191+ if (isset ($ actions ->selectedOwnership )) {
189192 $ finalData ['Ownership ' ] = $ actions ->selectedOwnership ;
190193 }
191194
@@ -206,33 +209,33 @@ public function execute($integrationDetails, $fieldValues, $fieldMap, $actions)
206209 }
207210 } elseif ($ actionName === 'add-campaign-member ' ) {
208211 $ campaignId = $ integrationDetails ->campaignId ;
209- $ leadId = empty ($ integrationDetails ->leadId ) ? null : $ integrationDetails ->leadId ;
210- $ contactId = empty ($ integrationDetails ->contactId ) ? null : $ integrationDetails ->contactId ;
211- $ statusId = empty ($ integrationDetails ->statusId ) ? null : $ integrationDetails ->statusId ;
212+ $ leadId = isset ($ integrationDetails ->leadId ) ? $ integrationDetails ->leadId : null ;
213+ $ contactId = isset ($ integrationDetails ->contactId ) ? $ integrationDetails ->contactId : null ;
214+ $ statusId = isset ($ integrationDetails ->statusId ) ? $ integrationDetails ->statusId : null ;
212215 $ insertCampaignMember = $ this ->insertCampaignMember ($ campaignId , $ leadId , $ contactId , $ statusId );
213216 if (\is_object ($ insertCampaignMember ) && property_exists ($ insertCampaignMember , 'id ' )) {
214217 LogHandler::save ($ this ->_integrationID , wp_json_encode (['type ' => 'CampaignMember ' , 'type_name ' => 'CampaignMember-create ' ]), 'success ' , wp_json_encode (wp_sprintf (__ ('Created campaign member id is : %s ' , 'bit-integrations ' ), $ insertCampaignMember ->id )));
215218 } else {
216219 LogHandler::save ($ this ->_integrationID , wp_json_encode (['type ' => 'CampaignMember ' , 'type_name ' => 'CampaignMember-create ' ]), 'error ' , wp_json_encode ($ insertCampaignMember ));
217220 }
218221 } elseif ($ actionName === 'task-create ' ) {
219- $ contactId = empty ($ integrationDetails ->contactId ) ? null : $ integrationDetails ->contactId ;
220- $ accountId = empty ($ integrationDetails ->accountId ) ? null : $ integrationDetails ->accountId ;
222+ $ contactId = isset ($ integrationDetails ->contactId ) ? $ integrationDetails ->contactId : null ;
223+ $ accountId = isset ($ integrationDetails ->accountId ) ? $ integrationDetails ->accountId : null ;
221224 $ subjectId = $ integrationDetails ->subjectId ;
222225 $ priorityId = $ integrationDetails ->priorityId ;
223- $ statusId = empty ($ integrationDetails ->statusId ) ? null : $ integrationDetails ->statusId ;
226+ $ statusId = isset ($ integrationDetails ->statusId ) ? $ integrationDetails ->statusId : null ;
224227 $ apiResponse = $ this ->createTask ($ contactId , $ accountId , $ subjectId , $ priorityId , $ statusId );
225228 if (\is_object ($ apiResponse ) && property_exists ($ apiResponse , 'id ' )) {
226229 LogHandler::save ($ this ->_integrationID , wp_json_encode (['type ' => 'Task ' , 'type_name ' => 'Task-create ' ]), 'success ' , wp_json_encode (wp_sprintf (__ ('Created task id is : %s ' , 'bit-integrations ' ), $ apiResponse ->id )));
227230 } else {
228231 LogHandler::save ($ this ->_integrationID , wp_json_encode (['type ' => 'Task ' , 'type_name ' => 'Task-create ' ]), 'error ' , wp_json_encode ($ apiResponse ));
229232 }
230233 } elseif ($ actionName === 'opportunity-create ' ) {
231- $ opportunityTypeId = empty ($ actions ->opportunityTypeId ) ? null : $ actions ->opportunityTypeId ;
232- $ opportunityStageId = empty ($ actions ->opportunityStageId ) ? null : $ actions ->opportunityStageId ;
233- $ opportunityLeadSourceId = empty ($ actions ->opportunityLeadSourceId ) ? null : $ actions ->opportunityLeadSourceId ;
234- $ accountId = empty ($ actions ->accountId ) ? null : $ actions ->accountId ;
235- $ campaignId = empty ($ actions ->campaignId ) ? null : $ actions ->campaignId ;
234+ $ opportunityTypeId = isset ($ actions ->opportunityTypeId ) ? $ actions ->opportunityTypeId : null ;
235+ $ opportunityStageId = isset ($ actions ->opportunityStageId ) ? $ actions ->opportunityStageId : null ;
236+ $ opportunityLeadSourceId = isset ($ actions ->opportunityLeadSourceId ) ? $ actions ->opportunityLeadSourceId : null ;
237+ $ accountId = isset ($ actions ->accountId ) ? $ actions ->accountId : null ;
238+ $ campaignId = isset ($ actions ->campaignId ) ? $ actions ->campaignId : null ;
236239 $ finalData = $ this ->generateReqDataFromFieldMap ($ fieldValues , $ fieldMap );
237240 $ opportunityResponse = $ this ->createOpportunity ($ finalData , $ opportunityTypeId , $ opportunityStageId , $ opportunityLeadSourceId , $ accountId , $ campaignId );
238241 if (\is_object ($ opportunityResponse ) && property_exists ($ opportunityResponse , 'id ' )) {
@@ -241,9 +244,9 @@ public function execute($integrationDetails, $fieldValues, $fieldMap, $actions)
241244 LogHandler::save ($ this ->_integrationID , wp_json_encode (['type ' => 'Opportunity ' , 'type_name ' => 'Opportunity-create ' ]), 'error ' , wp_json_encode ($ opportunityResponse ));
242245 }
243246 } elseif ($ actionName === 'event-create ' ) {
244- $ contactId = empty ($ actions ->contactId ) ? null : $ actions ->contactId ;
245- $ accountId = empty ($ actions ->accountId ) ? null : $ actions ->accountId ;
246- $ eventSubjectId = empty ($ actions ->eventSubjectId ) ? null : $ actions ->eventSubjectId ;
247+ $ contactId = isset ($ actions ->contactId ) ? $ actions ->contactId : null ;
248+ $ accountId = isset ($ actions ->accountId ) ? $ actions ->accountId : null ;
249+ $ eventSubjectId = isset ($ actions ->eventSubjectId ) ? $ actions ->eventSubjectId : null ;
247250 $ finalData = $ this ->generateReqDataFromFieldMap ($ fieldValues , $ fieldMap );
248251 $ createEventResponse = $ this ->createEvent ($ finalData , $ contactId , $ accountId , $ eventSubjectId );
249252 if (\is_object ($ createEventResponse ) && property_exists ($ createEventResponse , 'id ' )) {
@@ -252,15 +255,15 @@ public function execute($integrationDetails, $fieldValues, $fieldMap, $actions)
252255 LogHandler::save ($ this ->_integrationID , wp_json_encode (['type ' => 'Event ' , 'type_name ' => 'Event-create ' ]), 'error ' , wp_json_encode ($ createEventResponse ));
253256 }
254257 } elseif ($ actionName === 'case-create ' ) {
255- $ actionsData ['ContactId ' ] = empty ($ actions ->contactId ) ? null : $ actions ->contactId ;
256- $ actionsData ['AccountId ' ] = empty ($ actions ->accountId ) ? null : $ actions ->accountId ;
257- $ actionsData ['Status ' ] = empty ($ actions ->caseStatusId ) ? null : $ actions ->caseStatusId ;
258- $ actionsData ['Origin ' ] = empty ($ actions ->caseOriginId ) ? null : $ actions ->caseOriginId ;
259- $ actionsData ['Priority ' ] = empty ($ actions ->casePriorityId ) ? null : $ actions ->casePriorityId ;
260- $ actionsData ['Reason ' ] = empty ($ actions ->caseReason ) ? null : $ actions ->caseReason ;
261- $ actionsData ['Type ' ] = empty ($ actions ->caseType ) ? null : $ actions ->caseType ;
262- $ actionsData ['PotentialLiability__c ' ] = empty ($ actions ->potentialLiabilityId ) ? null : $ actions ->potentialLiabilityId ;
263- $ actionsData ['SLAViolation__c ' ] = empty ($ actions ->slaViolationId ) ? null : $ actions ->slaViolationId ;
258+ $ actionsData ['ContactId ' ] = isset ($ actions ->contactId ) ? $ actions ->contactId : null ;
259+ $ actionsData ['AccountId ' ] = isset ($ actions ->accountId ) ? $ actions ->accountId : null ;
260+ $ actionsData ['Status ' ] = isset ($ actions ->caseStatusId ) ? $ actions ->caseStatusId : null ;
261+ $ actionsData ['Origin ' ] = isset ($ actions ->caseOriginId ) ? $ actions ->caseOriginId : null ;
262+ $ actionsData ['Priority ' ] = isset ($ actions ->casePriorityId ) ? $ actions ->casePriorityId : null ;
263+ $ actionsData ['Reason ' ] = isset ($ actions ->caseReason ) ? $ actions ->caseReason : null ;
264+ $ actionsData ['Type ' ] = isset ($ actions ->caseType ) ? $ actions ->caseType : null ;
265+ $ actionsData ['PotentialLiability__c ' ] = isset ($ actions ->potentialLiabilityId ) ? $ actions ->potentialLiabilityId : null ;
266+ $ actionsData ['SLAViolation__c ' ] = isset ($ actions ->slaViolationId ) ? $ actions ->slaViolationId : null ;
264267
265268 $ finalData = $ this ->generateReqDataFromFieldMap ($ fieldValues , $ fieldMap );
266269 $ createCaseResponse = $ this ->createCase ($ finalData , $ actionsData );
@@ -296,18 +299,14 @@ public static function convertToSalesforceFormat($input)
296299 return $ input ;
297300 }
298301
299- if (is_numeric ($ input )) {
300- return $ input ;
301-
302- // ------------------------------------------------------------
303- // 1) Handle UNIX timestamps (10 or 13 digits)
304- // ------------------------------------------------------------
305- if (\strlen ($ input ) === 10 && preg_match ('/^\d{10}$/ ' , $ input )) {
306- return gmdate ('Y-m-d\TH:i:s\Z ' , (int ) $ input );
307- }
308- if (\strlen ($ input ) === 13 && preg_match ('/^\d{13}$/ ' , $ input )) {
309- return gmdate ('Y-m-d\TH:i:s\Z ' , (int ) ($ input / 1000 ));
310- }
302+ // ------------------------------------------------------------
303+ // 1) Handle UNIX timestamps (10 or 13 digits)
304+ // ------------------------------------------------------------
305+ if (self ::validateNumericDateWithLength ($ input , 10 )) {
306+ return gmdate ('Y-m-d\TH:i:s\Z ' , (int ) $ input );
307+ }
308+ if (self ::validateNumericDateWithLength ($ input , 13 )) {
309+ return gmdate ('Y-m-d\TH:i:s\Z ' , (int ) ($ input / 1000 ));
311310 }
312311
313312 // ------------------------------------------------------------
@@ -364,7 +363,7 @@ public static function convertToSalesforceFormat($input)
364363 // ------------------------------------------------------------
365364 // 7) Compact numeric formats (01022025, 20250201, 250201, 010225)
366365 // ------------------------------------------------------------
367- if (\strlen ($ clean) === 8 && preg_match ( ' /^\d{8}$/ ' , $ clean )) {
366+ if (self :: validateNumericDateWithLength ($ clean, 8 )) {
368367 // YYYYMMDD or DDMMYYYY or MMDDYYYY → try multiple interpretations
369368 $ candidates = [
370369 substr ($ clean , 0 , 4 ) . '- ' . substr ($ clean , 4 , 2 ) . '- ' . substr ($ clean , 6 , 2 ), // YMD
@@ -377,7 +376,7 @@ public static function convertToSalesforceFormat($input)
377376 }
378377 }
379378
380- if (\strlen ($ clean) === 6 && preg_match ( ' /^\d{6}$/ ' , $ clean )) {
379+ if (self :: validateNumericDateWithLength ($ clean, 6 )) {
381380 // DDMMYY / YYMMDD / MMDDYY
382381 $ yy = \intval (substr ($ clean , -2 ));
383382
@@ -449,4 +448,9 @@ private static function tryParseDateTimeImmutable($value)
449448 return ;
450449 }
451450 }
451+
452+ private static function validateNumericDateWithLength ($ input , $ length )
453+ {
454+ return is_numeric ($ input ) && \strlen ($ input ) === $ length ;
455+ }
452456}
0 commit comments