class Paymaster::UrlGenerator

Attributes

amount[RW]
description[RW]
email[RW]
expires[RW]
fail_url[RW]
fail_url_method[RW]
locale[RW]
number[RW]
payment_system[RW]
phone_number[RW]
sim_mode[RW]
success_url[RW]
success_url_method[RW]

Public Instance Methods

datetime(value) click to toggle source
# File lib/paymaster/url_generator.rb, line 49
def datetime(value)
  return unless value
  value.strftime("%Y-%m-%d %H:%M:%S")
end
endpoint() click to toggle source
# File lib/paymaster/url_generator.rb, line 17
def endpoint
  "https://lmi.paymaster.ua/#{fetch_locale}/index/get"
end
generate() click to toggle source
# File lib/paymaster/url_generator.rb, line 40
def generate
  "#{endpoint}?#{params_as_string}"
end
methods(method) click to toggle source
# File lib/paymaster/url_generator.rb, line 44
def methods(method)
  return unless method
  method.to_s == "post" ? 1 : 0
end
params() click to toggle source
# File lib/paymaster/url_generator.rb, line 21
def params
  {
    LMI_MERCHANT_ID: client.merchant_id,
    LMI_PAYMENT_AMOUNT: amount,
    LMI_PAYMENT_NO: number,
    LMI_PAYMENT_DESC: description,
    LMI_EXPIRES: datetime(expires),
    LMI_PAYER_PHONE_NUMBER: phone_number,
    LMI_PAYER_EMAIL: email,
    LMI_SUCCESS_URL: success_url,
    LMI_SUCCESS_METHOD: methods(success_url_method),
    LMI_FAIL_URL: fail_url,
    LMI_FAIL_METHOD: methods(fail_url_method),
    LMI_PAYMENT_SYSTEM: payment_system,
    LMI_SIM_MODE: sim_mode,
    LMI_HASH: signature,
  }.compact
end
params_as_string() click to toggle source
# File lib/paymaster/url_generator.rb, line 60
def params_as_string
  params.map { |k, v| "#{k}=#{v}" }.join("&")
end
signature() click to toggle source
# File lib/paymaster/url_generator.rb, line 54
def signature
  return unless client.secret_key
  string = "#{client.merchant_id}#{number}#{amount}#{client.secret_key}"
  Digest::SHA256.hexdigest(string).upcase
end

Private Instance Methods

fetch_locale() click to toggle source
# File lib/paymaster/url_generator.rb, line 66
def fetch_locale
  locale.to_s.in?(%w[ru uk en]) ? locale : "ru"
end