Module: Poundpay
- Defined in:
- lib/poundpay.rb,
lib/poundpay/rails.rb,
lib/poundpay/formats.rb,
lib/poundpay/version.rb,
lib/poundpay/callback.rb,
lib/poundpay/elements.rb,
lib/poundpay/resource.rb
Defined Under Namespace
Modules: Formats
Classes: Developer, Payment, Resource
Constant Summary
collapse
- WWW_URL =
"https://www.poundpay.com"
- API_URL =
"https://api.poundpay.com"
- API_VERSION =
"silver"
- VERSION =
"0.2.8"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.api_version ⇒ Object
83
84
85
|
# File 'lib/poundpay.rb', line 83
def api_version
@api_version || API_VERSION
end
|
.callback_url ⇒ Object
Returns the value of attribute callback_url.
14
15
16
|
# File 'lib/poundpay.rb', line 14
def callback_url
@callback_url
end
|
Class Method Details
.api_url ⇒ Object
75
76
77
|
# File 'lib/poundpay.rb', line 75
def api_url
@api_url || API_URL
end
|
.api_url=(value) ⇒ Object
79
80
81
|
# File 'lib/poundpay.rb', line 79
def api_url=(value)
@api_url = value.sub /(\/)$/, "" end
|
.clear_config! ⇒ Object
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/poundpay.rb', line 52
def clear_config!
@www_url = nil
@api_url = nil
@api_version = nil
@callback_url = nil
Resource.site = nil
Resource.user = nil
Resource.password = nil
@configured = false
end
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/poundpay.rb', line 16
def configure(developer_sid, auth_token)
warn "warning: Poundpay is already configured" if configured?
raise ArgumentError.new "developer_sid is required" unless developer_sid
raise ArgumentError.new "auth_token is required" unless auth_token
unless developer_sid.start_with? "DV"
raise ArgumentError.new "developer_sid should start with 'DV'. Make sure " \
"you're using the right developer_sid"
end
yield self if block_given?
api_url.sub! /(\/)$/, "" www_url.sub /(\/)$/, ""
Resource.site = "#{api_url}/#{api_version}/"
Resource.user = developer_sid
Resource.password = auth_token
@configured = true
if callback_url
@me = Developer.me
@me.callback_url = callback_url
@me.save!
end
end
|
43
44
45
46
47
48
49
50
|
# File 'lib/poundpay.rb', line 43
def configure_from_hash(config)
configure(config["developer_sid"], config["auth_token"]) do |c|
c.www_url = config["www_url"] || WWW_URL
c.api_url = config["api_url"] || API_URL
c.api_version = config["api_version"] || API_VERSION
c.callback_url = config["callback_url"] || nil
end
end
|
3
4
5
6
7
8
|
# File 'lib/poundpay/rails.rb', line 3
def self.configure_from_yaml(path)
pathname = Pathname.new Rails.root.join(path)
raise ArgumentError.new "File does not exist: #{pathname.to_s}" unless pathname.exist?
config = YAML::load_file(pathname)[Rails.env]
Poundpay.configure_from_hash(config)
end
|
63
64
65
|
# File 'lib/poundpay.rb', line 63
def configured?
@configured
end
|
.verified_callback?(signature, params = {}) ⇒ Boolean
5
6
7
8
9
|
# File 'lib/poundpay/callback.rb', line 5
def self.verified_callback?(signature, params = {})
@callback_url = Developer.me.callback_url unless @callback_url
signature == calculate_signature(@callback_url, params)
end
|
.www_url ⇒ Object
67
68
69
|
# File 'lib/poundpay.rb', line 67
def www_url
@www_url || WWW_URL
end
|
.www_url=(value) ⇒ Object
71
72
73
|
# File 'lib/poundpay.rb', line 71
def www_url=(value)
@www_url = value.sub /(\/)$/, "" end
|