Class: Stigg::Resources::V1::Contracts

Inherits:
Object
  • Object
show all
Defined in:
lib/stigg/resources/v1/contracts.rb,
sig/stigg/resources/v1/contracts.rbs

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Contracts

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Contracts.

Parameters:



219
220
221
# File 'lib/stigg/resources/v1/contracts.rb', line 219

def initialize(client:)
  @client = client
end

Instance Method Details

#create(customer_id:, subscriptions:, activation_end_date: nil, activation_start_date: nil, name: nil, po_number: nil, setup_billing: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::ContractCreateResponse

Some parameter documentations has been truncated, see Models::V1::ContractCreateParams for more details.

Creates a contract for a customer together with all of its (custom) subscriptions in a single atomic operation. Every new subscription is created inside one transaction — any validation or creation failure rolls the whole contract back. Each subscription entry is either a new subscription to create or a reference to an existing custom subscription. Returns the created contract.

Parameters:

  • customer_id (String)

    Body param: The customer ref ID the contract belongs to

  • subscriptions (Array<Stigg::Models::V1::ContractCreateParams::Subscription>)

    Body param: The subscriptions to attach to the contract (must be non-empty). Eac

  • activation_end_date (Time)

    Body param: Optional contract activation end date

  • activation_start_date (Time)

    Body param: Optional contract activation start date

  • name (String, nil)

    Body param: Optional contract name

  • po_number (String, nil)

    Body param: Optional purchase-order number

  • setup_billing (Boolean)

    Body param: Whether to set up billing for the contract by creating a billing con

  • x_account_id (String)

    Header param: Account ID — optional when authenticating with a user JWT (Bearer

  • x_environment_id (String)

    Header param: Environment ID — required when authenticating with a user JWT (Bea

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/stigg/resources/v1/contracts.rb', line 41

def create(params)
  parsed, options = Stigg::V1::ContractCreateParams.dump_request(params)
  header_params = {x_account_id: "x-account-id", x_environment_id: "x-environment-id"}
  @client.request(
    method: :post,
    path: "api/v1/contracts",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Stigg::Models::V1::ContractCreateResponse,
    options: options
  )
end

#delete(id, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::ContractDeleteResponse

Some parameter documentations has been truncated, see Models::V1::ContractDeleteParams for more details.

Deletes a contract: cancels the contract in the connected billing provider and cancels every subscription linked to it.

Parameters:

  • id (String)

    The unique identifier of the entity

  • x_account_id (String)

    Account ID — optional when authenticating with a user JWT (Bearer token); falls

  • x_environment_id (String)

    Environment ID — required when authenticating with a user JWT (Bearer token) on

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/stigg/resources/v1/contracts.rb', line 202

def delete(id, params = {})
  parsed, options = Stigg::V1::ContractDeleteParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["api/v1/contracts/%1$s/archive", id],
    headers: parsed.transform_keys(
      x_account_id: "x-account-id",
      x_environment_id: "x-environment-id"
    ),
    model: Stigg::Models::V1::ContractDeleteResponse,
    options: options
  )
end

#list(after: nil, before: nil, customer_external_id: nil, limit: nil, name: nil, state: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Internal::MyCursorIDPage<Stigg::Models::V1::ContractListResponse>

Some parameter documentations has been truncated, see Models::V1::ContractListParams for more details.

Retrieves a cursor-paginated list of contracts in the environment, fetched live from the connected billing provider. Each contract is enriched with a preview of its upcoming (next) invoice when one is available. Returns an empty list when no billing provider is connected. Supports filtering by customer external ID, state, and name.

Parameters:

  • after (String)

    Query param: Return items that come after this cursor

  • before (String)

    Query param: Return items that come before this cursor

  • customer_external_id (String)

    Query param: Filter by the exact external ID of the customer the contract belong

  • limit (Integer)

    Query param: Maximum number of items to return

  • name (String)

    Query param: Filter by exact contract name

  • state (String)

    Query param: Filter by contract state. Supports comma-separated values for multi

  • x_account_id (String)

    Header param: Account ID — optional when authenticating with a user JWT (Bearer

  • x_environment_id (String)

    Header param: Environment ID — required when authenticating with a user JWT (Bea

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/stigg/resources/v1/contracts.rb', line 165

def list(params = {})
  query_params = [:after, :before, :customer_external_id, :limit, :name, :state]
  parsed, options = Stigg::V1::ContractListParams.dump_request(params)
  query = Stigg::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :get,
    path: "api/v1/contracts",
    query: query.transform_keys(customer_external_id: "customerExternalId"),
    headers: parsed.except(*query_params).transform_keys(
      x_account_id: "x-account-id",
      x_environment_id: "x-environment-id"
    ),
    page: Stigg::Internal::MyCursorIDPage,
    model: Stigg::Models::V1::ContractListResponse,
    options: options
  )
end

#retrieve(id, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::ContractRetrieveResponse

Some parameter documentations has been truncated, see Models::V1::ContractRetrieveParams for more details.

Retrieves a single contract by its ID, enriched with a preview of its upcoming (next) invoice when one is available. Returns 404 when no contract with that ID exists in the environment.

Parameters:

  • id (String)

    The unique identifier of the entity

  • x_account_id (String)

    Account ID — optional when authenticating with a user JWT (Bearer token); falls

  • x_environment_id (String)

    Environment ID — required when authenticating with a user JWT (Bearer token) on

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/stigg/resources/v1/contracts.rb', line 74

def retrieve(id, params = {})
  parsed, options = Stigg::V1::ContractRetrieveParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["api/v1/contracts/%1$s", id],
    headers: parsed.transform_keys(
      x_account_id: "x-account-id",
      x_environment_id: "x-environment-id"
    ),
    model: Stigg::Models::V1::ContractRetrieveResponse,
    options: options
  )
end

#update(id, activation_end_date: nil, activation_start_date: nil, name: nil, po_number: nil, setup_billing: nil, subscription_ids: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::ContractUpdateResponse

Some parameter documentations has been truncated, see Models::V1::ContractUpdateParams for more details.

Updates a contract's metadata (name, PO number, activation dates) and optionally re-links its subscriptions. Best-effort re-syncs the change to the connected billing provider.

Parameters:

  • id (String)

    Path param: The unique identifier of the entity

  • activation_end_date (Time)

    Body param: New activation end date

  • activation_start_date (Time)

    Body param: New activation start date

  • name (String, nil)

    Body param: New contract name

  • po_number (String, nil)

    Body param: New purchase-order number

  • setup_billing (Boolean)

    Body param: Enable billing on a provision-access-only contract by creating a bil

  • subscription_ids (Array<String>)

    Body param: When provided, replaces the set of subscriptions linked to the contr

  • x_account_id (String)

    Header param: Account ID — optional when authenticating with a user JWT (Bearer

  • x_environment_id (String)

    Header param: Environment ID — required when authenticating with a user JWT (Bea

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/stigg/resources/v1/contracts.rb', line 120

def update(id, params = {})
  parsed, options = Stigg::V1::ContractUpdateParams.dump_request(params)
  header_params = {x_account_id: "x-account-id", x_environment_id: "x-environment-id"}
  @client.request(
    method: :patch,
    path: ["api/v1/contracts/%1$s", id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Stigg::Models::V1::ContractUpdateResponse,
    options: options
  )
end