Module: Mpp::X402::Header
- Extended by:
- T::Sig
- Defined in:
- lib/mpp/x402/header.rb
Overview
Base64 JSON codecs for x402 v2 headers.
x402 uses standard (not url-safe) base64 of JSON, unlike Payment-auth which uses base64url.
Class Method Summary collapse
- .decode_json(value) ⇒ Object
- .decode_payment_required(value) ⇒ Object
- .decode_payment_response(value) ⇒ Object
- .decode_payment_signature(value) ⇒ Object
- .encode_json(obj) ⇒ Object
- .encode_payment_required(payment_required) ⇒ Object
- .encode_payment_response(settle_response) ⇒ Object
- .encode_payment_signature(payment_payload) ⇒ Object
Class Method Details
.decode_json(value) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/mpp/x402/header.rb', line 62 def decode_json(value) json = decode_base64(value) parsed = JSON.parse(json) Kernel.raise Mpp::ParseError, "Invalid base64 JSON header." unless parsed.is_a?(Hash) parsed rescue JSON::ParserError Kernel.raise Mpp::ParseError, "Invalid base64 JSON header." end |
.decode_payment_required(value) ⇒ Object
25 26 27 28 29 |
# File 'lib/mpp/x402/header.rb', line 25 def decode_payment_required(value) parsed = decode_json(value) validate_payment_required!(parsed) parsed end |
.decode_payment_response(value) ⇒ Object
49 50 51 52 53 |
# File 'lib/mpp/x402/header.rb', line 49 def decode_payment_response(value) parsed = decode_json(value) validate_settle_response!(parsed) parsed end |
.decode_payment_signature(value) ⇒ Object
37 38 39 40 41 |
# File 'lib/mpp/x402/header.rb', line 37 def decode_payment_signature(value) parsed = decode_json(value) validate_payment_payload!(parsed) parsed end |
.encode_json(obj) ⇒ Object
56 57 58 59 |
# File 'lib/mpp/x402/header.rb', line 56 def encode_json(obj) json = Mpp::Json.compact_encode(obj) Base64.strict_encode64(json) end |
.encode_payment_required(payment_required) ⇒ Object
20 21 22 |
# File 'lib/mpp/x402/header.rb', line 20 def encode_payment_required(payment_required) encode_json(payment_required) end |
.encode_payment_response(settle_response) ⇒ Object
44 45 46 |
# File 'lib/mpp/x402/header.rb', line 44 def encode_payment_response(settle_response) encode_json(settle_response) end |
.encode_payment_signature(payment_payload) ⇒ Object
32 33 34 |
# File 'lib/mpp/x402/header.rb', line 32 def encode_payment_signature(payment_payload) encode_json(payment_payload) end |