Class: MetronomeSDK::Resources::V1::CreditGrants

Inherits:
Object
  • Object
show all
Defined in:
lib/metronome_sdk/resources/v1/credit_grants.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ CreditGrants

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

Parameters:



201
202
203
# File 'lib/metronome_sdk/resources/v1/credit_grants.rb', line 201

def initialize(client:)
  @client = client
end

Instance Method Details

#create(customer_id: , expires_at: , grant_amount: , name: , paid_amount: , priority: , credit_grant_type: nil, custom_fields: nil, effective_at: nil, invoice_date: nil, product_ids: nil, reason: nil, rollover_settings: nil, uniqueness_key: nil, request_options: {}) ⇒ MetronomeSDK::Models::V1::CreditGrantCreateResponse

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

Create a new credit grant. This is a Plans (deprecated) endpoint. New clients should implement using Contracts.

Parameters:

  • customer_id (String)

    the Metronome ID of the customer

  • expires_at (Time)

    The credit grant will only apply to usage or charges dated before this timestamp

  • grant_amount (MetronomeSDK::Models::V1::CreditGrantCreateParams::GrantAmount)

    the amount of credits granted

  • name (String)

    the name of the credit grant as it will appear on invoices

  • paid_amount (MetronomeSDK::Models::V1::CreditGrantCreateParams::PaidAmount)

    the amount paid for this credit grant

  • priority (Float)
  • credit_grant_type (String)
  • custom_fields (Hash{Symbol=>String})

    Custom fields to attach to the credit grant.

  • effective_at (Time)

    The credit grant will only apply to usage or charges dated on or after this time

  • invoice_date (Time)

    The date to issue an invoice for the paid_amount.

  • product_ids (Array<String>)

    The product(s) which these credits will be applied to. (If unspecified, the cred

  • reason (String)
  • rollover_settings (MetronomeSDK::Models::V1::CreditGrantCreateParams::RolloverSettings)

    Configure a rollover for this credit grant so if it expires it rolls over a conf

  • uniqueness_key (String)

    Prevents the creation of duplicates. If a request to create a record is made wit

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

Returns:

See Also:



48
49
50
51
52
53
54
55
56
57
# File 'lib/metronome_sdk/resources/v1/credit_grants.rb', line 48

def create(params)
  parsed, options = MetronomeSDK::V1::CreditGrantCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v1/credits/createGrant",
    body: parsed,
    model: MetronomeSDK::Models::V1::CreditGrantCreateResponse,
    options: options
  )
end

#edit(id: , credit_grant_type: nil, expires_at: nil, name: nil, request_options: {}) ⇒ MetronomeSDK::Models::V1::CreditGrantEditResponse

Edit an existing credit grant. This is a Plans (deprecated) endpoint. New clients should implement using Contracts.

Parameters:

  • id (String)

    the ID of the credit grant

  • credit_grant_type (String)

    the updated credit grant type

  • expires_at (Time)

    the updated expiration date for the credit grant

  • name (String)

    the updated name for the credit grant

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

Returns:

See Also:



118
119
120
121
122
123
124
125
126
127
# File 'lib/metronome_sdk/resources/v1/credit_grants.rb', line 118

def edit(params)
  parsed, options = MetronomeSDK::V1::CreditGrantEditParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v1/credits/editGrant",
    body: parsed,
    model: MetronomeSDK::Models::V1::CreditGrantEditResponse,
    options: options
  )
end

#list(limit: nil, next_page: nil, credit_grant_ids: nil, credit_type_ids: nil, customer_ids: nil, effective_before: nil, not_expiring_before: nil, request_options: {}) ⇒ MetronomeSDK::Internal::CursorPage<MetronomeSDK::Models::V1::CreditGrantListResponse>

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

List credit grants. This list does not included voided grants. This is a Plans (deprecated) endpoint. New clients should implement using Contracts.

