class SpookAndPay::Result
A small convenience class which wraps any results coming back from a provider. This is never instanced directly, but instead instances are created by the Provider classes.
Attributes
Readers for the various portions of a result's payload. Depending on the type of request any of these may be nil.
Readers for the various portions of a result's payload. Depending on the type of request any of these may be nil.
Readers for the various portions of a result's payload. Depending on the type of request any of these may be nil.
Readers for the various portions of a result's payload. Depending on the type of request any of these may be nil.
Public Class Methods
@param [true, false] successful @param Class raw @param Hash opts
# File lib/spook_and_pay/result.rb, line 13 def initialize(successful, raw, opts = {}) @successful = successful @raw = raw @transaction = opts[:transaction] if opts.has_key?(:transaction) @credit_card = opts[:credit_card] if opts.has_key?(:credit_card) @errors = opts[:errors] || [] end
Public Instance Methods
Checks to see if a credit card is present.
@return [true, false]
# File lib/spook_and_pay/result.rb, line 31 def credit_card? !credit_card.nil? end
Checks to see if any errors are present.
@return [true, false]
# File lib/spook_and_pay/result.rb, line 38 def errors? !errors.empty? end
Collects errors for a specific target, keyed by field.
@param Symbol target @return Hash @return Hash<Symbol, Array<SpookAndPay::SubmissionError>>
# File lib/spook_and_pay/result.rb, line 47 def errors_for(target) errors.select{|e| e.target == target}.reduce({}) do |h, e| h[e.field] ||= [] h[e.field] << e h end end
Returns the errors for a specific target and field.
@param Symbol target @param Symbol field @return Array<SpookAndPay::SubmissionError>
# File lib/spook_and_pay/result.rb, line 60 def errors_for_field(target, field) errors.select {|e| e.target == target and e.field == field} end
A nice helper for checking for failure.
@return [true, false]
# File lib/spook_and_pay/result.rb, line 74 def failure? !@successful end
A nice alias for checking for success.
@return [true, false]
# File lib/spook_and_pay/result.rb, line 67 def successful? @successful end
Checks to see if a transaction is present.
@return [true, false]
# File lib/spook_and_pay/result.rb, line 24 def transaction? !transaction.nil? end