module Paymaya::Helper
Constants
- MONEY_PARAMS
Public Class Methods
camelify(input)
click to toggle source
# File lib/paymaya/helper.rb, line 27 def self.camelify(input) transform(input, :camelify, :to_camelback_keys) end
checkout_public_auth_headers()
click to toggle source
# File lib/paymaya/helper.rb, line 79 def self.checkout_public_auth_headers auth_headers(Paymaya.config.checkout_public_key) end
checkout_secret_auth_headers()
click to toggle source
# File lib/paymaya/helper.rb, line 83 def self.checkout_secret_auth_headers auth_headers(Paymaya.config.checkout_secret_key) end
format_amount(num, currency)
click to toggle source
# File lib/paymaya/helper.rb, line 107 def self.format_amount(num, currency) Money.new(num, currency, '').to_s end
payment_facilitator(submerchant_id:, submerchant_name:, submerchant_city:, submerchant_pos_country:, submerchant_country_code:, submerchant_state_code: nil)
click to toggle source
# File lib/paymaya/helper.rb, line 9 def self.payment_facilitator(submerchant_id:, submerchant_name:, submerchant_city:, submerchant_pos_country:, submerchant_country_code:, submerchant_state_code: nil) pf = { smi: submerchant_id, smn: submerchant_name, mci: submerchant_city, mpc: submerchant_pos_country, mco: submerchant_country_code } pf[:mst] = submerchant_state_code unless submerchant_state_code.nil? pf end
payment_vault_public_auth_headers()
click to toggle source
# File lib/paymaya/helper.rb, line 71 def self.payment_vault_public_auth_headers auth_headers(Paymaya.config.payment_vault_public_key) end
payment_vault_secret_auth_headers()
click to toggle source
# File lib/paymaya/helper.rb, line 75 def self.payment_vault_secret_auth_headers auth_headers(Paymaya.config.payment_vault_secret_key) end
request(method, url, params, headers)
click to toggle source
# File lib/paymaya/helper.rb, line 95 def self.request(method, url, params, headers) response = RestClient::Request.execute( method: method, url: url, headers: headers, payload: camelify(params).to_json ) snakify(JSON.parse(response)) end
snakify(input)
click to toggle source
# File lib/paymaya/helper.rb, line 23 def self.snakify(input) transform(input, :snakify, :to_snake_keys) end
stringify_numbers(input, currency)
click to toggle source
# File lib/paymaya/helper.rb, line 51 def self.stringify_numbers(input, currency) if input.is_a? Hash output = {} input.each do |k, v| output[k] = if (MONEY_PARAMS.include? k) && (v.is_a? Numeric) format_amount(v, currency) else stringify_numbers(v, currency) end end output elsif input.is_a? Array input.map do |elem| stringify_numbers(elem, currency) end else input.to_s end end
Private Class Methods
auth_headers(key)
click to toggle source
# File lib/paymaya/helper.rb, line 87 def self.auth_headers(key) { authorization: "Basic #{Base64.strict_encode64(key + ':').chomp}", content_type: 'application/json' } end
transform(input, method_name, hash_method)
click to toggle source
# File lib/paymaya/helper.rb, line 31 def self.transform(input, method_name, hash_method) return transform_array(input, method_name) if input.is_a? Array return transform_hash(input, method_name, hash_method) if input.is_a? Hash input end
transform_array(input, method_name)
click to toggle source
# File lib/paymaya/helper.rb, line 37 def self.transform_array(input, method_name) input.map do |elem| send(method_name, elem) end end
transform_hash(input, method_name, hash_method)
click to toggle source
# File lib/paymaya/helper.rb, line 43 def self.transform_hash(input, method_name, hash_method) hash = input.send(hash_method) hash.each do |k, v| hash[k] = send(method_name, v) if v.is_a? Array end hash end