Class: Mpp::Server::ComposedResult

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#challengesObject (readonly)

Returns the value of attribute challenges.



16
17
18
# File 'lib/mpp/server/result.rb', line 16

def challenges
  @challenges
end

#credentialObject (readonly)

Returns the value of attribute credential.



19
20
21
# File 'lib/mpp/server/result.rb', line 19

def credential
  @credential
end

#extra_headersObject (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

#realmObject (readonly)

Returns the value of attribute realm.



28
29
30
# File 'lib/mpp/server/result.rb', line 28

def realm
  @realm
end

#receiptObject (readonly)

Returns the value of attribute receipt.



22
23
24
# File 'lib/mpp/server/result.rb', line 22

def receipt
  @receipt
end

#statusObject (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



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

#paymentObject



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

Returns:

  • (Boolean)


73
74
75
# File 'lib/mpp/server/result.rb', line 73

def payment_required?
  @status == 402
end

#payment_responseObject



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_responseObject



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