Class: WebToPay::Payment

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::AttributeMethods
Defined in:
lib/webtopay/payment.rb

Constant Summary collapse

ATTRIBUTES =
[:projectid, :orderid, :lang, :amount, :currency, :accepturl, :cancelurl, :callbackurl,
:country, :paytext, :p_email, :p_name, :p_surname, :payment, :test, :version]
UNDERSCORE_MAPPINGS =
{pname: :p_name, pemail: :p_email, psurname: :p_surname}

Instance Method Summary collapse

Constructor Details

#initialize(params = {}, user_params = {}) ⇒ Payment

Returns a new instance of Payment.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/webtopay/payment.rb', line 10

def initialize(params = {}, user_params = {})
  self.version = WebToPay::API_VERSION
  self.projectid = user_params[:projectid] || WebToPay.config.project_id
  @sign_password = user_params[:sign_password] || WebToPay.config.sign_password

  params.each_pair do |field, value|
    field_name = field.to_s.downcase.gsub('_', '').to_sym
    field_name = UNDERSCORE_MAPPINGS[field_name] || field_name
    self.public_send("#{field_name}=", value)
  end
end

Instance Method Details

#dataObject

encoded query



34
35
36
# File 'lib/webtopay/payment.rb', line 34

def data # encoded query
  @data ||= Base64.encode64(query).gsub("\n", '').gsub('/', '+').gsub('_', '-')
end

#queryObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/webtopay/payment.rb', line 22

def query
  @query ||= begin
    query = []
    ATTRIBUTES.each do |field|
      value = self.public_send(field)
      next if value.blank?
      query << "#{field}=#{ CGI::escape value.to_s}"
    end
    query.join('&')
  end
end

#signObject



42
43
44
# File 'lib/webtopay/payment.rb', line 42

def sign
  Digest::MD5.hexdigest(data + @sign_password)
end

#to_keyObject



46
47
# File 'lib/webtopay/payment.rb', line 46

def to_key
end

#urlObject



38
39
40
# File 'lib/webtopay/payment.rb', line 38

def url
  "https://www.mokejimai.lt/pay?data=#{CGI::escape data}&sign=#{CGI::escape sign}"
end