-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fb7353
commit f5b3686
Showing
12 changed files
with
807 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
app/services/integrations/hubspot/companies/deploy_properties_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,89 @@ | ||
# frozen_string_literal: true | ||
|
||
module Integrations | ||
module Hubspot | ||
module Companies | ||
class DeployPropertiesService < Integrations::Aggregator::BaseService | ||
VERSION = 1 | ||
|
||
def action_path | ||
"v1/hubspot/properties" | ||
end | ||
|
||
def call | ||
return unless integration.type == 'Integrations::HubspotIntegration' | ||
return result if integration.companies_properties_version == VERSION | ||
response = nil | ||
ActiveRecord::Base.transaction do | ||
response = http_client.post_with_response(payload, headers) | ||
integration.companies_properties_version = VERSION | ||
integration.save! | ||
end | ||
result.response = response | ||
result | ||
rescue LagoHttpClient::HttpError | ||
# code = code(e) | ||
# message = message(e) | ||
# deliver_error_webhook(customer:, code:, message:) | ||
end | ||
|
||
private | ||
|
||
def headers | ||
{ | ||
'Provider-Config-Key' => 'hubspot', | ||
'Authorization' => "Bearer #{secret_key}", | ||
'Connection-Id' => integration.connection_id | ||
} | ||
end | ||
|
||
def payload | ||
{ | ||
objectType: "companies", | ||
inputs: [ | ||
{ | ||
groupName: "companyinformation", | ||
name: "lago_customer_id", | ||
label: "Lago Customer Id", | ||
type: "string", | ||
fieldType: "text", | ||
displayOrder: -1, | ||
hasUniqueValue: true, | ||
searchableInGlobalSearch: true, | ||
formField: true | ||
}, | ||
{ | ||
groupName: "companyinformation", | ||
name: "lago_customer_external_id", | ||
label: "Lago Customer External Id", | ||
type: "string", | ||
fieldType: "text", | ||
displayOrder: -1, | ||
searchableInGlobalSearch: true, | ||
formField: true | ||
}, | ||
{ | ||
groupName: "companyinformation", | ||
name: "lago_billing_email", | ||
label: "Lago Billing Email", | ||
type: "string", | ||
fieldType: "text", | ||
searchableInGlobalSearch: true, | ||
formField: true | ||
}, | ||
{ | ||
groupName: "companyinformation", | ||
name: "lago_tax_identification_number", | ||
label: "Lago Tax Identification Number", | ||
type: "string", | ||
fieldType: "text", | ||
searchableInGlobalSearch: true, | ||
formField: true | ||
} | ||
] | ||
}.freeze | ||
end | ||
end | ||
end | ||
end | ||
end |
81 changes: 81 additions & 0 deletions
81
app/services/integrations/hubspot/contacts/deploy_properties_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,81 @@ | ||
# frozen_string_literal: true | ||
|
||
module Integrations | ||
module Hubspot | ||
module Contacts | ||
class DeployPropertiesService < Integrations::Aggregator::BaseService | ||
VERSION = 1 | ||
|
||
def action_path | ||
"v1/hubspot/properties" | ||
end | ||
|
||
def call | ||
return unless integration.type == 'Integrations::HubspotIntegration' | ||
return result if integration.contacts_properties_version == VERSION | ||
response = nil | ||
ActiveRecord::Base.transaction do | ||
response = http_client.post_with_response(payload, headers) | ||
integration.contacts_properties_version = VERSION | ||
integration.save! | ||
end | ||
result.response = response | ||
result | ||
rescue LagoHttpClient::HttpError | ||
# code = code(e) | ||
# message = message(e) | ||
# deliver_error_webhook(customer:, code:, message:) | ||
end | ||
|
||
private | ||
|
||
def headers | ||
{ | ||
'Provider-Config-Key' => 'hubspot', | ||
'Authorization' => "Bearer #{secret_key}", | ||
'Connection-Id' => integration.connection_id | ||
} | ||
end | ||
|
||
def payload | ||
{ | ||
objectType: "contacts", | ||
inputs: [ | ||
{ | ||
groupName: "contactinformation", | ||
name: "lago_customer_id", | ||
label: "Lago Customer Id", | ||
type: "string", | ||
fieldType: "text", | ||
displayOrder: -1, | ||
hasUniqueValue: true, | ||
searchableInGlobalSearch: true, | ||
formField: true | ||
}, | ||
{ | ||
groupName: "contactinformation", | ||
name: "lago_customer_external_id", | ||
label: "Lago Customer External Id", | ||
type: "string", | ||
fieldType: "text", | ||
displayOrder: -1, | ||
hasUniqueValue: true, | ||
searchableInGlobalSearch: true, | ||
formField: true | ||
}, | ||
{ | ||
groupName: "contactinformation", | ||
name: "lago_billing_email", | ||
label: "Lago Billing Email", | ||
type: "string", | ||
fieldType: "text", | ||
searchableInGlobalSearch: true, | ||
formField: true | ||
} | ||
] | ||
}.freeze | ||
end | ||
end | ||
end | ||
end | ||
end |
148 changes: 148 additions & 0 deletions
148
app/services/integrations/hubspot/invoices/deploy_object_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,148 @@ | ||
# frozen_string_literal: true | ||
|
||
module Integrations | ||
module Hubspot | ||
module Invoices | ||
class DeployObjectService < Integrations::Aggregator::BaseService | ||
VERSION = 1 | ||
|
||
def action_path | ||
"v1/hubspot/object" | ||
end | ||
|
||
def call | ||
return unless integration.type == 'Integrations::HubspotIntegration' | ||
return result if integration.invoices_properties_version == VERSION | ||
response = nil | ||
ActiveRecord::Base.transaction do | ||
response = http_client.post_with_response(payload, headers) | ||
integration.invoices_properties_version = VERSION | ||
integration.save! | ||
end | ||
result.response = response | ||
result | ||
rescue LagoHttpClient::HttpError | ||
# code = code(e) | ||
# message = message(e) | ||
# deliver_error_webhook(customer: nil, code:, message:) | ||
end | ||
|
||
private | ||
|
||
def headers | ||
{ | ||
'Provider-Config-Key' => 'hubspot', | ||
'Authorization' => "Bearer #{secret_key}", | ||
'Connection-Id' => integration.connection_id | ||
} | ||
end | ||
|
||
def payload | ||
{ | ||
name: "LagoInvoices", | ||
description: "Invoices issued by Lago billing engine", | ||
requiredProperties: [ | ||
"lago_invoice_id" | ||
], | ||
labels: { | ||
singular: "LagoInvoice", | ||
plural: "LagoInvoices" | ||
}, | ||
primaryDisplayProperty: "lago_invoice_number", | ||
secondaryDisplayProperties: %w[lago_invoice_status lago_invoice_id], | ||
searchableProperties: %w[lago_invoice_number lago_invoice_id], | ||
properties: [ | ||
{ | ||
name: "lago_invoice_id", | ||
label: "Lago Invoice Id", | ||
type: "string", | ||
fieldType: "text", | ||
hasUniqueValue: true, | ||
searchableInGlobalSearch: true | ||
}, | ||
{ | ||
name: "lago_invoice_number", | ||
label: "Lago Invoice Number", | ||
type: "string", | ||
fieldType: "text", | ||
searchableInGlobalSearch: true | ||
}, | ||
{ | ||
name: "lago_invoice_issuing_date", | ||
label: "Lago Invoice Issuing Date", | ||
type: "date", | ||
fieldType: "date" | ||
}, | ||
{ | ||
name: "lago_invoice_payment_due_date", | ||
label: "Lago Invoice Payment Due Date", | ||
type: "date", | ||
fieldType: "date" | ||
}, | ||
{ | ||
name: "lago_invoice_payment_overdue", | ||
label: "Lago Invoice Payment Overdue", | ||
groupName: "LagoInvoices", | ||
type: "bool", | ||
fieldType: "booleancheckbox", | ||
options: [ | ||
{ | ||
label: "True", | ||
value: "true" | ||
}, | ||
{ | ||
label: "False", | ||
value: "false" | ||
} | ||
] | ||
}, | ||
{ | ||
name: "lago_invoice_type", | ||
label: "Lago Invoice Type", | ||
type: "string", | ||
fieldType: "text" | ||
}, | ||
{ | ||
name: "lago_invoice_status", | ||
label: "Lago Invoice Status", | ||
type: "string", | ||
fieldType: "text" | ||
}, | ||
{ | ||
name: "lago_invoice_payment_status", | ||
label: "Lago Invoice Payment Status", | ||
type: "string", | ||
fieldType: "text" | ||
}, | ||
{ | ||
name: "lago_invoice_currency", | ||
label: "Lago Invoice Currency", | ||
type: "string", | ||
fieldType: "text" | ||
}, | ||
{ | ||
name: "lago_invoice_total_amount", | ||
label: "Lago Invoice Total Amount", | ||
type: "number", | ||
fieldType: "number" | ||
}, | ||
{ | ||
name: "lago_invoice_subtotal_excluding_taxes", | ||
label: "Lago Invoice Subtotal Excluding Taxes", | ||
type: "number", | ||
fieldType: "number" | ||
}, | ||
{ | ||
name: "lago_invoice_file_url", | ||
label: "Lago Invoice File URL", | ||
type: "string", | ||
fieldType: "file" | ||
} | ||
], | ||
associatedObjects: %w[COMPANY CONTACT] | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
57 changes: 57 additions & 0 deletions
57
app/services/integrations/hubspot/invoices/deploy_properties_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,57 @@ | ||
# frozen_string_literal: true | ||
|
||
module Integrations | ||
module Hubspot | ||
module Invoices | ||
class DeployPropertiesService < Integrations::Aggregator::BaseService | ||
VERSION = 1 | ||
|
||
def action_path | ||
"v1/hubspot/properties" | ||
end | ||
|
||
def call | ||
return unless integration.type == 'Integrations::HubspotIntegration' | ||
return result if integration.invoices_properties_version == VERSION | ||
response = nil | ||
ActiveRecord::Base.transaction do | ||
response = http_client.post_with_response(payload, headers) | ||
integration.invoices_properties_version = VERSION | ||
integration.save! | ||
end | ||
result.response = response | ||
result | ||
rescue LagoHttpClient::HttpError | ||
# code = code(e) | ||
# message = message(e) | ||
# deliver_error_webhook(customer:, code:, message:) | ||
end | ||
|
||
private | ||
|
||
def headers | ||
{ | ||
'Provider-Config-Key' => 'hubspot', | ||
'Authorization' => "Bearer #{secret_key}", | ||
'Connection-Id' => integration.connection_id | ||
} | ||
end | ||
|
||
def payload | ||
{ | ||
objectType: "LagoInvoices", | ||
inputs: [ | ||
{ | ||
groupName: "lagoinvoices_information", | ||
name: "example", | ||
label: "example label", | ||
type: "string", | ||
fieldType: "text" | ||
} | ||
] | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.