-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat hubspot customers services (#2674)
## Roadmap Task 👉 https://getlago.canny.io/feature-requests/p/integration-with-hubspot ## Context When creating or updating customers in Lago, we must sync them to Hubspot. Depending on if Lago customer is either company or individual, we need to call different services (Nango endpoints). ## Description This PR implements services that handle syncing the customers either as companies or contacts to Hubspot via Nango.
- Loading branch information
1 parent
c393c01
commit faa7518
Showing
85 changed files
with
3,237 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
.../aggregator/send_private_app_token_job.rb → ...ntegrations/hubspot/save_portal_id_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
module IntegrationCustomers | ||
class HubspotService < ::BaseService | ||
def initialize(integration:, customer:, subsidiary_id:, **params) | ||
@customer = customer | ||
@subsidiary_id = subsidiary_id | ||
@integration = integration | ||
@params = params&.with_indifferent_access | ||
|
||
super(nil) | ||
end | ||
|
||
def create | ||
create_result = create_service_class.call( | ||
integration:, | ||
customer:, | ||
subsidiary_id: nil | ||
) | ||
|
||
return create_result if create_result.error | ||
|
||
new_integration_customer = IntegrationCustomers::BaseCustomer.create!( | ||
integration:, | ||
customer:, | ||
external_customer_id: create_result.contact_id, | ||
email: create_result.email, | ||
type: 'IntegrationCustomers::HubspotCustomer', | ||
sync_with_provider: true, | ||
targeted_object: | ||
) | ||
|
||
result.integration_customer = new_integration_customer | ||
result | ||
end | ||
|
||
private | ||
|
||
attr_reader :integration, :customer, :subsidiary_id, :params | ||
|
||
def create_service_class | ||
@create_service_class ||= if targeted_object == 'contacts' | ||
Integrations::Aggregator::Contacts::CreateService | ||
else | ||
Integrations::Aggregator::Companies::CreateService | ||
end | ||
end | ||
|
||
def targeted_object | ||
@targeted_object ||= params[:targeted_object] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/services/integrations/aggregator/account_information_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module Integrations | ||
module Aggregator | ||
class AccountInformationService < BaseService | ||
def action_path | ||
'v1/account-information' | ||
end | ||
|
||
def call | ||
response = http_client.get(headers:) | ||
|
||
result.account_information = OpenStruct.new(response) | ||
result | ||
end | ||
|
||
private | ||
|
||
def headers | ||
{ | ||
'Connection-Id' => integration.connection_id, | ||
'Authorization' => "Bearer #{secret_key}", | ||
'Provider-Config-Key' => provider_key | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/services/integrations/aggregator/companies/base_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module Integrations | ||
module Aggregator | ||
module Companies | ||
class BaseService < Integrations::Aggregator::Contacts::BaseService | ||
def action_path | ||
"v1/#{provider}/companies" | ||
end | ||
|
||
private | ||
|
||
def process_hash_result(body) | ||
contact = body['succeededCompanies']&.first | ||
contact_id = contact&.dig('id') | ||
email = contact&.dig('email') | ||
|
||
if contact_id | ||
result.contact_id = contact_id | ||
result.email = email if email.present? | ||
else | ||
message = if body.key?('failedCompanies') | ||
body['failedCompanies'].first['validation_errors'].map { |error| error['Message'] }.join(". ") | ||
else | ||
body.dig('error', 'payload', 'message') | ||
end | ||
|
||
code = 'Validation error' | ||
|
||
deliver_error_webhook(customer:, code:, message:) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.