Module: Payfort
- Includes:
- HTTParty
- Defined in:
- lib/payfort.rb,
lib/payfort/charge.rb,
lib/payfort/version.rb,
lib/payfort/customer.rb,
lib/payfort/errors/banking_error.rb,
lib/payfort/errors/payfort_error.rb,
lib/payfort/errors/request_error.rb,
lib/payfort/errors/processing_error.rb,
lib/payfort/errors/authentication_error.rb
Defined Under Namespace
Classes: AuthenticationError, BankingError, Charge, Customer, PayfortError, ProcessingError, RequestError
Constant Summary
collapse
- VERSION =
'0.1'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
63
64
65
|
# File 'lib/payfort.rb', line 63
def api_key
@api_key
end
|
Class Method Details
.api_url(url = '') ⇒ Object
16
17
18
|
# File 'lib/payfort.rb', line 16
def self.api_url(url='')
@api_base + url
end
|
.get(url, query = {}) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/payfort.rb', line 55
def self.get(url, query={})
options = {basic_auth: {username: api_key, password: ''}}
options.merge!({query: query})
response = HTTParty.get(url, options)
JSON.parse(response.body);
end
|
.handle_response(response) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/payfort.rb', line 20
def self.handle_response(response)
body = JSON.parse(response.body);
if response.code.between?(200, 299) and !body.key?('error')
return body
end
case body['error']['type']
when 'banking'
raise Payfort::BankingError.new(body['error']['message'], body['error']['code'], response.code)
when 'authentication'
raise Payfort::AuthenticationError.new(body['error']['message'], body['error']['code'], response.code)
when 'processing'
raise Payfort::ProcessingError.new(body['error']['message'], body['error']['code'], response.code)
when 'request'
raise Payfort::RequestError.new(body['error']['message'], body['error']['code'], response.code)
end
raise Payfort::PayfortError.new(body['error']['message'], body['error']['code'], response.code)
end
|
.post(url, body = {}) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/payfort.rb', line 47
def self.post(url, body={})
options = {basic_auth: {username: api_key, password: ''}}
options.merge!({body: body})
response = HTTParty.post(url, options)
self.handle_response(response)
end
|