Class: Sendly::BusinessUpgradeResource

Inherits:
Object
  • Object
show all
Defined in:
lib/sendly/business_upgrade_resource.rb

Overview

Business Upgrade resource — Entity-Upgrade (“fork-with-new-number”)

Manages the toll-free business entity upgrade flow: when a customer forms a new legal entity (e.g. an LLC), this resource lets them reserve a new toll-free number under the new entity, submit it for carrier review, and atomically swap to it on approval — without disrupting outbound SMS during the 1-2 week review window.

Examples:

Validate before submitting

preview = client.business_upgrade.preflight(
  business_name: "Acme Holdings LLC",
  brn: "12-3456789",
  brn_type: "EIN",
  brn_country: "US",
  entity_type: "PRIVATE_PROFIT"
)

Submit an upgrade with the IRS letter

result = client.business_upgrade.start(
  "ws_abc",
  business_name: "Acme Holdings LLC",
  brn: "12-3456789",
  brn_type: "EIN",
  brn_country: "US",
  entity_type: "PRIVATE_PROFIT",
  ein_doc_path: "./CP-575.pdf"
)

See Also:

Constant Summary collapse

ENTITY_TYPES =

Entity types accepted by the carrier

%w[
  SOLE_PROPRIETOR
  PRIVATE_PROFIT
  PUBLIC_PROFIT
  NON_PROFIT
  GOVERNMENT
].freeze
BRN_TYPES =

Business Registration Number types

%w[EIN SSN DUNS CRA VAT LEI OTHER].freeze
DISPOSITIONS =

Disposition options for the old toll-free number after approval

%w[moved released].freeze

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ BusinessUpgradeResource

Returns a new instance of BusinessUpgradeResource.



54
55
56
# File 'lib/sendly/business_upgrade_resource.rb', line 54

def initialize(client)
  @client = client
end

Instance Method Details

#best_prefillHash

Get a “best-of” prefill across all the caller’s verified workspaces. Returns most-recent non-empty values per messaging field. Use this to pre-populate the upgrade form for users whose current workspace has incomplete data.

Returns:

  • (Hash)

    { “prefill” => {…}, “sourceWorkspaceCount” => Integer }



126
127
128
# File 'lib/sendly/business_upgrade_resource.rb', line 126

def best_prefill
  @client.get("/verification/best-prefill")
end

#cancel(workspace_id) ⇒ Hash

Cancel a pending entity upgrade for the given workspace. Releases the reserved toll-free number, deletes the new messaging profile, and removes the stored EIN document. Idempotent.

Parameters:

  • workspace_id (String)

Returns:

  • (Hash)

Raises:

  • (ArgumentError)


208
209
210
211
212
# File 'lib/sendly/business_upgrade_resource.rb', line 208

def cancel(workspace_id)
  raise ArgumentError, "Workspace ID is required" if workspace_id.nil? || workspace_id.empty?

  @client.post("/workspaces/#{url_escape(workspace_id)}/upgrade/cancel", {})
end

#preflight(business_name: nil, brn: nil, brn_type: nil, brn_country: nil, entity_type: nil, doing_business_as: nil, website: nil, address1: nil, address2: nil, city: nil, state: nil, zip: nil, address_country: nil, contact_first_name: nil, contact_last_name: nil, contact_email: nil, contact_phone: nil, monthly_volume: nil, use_case: nil, use_case_summary: nil, sample_messages: nil, opt_in_workflow: nil, privacy_url: nil, terms_url: nil, additional_information: nil, age_gated_content: nil) ⇒ Hash

Validate a candidate entity upgrade payload before submission. Returns issues + proposed auto-fixes. No writes — purely advisory.

Accepts the same fields as start. Returns a hash with verdict (+“ready”+, “warnings”, “blocked”), issues, and proposedFixes.

Parameters:

  • business_name (String, nil) (defaults to: nil)
  • brn (String, nil) (defaults to: nil)
  • brn_type (String, nil) (defaults to: nil)

    One of BRN_TYPES

  • brn_country (String, nil) (defaults to: nil)

    ISO country code

  • entity_type (String, nil) (defaults to: nil)

    One of ENTITY_TYPES

  • doing_business_as (String, nil) (defaults to: nil)
  • website (String, nil) (defaults to: nil)
  • address1 (String, nil) (defaults to: nil)
  • address2 (String, nil) (defaults to: nil)
  • city (String, nil) (defaults to: nil)
  • state (String, nil) (defaults to: nil)
  • zip (String, nil) (defaults to: nil)
  • address_country (String, nil) (defaults to: nil)
  • contact_first_name (String, nil) (defaults to: nil)
  • contact_last_name (String, nil) (defaults to: nil)
  • contact_email (String, nil) (defaults to: nil)
  • contact_phone (String, nil) (defaults to: nil)
  • monthly_volume (String, nil) (defaults to: nil)
  • use_case (String, nil) (defaults to: nil)
  • use_case_summary (String, nil) (defaults to: nil)
  • sample_messages (String, nil) (defaults to: nil)
  • opt_in_workflow (String, nil) (defaults to: nil)
  • privacy_url (String, nil) (defaults to: nil)
  • terms_url (String, nil) (defaults to: nil)
  • additional_information (String, nil) (defaults to: nil)
  • age_gated_content (Boolean, nil) (defaults to: nil)

