| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Core\Util; |
| 4 |
|
| 5 |
use BitCode\BitForm\Core\Database\FormEntryLogModel; |
| 6 |
|
| 7 |
final class ApiResponse |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Log API response |
| 11 |
* |
| 12 |
* @param int $logID |
| 13 |
* @param int $integrationId |
| 14 |
* @param array $apiType |
| 15 |
* @param string $responseType |
| 16 |
* @param mixed $apiResponse |
| 17 |
* @param array $entryDetails = [] (optional) - (default: ['formId' => 0, 'entryId' => 0, 'fieldValues' => []]) |
| 18 |
* |
| 19 |
* @return bool |
| 20 |
*/ |
| 21 |
public function apiResponse($logID, $integrationId, $apiType, $responseType, $apiResponse, $entryDetails = []) |
| 22 |
{ |
| 23 |
if (!$apiType || !$apiResponse) { |
| 24 |
return false; |
| 25 |
} |
| 26 |
$apiType = wp_json_encode($apiType); |
| 27 |
$apiResponse = wp_json_encode($apiResponse); |
| 28 |
|
| 29 |
$ipTool = new IpTool(); |
| 30 |
$user_details = $ipTool->getUserDetail(); |
| 31 |
$formEntryModel = new FormEntryLogModel(); |
| 32 |
$result = $formEntryModel->log_history_insert( |
| 33 |
[ |
| 34 |
'log_id' => $logID, |
| 35 |
'integration_id' => $integrationId, |
| 36 |
'api_type' => $apiType, |
| 37 |
'response_type' => $responseType, |
| 38 |
'response_obj' => $apiResponse, |
| 39 |
'created_at' => $user_details['time'], |
| 40 |
] |
| 41 |
); |
| 42 |
|
| 43 |
$fieldValues = []; |
| 44 |
|
| 45 |
if (isset($entryDetails['fieldValues']) && $entryDetails['fieldValues']) { |
| 46 |
$fieldValues = $entryDetails['fieldValues']; |
| 47 |
} |
| 48 |
|
| 49 |
$formId = isset($entryDetails['formId']) && !empty($entryDetails['formId']) ? $entryDetails['formId'] : 0; |
| 50 |
$entryId = isset($entryDetails['entryId']) && !empty($entryDetails['entryId']) ? $entryDetails['entryId'] : 0; |
| 51 |
|
| 52 |
if ('error' === $responseType) { |
| 53 |
// $this->sendErrorEmail($logID, $integrationId, $apiType, $apiResponse, $entryDetails); |
| 54 |
do_action('bitform_integration_api_response_error', $formId, $entryId, $logID, $integrationId, $apiType, $apiResponse, $fieldValues); |
| 55 |
} |
| 56 |
|
| 57 |
if ('success' === $responseType) { |
| 58 |
// $this->sendSuccessEmail($logID, $integrationId, $apiType, $apiResponse, $entryDetails); |
| 59 |
do_action('bitform_integration_api_response_success', $formId, $entryId, $logID, $integrationId, $apiType, $apiResponse, $fieldValues); |
| 60 |
} |
| 61 |
|
| 62 |
return $result; |
| 63 |
} |
| 64 |
} |
| 65 |
|