diff --git a/src/freeform_next/Controllers/MailingListsController.php b/src/freeform_next/Controllers/MailingListsController.php
index 49a1f389..fc8af8c9 100644
--- a/src/freeform_next/Controllers/MailingListsController.php
+++ b/src/freeform_next/Controllers/MailingListsController.php
@@ -33,18 +33,22 @@ public function handle($id = null)
return $this->index();
}
- if ($id === 'check') {
+ if ($id === "check") {
return $this->check();
}
- if ($id === 'get') {
+ if ($id === "get") {
return $this->getIntegrationsAjax();
}
- if ($id === 'delete') {
+ if ($id === "delete") {
return $this->batchDelete();
}
+ if ($id === "authorize") {
+ return $this->authorize();
+ }
+
return $this->edit($id);
}
@@ -54,16 +58,16 @@ public function handle($id = null)
public function index()
{
/** @var Table $table */
- $table = ee('CP/Table', ['sortable' => false, 'searchable' => false]);
+ $table = ee("CP/Table", ["sortable" => false, "searchable" => false]);
$table->setColumns(
[
- 'id' => ['type' => Table::COL_ID],
- 'Name' => ['type' => Table::COL_TEXT],
- 'Handle' => ['type' => Table::COL_TEXT],
- 'Service Provider' => ['type' => Table::COL_TEXT],
- 'manage' => ['type' => Table::COL_TOOLBAR],
- ['type' => Table::COL_CHECKBOX, 'name' => 'selection'],
+ "id" => ["type" => Table::COL_ID],
+ "Name" => ["type" => Table::COL_TEXT],
+ "Handle" => ["type" => Table::COL_TEXT],
+ "Service Provider" => ["type" => Table::COL_TEXT],
+ "manage" => ["type" => Table::COL_TOOLBAR],
+ ["type" => Table::COL_CHECKBOX, "name" => "selection"],
]
);
@@ -74,64 +78,64 @@ public function index()
$tableData[] = [
$integration->id,
[
- 'content' => $integration->name,
- 'href' => $this->getLink('integrations/mailing_lists/' . $integration->id),
+ "content" => $integration->name,
+ "href" => $this->getLink("integrations/mailing_lists/" . $integration->id),
],
$integration->handle,
$integration->getIntegrationObject()->getServiceProvider(),
[
- 'toolbar_items' => [
- 'edit' => [
- 'href' => UrlHelper::getLink('integrations/mailing_lists/' . $integration->id),
- 'title' => lang('edit'),
+ "toolbar_items" => [
+ "edit" => [
+ "href" => UrlHelper::getLink("integrations/mailing_lists/" . $integration->id),
+ "title" => lang("edit"),
],
],
],
[
- 'name' => 'id_list[]',
- 'value' => $integration->id,
- 'data' => [
- 'confirm' => lang('Integration') . ': ' . htmlentities(
+ "name" => "id_list[]",
+ "value" => $integration->id,
+ "data" => [
+ "confirm" => lang("Integration") . ": " . htmlentities(
$integration->name,
ENT_QUOTES
- ) . '',
+ ) . "",
],
],
];
}
$table->setData($tableData);
- $table->setNoResultsText('No results');
+ $table->setNoResultsText("No results");
- $removeModal = new ConfirmRemoveModal($this->getLink('integrations/mailing_lists/delete'));
- $removeModal->setKind('Mailing List Integrations');
+ $removeModal = new ConfirmRemoveModal($this->getLink("integrations/mailing_lists/delete"));
+ $removeModal->setKind("Mailing List Integrations");
$serviceProviderTypes = $this->getMailingListService()->getAllMailingListServiceProviders();
if (count($serviceProviderTypes)) {
$formRightLinks = [
[
- 'title' => lang('New Integration'),
- 'link' => $this->getLink('integrations/mailing_lists/new'),
+ "title" => lang("New Integration"),
+ "link" => $this->getLink("integrations/mailing_lists/new"),
],
];
} else {
$formRightLinks = [
[
- 'title' => lang('Upgrade to Pro to Enable'),
- 'link' => 'https://docs.solspace.com/expressionengine/freeform/v3/',
+ "title" => lang("Upgrade to Pro to Enable"),
+ "link" => "https://docs.solspace.com/expressionengine/freeform/v3/",
],
];
}
$view = new CpView(
- 'integrations/table',
+ "integrations/table",
[
- 'table' => $table->viewData(),
- 'cp_page_title' => lang('Mailing List Integrations'),
- 'form_right_links' => $formRightLinks,
+ "table" => $table->viewData(),
+ "cp_page_title" => lang("Mailing List Integrations"),
+ "form_right_links" => $formRightLinks,
]
);
- $view->setHeading(lang('Mailing List Integrations'));
+ $view->setHeading(lang("Mailing List Integrations"));
$view->addModal($removeModal);
return $view;
@@ -148,10 +152,10 @@ public function edit($id)
$serviceProviderTypes = $this->getMailingListService()->getAllMailingListServiceProviders();
if (empty($serviceProviderTypes)) {
- return new RedirectView('https://docs.solspace.com/expressionengine/freeform/v3/');
+ return new RedirectView("https://docs.solspace.com/expressionengine/freeform/v3/");
}
- if ($id === 'new') {
+ if ($id === "new") {
$model = IntegrationModel::create(IntegrationModel::TYPE_MAILING_LIST);
$model->class = array_keys($serviceProviderTypes)[0];
} else {
@@ -159,21 +163,21 @@ public function edit($id)
}
if (!$model) {
- throw new IntegrationException('Integration does not exist');
+ throw new IntegrationException("Integration does not exist");
}
$errors = null;
- if (isset($_POST['class'])) {
+ if (isset($_POST["class"])) {
$errors = $this->save($model);
if (empty($errors)) {
- $view = new RedirectView($this->getLink('integrations/mailing_lists/'));
+ $view = new RedirectView($this->getLink("integrations/mailing_lists/"));
return $view;
}
}
- if (ee()->input->get('code')) {
+ if (ee()->input->get("code")) {
$this->handleAuthorization($model);
}
@@ -199,14 +203,15 @@ public function edit($id)
$hash = md5($className);
$settingGroups[] = [
- 'title' => $item->getLabel(),
- 'desc' => $item->getInstructions(),
- 'group' => $hash,
- 'fields' => [
- $hash . '-' . $item->getHandle() => [
- 'type' => $item->getType() === SettingBlueprint::TYPE_BOOL ? 'yes_no' : 'text',
- 'required' => $item->isRequired(),
- 'value' => isset($settings[$item->getHandle()]) ? $settings[$item->getHandle()] : null,
+ "title" => $item->getLabel(),
+ "desc" => $item->getInstructions(),
+ "group" => $hash,
+ "fields" => [
+ $hash . "-" . $item->getHandle() => [
+ "type" => $item->getType() === SettingBlueprint::TYPE_BOOL ? "yes_no" : "text",
+ "required" => $item->isRequired(),
+ "value" => isset($settings[$item->getHandle()]) ? $settings[$item->getHandle()] : $item->getValue(),
+ "attrs" => $item->getAttributes(),
],
],
];
@@ -216,51 +221,51 @@ public function edit($id)
$sectionData = [
[
[
- 'title' => lang('Service Provider'),
- 'fields' => [
- 'class' => [
- 'type' => 'select',
- 'value' => $model->class,
- 'choices' => $types,
- 'group_toggle' => $targets,
+ "title" => lang("Service Provider"),
+ "fields" => [
+ "class" => [
+ "type" => "select",
+ "value" => $model->class,
+ "choices" => $types,
+ "group_toggle" => $targets,
],
],
],
[
- 'title' => 'Name',
- 'desc' => 'What this integration will be called in the CP.',
- 'fields' => [
- 'name' => [
- 'type' => 'text',
- 'value' => $model->name,
- 'attrs' => 'data-generator-base',
+ "title" => "Name",
+ "desc" => "What this integration will be called in the CP.",
+ "fields" => [
+ "name" => [
+ "type" => "text",
+ "value" => $model->name,
+ "attrs" => "data-generator-base",
],
],
],
[
- 'title' => 'Handle',
- 'desc' => 'The unique name used to identify this integration.',
- 'fields' => [
- 'handle' => [
- 'type' => 'text',
- 'value' => $model->handle,
- 'attrs' => 'data-generator-target',
+ "title" => "Handle",
+ "desc" => "The unique name used to identify this integration.",
+ "fields" => [
+ "handle" => [
+ "type" => "text",
+ "value" => $model->handle,
+ "attrs" => "data-generator-target",
],
],
],
],
- 'Settings' => $settingGroups,
+ "Settings" => $settingGroups,
];
if ($model->id) {
- $link = $this->getLink('integrations/mailing_lists/check');
+ $link = $this->getLink("integrations/mailing_lists/check");
$sectionData[0][] = [
- 'title' => 'Is Authorized?',
- 'desc' => 'Is the connection authorized?',
- 'fields' => [
- 'handle' => [
- 'type' => 'html',
- 'content' => '
+ "title" => "Is Authorized?",
+ "desc" => "Is the connection authorized?",
+ "fields" => [
+ "handle" => [
+ "type" => "html",
+ "content" => '
Authorized
@@ -284,27 +289,27 @@ public function edit($id)
ee()->cp->add_js_script(
[
- 'file' => ['cp/form_group'],
+ "file" => ["cp/form_group"],
]
);
$view = new CpView(
- 'integrations/edit',
+ "integrations/edit",
[
- 'cp_page_title' => 'Mailing List Integration',
- 'base_url' => $this->getLink('integrations/mailing_lists/' . $id),
- 'sections' => $sectionData,
- 'save_btn_text' => 'Save',
- 'save_btn_text_working' => 'Saving',
- 'errors' => $errors,
+ "cp_page_title" => "Mailing List Integration",
+ "base_url" => $this->getLink("integrations/mailing_lists/" . $id),
+ "sections" => $sectionData,
+ "save_btn_text" => "Save",
+ "save_btn_text_working" => "Saving",
+ "errors" => $errors,
]
);
$view
- ->setHeading($model->name ?: 'New Mailing List Integration')
- ->addBreadcrumb(new NavigationLink('Mailing List Integrations', 'integrations/mailing_lists'))
- ->addJavascript('integrations')
- ->addJavascript('handleGenerator');
+ ->setHeading($model->name ?: "New Mailing List Integration")
+ ->addBreadcrumb(new NavigationLink("Mailing List Integrations", "integrations/mailing_lists"))
+ ->addJavascript("integrations")
+ ->addJavascript("handleGenerator");
return $view;
}
@@ -318,21 +323,21 @@ public function save(IntegrationModel $model)
{
$isNew = !$model->id;
- $class = ee()->input->post('class');
+ $class = ee()->input->post("class");
$hash = md5($class);
- $name = ee()->input->post('name');
- $handle = ee()->input->post('handle');
+ $name = ee()->input->post("name");
+ $handle = ee()->input->post("handle");
$rules = [
- 'class' => 'required',
- 'name' => 'required',
- 'handle' => 'required',
+ "class" => "required",
+ "name" => "required",
+ "handle" => "required",
];
$postedSettings = [];
foreach ($_POST as $key => $value) {
if (strpos($key, $hash) === 0) {
- $postedSettings[str_replace($hash . '-', '', $key)] = $value;
+ $postedSettings[str_replace($hash . "-", "", $key)] = $value;
}
}
@@ -350,11 +355,11 @@ public function save(IntegrationModel $model)
$settings[$blueprintHandle] = $value;
if ($blueprint->isRequired()) {
- $rules["{$hash}-{$blueprint->getHandle()}"] = 'required';
+ $rules["{$hash}-{$blueprint->getHandle()}"] = "required";
}
}
- $validation = ee('Validation')->make($rules)->validate($_POST);
+ $validation = ee("Validation")->make($rules)->validate($_POST);
if (!$validation->isValid()) {
return $validation;
}
@@ -365,11 +370,9 @@ public function save(IntegrationModel $model)
$model->class = $class;
$model->forceUpdate = true;
- $model->getIntegrationObject()->onBeforeSave($model);
-
- if ($isNew) {
- $model->getIntegrationObject()->initiateAuthentication();
- }
+ $integration = $model->getIntegrationObject();
+ $integration->onBeforeSave($model);
+ $integration->initiateAuthentication();
if (!ExtensionHelper::call(ExtensionHelper::HOOK_MAILING_LISTS_BEFORE_SAVE, $model, $isNew)) {
return null;
@@ -379,10 +382,10 @@ public function save(IntegrationModel $model)
ExtensionHelper::call(ExtensionHelper::HOOK_MAILING_LISTS_AFTER_SAVE, $model, $isNew);
- ee('CP/Alert')
- ->makeInline('shared-form')
+ ee("CP/Alert")
+ ->makeInline("shared-form")
->asSuccess()
- ->withTitle(lang('Success'))
+ ->withTitle(lang("Success"))
->defer();
return null;
@@ -410,9 +413,9 @@ public function getIntegrationsAjax()
*/
public function batchDelete()
{
- if (isset($_POST['id_list'])) {
+ if (isset($_POST["id_list"])) {
$ids = [];
- foreach ($_POST['id_list'] as $id) {
+ foreach ($_POST["id_list"] as $id) {
$ids[] = (int) $id;
}
@@ -429,7 +432,35 @@ public function batchDelete()
}
}
- return new RedirectView($this->getLink('integrations/mailing_lists/'));
+ return new RedirectView($this->getLink("integrations/mailing_lists/"));
+ }
+
+ /**
+ * Handle OAuth2 authorization
+ *
+ * @return void|RedirectView
+ * @throws IntegrationException
+ */
+ public function authorize()
+ {
+ $code = ee()->input->get("code");
+ if (empty($code)) {
+ return;
+ }
+
+ $state = ee()->input->get("state");
+ if (empty($state)) {
+ return;
+ }
+
+ $model = MailingListRepository::getInstance()->getIntegrationById($state);
+ if (!$model) {
+ return;
+ }
+
+ $this->handleAuthorization($model);
+
+ return new RedirectView($this->getLink("integrations/mailing_lists/" . $model->getIntegrationObject()->getId()));
}
/**
@@ -440,18 +471,24 @@ public function batchDelete()
private function handleAuthorization(IntegrationModel $model)
{
$integration = $model->getIntegrationObject();
- $code = ee()->input->get('code');
+ $code = ee()->input->get("code");
if (!$integration instanceof MailingListOAuthConnector || empty($code)) {
return;
}
$accessToken = $integration->fetchAccessToken();
-
$model->accessToken = $accessToken;
$model->settings = $integration->getSettings();
+ $model->settings = json_encode($model->settings);
- $this->save($model);
+ if (!ExtensionHelper::call(ExtensionHelper::HOOK_MAILING_LISTS_BEFORE_SAVE, $model)) {
+ return;
+ }
+
+ $model->save();
+
+ ExtensionHelper::call(ExtensionHelper::HOOK_MAILING_LISTS_AFTER_SAVE, $model);
}
/**
@@ -475,24 +512,44 @@ private function check()
{
$view = new AjaxView();
- $id = ee()->input->post('id');
+ $id = ee()->input->post("id");
$model = MailingListRepository::getInstance()->getIntegrationById($id);
$integration = $model->getIntegrationObject();
if (!$model) {
- $view->addVariable('success', false);
- $view->addError('Integration does not exist');
+ $view->addVariable("success", false);
+ $view->addError("Integration does not exist");
}
try {
if ($integration->checkConnection()) {
- $view->addVariable('success', true);
+ $view->addVariable("success", true);
} else {
- $view->addVariable('success', false);
- $view->addError('Could not connect');
+ $view->addVariable("success", false);
+ $view->addError("Could not connect");
}
} catch (BadResponseException $e) {
- $view->addVariable('success', false);
+ if ($integration instanceof TokenRefreshInterface) {
+ try {
+ if ($integration->refreshToken() && $integration->isAccessTokenUpdated()) {
+ $mailingListService = new MailingListsService();
+ $mailingListService->updateAccessToken($integration);
+
+ $view->addVariable("success", true);
+ } else {
+ $view->addVariable("success", false);
+ $view->addError($e->getResponse()->getBody(true));
+ }
+ } catch (\Exception $e) {
+ $view->addVariable("success", false);
+ $view->addError($e->getMessage());
+ }
+ } else {
+ $view->addVariable("success", false);
+ $view->addError($e->getMessage());
+ }
+
+ $view->addVariable("success", false);
$view->addError($e->getResponse()->getBody(true));
}
diff --git a/src/freeform_next/Integrations/MailingLists/ConstantContactV3.php b/src/freeform_next/Integrations/MailingLists/ConstantContactV3.php
new file mode 100644
index 00000000..12867b5a
--- /dev/null
+++ b/src/freeform_next/Integrations/MailingLists/ConstantContactV3.php
@@ -0,0 +1,336 @@
+getEndpoint("/contact_lists");
+
+ $response = $client->get($endpoint, [
+ "headers" => [
+ "Authorization" => "Bearer " . $this->getAccessToken(),
+ "Content-Type" => "application/json"
+ ]
+ ]);
+ } catch (BadResponseException $e) {
+ $responseBody = $e->getResponse()->getBody();
+
+ $errorMessage = implode(", ", [$responseBody, $e->getMessage()]);
+
+ $this->getLogger()->error($errorMessage, self::LOG_CATEGORY);
+
+ return false;
+ }
+
+ $status = $response->getStatusCode();
+ if ($status !== 200) {
+ $errorMessage = "Could not connect to ConstantContact API";
+
+ $this->getLogger()->error($errorMessage, self::LOG_CATEGORY);
+
+ return false;
+ }
+
+ $json = json_decode($response->getBody());
+
+ return isset($json->lists);
+ }
+
+ /**
+ * @return void
+ */
+ public function initiateAuthentication()
+ {
+ $data = [
+ "response_type" => "code",
+ "client_id" => $this->getClientId(),
+ "redirect_uri" => $this->getReturnUri(),
+ "scope" => "offline_access contact_data account_read account_update campaign_data",
+ "state" => $this->getId()
+ ];
+
+ header("Location: " . $this->getAuthorizeUrl() . "?" . http_build_query($data));
+ die();
+ }
+
+ /**
+ * @return bool
+ * @throws IntegrationException|GuzzleException
+ */
+ public function refreshToken()
+ {
+ return (bool) $this->fetchAccessToken();
+ }
+
+ /**
+ * @param ListObject $mailingList
+ * @param array $emails
+ * @param array $mappedValues
+ * @return bool
+ * @throws IntegrationException|GuzzleException
+ */
+ public function pushEmails(ListObject $mailingList, array $emails, array $mappedValues)
+ {
+ try {
+ $data = [];
+
+ foreach ($mappedValues as $key => $value) {
+ if (preg_match("/^street_address_(.*)/", $key, $matches)) {
+ if (empty($cdta["street_address"])) {
+ $data["street_address"] = [];
+ }
+
+ $data["street_address"][$matches[1]] = $value;
+ } elseif (preg_match("/^custom_(.*)/", $key, $matches)) {
+ if (empty($data["custom_fields"])) {
+ $data["custom_fields"] = [];
+ }
+
+ $data["custom_fields"][] = [
+ "custom_field_id" => $matches[1],
+ "value" => $value,
+ ];
+ } else {
+ $data[$key] = $value;
+ }
+ }
+
+ if (isset($data["street_address"]) && empty($data["street_address"]["kind"])) {
+ $data["street_address"]["kind"] = "home";
+ }
+
+ $email = reset($emails);
+ $email = strtolower($email);
+
+ $data = array_merge(
+ [
+ "email_address" => $email,
+ "create_source" => "Contact",
+ "list_memberships" => [$mailingList->getId()]
+ ],
+ $data
+ );
+
+ $client = new Client();
+
+ $endpoint = $this->getEndpoint("/contacts/sign_up_form");
+
+ $response = $client->post($endpoint, [
+ "headers" => [
+ "Authorization" => "Bearer " . $this->getAccessToken(),
+ "Content-Type" => "application/json"
+ ],
+ "body" => json_encode($data)
+ ]);
+ } catch (BadResponseException $e) {
+ $responseBody = $e->getResponse()->getBody();
+
+ $errorMessage = implode(", ", [$responseBody, $e->getMessage()]);
+
+ $this->getLogger()->error($errorMessage, self::LOG_CATEGORY);
+
+ throw new IntegrationException($this->getTranslator()->translate($errorMessage));
+ }
+
+ $status = $response->getStatusCode();
+ if ($status !== 200) {
+ $errorMessage = "Could not add contacts to ConstantContact list";
+
+ $this->getLogger()->error($errorMessage, self::LOG_CATEGORY);
+
+ throw new IntegrationException($this->getTranslator()->translate($errorMessage));
+ }
+
+ return true;
+ }
+
+ /**
+ * @return ListObject[]
+ * @throws IntegrationException|GuzzleException
+ */
+ public function fetchLists()
+ {
+ try {
+ $client = new Client();
+
+ $endpoint = $this->getEndpoint("/contact_lists");
+
+ $response = $client->get($endpoint, [
+ "headers" => [
+ "Authorization" => "Bearer " . $this->getAccessToken(),
+ "Content-Type" => "application/json"
+ ]
+ ]);
+ } catch (BadResponseException $e) {
+ $responseBody = $e->getResponse()->getBody();
+
+ $errorMessage = implode(', ', [$responseBody, $e->getMessage()]);
+
+ $this->getLogger()->error($errorMessage, self::LOG_CATEGORY);
+
+ throw new IntegrationException($this->getTranslator()->translate($errorMessage));
+ }
+
+ $status = $response->getStatusCode();
+ if ($status !== 200) {
+ $errorMessage = "Could not fetch ConstantContact lists";
+
+ $this->getLogger()->error($errorMessage, self::LOG_CATEGORY);
+
+ throw new IntegrationException($this->getTranslator()->translate($errorMessage));
+ }
+
+ $json = json_decode($response->getBody());
+
+ $lists = [];
+
+ if (isset($json->lists)) {
+ foreach ($json->lists as $list) {
+ if (isset($list->list_id, $list->name)) {
+ $lists[] = new ListObject(
+ $this,
+ $list->list_id,
+ $list->name,
+ $this->fetchFields($list->list_id)
+ );
+ }
+ }
+ }
+
+ return $lists;
+ }
+
+ /**
+ * @param string $listId
+ * @return FieldObject[]
+ * @throws IntegrationException|GuzzleException
+ */
+ public function fetchFields($listId)
+ {
+ try {
+ $client = new Client();
+
+ $endpoint = $this->getEndpoint("/contact_custom_fields?limit=100");
+
+ $response = $client->get($endpoint, [
+ "headers" => [
+ "Authorization" => "Bearer " . $this->getAccessToken(),
+ "Content-Type" => "application/json"
+ ]
+ ]);
+ } catch (BadResponseException $e) {
+ $responseBody = $e->getResponse()->getBody();
+
+ $errorMessage = implode(", ", [$responseBody, $e->getMessage()]);
+
+ $this->getLogger()->error($errorMessage, self::LOG_CATEGORY);
+
+ throw new IntegrationException($this->getTranslator()->translate($errorMessage));
+ }
+
+ $status = $response->getStatusCode();
+ if ($status !== 200) {
+ $errorMessage = "Could not fetch ConstantContact custom fields";
+
+ $this->getLogger()->error($errorMessage, self::LOG_CATEGORY);
+
+ throw new IntegrationException($this->getTranslator()->translate($errorMessage));
+ }
+
+ $json = json_decode($response->getBody());
+
+ $fieldList = [];
+
+ $fieldList[] = new FieldObject("first_name", "First Name", FieldObject::TYPE_STRING, false);
+ $fieldList[] = new FieldObject("last_name", "Last Name", FieldObject::TYPE_STRING, false);
+ $fieldList[] = new FieldObject("job_title", "Job Title", FieldObject::TYPE_STRING, false);
+ $fieldList[] = new FieldObject("company_name", "Company Name", FieldObject::TYPE_STRING, false);
+ $fieldList[] = new FieldObject("phone_number", "Phone Number", FieldObject::TYPE_STRING, false);
+ $fieldList[] = new FieldObject("anniversary", "Anniversary", FieldObject::TYPE_STRING, false);
+ $fieldList[] = new FieldObject("birthday_month", "Birthday Month", FieldObject::TYPE_NUMERIC, false);
+ $fieldList[] = new FieldObject("birthday_day", "Birthday Day", FieldObject::TYPE_NUMERIC, false);
+ $fieldList[] = new FieldObject("street_address_kind", "Address: Kind", FieldObject::TYPE_STRING, false);
+ $fieldList[] = new FieldObject("street_address_street", "Address: Street", FieldObject::TYPE_STRING, false);
+ $fieldList[] = new FieldObject("street_address_city", "Address: City", FieldObject::TYPE_STRING, false);
+ $fieldList[] = new FieldObject("street_address_state", "Address: State", FieldObject::TYPE_STRING, false);
+ $fieldList[] = new FieldObject("street_address_postal_code", "Address: Postal Code", FieldObject::TYPE_STRING, false);
+ $fieldList[] = new FieldObject("street_address_country", "Address: Country", FieldObject::TYPE_STRING, false);
+
+ if (empty($json->custom_fields)) {
+ return $fieldList;
+ }
+
+ foreach ($json->custom_fields as $field) {
+ $fieldList[] = new FieldObject(
+ "custom_".$field->custom_field_id,
+ $field->label,
+ FieldObject::TYPE_STRING,
+ false
+ );
+ }
+
+ return $fieldList;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAuthorizeUrl()
+ {
+ return "https://authz.constantcontact.com/oauth2/default/v1/authorize";
+ }
+
+ /**
+ * @return string
+ */
+ public function getAccessTokenUrl()
+ {
+ return "https://authz.constantcontact.com/oauth2/default/v1/token";
+ }
+
+ /**
+ * @return string
+ */
+ public function getApiRootUrl()
+ {
+ return "https://api.cc.email/v3";
+ }
+}
diff --git a/src/freeform_next/Library/Integrations/MailingLists/MailingListOAuthConnector.php b/src/freeform_next/Library/Integrations/MailingLists/MailingListOAuthConnector.php
index ac5989a9..975e9811 100644
--- a/src/freeform_next/Library/Integrations/MailingLists/MailingListOAuthConnector.php
+++ b/src/freeform_next/Library/Integrations/MailingLists/MailingListOAuthConnector.php
@@ -35,8 +35,10 @@ public static function getSettingBlueprints()
SettingBlueprint::TYPE_TEXT,
self::SETTING_RETURN_URI,
"OAuth 2.0 Return URI",
- "You must specify this as the Return URI in your app settings to be able to authorize your credentials. DO NOT CHANGE THIS.",
- true
+ "You must specify this Return URI in your OAuth2 app settings to be able to authorize your credentials. DO NOT CHANGE THIS.",
+ true,
+ "readonly",
+ ee()->config->item("site_url") ."admin.php?/cp/addons/settings/freeform_next/integrations/mailing_lists/authorize"
),
new SettingBlueprint(
SettingBlueprint::TYPE_TEXT,
@@ -98,10 +100,10 @@ public function fetchAccessToken()
try {
$response = $client->post($this->getAccessTokenUrl(), [
- 'headers' => [
- 'Content-Type' => 'application/x-www-form-urlencoded',
+ "headers" => [
+ "Content-Type" => "application/x-www-form-urlencoded",
],
- 'body' => $body,
+ "body" => $body,
]);
} catch (BadResponseException $e) {
throw new IntegrationException($e->getResponse()->getBody(true));
diff --git a/src/freeform_next/Library/Integrations/SettingBlueprint.php b/src/freeform_next/Library/Integrations/SettingBlueprint.php
index 2c320705..ea37b4ff 100644
--- a/src/freeform_next/Library/Integrations/SettingBlueprint.php
+++ b/src/freeform_next/Library/Integrations/SettingBlueprint.php
@@ -34,6 +34,12 @@ class SettingBlueprint
/** @var bool */
private $required;
+ /** @var string */
+ private $attributes;
+
+ /** @var string */
+ private $value;
+
/**
* @return array
*/
@@ -54,19 +60,25 @@ public static function getEditableTypes()
* @param string $label
* @param string $instructions
* @param bool $required
+ * @param string $attributes
+ * @param string $value
*/
public function __construct(
$type,
$handle,
$label,
$instructions,
- $required = false
+ $required = false,
+ $attributes = "",
+ $value = ""
) {
$this->type = $type;
$this->handle = $handle;
$this->label = $label;
$this->instructions = $instructions;
$this->required = (bool)$required;
+ $this->attributes = $attributes;
+ $this->value = $value;
}
/**
@@ -109,6 +121,22 @@ public function isRequired()
return $this->required;
}
+ /**
+ * @return string
+ */
+ public function getAttributes()
+ {
+ return $this->attributes;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getValue()
+ {
+ return $this->value;
+ }
+
/**
* @return bool
*/
diff --git a/src/freeform_next/Services/MailingListsService.php b/src/freeform_next/Services/MailingListsService.php
index 158eb079..c04ce799 100644
--- a/src/freeform_next/Services/MailingListsService.php
+++ b/src/freeform_next/Services/MailingListsService.php
@@ -438,4 +438,17 @@ public function onAfterResponse(AbstractIntegration $integration, ResponseInterf
{
}
+
+ /**
+ * Update the access token of an integration
+ *
+ * @param AbstractMailingListIntegration $integration
+ */
+ public function updateAccessToken(AbstractMailingListIntegration $integration)
+ {
+ $model = MailingListRepository::getInstance()->getIntegrationById($integration->getId());
+ $model->accessToken = $integration->getAccessToken();
+ $model->updateSettings($integration->getSettings());
+ $model->save();
+ }
}
diff --git a/src/freeform_next/addon.setup.php b/src/freeform_next/addon.setup.php
index b526f0b1..e8017790 100644
--- a/src/freeform_next/addon.setup.php
+++ b/src/freeform_next/addon.setup.php
@@ -27,7 +27,7 @@
if (!$ftExists) {
ee()->db->insert('exp_fieldtypes', [
'name' => 'freeform_next',
- 'version' => '3.1.3',
+ 'version' => '3.1.4',
'settings' => 'YTowOnt9',
'has_global_settings' => 'n',
]);
@@ -50,7 +50,7 @@
'name' => 'Freeform',
'module_name' => 'Freeform_next',
'description' => 'Powerful form builder',
- 'version' => '3.1.3',
+ 'version' => '3.1.4',
'namespace' => 'Solspace\Addons\FreeformNext',
'settings_exist' => true,
'models' => [
diff --git a/src/freeform_next/upd.freeform_next.php b/src/freeform_next/upd.freeform_next.php
index 74a43fbf..52aa1882 100644
--- a/src/freeform_next/upd.freeform_next.php
+++ b/src/freeform_next/upd.freeform_next.php
@@ -484,6 +484,15 @@ public function runMigrations($previousVersion = null)
");
}
+ if (version_compare($previousVersion, '3.1.3', '<=')) {
+ ee()->db
+ ->query("
+ ALTER TABLE exp_freeform_next_integrations
+ MODIFY COLUMN `accessToken`
+ TEXT NULL
+ ");
+ }
+
return true;
}