Returns:

  • (Hash)

    Preflight report



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/sendly/business_upgrade_resource.rb', line 92

def preflight(business_name: nil, brn: nil, brn_type: nil, brn_country: nil,
              entity_type: nil, doing_business_as: nil, website: nil,
              address1: nil, address2: nil, city: nil, state: nil, zip: nil,
              address_country: nil, contact_first_name: nil,
              contact_last_name: nil, contact_email: nil, contact_phone: nil,
              monthly_volume: nil, use_case: nil, use_case_summary: nil,
              sample_messages: nil, opt_in_workflow: nil, privacy_url: nil,
              terms_url: nil, additional_information: nil,
              age_gated_content: nil)
  body = build_upgrade_body(
    business_name: business_name, brn: brn, brn_type: brn_type,
    brn_country: brn_country, entity_type: entity_type,
    doing_business_as: doing_business_as, website: website,
    address1: address1, address2: address2, city: city, state: state,
    zip: zip, address_country: address_country,
    contact_first_name: contact_first_name,
    contact_last_name: contact_last_name, contact_email: contact_email,
    contact_phone: contact_phone, monthly_volume: monthly_volume,
    use_case: use_case, use_case_summary: use_case_summary,
    sample_messages: sample_messages, opt_in_workflow: opt_in_workflow,
    privacy_url: privacy_url, terms_url: terms_url,
    additional_information: additional_information,
    age_gated_content: age_gated_content
  )

  @client.post("/verification/preflight", body)
end

#resubmit(workspace_id, business_name: nil, brn: nil, brn_type: nil, brn_country: nil, entity_type: nil, doing_business_as: nil, website: nil, address1: nil, address2: nil, city: nil, state: nil, zip: nil, address_country: nil, contact_first_name: nil, contact_last_name: nil, contact_email: nil, contact_phone: nil, monthly_volume: nil, use_case: nil, use_case_summary: nil, sample_messages: nil, opt_in_workflow: nil, privacy_url: nil, terms_url: nil, additional_information: nil, age_gated_content: nil, ein_doc_path: nil, ein_doc: nil, ein_doc_filename: nil, ein_doc_content_type: nil) ⇒ Hash

Resubmit a rejected (or waiting-for-customer) entity upgrade with updated fields and optionally a new EIN document. All fields are optional — only the ones you pass are sent.

Parameters:

  • workspace_id (String)

Returns:

  • (Hash)

Raises:

  • (ArgumentError)


220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/sendly/business_upgrade_resource.rb', line 220

def resubmit(workspace_id, business_name: nil, brn: nil, brn_type: nil,
             brn_country: nil, entity_type: nil, doing_business_as: nil,
             website: nil, address1: nil, address2: nil, city: nil,
             state: nil, zip: nil, address_country: nil,
             contact_first_name: nil, contact_last_name: nil,
             contact_email: nil, contact_phone: nil, monthly_volume: nil,
             use_case: nil, use_case_summary: nil, sample_messages: nil,
             opt_in_workflow: nil, privacy_url: nil, terms_url: nil,
             additional_information: nil, age_gated_content: nil,
             ein_doc_path: nil, ein_doc: nil, ein_doc_filename: nil,
             ein_doc_content_type: nil)
  raise ArgumentError, "Workspace ID is required" if workspace_id.nil? || workspace_id.empty?

  fields = build_upgrade_body(
    business_name: business_name, brn: brn, brn_type: brn_type,
    brn_country: brn_country, entity_type: entity_type,
    doing_business_as: doing_business_as, website: website,
    address1: address1, address2: address2, city: city, state: state,
    zip: zip, address_country: address_country,
    contact_first_name: contact_first_name,
    contact_last_name: contact_last_name, contact_email: contact_email,
    contact_phone: contact_phone, monthly_volume: monthly_volume,
    use_case: use_case, use_case_summary: use_case_summary,
    sample_messages: sample_messages, opt_in_workflow: opt_in_workflow,
    privacy_url: privacy_url, terms_url: terms_url,
    additional_information: additional_information,
    age_gated_content: age_gated_content
  )

  post_multipart_with_fields(
    "/workspaces/#{url_escape(workspace_id)}/upgrade/resubmit",
    fields,
    ein_doc_path: ein_doc_path,
    ein_doc: ein_doc,
    ein_doc_filename: ein_doc_filename,
    ein_doc_content_type: ein_doc_content_type
  )
end

#set_disposition(workspace_id, disposition:, target_workspace_id: nil) ⇒ Hash

After a successful entity-upgrade approval, choose what happens to the old toll-free number:

  • “moved”: keep it active under another workspace owned by the same user (requires target_workspace_id)

  • “released”: return it to the carrier pool

Parameters:

  • workspace_id (String)
  • disposition (String)

    “moved” or “released”

  • target_workspace_id (String, nil) (defaults to: nil)

    Required when disposition is “moved”

Returns:

  • (Hash)

Raises:

  • (ArgumentError)


