Class: X402::PaymentRequirement
- Inherits:
-
Object
- Object
- X402::PaymentRequirement
- Defined in:
- lib/x402/payment_requirement.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#asset ⇒ Object
Returns the value of attribute asset.
-
#description ⇒ Object
Returns the value of attribute description.
-
#extra ⇒ Object
Returns the value of attribute extra.
-
#max_timeout_seconds ⇒ Object
Returns the value of attribute max_timeout_seconds.
-
#mime_type ⇒ Object
Returns the value of attribute mime_type.
-
#network ⇒ Object
Returns the value of attribute network.
-
#output_schema ⇒ Object
Returns the value of attribute output_schema.
-
#pay_to ⇒ Object
Returns the value of attribute pay_to.
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#scheme ⇒ Object
Returns the value of attribute scheme.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ PaymentRequirement
constructor
A new instance of PaymentRequirement.
- #max_amount_required ⇒ Object
- #to_h(version: nil) ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ PaymentRequirement
Returns a new instance of PaymentRequirement.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/x402/payment_requirement.rb', line 8 def initialize(attributes = {}) attrs = attributes.with_indifferent_access @scheme = attrs[:scheme] || "exact" @network = normalize_network(attrs[:network]) @amount = attrs[:maxAmountRequired] || attrs[:max_amount_required] || attrs[:amount] @asset = attrs[:asset] @pay_to = attrs[:payTo] || attrs[:pay_to] @resource = attrs[:resource] @description = attrs[:description] @max_timeout_seconds = attrs[:maxTimeoutSeconds] || attrs[:max_timeout_seconds] || 600 @mime_type = attrs[:mimeType] || attrs[:mime_type] || "application/json" @output_schema = attrs[:outputSchema] || attrs[:output_schema] @extra = attrs[:extra] @version = attrs[:version] end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
5 6 7 |
# File 'lib/x402/payment_requirement.rb', line 5 def amount @amount end |
#asset ⇒ Object
Returns the value of attribute asset.
5 6 7 |
# File 'lib/x402/payment_requirement.rb', line 5 def asset @asset end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/x402/payment_requirement.rb', line 5 def description @description end |
#extra ⇒ Object
Returns the value of attribute extra.
5 6 7 |
# File 'lib/x402/payment_requirement.rb', line 5 def extra @extra end |
#max_timeout_seconds ⇒ Object
Returns the value of attribute max_timeout_seconds.
5 6 7 |
# File 'lib/x402/payment_requirement.rb', line 5 def max_timeout_seconds @max_timeout_seconds end |
#mime_type ⇒ Object
Returns the value of attribute mime_type.
5 6 7 |
# File 'lib/x402/payment_requirement.rb', line 5 def mime_type @mime_type end |
#network ⇒ Object
Returns the value of attribute network.
5 6 7 |
# File 'lib/x402/payment_requirement.rb', line 5 def network @network end |
#output_schema ⇒ Object
Returns the value of attribute output_schema.
5 6 7 |
# File 'lib/x402/payment_requirement.rb', line 5 def output_schema @output_schema end |
#pay_to ⇒ Object
Returns the value of attribute pay_to.
5 6 7 |
# File 'lib/x402/payment_requirement.rb', line 5 def pay_to @pay_to end |
#resource ⇒ Object
Returns the value of attribute resource.
5 6 7 |
# File 'lib/x402/payment_requirement.rb', line 5 def resource @resource end |
#scheme ⇒ Object
Returns the value of attribute scheme.
5 6 7 |
# File 'lib/x402/payment_requirement.rb', line 5 def scheme @scheme end |
#version ⇒ Object
Returns the value of attribute version.
5 6 7 |
# File 'lib/x402/payment_requirement.rb', line 5 def version @version end |
Instance Method Details
#max_amount_required ⇒ Object
25 26 27 |
# File 'lib/x402/payment_requirement.rb', line 25 def max_amount_required @amount end |
#to_h(version: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/x402/payment_requirement.rb', line 29 def to_h(version: nil) v = version || @version || X402.configuration.version version_strategy = X402::Versions.for(v) version_strategy.format_requirement( scheme: scheme, network: network, amount: amount, asset: asset, pay_to: pay_to, resource: resource, description: description, max_timeout_seconds: max_timeout_seconds, mime_type: mime_type, extra: extra ) end |
#to_json(*args) ⇒ Object
47 48 49 |
# File 'lib/x402/payment_requirement.rb', line 47 def to_json(*args) to_h.to_json(*args) end |