Class: X402::Payments::V2::PayloadBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/x402/payments/v2/payload_builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authorization:, signature:, resource:, accepted:, extensions: {}) ⇒ PayloadBuilder

Returns a new instance of PayloadBuilder.



9
10
11
12
13
14
15
# File 'lib/x402/payments/v2/payload_builder.rb', line 9

def initialize(authorization:, signature:, resource:, accepted:, extensions: {})
  @authorization = authorization
  @signature = signature
  @resource = resource
  @accepted = accepted
  @extensions = extensions || {}
end

Instance Attribute Details

#acceptedObject (readonly)

Returns the value of attribute accepted.



7
8
9
# File 'lib/x402/payments/v2/payload_builder.rb', line 7

def accepted
  @accepted
end

#authorizationObject (readonly)

Returns the value of attribute authorization.



7
8
9
# File 'lib/x402/payments/v2/payload_builder.rb', line 7

def authorization
  @authorization
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



7
8
9
# File 'lib/x402/payments/v2/payload_builder.rb', line 7

def extensions
  @extensions
end

#resourceObject (readonly)

Returns the value of attribute resource.



7
8
9
# File 'lib/x402/payments/v2/payload_builder.rb', line 7

def resource
  @resource
end

#signatureObject (readonly)

Returns the value of attribute signature.



7
8
9
# File 'lib/x402/payments/v2/payload_builder.rb', line 7

def signature
  @signature
end

Class Method Details

.build(authorization:, signature:, resource:, accepted:, extensions: {}) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/x402/payments/v2/payload_builder.rb', line 60

def build(authorization:, signature:, resource:, accepted:, extensions: {})
  new(
    authorization: authorization,
    signature: signature,
    resource: resource,
    accepted: accepted,
    extensions: extensions
  ).build
end

Instance Method Details

#buildObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/x402/payments/v2/payload_builder.rb', line 17

def build
  {
    x402Version: 2,
    resource: build_resource,
    accepted: build_accepted,
    payload: {
      signature: signature,
      authorization: {
        from: authorization[:from],
        to: authorization[:to],
        value: authorization[:value],
        validAfter: authorization[:valid_after],
        validBefore: authorization[:valid_before],
        nonce: authorization[:nonce]
      }
    },
    extensions: extensions
  }
end