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.3.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_versionObject



84
85
86
# File 'lib/poundpay.rb', line 84

def api_version
  @api_version || API_VERSION
end

.callback_urlObject

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_urlObject



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 /(\/)$/, ""  # Remove trailing backslash
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

.configure(developer_sid, auth_token) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Poundpay)

    the object that the method was called on



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! /(\/)$/, ""  # Remove trailing backslash
  www_url.sub /(\/)$/, ""
  Resource.site = "#{api_url}/#{api_version}/"
  Resource.user = developer_sid
  Resource.password = auth_token
  @configured = true

  # Set callback_url if defined in configuration
  if callback_url
    @me = Developer.me
    @me.callback_url = callback_url
    @me.save!
  end
end

.configure_from_hash(config) ⇒ Object



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

.configure_from_yaml(path) ⇒ Object



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

.configured?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/poundpay.rb', line 64

def configured?
  @configured
end

.verified_callback?(signature, params = {}) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
# File 'lib/poundpay/callback.rb', line 5

def self.verified_callback?(signature, params = {})
  # Make a request to Poundpay for callback_url once
  @callback_url = Developer.me.callback_url unless @callback_url
  signature == calculate_signature(@callback_url, params)
end

.www_urlObject



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 /(\/)$/, ""  # Remove trailing backslash
end