Skip to content

Commit

Permalink
feat: added the services
Browse files Browse the repository at this point in the history
  • Loading branch information
brunomiguelpinto committed Oct 4, 2024
1 parent 0fb7353 commit f5b3686
Show file tree
Hide file tree
Showing 12 changed files with 807 additions and 0 deletions.
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
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 app/services/integrations/hubspot/invoices/deploy_object_service.rb
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
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
Loading

0 comments on commit f5b3686

Please sign in to comment.