Skip to content

Commit

Permalink
fixing hubspot integration
Browse files Browse the repository at this point in the history
  • Loading branch information
iruzevic committed Nov 24, 2022
1 parent 6f371a6 commit 43b6c57
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/).

## [2.2.0]

### Changed
- HubSpot internal logic for api auth. Switching from API Key to Private App.

## [2.1.0]

### Fixed
Expand Down Expand Up @@ -150,6 +155,7 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a

- Initial production release.

[2.2.0]: https://github.com/infinum/eightshift-forms/compare/2.1.0...2.2.0
[2.1.0]: https://github.com/infinum/eightshift-forms/compare/2.0.1...2.1.0
[2.0.1]: https://github.com/infinum/eightshift-forms/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/infinum/eightshift-forms/compare/1.4.0...2.0.0
Expand Down
2 changes: 1 addition & 1 deletion eightshift-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Description: Eightshift form builder plugin.
* Author: Team Eightshift
* Author URI: https://eightshift.com/
* Version: 2.1.0
* Version: 2.2.0
* Text Domain: eightshift-forms
*
* @package EightshiftForms
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eightshift/eightshift-forms",
"version": "2.1.0",
"version": "2.2.0",
"description": "This repository contains all the tools you need to start building a modern WordPress project.",
"authors": [
{
Expand Down
6 changes: 3 additions & 3 deletions src/Integrations/Greenhouse/GreenhouseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ private function getGreenhouseJob(string $jobId)
/**
* Set headers used for fetching data.
*
* @param boolean $postHeaders If using post method we need to send Authorization header and type in the request.
* @param boolean $isCurl If using post method we need to send Authorization header and type in the request.
*
* @return array<int|string, string>
*/
private function getHeaders(bool $postHeaders = false): array
private function getHeaders(bool $isCurl = false): array
{
if ($postHeaders) {
if ($isCurl) {
return [
'Authorization: Basic ' . $this->getApiKey(),
'Content-Type: multipart/form-data',
Expand Down
16 changes: 12 additions & 4 deletions src/Integrations/Hubspot/HubspotClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,15 @@ private function postFileMedia(array $file, string $formId): string
\CURLOPT_FAILONERROR => true,
\CURLOPT_POST => true,
\CURLOPT_RETURNTRANSFER => true,
\CURLOPT_POSTFIELDS => $postData
\CURLOPT_POSTFIELDS => $postData,
\CURLOPT_HTTPHEADER => $this->getHeaders(true),
]
);

$response = \curl_exec($curl); // phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_exec
$statusCode = \curl_getinfo($curl, \CURLINFO_HTTP_CODE); // phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_getinfo
\curl_close($curl); // phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_close

error_log( print_r( ( $statusCode ), true ) );

if ($statusCode === 200) {
$response = \json_decode((string) $response, true);

Expand Down Expand Up @@ -562,10 +561,19 @@ private function getHubspotItems()
/**
* Set headers used for fetching data.
*
* @param boolean $isCurl If using post method we need to send Authorization header and type in the request.
*
* @return array<string, mixed>
*/
private function getHeaders(): array
private function getHeaders(bool $isCurl = false): array
{
if ($isCurl) {
return [
'Content-Type: multipart/form-data',
'Authorization: Bearer ' . $this->getApiKey(),
];
}

return [
'Content-Type' => 'application/json; charset=utf-8',
'Authorization' => "Bearer {$this->getApiKey()}"
Expand Down
5 changes: 3 additions & 2 deletions src/Integrations/Hubspot/SettingsHubspot.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,9 @@ public function getSettingsGlobalData(): array
'introSubtitle' => \__('<ol>
<li>Log in to your HubSpot account</li>
<li>Click on the settings cog icon in the top right, next to your account</li>
<li>In the menu on the left, under <strong>Integrations</strong> click <strong>API Key</strong></li>
<li>On the page that loads in the <strong>Active API key</strong> panel, click on <strong>Show</strong>, verify the captcha if needed, then click <strong>Copy</strong></li>
<li>In the menu on the left, under <strong>Integrations</strong> click <strong>Private Apps</strong></li>
<li>Click on <strong>Create a private app</strong></li>
<li>Provide the app name and these scopes: <strong>forms, files, crm.objects.contacts.write, crm.schemas.custom.read</strong>.</li>
<li>Copy the API key into the field below or use the global constant.</li>
</ol>', 'eightshift-forms'),
],
Expand Down
3 changes: 1 addition & 2 deletions src/Rest/ApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use EightshiftForms\Settings\SettingsHelper;
use EightshiftForms\Troubleshooting\SettingsTroubleshooting;
use EightshiftFormsVendor\EightshiftLibs\Helpers\Components;
use WP_Error;

/**
* ApiHelper trait.
Expand Down Expand Up @@ -59,7 +58,7 @@ public function getApiReponseDetails(
): array {

// Do regular stuff if this is not and WP_Error.
if (!is_wp_error($response)) {
if (!\is_wp_error($response)) {
if ($isCurl) {
$code = $response['status'] ?? 200;
$body = $response;
Expand Down
2 changes: 1 addition & 1 deletion src/Settings/SettingsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getOptionValueGroup(string $key): array
return [];
}

return unserialize($value);
return \unserialize($value); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
}

/**
Expand Down

0 comments on commit 43b6c57

Please sign in to comment.