270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/sendly/business_upgrade_resource.rb', line 270

def set_disposition(workspace_id, disposition:, target_workspace_id: nil)
  raise ArgumentError, "Workspace ID is required" if workspace_id.nil? || workspace_id.empty?
  unless DISPOSITIONS.include?(disposition)
    raise ArgumentError, "disposition must be one of: #{DISPOSITIONS.join(", ")}"
  end
  if disposition == "moved" && (target_workspace_id.nil? || target_workspace_id.empty?)
    raise ArgumentError, "target_workspace_id is required when disposition is 'moved'"
  end

  body = { disposition: disposition }
  body[:targetOrgId] = target_workspace_id if target_workspace_id

  @client.post("/workspaces/#{url_escape(workspace_id)}/upgrade/disposition", body)
end

#start(workspace_id, business_name:, brn:, brn_type:, brn_country:, entity_type:, doing_business_as: nil, website: nil, address1: nil, address2: nil, city: nil, state: nil, zip: nil, address_country: nil, contact_first_name: nil, contact_last_name: nil, contact_email: nil, contact_phone: nil, monthly_volume: nil, use_case: nil, use_case_summary: nil, sample_messages: nil, opt_in_workflow: nil, privacy_url: nil, terms_url: nil, additional_information: nil, age_gated_content: nil, ein_doc_path: nil, ein_doc: nil, ein_doc_filename: nil, ein_doc_content_type: nil) ⇒ Hash

Start an entity upgrade for the given workspace. Auto-provisions a new toll-free number + messaging profile and submits to the carrier for review. Returns the pending verification details.

The current toll-free number continues sending throughout the 1-2 week carrier review; on approval, an atomic swap promotes the new number.

The EIN document (when supplied) is uploaded as multipart form-data under the einDoc field. Provide either ein_doc_path (a path on disk) or ein_doc (raw bytes / IO) — not both.

Parameters:

  • workspace_id (String)
  • business_name (String)
  • brn (String)
  • brn_type (String)

    One of BRN_TYPES

  • brn_country (String)

    ISO country code

  • entity_type (String)

    One of ENTITY_TYPES

  • ein_doc_path (String, nil) (defaults to: nil)

    Path to the EIN/CP-575 PDF

  • ein_doc (String, IO, nil) (defaults to: nil)

    Raw EIN PDF bytes or IO

  • ein_doc_filename (String, nil) (defaults to: nil)

    Filename (defaults to “ein-doc.pdf”)

  • ein_doc_content_type (String, nil) (defaults to: nil)

    MIME type (defaults to “application/pdf”)

Returns:

  • (Hash)

    Upgrade start response

Raises:

  • (ArgumentError)


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/sendly/business_upgrade_resource.rb', line 153

def start(workspace_id, business_name:, brn:, brn_type:, brn_country:,
          entity_type:, doing_business_as: nil, website: nil,
          address1: nil, address2: nil, city: nil, state: nil, zip: nil,
          address_country: nil, contact_first_name: nil,
          contact_last_name: nil, contact_email: nil, contact_phone: nil,
          monthly_volume: nil, use_case: nil, use_case_summary: nil,
          sample_messages: nil, opt_in_workflow: nil, privacy_url: nil,
          terms_url: nil, additional_information: nil,
          age_gated_content: nil, ein_doc_path: nil, ein_doc: nil,
          ein_doc_filename: nil, ein_doc_content_type: nil)
  raise ArgumentError, "Workspace ID is required" if workspace_id.nil? || workspace_id.empty?

  fields = build_upgrade_body(
    business_name: business_name, brn: brn, brn_type: brn_type,
    brn_country: brn_country, entity_type: entity_type,
    doing_business_as: doing_business_as, website: website,
    address1: address1, address2: address2, city: city, state: state,
    zip: zip, address_country: address_country,
    contact_first_name: contact_first_name,
    contact_last_name: contact_last_name, contact_email: contact_email,
    contact_phone: contact_phone, monthly_volume: monthly_volume,
    use_case: use_case, use_case_summary: use_case_summary,
    sample_messages: sample_messages, opt_in_workflow: opt_in_workflow,
    privacy_url: privacy_url, terms_url: terms_url,
    additional_information: additional_information,
    age_gated_content: age_gated_content
  )

  post_multipart_with_fields(
    "/workspaces/#{url_escape(workspace_id)}/upgrade",
    fields,
    ein_doc_path: ein_doc_path,
    ein_doc: ein_doc,
    ein_doc_filename: ein_doc_filename,
    ein_doc_content_type: ein_doc_content_type
  )
end

#status(workspace_id) ⇒ Hash

Check whether the given workspace has a pending entity upgrade. Returns { “pending” => nil } when no upgrade is in flight.

Parameters:

  • workspace_id (String)

Returns:

  • (Hash)

Raises:

  • (ArgumentError)


196
197
198
199
200
# File 'lib/sendly/business_upgrade_resource.rb', line 196

def status(workspace_id)
  raise ArgumentError, "Workspace ID is required" if workspace_id.nil? || workspace_id.empty?

  @client.get("/workspaces/#{url_escape(workspace_id)}/upgrade/status")
end