Class: Paytureman::Api
- Inherits:
-
Object
- Object
- Paytureman::Api
- Defined in:
- lib/payture/api.rb
Instance Attribute Summary collapse
-
#rest_client ⇒ Object
writeonly
Sets the attribute rest_client.
Instance Method Summary collapse
- #charge(order_id) ⇒ Object
- #init(order_id, amount, ip, description = {}) ⇒ Object
-
#initialize(host, key, password) ⇒ Api
constructor
A new instance of Api.
- #pay_url(session_id) ⇒ Object
- #refund(order_id, amount) ⇒ Object
- #status(order_id) ⇒ Object
- #unblock(order_id, amount) ⇒ Object
Constructor Details
#initialize(host, key, password) ⇒ Api
Returns a new instance of Api.
5 6 7 8 9 |
# File 'lib/payture/api.rb', line 5 def initialize(host, key, password) @host = host @key = key @password = password end |
Instance Attribute Details
#rest_client=(value) ⇒ Object
Sets the attribute rest_client
3 4 5 |
# File 'lib/payture/api.rb', line 3 def rest_client=(value) @rest_client = value end |
Instance Method Details
#charge(order_id) ⇒ Object
27 28 29 30 |
# File 'lib/payture/api.rb', line 27 def charge(order_id) response = make_request(:charge, order_id: order_id, password: @password) response[:success] end |
#init(order_id, amount, ip, description = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/payture/api.rb', line 11 def init(order_id, amount, ip, description = {}) data = { SessionType: :Block, OrderId: order_id, Amount: amount, IP: ip } data.merge!(description) init_params = { 'Data' => URI.escape(data.map { |k, v| "#{k.to_s.camelize}=#{v}" }.join(';')) } response = make_request(:init, init_params) response[:success] && response[:session_id] end |
#pay_url(session_id) ⇒ Object
23 24 25 |
# File 'lib/payture/api.rb', line 23 def pay_url(session_id) "#{url_for(:pay)}?SessionId=#{session_id}" end |
#refund(order_id, amount) ⇒ Object
32 33 34 35 |
# File 'lib/payture/api.rb', line 32 def refund(order_id, amount) response = make_request(:refund, order_id: order_id, amount: amount, password: @password) response[:success] end |
#status(order_id) ⇒ Object
42 43 44 45 46 |
# File 'lib/payture/api.rb', line 42 def status(order_id) response = make_request(:pay_status, order_id: order_id) return :prepared if !response[:success] && response[:err_code] == :none response[:success] && response[:state] end |
#unblock(order_id, amount) ⇒ Object
37 38 39 40 |
# File 'lib/payture/api.rb', line 37 def unblock(order_id, amount) response = make_request(:unblock, order_id: order_id, amount: amount, password: @password) response[:success] end |