| @@ -8,8 +8,9 @@ | ||
| 8 | 8 | namespace BitCode\BitForm\Core\Integration; |
| 9 | 9 | |
| 10 | 10 | use BitCode\BitForm\Core\Database\FormEntryModel; |
| 11 | 11 | use BitCode\BitForm\Core\Database\FormModel; |
| 12 | +use BitCode\BitForm\Core\Util\ApiResponse; | |
| 12 | 13 | use BitCode\BitForm\Core\Util\SmartTags; |
| 13 | 14 | use BitCode\BitForm\Core\Util\Utilities; |
| 14 | 15 | /** |
| 15 | 16 | * Provides details of available integration and helps to |
| @@ -56,10 +57,10 @@ | ||
| 56 | 57 | |
| 57 | 58 | /** |
| 58 | 59 | * Checks a Integration Exists or not |
| 59 | 60 | * |
| 60 | - * @param String $name Name of Integration | |
| 61 | - * @return boolean | |
| 61 | + * @param string $name Name of Integration | |
| 62 | + * @return boolean | string | |
| 62 | 63 | */ |
| 63 | 64 | protected static function isExists($name) |
| 64 | 65 | { |
| 65 | 66 | $path = Utilities::getRealPath(__DIR__, $name); |
| @@ -87,11 +88,11 @@ | ||
| 87 | 88 | * This function helps to get single integration information |
| 88 | 89 | * |
| 89 | 90 | * @return bool setIntegration() |
| 90 | 91 | */ |
| 91 | - public function getIntegration($integartionBaseName) | |
| 92 | + public function getIntegration($integrationBaseName) | |
| 92 | 93 | { |
| 93 | - return $this->setIntegration($integartionBaseName); | |
| 94 | + return $this->setIntegration($integrationBaseName); | |
| 94 | 95 | } |
| 95 | 96 | |
| 96 | 97 | public function registerAjax() |
| 97 | 98 | { |
| @@ -97,14 +98,14 @@ | ||
| 97 | 98 | { |
| 98 | 99 | $dirs = new FilesystemIterator(__DIR__); |
| 99 | 100 | foreach ($dirs as $dirInfo) { |
| 100 | 101 | if ($dirInfo->isDir()) { |
| 101 | - $integartionBaseName = basename($dirInfo); | |
| 102 | + $integrationBaseName = basename($dirInfo); | |
| 102 | 103 | if ( |
| 103 | - file_exists(__DIR__ . '/' . $integartionBaseName) | |
| 104 | - && file_exists(__DIR__ . '/' . $integartionBaseName . '/' . $integartionBaseName . 'Handler.php') | |
| 104 | + file_exists(__DIR__ . '/' . $integrationBaseName) | |
| 105 | + && file_exists(__DIR__ . '/' . $integrationBaseName . '/' . $integrationBaseName . 'Handler.php') | |
| 105 | 106 | ) { |
| 106 | - $integration = __NAMESPACE__ . "\\{$integartionBaseName}\\{$integartionBaseName}Handler"; | |
| 107 | + $integration = __NAMESPACE__ . "\\{$integrationBaseName}\\{$integrationBaseName}Handler"; | |
| 107 | 108 | if (method_exists($integration, 'registerAjax')) { |
| 108 | 109 | $integration::registerAjax(); |
| 109 | 110 | // (new $integration(0, 0))->registerAjax(); |
| 110 | 111 | } |
| @@ -156,12 +157,12 @@ | ||
| 156 | 157 | |
| 157 | 158 | /** |
| 158 | 159 | * This function helps to execute Integration |
| 159 | 160 | * |
| 160 | - * @param Array $integrations List of integrstion to execute. | |
| 161 | + * @param array $integrations List of integration to execute. | |
| 161 | 162 | * Element will be json string like {"id":1} |
| 162 | - * @param Array $fieldValues Values of submitted fields | |
| 163 | - * @param Integer $formID ID of current form | |
| 163 | + * @param array $fieldValues Values of submitted fields | |
| 164 | + * @param integer $formID ID of current form | |
| 164 | 165 | * |
| 165 | 166 | * @return void Nothing to return |
| 166 | 167 | */ |
| 167 | 168 | public static function executeIntegrations($integrations, $fieldValues, $formID, $logID = null, $entryID = 0) |
| @@ -166,8 +167,9 @@ | ||
| 166 | 167 | */ |
| 167 | 168 | public static function executeIntegrations($integrations, $fieldValues, $formID, $logID = null, $entryID = 0) |
| 168 | 169 | { |
| 169 | 170 | $integrationHandler = new IntegrationHandler($formID); |
| 171 | + $logResponse = new ApiResponse(); | |
| 170 | 172 | if (is_array($integrations)) { |
| 171 | 173 | foreach ($integrations as $integrationIDStr) { |
| 172 | 174 | if (!is_string($integrationIDStr)) { |
| 173 | 175 | return; |
| @@ -177,8 +179,11 @@ | ||
| 177 | 179 | $integrationResult |
| 178 | 180 | = $integrationHandler->getAIntegration($integrationID); |
| 179 | 181 | $integrationDetails = is_wp_error($integrationResult) ? null : $integrationResult[0]; |
| 180 | 182 | $integrationName = is_null($integrationDetails) ? null : ucfirst(str_replace(' ', '', $integrationDetails->integration_type)); |
| 183 | + if ('Brevo(SendinBlue)' === $integrationName) { | |
| 184 | + $integrationName = 'SendinBlue'; | |
| 185 | + } | |
| 181 | 186 | if (!is_null($integrationName) && static::isExists($integrationName)) { |
| 182 | 187 | $integration = static::isExists($integrationName); |
| 183 | 188 | $handler = new $integration($integrationID, $formID); |
| 184 | 189 | $integDetails = is_string($integrationDetails->integration_details) ? json_decode($integrationDetails->integration_details) : $integrationDetails->integration_details; |
| @@ -186,8 +191,22 @@ | ||
| 186 | 191 | $sptagData = self::specialTagFields($integDetails->field_map); |
| 187 | 192 | $fieldValues = $fieldValues + $sptagData; |
| 188 | 193 | } |
| 189 | 194 | $handler->execute($integrationHandler, $integrationDetails, $fieldValues, $entryID, $logID); |
| 195 | + } else { | |
| 196 | + do_action('bitform_integration_run_failure', $integrationID, $formID); | |
| 197 | + | |
| 198 | + $errorMsg = apply_filters('bitform_filter_integration_run_failure_message', __('Integration execution failed', 'bit-form'), $integrationID, $formID); | |
| 199 | + | |
| 200 | + error_log('[+] Integration execution failed: ' . print_r($errorMsg, true)); | |
| 201 | + | |
| 202 | + $logResponse->apiResponse( | |
| 203 | + $logID, | |
| 204 | + $integrationID, | |
| 205 | + ['type' => 'record', 'type_name' => $integrationName || 'Integration'], | |
| 206 | + 'errors', | |
| 207 | + $errorMsg | |
| 208 | + ); | |
| 190 | 209 | } |
| 191 | 210 | } |
| 192 | 211 | } |
| 193 | 212 | } |