Skip to content

Commit

Permalink
define callback_url directly in yml file
Browse files Browse the repository at this point in the history
  • Loading branch information
matin committed Apr 24, 2011
1 parent f855004 commit 3a80936
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.rdoc
Expand Up @@ -18,12 +18,14 @@ Poundpay is a payments platform for marketplaces
development:
developer_sid: DV0383d447360511e0bbac00264a09ff3c
auth_token: c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a
callback_url: http://staging.awesomemarketplace.com/payments/callback
www_url: https://www-sandbox.poundpay.com
api_url: https://api-sandbox.poundpay.com

production:
developer_sid: DV8dd93f0f3c6411e0863f00264a09ff3c
auth_token: d8c4ea1bafd3fcac8c1062a72c22bcdb09321deb1041df257165cd6449def0de
callback_url: http://www.awesomemarketplace.com/payments/callback

4. Create the file config/initializers/poundpay.rb and add the following

Expand Down
10 changes: 10 additions & 0 deletions lib/poundpay.rb
Expand Up @@ -11,6 +11,7 @@ module Poundpay

class << self
attr_writer :api_version
attr_accessor :callback_url

def configure(developer_sid, auth_token)
warn "warning: Poundpay is already configured" if configured?
Expand All @@ -30,20 +31,29 @@ def configure(developer_sid, auth_token)
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

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

def clear_config!
@www_url = nil
@api_url = nil
@api_version = nil
@callback_url = nil
Resource.site = nil
Resource.user = nil
Resource.password = nil
Expand Down
21 changes: 21 additions & 0 deletions spec/poundpay_spec.rb
Expand Up @@ -56,6 +56,17 @@
Poundpay.api_url.should == "https://api-sandbox.poundpay.com"
Poundpay.api_version.should == "gold"
end

it "should configure callback_url" do
callback_url = "http://awesomemarketplace.com/payments/callback"
@developer = Poundpay::Developer.new
@developer.should_receive(:save!)
Poundpay::Developer.should_receive(:me).and_return(@developer)
Poundpay.configure("DV0383d447360511e0bbac00264a09ff3c", "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a") do |c|
c.callback_url = callback_url
end
@developer.callback_url.should == callback_url
end
end

describe ".configure_from_hash" do
Expand Down Expand Up @@ -104,6 +115,16 @@
it "should not accept an invalid configuration" do
expect { Poundpay.configure_from_hash @config["invalid"] }.to raise_error(ArgumentError)
end

it "should configure callback_url" do
config = @config["production"]
config["callback_url"] = "http://awesomemarketplace.com/payments/callback"
@developer = Poundpay::Developer.new
@developer.should_receive(:save!)
Poundpay::Developer.should_receive(:me).and_return(@developer)
Poundpay.configure_from_hash config
@developer.callback_url.should == config["callback_url"]
end
end

describe ".clear_config!" do
Expand Down

0 comments on commit 3a80936

Please sign in to comment.