← All changes
|
includes/Core/Integration/ElasticEmail/ElasticEmailHandler.php
+38
-11
2.10.0
→
3.3.1
View file →
| @@ -5,10 +5,15 @@ | ||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | namespace BitCode\BitForm\Core\Integration\ElasticEmail; |
| 8 | 8 | |
| 9 | +if (!defined('ABSPATH')) { | |
| 10 | + exit; | |
| 11 | +} | |
| 12 | + | |
| 9 | 13 | use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 10 | 14 | use BitCode\BitForm\Core\Util\HttpHelper; |
| 15 | +use BitCode\BitForm\GlobalHelper; | |
| 11 | 16 | use WP_Error; |
| 12 | 17 | |
| 13 | 18 | /** |
| 14 | 19 | * Provide functionality for ZohoCrm integration |
| @@ -14,8 +19,18 @@ | ||
| 14 | 19 | * Provide functionality for ZohoCrm integration |
| 15 | 20 | */ |
| 16 | 21 | class ElasticEmailHandler |
| 17 | 22 | { |
| 23 | + private $formID; | |
| 24 | + | |
| 25 | + private $integrationID; | |
| 26 | + | |
| 27 | + public function __construct($integrationID, $fromID) | |
| 28 | + { | |
| 29 | + $this->formID = $fromID; | |
| 30 | + $this->integrationID = $integrationID; | |
| 31 | + } | |
| 32 | + | |
| 18 | 33 | public static function registerAjax() |
| 19 | 34 | { |
| 20 | 35 | add_action('wp_ajax_bitforms_elasticemail_authorize', [__CLASS__, 'elasticEmailAuthorize']); |
| 21 | 36 | add_action('wp_ajax_bitforms_get_all_lists', [__CLASS__, 'getAllLists']); |
| @@ -22,12 +37,17 @@ | ||
| 22 | 37 | } |
| 23 | 38 | |
| 24 | 39 | public static function elasticEmailAuthorize() |
| 25 | 40 | { |
| 26 | - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) { | |
| 27 | - $inputJSON = file_get_contents('php://input'); | |
| 28 | - $requestsParams = json_decode($inputJSON); | |
| 41 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 42 | + GlobalHelper::requirePostMethod(); | |
| 29 | 43 | |
| 44 | + try { | |
| 45 | + $requestsParams = GlobalHelper::formatRequestData(); | |
| 46 | + } catch (\InvalidArgumentException $e) { | |
| 47 | + wp_send_json_error($e->getMessage(), 400); | |
| 48 | + } | |
| 49 | + | |
| 30 | 50 | if (empty($requestsParams->api_key)) { |
| 31 | 51 | wp_send_json_error( |
| 32 | 52 | __( |
| 33 | 53 | 'Requested parameter is empty', |
| @@ -39,15 +59,16 @@ | ||
| 39 | 59 | |
| 40 | 60 | $apiEndpoint = 'https://api.elasticemail.com/v4/lists'; |
| 41 | 61 | $apiKey = $requestsParams->api_key; |
| 42 | 62 | $header = [ |
| 43 | - 'X-ElasticEmail-ApiKey' => 22423423423423423, | |
| 63 | + 'X-ElasticEmail-ApiKey' => $apiKey, | |
| 44 | 64 | 'Accept' => '*/*', |
| 45 | 65 | ]; |
| 46 | 66 | $apiResponse = HttpHelper::get($apiEndpoint, null, $header); |
| 67 | + | |
| 47 | 68 | if (is_wp_error($apiResponse) || isset($apiResponse->Error)) { |
| 48 | 69 | wp_send_json_error( |
| 49 | - empty($apiResponse->code) ? 'Unknown' : $apiResponse->Error, | |
| 70 | + $apiResponse->Error, | |
| 50 | 71 | 400 |
| 51 | 72 | ); |
| 52 | 73 | } |
| 53 | 74 | wp_send_json_success(true); |
| @@ -55,13 +76,19 @@ | ||
| 55 | 76 | } |
| 56 | 77 | |
| 57 | 78 | public static function getAllLists() |
| 58 | 79 | { |
| 59 | - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) { | |
| 80 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 60 | 81 | $response = null; |
| 61 | - $inputJSON = file_get_contents('php://input'); | |
| 62 | - $requestsParams = json_decode($inputJSON); | |
| 63 | 82 | |
| 83 | + GlobalHelper::requirePostMethod(); | |
| 84 | + | |
| 85 | + try { | |
| 86 | + $requestsParams = GlobalHelper::formatRequestData(); | |
| 87 | + } catch (\InvalidArgumentException $e) { | |
| 88 | + wp_send_json_error($e->getMessage(), 400); | |
| 89 | + } | |
| 90 | + | |
| 64 | 91 | if (empty($requestsParams->apiKey)) { |
| 65 | 92 | wp_send_json_error( |
| 66 | 93 | __( |
| 67 | 94 | 'Requested parameter is empty', |
| @@ -108,15 +135,15 @@ | ||
| 108 | 135 | || empty($fieldMap) |
| 109 | 136 | ) { |
| 110 | 137 | return new WP_Error('REQ_FIELD_EMPTY', __('module, fields are required for Elastic Email api', 'bit-form')); |
| 111 | 138 | } |
| 112 | - $recordApiHelper = new RecordApiHelper($api_key, $integId, $logID, $integrationDetails); | |
| 139 | + $recordApiHelper = new RecordApiHelper($api_key, $integId, $logID, $integrationDetails, $entryID); | |
| 113 | 140 | $elasticEmailApiResponse = $recordApiHelper->execute( |
| 114 | 141 | $integId, |
| 115 | 142 | $fieldValues, |
| 116 | 143 | $fieldMap, |
| 117 | - $integrationDetails | |
| 118 | - // $actions | |
| 144 | + $integrationDetails, | |
| 145 | + $this->formID, | |
| 119 | 146 | ); |
| 120 | 147 | |
| 121 | 148 | if (is_wp_error($elasticEmailApiResponse)) { |
| 122 | 149 | return $elasticEmailApiResponse; |