Class: VivaPayAPI::Transaction

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/vivapayapi.rb

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Transaction

Returns a new instance of Transaction.



9
10
11
# File 'lib/vivapayapi.rb', line 9

def initialize(username, password)
	@auth = {:username => username , :password => password }
end

Instance Method Details

#amountObject



37
38
39
40
41
42
# File 'lib/vivapayapi.rb', line 37

def amount
	unless @response.nil?
		@response["Amount"]
	end
	return nil
end

#capture(token) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/vivapayapi.rb', line 13

def capture(token)
	@response = self.class.post("/transactions", 
       :basic_auth => @auth,
	:body => {
	:PaymentToken => token}.to_json,
       :headers => { 'Content-Type' => 'application/json' },
       :debug_output => $stdout).parsed_response
       return @response
end

#error_codeObject



51
52
53
54
55
56
# File 'lib/vivapayapi.rb', line 51

def error_code
	unless @response.nil?
		return @response["ErrorCode"]
	end
	return nil
end

#error_textObject



44
45
46
47
48
49
# File 'lib/vivapayapi.rb', line 44

def error_text
	unless @response.nil?
		return @response["ErrorText"]
	end
	return nil
end

#responseObject



58
59
60
# File 'lib/vivapayapi.rb', line 58

def response
	@response
end

#statusObject



30
31
32
33
34
35
# File 'lib/vivapayapi.rb', line 30

def status
	unless @response.nil?
		return @response["StatusId"]
	end
	return nil
end

#successful?Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
# File 'lib/vivapayapi.rb', line 62

def successful?
	unless @response.nil?
		return @response["ErrorCode"]==0
	end
	return nil
end

#transaction_idObject



23
24
25
26
27
28
# File 'lib/vivapayapi.rb', line 23

def transaction_id
	unless @response.nil?
		return @response["TransactionId"]
	end
	return nil
end