Class: Telnyx::Resources::X402::CreditAccount

Inherits:
Object
  • Object
show all
Defined in:
lib/telnyx/resources/x402/credit_account.rb

Overview

Operations for x402 cryptocurrency payment transactions. Fund your Telnyx account using USDC stablecoin payments via the x402 protocol.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ CreditAccount

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

Parameters:



70
71
72
# File 'lib/telnyx/resources/x402/credit_account.rb', line 70

def initialize(client:)
  @client = client
end

Instance Method Details

#create_quote(amount_usd:, request_options: {}) ⇒ Telnyx::Models::X402::CreditAccountCreateQuoteResponse

Creates a payment quote for the specified USD amount. Returns payment details including the x402 payment requirements, network, and expiration time. The quote must be settled before it expires.

Parameters:

  • amount_usd (String)

    Amount in USD to fund (minimum 5.00, maximum 10000.00).

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

Returns:

See Also:



22
23
24
25
26
27
28
29
30
31
# File 'lib/telnyx/resources/x402/credit_account.rb', line 22

def create_quote(params)
  parsed, options = Telnyx::X402::CreditAccountCreateQuoteParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v2/x402/credit_account/quote",
    body: parsed,
    model: Telnyx::Models::X402::CreditAccountCreateQuoteResponse,
    options: options
  )
end

#settle(id:, payment_signature: nil, header_payment_signature: nil, request_options: {}) ⇒ Telnyx::Models::X402::CreditAccountSettleResponse

Some parameter documentations has been truncated, see Models::X402::CreditAccountSettleParams for more details.

Settles an x402 payment using the quote ID and a signed payment authorization. The payment signature can be provided via the ‘PAYMENT-SIGNATURE` header or the `payment_signature` body parameter. Settlement is idempotent — submitting the same quote ID multiple times returns the existing transaction.

Parameters:

  • id (String)

    Body param: The quote ID to settle.

  • payment_signature (String)

    Body param: Base64-encoded signed payment authorization (x402 PaymentPayload). C

  • header_payment_signature (String)

    Header param: Signed payment authorization for the quote. Alternative to providi

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

Returns:

See Also:



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/telnyx/resources/x402/credit_account.rb', line 54

def settle(params)
  parsed, options = Telnyx::X402::CreditAccountSettleParams.dump_request(params)
  header_params = {header_payment_signature: "payment-signature"}
  @client.request(
    method: :post,
    path: "v2/x402/credit_account",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Telnyx::Models::X402::CreditAccountSettleResponse,
    options: options
  )
end