Class: Paytureman::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/payture/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute rest_client to.



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



28
29
30
31
# File 'lib/payture/api.rb', line 28

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
22
# 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 { |a| a.join('=').camelize }.join(';'))
  }

  response = make_request(:init, init_params)
  response[:success] && response[:session_id]
end

#pay_url(session_id) ⇒ Object



24
25
26
# File 'lib/payture/api.rb', line 24

def pay_url(session_id)
  "#{url_for(:pay)}?SessionId=#{session_id}"
end

#refund(order_id, amount) ⇒ Object



33
34
35
36
# File 'lib/payture/api.rb', line 33

def refund(order_id, amount)
  response = make_request(:refund, order_id: order_id, amount: amount, password: @password)
  response[:success]
end

#status(order_id) ⇒ Object



43
44
45
46
47
# File 'lib/payture/api.rb', line 43

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



38
39
40
41
# File 'lib/payture/api.rb', line 38

def unblock(order_id, amount)
  response = make_request(:unblock, order_id: order_id, amount: amount, password: @password)
  response[:success]
end