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: ChargePermission, Developer, Payment, Resource, User
Constant Summary
collapse
- WWW_URL =
"https://www.poundpay.com"
- API_URL =
"https://api.poundpay.com"
- API_VERSION =
"silver"
- VERSION =
"0.4.0"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.api_version ⇒ Object
84
85
86
|
# File 'lib/poundpay.rb', line 84
def api_version
@api_version || API_VERSION
end
|
.callback_url ⇒ Object
Returns the value of attribute callback_url.
15
16
17
|
# File 'lib/poundpay.rb', line 15
def callback_url
@callback_url
end
|
Class Method Details
.api_url ⇒ Object
76
77
78
|
# File 'lib/poundpay.rb', line 76
def api_url
@api_url || API_URL
end
|
.api_url=(value) ⇒ Object
80
81
82
|
# File 'lib/poundpay.rb', line 80
def api_url=(value)
@api_url = value.sub /(\/)$/, "" end
|
.clear_config! ⇒ Object
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/poundpay.rb', line 53
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
|
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
42
|
# File 'lib/poundpay.rb', line 17
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
|
44
45
46
47
48
49
50
51
|
# File 'lib/poundpay.rb', line 44
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
|
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/poundpay/rails.rb', line 5
def self.configure_from_yaml(path)
pathname = Rails.root.join(path)
raise ArgumentError, "File does not exist: #{pathname}" unless pathname.exist?
config = pathname.read
config = ERB.new(config).result if pathname.extname == '.erb'
config = YAML.load(config)[Rails.env]
Poundpay.configure_from_hash(config)
end
|
64
65
66
|
# File 'lib/poundpay.rb', line 64
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
68
69
70
|
# File 'lib/poundpay.rb', line 68
def www_url
@www_url || WWW_URL
end
|
.www_url=(value) ⇒ Object
72
73
74
|
# File 'lib/poundpay.rb', line 72
def www_url=(value)
@www_url = value.sub /(\/)$/, "" end
|