Class: WebToPay::Payment
- Inherits:
-
Object
- Object
- WebToPay::Payment
- 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
-
#data ⇒ Object
encoded query.
-
#initialize(params = {}, user_params = {}) ⇒ Payment
constructor
A new instance of Payment.
- #query ⇒ Object
- #sign ⇒ Object
- #to_key ⇒ Object
- #url ⇒ Object
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
#data ⇒ Object
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 |
#query ⇒ Object
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 |
#sign ⇒ Object
42 43 44 |
# File 'lib/webtopay/payment.rb', line 42 def sign Digest::MD5.hexdigest(data + @sign_password) end |
#to_key ⇒ Object
46 47 |
# File 'lib/webtopay/payment.rb', line 46 def to_key end |
#url ⇒ Object
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 |