Class: Blockchain0x::Resources::PaymentRequests

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

Overview

PaymentRequestsResource is ‘client.payment_requests.*`.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ PaymentRequests

Returns a new instance of PaymentRequests.



40
41
42
# File 'lib/blockchain0x/resources/payment_requests.rb', line 40

def initialize(client)
  @client = client
end

Instance Method Details

#settle(payment_request_id, body) ⇒ Hash

Settle a payment request with the on-chain proof tuple.

Parameters:

  • payment_request_id (String)

    the ‘pr_*` id from the 402 `accepts[].paymentRequestId` field.

  • body (PaymentRequestSettleBody, Hash)

    either the typed Struct OR a plain hash with the canonical camelCase shape - the x402 server adapter already passes the dict directly.

Returns:

  • (Hash)

    the raw envelope ‘{ ’id’, ‘status’ => ‘settled’, ‘settledTxHash’, ‘settledAt’ }‘.

Raises:

  • (ArgumentError)

    when payment_request_id is empty.

  • (Blockchain0x::Error)

    on any non-2xx envelope.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/blockchain0x/resources/payment_requests.rb', line 55

def settle(payment_request_id, body)
  if payment_request_id.nil? || payment_request_id.to_s.empty?
    raise ArgumentError, 'payment_request_id is required'
  end

  wire_body =
    if body.respond_to?(:to_h_wire)
      body.to_h_wire
    else
      # Accept the canonical camelCase shape verbatim - the
      # x402 server adapter already passes this exact shape.
      body.to_h.transform_keys(&:to_s)
    end

  @client.post("/v1/payment-requests/#{payment_request_id}/settle", body: wire_body)
end