diff --git a/config/wsdl.xml b/config/wsdl.xml
index f2a69c8..1071055 100644
--- a/config/wsdl.xml
+++ b/config/wsdl.xml
@@ -1 +1 @@
-481632
\ No newline at end of file
+481632
\ No newline at end of file
diff --git a/lib/okpay.rb b/lib/okpay.rb
index a10fac3..f920ff0 100644
--- a/lib/okpay.rb
+++ b/lib/okpay.rb
@@ -1,26 +1,24 @@
require 'savon'
-module Okpay
+module Okpay
class API
class Client
-
- class ::String
- def camelize
- self.gsub!(/^[a-z]|[\s_]+[a-z]/) { |a| a.upcase }
- self.gsub!(/[\s_]/, '')
- self
- end
+ def okpay_camelize(str)
+ result = str.gsub(/^[a-z]|[\s_]+[a-z]/) { |a| a.upcase }
+ result = result.gsub(/[\s_]/, '')
+ result
end
-
+
DEFAULTS = {
:wsdl => File.join(File.dirname(File.expand_path(__FILE__)), '../config/wsdl.xml')
}
-
+
METHODS = {
- :get_date_time => [],
+ :account_check => [:account],
+ :get_date_time => [],
:wallet_get_balance => [],
:wallet_get_currency_balance => [:currency],
- :send_money => [:reciever, :currency, :amount, :comment, :is_receiver_pays_fees, :invoice],
+ :send_money => [:receiver, :currency, :amount, :comment, :is_receiver_pays_fees, :invoice],
:account_check => [:account],
:transaction_get => [:txn_id, :invoice],
:transaction_history => [:from, :till, :page_size, :page_number],
@@ -28,34 +26,39 @@ def camelize
:withdraw_to_ecurrency => [:payment_method, :pay_system_account, :amount, :currency, :fees_from_amount, :invoice],
:withdraw_to_ecurrency_calculate => [:payment_method, :amount, :currency, :fees_from_amount]
}
-
- def initialize(wallet_id, api_key, options={})
- @api_key = api_key.strip
- @wallet_id = wallet_id.strip
+
+ class_attribute :wallet_id, :api_key
+
+ def initialize(options = {})
+ @api_key = options[:api_key] || api_key
+ @wallet_id = options[:wallet_id] || wallet_id
+ fail('OKPAY api_key is not configured') unless @api_key
+ fail('OKPAY wallet_id is not configured') unless @wallet_id
+ @api_key.strip!
+ @wallet_id.strip!
@config = DEFAULTS.merge! options
@soap_client = Savon.client(wsdl: @config[:wsdl])
end
-
- METHODS.each_pair do |method,args|
+
+ METHODS.each_pair do |method, args|
class_eval %{
def #{method}(#{args.join(',')})
message = {"WalletID" => @wallet_id, "SecurityToken" => security_token}
#{args}.each do |arg|
- message[arg.to_s.camelize] = eval arg.to_s
+ message[okpay_camelize(arg.to_s)] = eval arg.to_s
end
response = @soap_client.call(:#{method}, message: message)
response.body[:#{method}_response][:#{method}_result]
end
}
end
-
+
private
-
+
def security_token
okpay_timestamp = Time.now.utc.strftime('%Y%m%d:%H')
Digest::SHA256.hexdigest("#{@api_key}:#{okpay_timestamp}").to_s.upcase
end
-
end
end
end