class PaymentsJs
Attributes
address[RW]
amount[RW]
api_key[RW]
auth_key[RW]
city[RW]
environment[RW]
mid[RW]
name[RW]
postback_url[RW]
pre_auth[RW]
request_id[RW]
request_type[RW]
salt[RW]
state[RW]
zip[RW]
Public Class Methods
new(args = {})
click to toggle source
# File lib/paymentsjs-rails.rb, line 29 def initialize(args = {}) @api_key = PaymentsJs.api_key @mid = PaymentsJs.mid @mkey = PaymentsJs.mkey @api_secret = PaymentsJs.api_secret @request_type = args[:request_type].present? ? args[:request_type] : PaymentsJs.request_type @request_id = args[:request_id] @postback_url = args[:postback_url].present? ? args[:postback_url] : PaymentsJs.postback_url @amount = args[:amount] @pre_auth = args[:pre_auth].present? ? args[:pre_auth] : PaymentsJs.pre_auth @environment = args[:environment].present? ? args[:environment] : PaymentsJs.environment # Generate the salt and iv at initialization so they can be consistently called @iv = OpenSSL::Random.pseudo_bytes(16) @salt = generate_salt(@iv) end
Public Instance Methods
generate_salt(iv)
click to toggle source
Generate a salt
# File lib/paymentsjs-rails.rb, line 14 def generate_salt(iv) salt = iv.unpack('H*').first salt = salt.bytes.to_a salt = salt.pack('U*') Base64.strict_encode64(salt) end
get_auth_key()
click to toggle source
# File lib/paymentsjs-rails.rb, line 49 def get_auth_key cipher = OpenSSL::Cipher::AES.new(256, :CBC) cipher.encrypt req = { "apiKey" => @api_key, "merchantId" => @mid, "merchantKey" => @mkey, "requestType" => @request_type, "requestId" => @request_id, "postbackUrl" => @postback_url, "amount" => @amount, "nonce" => @salt, "preAuth" => @pre_auth, "environment" => @environment } data = JSON.generate(req) key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(@api_secret, @salt, 1500, 32) cipher.key = key cipher.iv = @iv auth_key = cipher.update(data) + cipher.final() Base64.strict_encode64(auth_key) end
get_salt()
click to toggle source
# File lib/paymentsjs-rails.rb, line 75 def get_salt @salt end