Class: PaymentsJs
- Inherits:
-
Object
- Object
- PaymentsJs
- Extended by:
- Configuration
- Defined in:
- lib/paymentsjs-rails.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#auth_key ⇒ Object
Returns the value of attribute auth_key.
-
#city ⇒ Object
Returns the value of attribute city.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#mid ⇒ Object
Returns the value of attribute mid.
-
#name ⇒ Object
Returns the value of attribute name.
-
#postback_url ⇒ Object
Returns the value of attribute postback_url.
-
#pre_auth ⇒ Object
Returns the value of attribute pre_auth.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
-
#request_type ⇒ Object
Returns the value of attribute request_type.
-
#salt ⇒ Object
Returns the value of attribute salt.
-
#state ⇒ Object
Returns the value of attribute state.
-
#zip ⇒ Object
Returns the value of attribute zip.
Instance Method Summary collapse
-
#generate_salt(iv) ⇒ Object
Generate a salt.
- #get_auth_key ⇒ Object
- #get_salt ⇒ Object
-
#initialize(args = {}) ⇒ PaymentsJs
constructor
A new instance of PaymentsJs.
Methods included from Configuration
Constructor Details
#initialize(args = {}) ⇒ PaymentsJs
Returns a new instance of PaymentsJs.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def address @address end |
#amount ⇒ Object
Returns the value of attribute amount.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def amount @amount end |
#api_key ⇒ Object
Returns the value of attribute api_key.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def api_key @api_key end |
#auth_key ⇒ Object
Returns the value of attribute auth_key.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def auth_key @auth_key end |
#city ⇒ Object
Returns the value of attribute city.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def city @city end |
#environment ⇒ Object
Returns the value of attribute environment.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def environment @environment end |
#mid ⇒ Object
Returns the value of attribute mid.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def mid @mid end |
#name ⇒ Object
Returns the value of attribute name.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def name @name end |
#postback_url ⇒ Object
Returns the value of attribute postback_url.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def postback_url @postback_url end |
#pre_auth ⇒ Object
Returns the value of attribute pre_auth.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def pre_auth @pre_auth end |
#request_id ⇒ Object
Returns the value of attribute request_id.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def request_id @request_id end |
#request_type ⇒ Object
Returns the value of attribute request_type.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def request_type @request_type end |
#salt ⇒ Object
Returns the value of attribute salt.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def salt @salt end |
#state ⇒ Object
Returns the value of attribute state.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def state @state end |
#zip ⇒ Object
Returns the value of attribute zip.
27 28 29 |
# File 'lib/paymentsjs-rails.rb', line 27 def zip @zip end |
Instance Method Details
#generate_salt(iv) ⇒ Object
Generate a salt
14 15 16 17 18 19 |
# 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 ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# 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 ⇒ Object
75 76 77 |
# File 'lib/paymentsjs-rails.rb', line 75 def get_salt @salt end |