Class: Spree::OmnikassaPaymentRequest

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

Overview

OmnikassaPaymentRequest deals with the data for the actual request to and fro Omnikassa.

Not a persistent object: will not interact or get saved in the database.

It requires amount and order_id to be passed in on creation.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount, transaction_reference, response_code = nil) ⇒ OmnikassaPaymentRequest

Returns a new instance of OmnikassaPaymentRequest.



14
15
16
17
18
19
20
21
22
23
# File 'app/models/spree/omnikassa_payment_request.rb', line 14

def initialize(amount, transaction_reference, response_code = nil)
  @payment_method = Spree::PaymentMethod::Omnikassa.fetch_payment_method
  if transaction_reference.to_s.include? merchant_id
    @amount = amount
    @order_id = transaction_reference.to_s.match(merchant_id).post_match
    @response_code = response_code
  else
    raise "transactionReference cannot be parsed"
  end
end

Instance Attribute Details

#amount=(value) ⇒ Object

Sets the attribute amount

Parameters:

  • value

    the value to set the attribute amount to.



12
13
14
# File 'app/models/spree/omnikassa_payment_request.rb', line 12

def amount=(value)
  @amount = value
end

#order_id=(value) ⇒ Object

Sets the attribute order_id

Parameters:

  • value

    the value to set the attribute order_id to.



12
13
14
# File 'app/models/spree/omnikassa_payment_request.rb', line 12

def order_id=(value)
  @order_id = value
end

#payment_methodObject

Returns the value of attribute payment_method.



12
13
14
# File 'app/models/spree/omnikassa_payment_request.rb', line 12

def payment_method
  @payment_method
end

Class Method Details

.build_transaction_reference(order_id) ⇒ Object



44
45
46
47
# File 'app/models/spree/omnikassa_payment_request.rb', line 44

def self.build_transaction_reference order_id
  @payment_method ||= Spree::PaymentMethod::Omnikassa.fetch_payment_method
  @payment_method.preferred_merchant_id + order_id.to_s
end

Instance Method Details

#dataObject

Generates datastring according to omnikassa requirements §9. name=value|name=value.



27
28
29
# File 'app/models/spree/omnikassa_payment_request.rb', line 27

def data
  "amount=#{amount}|orderId=#{order_id}|currencyCode=#{currency_code}|merchantId=#{merchant_id}|normalReturnUrl=#{normal_return_url}|automaticResponseUrl=#{automatic_response_url}|transactionReference=#{transaction_reference}|keyVersion=#{key_version}"
end

#interface_versionObject



31
32
33
# File 'app/models/spree/omnikassa_payment_request.rb', line 31

def interface_version
  "HP_1.0"
end

#sealObject



35
36
37
# File 'app/models/spree/omnikassa_payment_request.rb', line 35

def seal
  ::Digest::SHA2.hexdigest(data + @payment_method.preferred_secret_key)
end

#to_sObject

to_s magic method simply wraps the data string generator.



40
41
42
# File 'app/models/spree/omnikassa_payment_request.rb', line 40

def to_s
  data
end