Class: X402::Payments::V1::PayloadBuilder

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authorization:, signature:, scheme:, network:) ⇒ PayloadBuilder

Returns a new instance of PayloadBuilder.



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

def initialize(authorization:, signature:, scheme:, network:)
  @authorization = authorization
  @signature = signature
  @scheme = scheme
  @network = network
end

Instance Attribute Details

#authorizationObject (readonly)

Returns the value of attribute authorization.



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

def authorization
  @authorization
end

#networkObject (readonly)

Returns the value of attribute network.



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

def network
  @network
end

#schemeObject (readonly)

Returns the value of attribute scheme.



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

def scheme
  @scheme
end

#signatureObject (readonly)

Returns the value of attribute signature.



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

def signature
  @signature
end

Class Method Details

.build(authorization:, signature:, scheme:, network:) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/x402/payments/v1/payload_builder.rb', line 36

def build(authorization:, signature:, scheme:, network:)
  new(
    authorization: authorization,
    signature: signature,
    scheme: scheme,
    network: network
  ).build
end

Instance Method Details

#buildObject



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

def build
  {
    x402Version: 1,
    scheme: scheme,
    network: network,
    payload: {
      signature: signature,
      authorization: {
        from: authorization[:from],
        to: authorization[:to],
        value: authorization[:value],
        validAfter: authorization[:valid_after],
        validBefore: authorization[:valid_before],
        nonce: authorization[:nonce]
      }
    }
  }
end