Class: Mpp::Server::ComposedResult
- Inherits:
-
Object
- Object
- Mpp::Server::ComposedResult
- Extended by:
- T::Sig
- Defined in:
- lib/mpp/server/result.rb
Overview
Result of a composed (or multi-method) payment verification.
Either a 402 with one or more Challenges, or a verified payment.
Instance Attribute Summary collapse
-
#challenges ⇒ Object
readonly
Returns the value of attribute challenges.
-
#credential ⇒ Object
readonly
Returns the value of attribute credential.
-
#extra_headers ⇒ Object
readonly
Returns the value of attribute extra_headers.
-
#realm ⇒ Object
readonly
Returns the value of attribute realm.
-
#receipt ⇒ Object
readonly
Returns the value of attribute receipt.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
- .paid(credential, receipt, realm:, extra_headers: {}) ⇒ Object
- .payment_required(challenges, realm:, extra_headers: {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(status:, realm:, challenges: [], credential: nil, receipt: nil, extra_headers: {}) ⇒ ComposedResult
constructor
A new instance of ComposedResult.
- #payment ⇒ Object
- #payment_required? ⇒ Boolean
- #payment_response ⇒ Object
- #to_response ⇒ Object
Constructor Details
#initialize(status:, realm:, challenges: [], credential: nil, receipt: nil, extra_headers: {}) ⇒ ComposedResult
Returns a new instance of ComposedResult.
40 41 42 43 44 45 46 47 |
# File 'lib/mpp/server/result.rb', line 40 def initialize(status:, realm:, challenges: [], credential: nil, receipt: nil, extra_headers: {}) @status = T.let(status, Integer) @realm = T.let(realm, String) @challenges = T.let(challenges, T::Array[Mpp::Challenge]) @credential = T.let(credential, T.untyped) @receipt = T.let(receipt, T.nilable(Mpp::Receipt)) @extra_headers = T.let(extra_headers, T::Hash[String, T.untyped]) end |
Instance Attribute Details
#challenges ⇒ Object (readonly)
Returns the value of attribute challenges.
16 17 18 |
# File 'lib/mpp/server/result.rb', line 16 def challenges @challenges end |
#credential ⇒ Object (readonly)
Returns the value of attribute credential.
19 20 21 |
# File 'lib/mpp/server/result.rb', line 19 def credential @credential end |
#extra_headers ⇒ Object (readonly)
Returns the value of attribute extra_headers.
25 26 27 |
# File 'lib/mpp/server/result.rb', line 25 def extra_headers @extra_headers end |
#realm ⇒ Object (readonly)
Returns the value of attribute realm.
28 29 30 |
# File 'lib/mpp/server/result.rb', line 28 def realm @realm end |
#receipt ⇒ Object (readonly)
Returns the value of attribute receipt.
22 23 24 |
# File 'lib/mpp/server/result.rb', line 22 def receipt @receipt end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
13 14 15 |
# File 'lib/mpp/server/result.rb', line 13 def status @status end |
Class Method Details
.paid(credential, receipt, realm:, extra_headers: {}) ⇒ Object
68 69 70 |
# File 'lib/mpp/server/result.rb', line 68 def self.paid(credential, receipt, realm:, extra_headers: {}) new(status: 200, realm: realm, credential: credential, receipt: receipt, extra_headers: extra_headers) end |
.payment_required(challenges, realm:, extra_headers: {}) ⇒ Object
56 57 58 |
# File 'lib/mpp/server/result.rb', line 56 def self.payment_required(challenges, realm:, extra_headers: {}) new(status: 402, realm: realm, challenges: challenges, extra_headers: extra_headers) end |
Instance Method Details
#payment ⇒ Object
79 80 81 82 83 |
# File 'lib/mpp/server/result.rb', line 79 def payment Kernel.raise ArgumentError, "payment is not available for a 402 response" if payment_required? [@credential, @receipt] end |
#payment_required? ⇒ Boolean
73 74 75 |
# File 'lib/mpp/server/result.rb', line 73 def payment_required? @status == 402 end |
#payment_response ⇒ Object
86 87 88 89 |
# File 'lib/mpp/server/result.rb', line 86 def payment_response value = @extra_headers["PAYMENT-RESPONSE"] value.is_a?(String) ? value : nil end |
#to_response ⇒ Object
93 94 95 96 97 |
# File 'lib/mpp/server/result.rb', line 93 def to_response Kernel.raise ArgumentError, "to_response is only valid for 402 results" unless payment_required? Decorator.make_challenge_response(@challenges, @realm, extra_headers: @extra_headers) end |