diff --git a/app/services/integrations/hubspot/companies/deploy_properties_service.rb b/app/services/integrations/hubspot/companies/deploy_properties_service.rb new file mode 100644 index 00000000000..b012cbea164 --- /dev/null +++ b/app/services/integrations/hubspot/companies/deploy_properties_service.rb @@ -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 diff --git a/app/services/integrations/hubspot/contacts/deploy_properties_service.rb b/app/services/integrations/hubspot/contacts/deploy_properties_service.rb new file mode 100644 index 00000000000..9fc4cf9583f --- /dev/null +++ b/app/services/integrations/hubspot/contacts/deploy_properties_service.rb @@ -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 diff --git a/app/services/integrations/hubspot/invoices/deploy_object_service.rb b/app/services/integrations/hubspot/invoices/deploy_object_service.rb new file mode 100644 index 00000000000..903f6de21ba --- /dev/null +++ b/app/services/integrations/hubspot/invoices/deploy_object_service.rb @@ -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 diff --git a/app/services/integrations/hubspot/invoices/deploy_properties_service.rb b/app/services/integrations/hubspot/invoices/deploy_properties_service.rb new file mode 100644 index 00000000000..9ce2f18b28c --- /dev/null +++ b/app/services/integrations/hubspot/invoices/deploy_properties_service.rb @@ -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 diff --git a/app/services/integrations/hubspot/subscriptions/deploy_object_service.rb b/app/services/integrations/hubspot/subscriptions/deploy_object_service.rb new file mode 100644 index 00000000000..6c3a587995d --- /dev/null +++ b/app/services/integrations/hubspot/subscriptions/deploy_object_service.rb @@ -0,0 +1,155 @@ +# frozen_string_literal: true + +module Integrations + module Hubspot + module Subscriptions + 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.subscriptions_properties_version == VERSION + response = nil + ActiveRecord::Base.transaction do + response = http_client.post_with_response(payload, headers) + integration.subscriptions_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 + { + secondaryDisplayProperties: [ + "lago_external_subscription_id" + ], + requiredProperties: [ + "lago_subscription_id" + ], + searchableProperties: %w[lago_subscription_id lago_external_subscription_id], + name: "LagoSubscriptions", + associatedObjects: %w[COMPANY CONTACT], + properties: [ + { + name: "lago_subscription_id", + label: "Lago Subscription Id", + type: "string", + fieldType: "text", + hasUniqueValue: true, + searchableInGlobalSearch: true + }, + { + name: "lago_external_subscription_id", + label: "Lago External Subscription Id", + type: "string", + fieldType: "text", + searchableInGlobalSearch: true + }, + { + name: "lago_subscription_name", + label: "Lago Subscription Name", + type: "string", + fieldType: "text" + }, + { + name: "lago_subscription_plan_code", + label: "Lago Subscription Plan Code", + type: "string", + fieldType: "text" + }, + { + name: "lago_subscription_status", + label: "Lago Subscription Status", + type: "string", + fieldType: "text" + }, + { + name: "lago_subscription_created_at", + label: "Lago Subscription Created At", + type: "date", + fieldType: "date" + }, + { + name: "lago_subscription_started_at", + label: "Lago Subscription Started At", + type: "date", + fieldType: "date" + }, + { + name: "lago_subscription_ending_at", + label: "Lago Subscription Ending At", + type: "date", + fieldType: "date" + }, + { + name: "lago_subscription_at", + label: "Lago Subscription At", + type: "date", + fieldType: "date" + }, + { + name: "lago_subscription_terminated_at", + label: "Lago Subscription Terminated At", + type: "date", + fieldType: "date" + }, + { + name: "lago_subscription_trial_ended_at", + label: "Lago Subscription Trial Ended At", + type: "date", + fieldType: "date" + }, + { + name: "lago_billing_time", + label: "Lago Billing Time", + type: "enumeration", + fieldType: "radio", + displayOrder: -1, + hasUniqueValue: false, + searchableInGlobalSearch: true, + formField: true, + options: [ + { + label: "Calendar", + value: "calendar", + displayOrder: 1 + }, + { + label: "Anniversary", + value: "anniversary", + displayOrder: 2 + } + ] + } + ], + labels: { + singular: "LagoSubscription", + plural: "LagoSubscriptions" + }, + primaryDisplayProperty: "lago_subscription_id", + description: "string" + } + end + end + end + end +end diff --git a/app/services/integrations/hubspot/subscriptions/deploy_properties_service.rb b/app/services/integrations/hubspot/subscriptions/deploy_properties_service.rb new file mode 100644 index 00000000000..be27628fffc --- /dev/null +++ b/app/services/integrations/hubspot/subscriptions/deploy_properties_service.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +module Integrations + module Hubspot + module Subscriptions + 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.subscriptions_properties_version == VERSION + response = nil + ActiveRecord::Base.transaction do + response = http_client.post_with_response(payload, headers) + integration.subscriptions_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: "LagoSubscriptions", + inputs: [ + { + groupName: "lagosubscriptions_information", + name: "example", + label: "example label", + type: "string", + fieldType: "text" + } + ] + } + end + end + end + end +end