Class: Spree::OmnikassaPaymentResponse

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/omnikassa_payment_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject (readonly)

Returns the value of attribute attributes.



4
5
6
# File 'app/models/spree/omnikassa_payment_response.rb', line 4

def attributes
  @attributes
end

#dataObject

Returns the value of attribute data.



3
4
5
# File 'app/models/spree/omnikassa_payment_response.rb', line 3

def data
  @data
end

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

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

#orderObject

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

#paymentObject

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_levelObject

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

Returns:

  • (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