Skip to content

Commit a917f4f

Browse files
authored
Merge pull request #45 from umbraco/feature/update-contact-optional
Allow contact update flag for CRM
2 parents 4f73f06 + 002ab52 commit a917f4f

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

azure-pipeline - Crm.ActiveCampaign.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ steps:
4343
inputs:
4444
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
4545
ArtifactName: 'drop'
46-
publishLocation: 'Container'
46+
publishLocation: 'Container'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+

2+
using System.Collections.Specialized;
3+
4+
namespace Umbraco.Forms.Integrations.Crm.Hubspot.Configuration
5+
{
6+
public class HubspotSettings
7+
{
8+
public HubspotSettings(NameValueCollection appSettings)
9+
{
10+
var settings = appSettings["Umbraco.Forms.Integrations.Crm.Hubspot.AllowContactUpdate"];
11+
AllowContactUpdate = bool.TryParse(settings, out var result)
12+
? result : false;
13+
}
14+
15+
public bool AllowContactUpdate { get; }
16+
}
17+
}

src/Umbraco.Forms.Integrations.Crm.Hubspot/Services/HubspotContactService.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Newtonsoft.Json;
22
using System;
33
using System.Collections.Generic;
4+
using System.Configuration;
45
using System.Linq;
56
using System.Net;
67
using System.Net.Http;
@@ -12,6 +13,7 @@
1213
using Umbraco.Core.Services;
1314
using Umbraco.Forms.Core;
1415
using Umbraco.Forms.Core.Persistence.Dtos;
16+
using Umbraco.Forms.Integrations.Crm.Hubspot.Configuration;
1517
using Umbraco.Forms.Integrations.Crm.Hubspot.Extensions;
1618
using Umbraco.Forms.Integrations.Crm.Hubspot.Models;
1719
using Umbraco.Forms.Integrations.Crm.Hubspot.Models.Dtos;
@@ -31,6 +33,7 @@ public class HubspotContactService : IContactService
3133
private readonly ILogger _logger;
3234
private readonly AppCaches _appCaches;
3335
private readonly IKeyValueService _keyValueService;
36+
private readonly HubspotSettings _settings;
3437

3538
private const string CrmApiHost = "https://api.hubapi.com";
3639
private static readonly string CrmV3ApiBaseUrl = $"{CrmApiHost}/crm/v3/";
@@ -53,6 +56,8 @@ public HubspotContactService(IFacadeConfiguration configuration, ILogger logger,
5356
_logger = logger;
5457
_appCaches = appCaches;
5558
_keyValueService = keyValueService;
59+
60+
_settings = new HubspotSettings(ConfigurationManager.AppSettings);
5661
}
5762

5863
public AuthenticationMode IsAuthorizationConfigured() => GetConfiguredAuthenticationDetails().Mode;
@@ -194,7 +199,12 @@ public async Task<CommandResult> PostContactAsync(Record record, List<MappedProp
194199
// A 409 - Conflict response indicates that the contact (by email address) already exists.
195200
if (response.StatusCode == HttpStatusCode.Conflict)
196201
{
197-
return await UpdateContactAsync(record, authenticationDetails, propertiesRequestV1, emailValue);
202+
if (!_settings.AllowContactUpdate)
203+
_logger.Info<HubspotContactService>("Contact already exists in HubSpot CRM and workflow is configured to not apply updates, so update of information was skipped.");
204+
205+
return _settings.AllowContactUpdate
206+
? await UpdateContactAsync(record, authenticationDetails, propertiesRequestV1, emailValue)
207+
: CommandResult.Success;
198208
}
199209
else
200210
{

0 commit comments

Comments
 (0)