Class: Stigg::Resources::V1::Credits::Grants

Inherits:
Object
  • Object
show all
Defined in:
lib/stigg/resources/v1/credits/grants.rb

Overview

Operations related to credit grants

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Grants

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 Grants.

Parameters:



158
159
160
# File 'lib/stigg/resources/v1/credits/grants.rb', line 158

def initialize(client:)
  @client = client
end

Instance Method Details

#create(amount:, currency_id:, customer_id:, display_name:, grant_type:, await_payment_confirmation: nil, billing_information: nil, comment: nil, cost: nil, effective_at: nil, expire_at: nil, metadata: nil, payment_collection_method: nil, priority: nil, resource_id: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Credits::CreditGrantResponse

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

Creates a new credit grant for a customer with specified amount, type, and optional billing configuration.

Parameters:

  • amount (Float)

    Body param: The credit amount to grant

  • currency_id (String)

    Body param: The credit currency ID (required)

  • customer_id (String)

    Body param: The customer ID to grant credits to (required)

  • display_name (String)

    Body param: The display name for the credit grant

  • grant_type (Symbol, Stigg::Models::V1::Credits::GrantCreateParams::GrantType)

    Body param: The type of credit grant (PAID, PROMOTIONAL)

  • await_payment_confirmation (Boolean)

    Body param: Whether to wait for payment confirmation before returning (default:

  • billing_information (Stigg::Models::V1::Credits::GrantCreateParams::BillingInformation)

    Body param: Billing information for the credit grant

  • comment (String)

    Body param: An optional comment on the credit grant

  • cost (Stigg::Models::V1::Credits::GrantCreateParams::Cost)

    Body param: The monetary cost of the credit grant

  • effective_at (Time)

    Body param: The date when the credit grant becomes effective

  • expire_at (Time)

    Body param: The date when the credit grant expires

  • metadata (Hash{Symbol=>String})

    Body param: Additional metadata for the credit grant

  • payment_collection_method (Symbol, Stigg::Models::V1::Credits::GrantCreateParams::PaymentCollectionMethod)

    Body param: The payment collection method (CHARGE, INVOICE, NONE)

  • priority (Integer)

    Body param: The priority of the credit grant (lower number = higher priority)

  • resource_id (String)

    Body param: The resource ID to scope the grant to

  • 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:



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/stigg/resources/v1/credits/grants.rb', line 56

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

#list(customer_id:, after: nil, before: nil, created_at: nil, currency_id: nil, limit: nil, resource_id: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Internal::MyCursorIDPage<Stigg::Models::V1::Credits::GrantListResponse>

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

Retrieves a paginated list of credit grants for a customer.

Parameters:

  • customer_id (String)

    Query param: Filter by customer ID (required)

  • after (String)

    Query param: Return items that come after this cursor

  • before (String)

    Query param: Return items that come before this cursor

  • created_at (Stigg::Models::V1::Credits::GrantListParams::CreatedAt)

    Query param: Filter by creation date using range operators: gt, gte, lt, lte

  • currency_id (String)

    Query param: Filter by currency ID

  • limit (Integer)

    Query param: Maximum number of items to return

  • resource_id (String)

    Query param: Filter by resource ID. When omitted, only grants without a resource

  • 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:



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/stigg/resources/v1/credits/grants.rb', line 99

def list(params)
  query_params = [:customer_id, :after, :before, :created_at, :currency_id, :limit, :resource_id]
  parsed, options = Stigg::V1::Credits::GrantListParams.dump_request(params)
  query = Stigg::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :get,
    path: "api/v1/credits/grants",
    query: query.transform_keys(
      customer_id: "customerId",
      created_at: "createdAt",
      currency_id: "currencyId",
      resource_id: "resourceId"
    ),
    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::Credits::GrantListResponse,
    options: options
  )
end

#void(id, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Credits::CreditGrantResponse

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

Voids an existing credit grant, preventing further consumption of the remaining credits.

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:



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/stigg/resources/v1/credits/grants.rb', line 141

def void(id, params = {})
  parsed, options = Stigg::V1::Credits::GrantVoidParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["api/v1/credits/grants/%1$s/void", id],
    headers: parsed.transform_keys(
      x_account_id: "x-account-id",
      x_environment_id: "x-environment-id"
    ),
    model: Stigg::V1::Credits::CreditGrantResponse,
    options: options
  )
end