Class: Spree::OmnikassaPaymentResponse
- Inherits:
-
Object
- Object
- Spree::OmnikassaPaymentResponse
- Defined in:
- app/models/spree/omnikassa_payment_response.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#data ⇒ Object
Returns the value of attribute data.
-
#payment_method ⇒ Object
readonly
Returns the value of attribute payment_method.
-
#seal ⇒ Object
readonly
Returns the value of attribute seal.
Instance Method Summary collapse
-
#initialize(seal, data) ⇒ OmnikassaPaymentResponse
constructor
A new instance of OmnikassaPaymentResponse.
-
#order ⇒ Object
Finds the order trough ActiveRecord.
-
#payment ⇒ Object
Finds a payment with provided parameters trough activeRecord.
-
#response_level ⇒ Object
Level can be :success, :pending, :cancelled or :failed.
- #valid? ⇒ Boolean
Constructor Details
#initialize(seal, data) ⇒ OmnikassaPaymentResponse
Returns a new instance of OmnikassaPaymentResponse.
6 7 8 9 10 11 |
# File 'app/models/spree/omnikassa_payment_response.rb', line 6 def initialize seal, data @payment_method = Spree::PaymentMethod::Omnikassa.fetch_payment_method @seal = seal @data = data @attributes = to_h end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'app/models/spree/omnikassa_payment_response.rb', line 4 def attributes @attributes end |
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'app/models/spree/omnikassa_payment_response.rb', line 3 def data @data end |
#payment_method ⇒ Object (readonly)
Returns the value of attribute payment_method.
4 5 6 |
# File 'app/models/spree/omnikassa_payment_response.rb', line 4 def payment_method @payment_method end |
#seal ⇒ Object (readonly)
Returns the value of attribute seal.
4 5 6 |
# File 'app/models/spree/omnikassa_payment_response.rb', line 4 def seal @seal end |
Instance Method Details
#order ⇒ Object
Finds the order trough ActiveRecord
31 32 33 |
# File 'app/models/spree/omnikassa_payment_response.rb', line 31 def order Spree::Order.find(@attributes[:order_id].to_i) end |
#payment ⇒ Object
Finds a payment with provided parameters trough activeRecord.
24 25 26 27 28 |
# File 'app/models/spree/omnikassa_payment_response.rb', line 24 def payment Spree::Payment.find(:first, :conditions => { :payment_method_id => @payment_method.id, :order_id => @attributes[:order_id]} ) || raise(ActiveRecord::RecordNotFound) end |
#response_level ⇒ Object
Level can be :success, :pending, :cancelled or :failed
36 37 38 39 40 41 42 43 44 |
# File 'app/models/spree/omnikassa_payment_response.rb', line 36 def response_level response_codes.each do |level, codes| if codes.include?(@attributes[:response_code].to_i) return level end end nil end |
#valid? ⇒ Boolean
13 14 15 16 17 18 19 20 21 |
# File 'app/models/spree/omnikassa_payment_response.rb', line 13 def valid? return false unless @seal == ::Digest::SHA2.hexdigest(@data + @payment_method.preferred_secret_key) required_attributes.each do |required_attribute| return false unless @attributes.has_key? required_attribute.underscore.to_sym end true end |