Class: Paybox::System::Base
- Inherits:
-
Object
- Object
- Paybox::System::Base
- Defined in:
- lib/paybox_system.rb
Constant Summary collapse
- @@config =
{}
Class Method Summary collapse
- .check_response?(params, sign) ⇒ Boolean
- .config ⇒ Object
- .config=(new_config) ⇒ Object
- .hash_form_fields_from(options = {}) ⇒ Object
Class Method Details
.check_response?(params, sign) ⇒ Boolean
41 42 43 44 45 46 |
# File 'lib/paybox_system.rb', line 41 def self.check_response?(params, sign) digest = OpenSSL::Digest::SHA1.new public_key = OpenSSL::PKey::RSA.new(File.read(File.(File.dirname(__FILE__) + '/../docs/pubkey.pem'))) public_key.verify(digest, Base64.decode64(Rack::Utils.unescape(sign)), params) end |
.config ⇒ Object
11 12 13 |
# File 'lib/paybox_system.rb', line 11 def self.config @@config end |
.config=(new_config) ⇒ Object
15 16 17 |
# File 'lib/paybox_system.rb', line 15 def self.config=(new_config) @@config = new_config end |
.hash_form_fields_from(options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/paybox_system.rb', line 19 def self.hash_form_fields_from( = {}) raise StandardError, "missing :secret_key in config Hash" unless @@config[:secret_key] = Hash[.map { |k, v| ["PBX_#{k.to_s.upcase}", v] }] ["PBX_HASH"] = "SHA512" date_iso = Time.now.iso8601 ["PBX_TIME"] = date_iso base_params_query = .to_a.map { |a| a.join("=") }.join("&") key = @@config[:secret_key] binary_key = [key].pack("H*") signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha512'), binary_key, base_params_query).upcase ["PBX_HMAC"] = signature end |