Class: Rubykassa::PaymentInterface

Inherits:
Object
  • Object
show all
Includes:
SignatureGenerator
Defined in:
lib/rubykassa/payment_interface.rb

Constant Summary collapse

PARAMS_CONFORMITY =
{
  login:       "MrchLogin",
  total:       "OutSum",
  invoice_id:  "InvId",
  signature:   "SignatureValue",
  email:       "Email",
  currency:    "IncCurrLabel",
  description: "Desc",
  culture:     "Culture"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SignatureGenerator

#custom_params, #generate_signature_for, #params_string

Constructor Details

#initialize(&block) ⇒ PaymentInterface

Returns a new instance of PaymentInterface.



21
22
23
24
# File 'lib/rubykassa/payment_interface.rb', line 21

def initialize &block
  instance_eval &block if block_given?
  shpfy_params
end

Instance Attribute Details

#invoice_idObject

Returns the value of attribute invoice_id.



19
20
21
# File 'lib/rubykassa/payment_interface.rb', line 19

def invoice_id
  @invoice_id
end

#paramsObject

Returns the value of attribute params.



19
20
21
# File 'lib/rubykassa/payment_interface.rb', line 19

def params
  @params
end

#totalObject

Returns the value of attribute total.



19
20
21
# File 'lib/rubykassa/payment_interface.rb', line 19

def total
  @total
end

Instance Method Details

#base_urlObject



30
31
32
# File 'lib/rubykassa/payment_interface.rb', line 30

def base_url
  test_mode? ? "http://test.robokassa.ru/Index.aspx" : "https://merchant.roboxchange.com/Index.aspx"
end

#initial_optionsObject



46
47
48
49
50
51
52
53
# File 'lib/rubykassa/payment_interface.rb', line 46

def initial_options
  {
    login: Rubykassa.,
    total: @total,
    invoice_id: @invoice_id,
    signature: generate_signature_for(:payment)
  }.merge(Hash[@params.sort.map {|param_name| [param_name[0], param_name[1]]}])
end

#pay_url(extra_params = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rubykassa/payment_interface.rb', line 34

def pay_url(extra_params = {})
  extra_params = extra_params.slice(:currency, :description, :email, :culture)

  "#{base_url}?" + initial_options.merge(extra_params).map do |key, value| 
    if key =~ /^shp/
      "#{key}=#{value}"
    else
      "#{PARAMS_CONFORMITY[key]}=#{value}"
    end
  end.compact.join("&")
end

#test_mode?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/rubykassa/payment_interface.rb', line 26

def test_mode?
  Rubykassa.mode == :test
end