class Epa::Soap::Client
Constants
- DEFAULTS
Attributes
client[RW]
client_id[RW]
config[RW]
secret_key[RW]
Public Class Methods
new(client_id, secret_key, options = {})
click to toggle source
# File lib/epa/soap/client.rb, line 19 def initialize(client_id, secret_key, options = {}) @client_id = client_id @secret_key = secret_key @config = DEFAULTS.merge options end
Public Instance Methods
balance(currency = 'USD', e_wallet = nil)
click to toggle source
# File lib/epa/soap/client.rb, line 57 def balance(currency = 'USD', e_wallet = nil) wallet = if e_wallet get_balances.detect{|b| b[:currency] == currency && b[:e_wallet_number] == e_wallet} else get_balances.detect{|b| b[:currency] == currency} end wallet[:balance].to_f if wallet end
call_soap_api(operation, params, return_key = nil)
click to toggle source
# File lib/epa/soap/client.rb, line 109 def call_soap_api operation, params, return_key = nil response = client.call operation, :message => prepare_body(params) result = response.body[:"#{operation}_response"][:"#{operation}_result"] if result[:response_code] == 'Ok' return result if return_key.nil? if return_key.is_a? Array return_key.each { |value| result = result.[](value) } result else result[return_key] end else raise ApiError, result[:response_code] end end
get_balance(currency, wallet)
click to toggle source
# File lib/epa/soap/client.rb, line 47 def get_balance(currency, wallet) payload = { external_partner_id: client_id, currency: currency, e_wallet: wallet } call_soap_api __method__, payload, :balance end
get_balances()
click to toggle source
# File lib/epa/soap/client.rb, line 39 def get_balances payload = { external_partner_id: client_id } call_soap_api __method__, payload, [:balances, :e_wallet_balance] end
get_incoming_transactions(options)
click to toggle source
# File lib/epa/soap/client.rb, line 89 def get_incoming_transactions options payload = { external_partner_id: client_id, date_from: options[:date_from], date_to: options[:date_to], currency: options[:currency] || 'USD' } call_soap_api __method__, payload, [:transactions, :incoming_transaction] end
get_transaction(options)
click to toggle source
# File lib/epa/soap/client.rb, line 100 def get_transaction(options) payload = { external_partner_id: client_id, e_wallet: options[:e_wallet], transaction_id: options[:transaction_id] } call_soap_api __method__, payload, :transaction end
internal_payment(options)
click to toggle source
# File lib/epa/soap/client.rb, line 66 def internal_payment(options) payload = { external_partner_id: client_id, from_wallet_id: options[:from_wallet_id], to_wallet_id: options[:to_wallet_id], amount: options[:amount], currency: options[:currency], payment_id: options[:payment_id], details: options[:details] } call_soap_api __method__, payload, :transaction_id end
operations()
click to toggle source
available operations for Epayments API
# File lib/epa/soap/client.rb, line 35 def operations client.operations end
transfer_funds(options)
click to toggle source
# File lib/epa/soap/client.rb, line 80 def transfer_funds(options) internal_payment from_wallet_id: options[:from], to_wallet_id: options[:to], amount: options[:amount], currency: options[:currency] || 'USD', payment_id: options[:payment_id] || rand(2**32), details: options[:details] end
Private Instance Methods
format_before_sign(value)
click to toggle source
formats values to meet signature formatting requirements
# File lib/epa/soap/client.rb, line 134 def format_before_sign value case value when Time value.strftime("%Y.%m.%d") when Float '%.2f' % value else value.to_s end end
prepare_body(params)
click to toggle source
generates body of SOAP request
# File lib/epa/soap/client.rb, line 146 def prepare_body params body_params = ActiveSupport::OrderedHash.new params.each do |k, v| value = if v.respond_to? :strftime v.strftime("%Y-%m-%dT%T") else v.to_s end body_params[config[:namespace_identifier].to_s + ':' + k.to_s.camelize(:lower)] = value end body_params[config[:namespace_identifier].to_s + ":sign"] = sign(params) body_params end
sign(params)
click to toggle source
generates signature
# File lib/epa/soap/client.rb, line 128 def sign params signature = params.values.map { |v| format_before_sign(v) }.join('') + secret_key Digest::MD5.hexdigest(signature).upcase end