-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHubSpotService.php
More file actions
56 lines (46 loc) · 1.25 KB
/
HubSpotService.php
File metadata and controls
56 lines (46 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace FormatD\HubSpot\Service;
use HubSpot\Discovery\Discovery;
use Neos\Flow\Annotations as Flow;
use Psr\Http\Message\ResponseInterface;
/**
* @Flow\Scope("singleton")
*/
class HubSpotService
{
/**
* @var array
* @Flow\InjectConfiguration(path="api", package="FormatD.HubSpot")
*/
protected array $apiConfiguration;
/**
* @var Discovery
*/
protected Discovery $hubspotApi;
/**
* @return void
*/
public function initializeObject(): void {
$this->hubspotApi = \HubSpot\Factory::createWithAccessToken($this->apiConfiguration['accessToken']);
}
/**
* @param string $formGuid
* @param array $formFields
* @param array $context
* @param array $legalConsentOptions
* @return ResponseInterface
*/
public function submitForm(string $formGuid, array $formFields, array $context, array $legalConsentOptions): ResponseInterface {
$requestOptions = [
'method' => 'POST',
'baseUrl' => 'https://api.hsforms.com',
'path' => '/submissions/v3/integration/submit/' . $this->apiConfiguration['portalId'] . '/' . $formGuid,
'body' => [
"fields" => $formFields,
"context" => $context,
"legalConsentOptions" => $legalConsentOptions,
],
];
return $this->hubspotApi->apiRequest($requestOptions);
}
}