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:



128
129
130
# File 'lib/stigg/resources/v1/credits/grants.rb', line 128

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, request_options: {}) ⇒ Stigg::Models::V1::Credits::CreditGrantResponse

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

Parameters:

  • amount (Float)

    The credit amount to grant

  • currency_id (String)

    The credit currency ID (required)

  • customer_id (String)

    The customer ID to grant credits to (required)

  • display_name (String)

    The display name for the credit grant

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

    The type of credit grant (PAID, PROMOTIONAL)

  • await_payment_confirmation (Boolean)

    Whether to wait for payment confirmation before returning (default: true)

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

    Billing information for the credit grant

  • comment (String)

    An optional comment on the credit grant

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

    The monetary cost of the credit grant

  • effective_at (Time)

    The date when the credit grant becomes effective

  • expire_at (Time)

    The date when the credit grant expires

  • metadata (Hash{Symbol=>String})

    Additional metadata for the credit grant

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

    The payment collection method (CHARGE, INVOICE, NONE)

  • priority (Integer)

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

  • resource_id (String)

    The resource ID to scope the grant to

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

Returns:

See Also:



49
50
51
52
53
54
55
56
57
58
# File 'lib/stigg/resources/v1/credits/grants.rb', line 49

def create(params)
  parsed, options = Stigg::V1::Credits::GrantCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "api/v1/credits/grants",
    body: parsed,
    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, 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)

    Filter by customer ID (required)

  • after (String)

    Return items that come after this cursor

  • before (String)

    Return items that come before this cursor

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

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

  • currency_id (String)

    Filter by currency ID

  • limit (Integer)

    Maximum number of items to return

  • resource_id (String)

    Filter by resource ID. When omitted, only grants without a resource are returned

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

Returns:

See Also:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/stigg/resources/v1/credits/grants.rb', line 86

def list(params)
  parsed, options = Stigg::V1::Credits::GrantListParams.dump_request(params)
  query = Stigg::Internal::Util.encode_query_params(parsed)
  @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"
    ),
    page: Stigg::Internal::MyCursorIDPage,
    model: Stigg::Models::V1::Credits::GrantListResponse,
    options: options
  )
end

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

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

Parameters:

  • id (String)

    The unique identifier of the entity

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

Returns:

See Also:



116
117
118
119
120
121
122
123
# File 'lib/stigg/resources/v1/credits/grants.rb', line 116

def void(id, params = {})
  @client.request(
    method: :post,
    path: ["api/v1/credits/grants/%1$s/void", id],
    model: Stigg::V1::Credits::CreditGrantResponse,
    options: params[:request_options]
  )
end