Class: Blockchain0x::Resources::Payments

Inherits:
Object
  • Object
show all
Defined in:
lib/blockchain0x/resources/payments.rb

Overview

‘client.payments.*` resource.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Payments

Returns a new instance of Payments.



51
52
53
# File 'lib/blockchain0x/resources/payments.rb', line 51

def initialize(client)
  @client = client
end

Instance Method Details

#create(body:, idempotency_key: nil) ⇒ Hash

Submit an outbound payment.

Parameters:

  • body (PaymentCreateBody, Hash)

    either the typed Struct OR a plain hash with the canonical camelCase shape - the x402 client wrapper passes a hash directly so it just works.

  • idempotency_key (String, nil) (defaults to: nil)

    explicit override; otherwise the underlying Client mints a uuid4.

Returns:

  • (Hash)

    raw envelope ‘{ ’id’, ‘agentId’, ‘status’, ‘txHash’?, ‘amountWei’, ‘network’, … }‘.

Raises:

  • (ArgumentError)

    when any required field is empty.

  • (Blockchain0x::Error)

    on any non-2xx envelope.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/blockchain0x/resources/payments.rb', line 66

def create(body:, idempotency_key: nil)
  wire =
    if body.respond_to?(:to_h_wire)
      body.to_h_wire
    else
      body.to_h.transform_keys(&:to_s)
    end

  raise ArgumentError, 'agentId is required' if wire['agentId'].nil? || wire['agentId'].empty?
  raise ArgumentError, 'to is required' if wire['to'].nil? || wire['to'].empty?
  raise ArgumentError, 'amountWei is required' if wire['amountWei'].nil? || wire['amountWei'].empty?

  @client.post('/v1/payments', body: wire, idempotency_key: idempotency_key)
end