Parameters:

  • limit (Integer)

    Query param: Max number of results that should be returned

  • next_page (String)

    Query param: Cursor that indicates where the next page of results should start.

  • credit_grant_ids (Array<String>)

    Body param: An array of credit grant IDs. If this is specified, neither credit_t

  • credit_type_ids (Array<String>)

    Body param: An array of credit type IDs. This must not be specified if credit_gr

  • customer_ids (Array<String>)

    Body param: An array of Metronome customer IDs. This must not be specified if cr

  • effective_before (Time)

    Body param: Only return credit grants that are effective before this timestamp (

  • not_expiring_before (Time)

    Body param: Only return credit grants that expire at or after this timestamp.

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

Returns:

See Also:



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/metronome_sdk/resources/v1/credit_grants.rb', line 86

def list(params = {})
  parsed, options = MetronomeSDK::V1::CreditGrantListParams.dump_request(params)
  query_params = [:limit, :next_page]
  @client.request(
    method: :post,
    path: "v1/credits/listGrants",
    query: parsed.slice(*query_params),
    body: parsed.except(*query_params),
    page: MetronomeSDK::Internal::CursorPage,
    model: MetronomeSDK::Models::V1::CreditGrantListResponse,
    options: options
  )
end

#list_entries(next_page: nil, sort: nil, credit_type_ids: nil, customer_ids: nil, ending_before: nil, starting_on: nil, request_options: {}) ⇒ MetronomeSDK::Internal::CursorPageWithoutLimit<MetronomeSDK::Models::V1::CreditGrantListEntriesResponse>

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

Fetches a list of credit ledger entries. Returns lists of ledgers per customer. Ledger entries are returned in chronological order. Ledger entries associated with voided credit grants are not included. This is a Plans (deprecated) endpoint. New clients should implement using Contracts.

effective_

Parameters:

  • next_page (String)

    Query param: Cursor that indicates where the next page of results should start.

  • sort (Symbol, MetronomeSDK::Models::V1::CreditGrantListEntriesParams::Sort)

    Query param: Ledgers sort order by date, asc or desc. Defaults to asc.

  • credit_type_ids (Array<String>)

    Body param: A list of Metronome credit type IDs to fetch ledger entries for. If

  • customer_ids (Array<String>)

    Body param: A list of Metronome customer IDs to fetch ledger entries for. If abs

  • ending_before (Time)

    Body param: If supplied, ledger entries will only be returned with an

  • starting_on (Time)

    Body param: If supplied, only ledger entries effective at or after this time wil

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

Returns:

See Also:



157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/metronome_sdk/resources/v1/credit_grants.rb', line 157

def list_entries(params = {})
  parsed, options = MetronomeSDK::V1::CreditGrantListEntriesParams.dump_request(params)
  query_params = [:next_page, :sort]
  @client.request(
    method: :post,
    path: "v1/credits/listEntries",
    query: parsed.slice(*query_params),
    body: parsed.except(*query_params),
    page: MetronomeSDK::Internal::CursorPageWithoutLimit,
    model: MetronomeSDK::Models::V1::CreditGrantListEntriesResponse,
    options: options
  )
end

#void(id: , release_uniqueness_key: nil, void_credit_purchase_invoice: nil, request_options: {}) ⇒ MetronomeSDK::Models::V1::CreditGrantVoidResponse

Void a credit grant. This is a Plans (deprecated) endpoint. New clients should implement using Contracts.

Parameters:

  • id (String)
  • release_uniqueness_key (Boolean)

    If true, resets the uniqueness key on this grant so it can be re-used

  • void_credit_purchase_invoice (Boolean)

    If true, void the purchase invoice associated with the grant

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

Returns:

See Also:



187
188
189
190
191
192
193
194
195
196
# File 'lib/metronome_sdk/resources/v1/credit_grants.rb', line 187

def void(params)
  parsed, options = MetronomeSDK::V1::CreditGrantVoidParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v1/credits/voidGrant",
    body: parsed,
    model: MetronomeSDK::Models::V1::CreditGrantVoidResponse,
    options: options
  )
end