poundpay 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,25 +1,29 @@
1
1
  == Poundpay
2
2
 
3
- Poundpay is payments platform for marketplaces
3
+ Poundpay is a payments platform for marketplaces
4
4
 
5
5
 
6
6
  == Adding Poundpay to Rails
7
7
 
8
8
  1. Add the following to your Gemfile
9
9
 
10
- gem 'poundpay', '~> 0.1.2'
10
+ gem 'poundpay', '~> 0.2.0'
11
11
 
12
12
  2. At the command prompt, install the gem with bundler
13
13
 
14
14
  bundle install
15
15
 
16
- 3. Add your Poundpay configuration to config/initializers/poundpay.rb
16
+ 3. Add your configuration to config/poundpay.yml in your Rails project
17
17
 
18
- Poundpay.configure(
19
- "DV0383d447360511e0bbac00264a09ff3c", # developer_sid
20
- "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a", # auth_token
21
- api_url = "https://api-sandbox.poundpay.com" # Note: Leave out for production
22
- )
18
+ development:
19
+ developer_sid: DV0383d447360511e0bbac00264a09ff3c
20
+ auth_token: c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a
21
+ www_url: https://www-sandbox.poundpay.com
22
+ api_url: https://api-sandbox.poundpay.com
23
+
24
+ production:
25
+ developer_sid: DV8dd93f0f3c6411e0863f00264a09ff3c
26
+ auth_token: d8c4ea1bafd3fcac8c1062a72c22bcdb09321deb1041df257165cd6449def0de
23
27
 
24
28
  4. Protect your callback controller
25
29
 
@@ -60,13 +64,14 @@ the repeat flow when they are not prompted to reenter their credit card informat
60
64
  payment_sid: <%= @payment.sid %>,
61
65
  success: handlePaymentSuccess,
62
66
  error: handlePaymentError,
63
- cardholder_name: 'Fred Nietzsche', // note: optional
64
- phone_number: '4085551234', // note: optional
65
- server: 'https://www-sandbox.poundpay.com' // note: exclude this property when in production
67
+ cardholder_name: "Fred Nietzsche", // Optional
68
+ phone_number: "4085551234", // Optional
69
+ server: "#{Poundpay.www_url}"
66
70
  });
67
71
  </script>
68
72
 
69
73
 
70
74
  == Releasing a payment
71
75
 
76
+ payment = Payment.find(payment_sid)
72
77
  payment.release
@@ -0,0 +1,6 @@
1
+ if defined? Rails and Rails.root.join("config", "poundpay.yml").exist?
2
+ module Poundpay
3
+ @rails_config = YAML::load_file(Rails.root.join("config", "poundpay.yml"))[Rails.env]
4
+ Poundpay.configure_from_hash(@rails_config)
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Poundpay
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/poundpay.rb CHANGED
@@ -1,19 +1,81 @@
1
1
  require 'poundpay/resource'
2
2
  require 'poundpay/elements'
3
3
  require 'poundpay/callback'
4
+ require 'poundpay/rails'
5
+
4
6
 
5
7
  module Poundpay
8
+ WWW_URL = "https://www.poundpay.com"
6
9
  API_URL = "https://api.poundpay.com"
7
10
  API_VERSION = "silver"
8
11
 
9
- def self.configure(developer_sid, auth_token, api_url=API_URL, version=API_VERSION)
10
- unless developer_sid.start_with? "DV"
11
- raise ArgumentError.new "developer_sid should start with 'DV'. Make sure " \
12
- "you're using the right developer_sid"
12
+ class << self
13
+ attr_writer :api_version
14
+
15
+ def configure(developer_sid, auth_token)
16
+ if not developer_sid
17
+ raise ArgumentError.new "developer_sid is required"
18
+ end
19
+
20
+ if not auth_token
21
+ raise ArgumentError.new "auth_token is required"
22
+ end
23
+
24
+ unless developer_sid.start_with? "DV"
25
+ raise ArgumentError.new "developer_sid should start with 'DV'. Make sure " \
26
+ "you're using the right developer_sid"
27
+ end
28
+
29
+ yield self if block_given?
30
+
31
+ api_url.sub! /(\/)$/, "" # Remove trailing backslash
32
+ www_url.sub /(\/)$/, ""
33
+ Resource.site = "#{api_url}/#{api_version}/"
34
+ Resource.user = developer_sid
35
+ Resource.password = auth_token
36
+ @configured = true
37
+ end
38
+
39
+ def configure_from_hash(config)
40
+ configure(config["developer_sid"], config["auth_token"]) do |c|
41
+ c.www_url = config["www_url"] || WWW_URL
42
+ c.api_url = config["api_url"] || API_URL
43
+ c.api_version = config["api_version"] || API_VERSION
44
+ end
45
+ end
46
+
47
+ def clear_config!
48
+ @www_url = nil
49
+ @api_url = nil
50
+ @api_version = nil
51
+ Resource.site = nil
52
+ Resource.user = nil
53
+ Resource.password = nil
54
+ @configured = false
55
+ end
56
+
57
+ def configured?
58
+ @configured
59
+ end
60
+
61
+ def www_url
62
+ @www_url || WWW_URL
63
+ end
64
+
65
+ def www_url=(value)
66
+ @www_url = value.sub /(\/)$/, "" # Remove trailing backslash
67
+ end
68
+
69
+ def api_url
70
+ @api_url || API_URL
71
+ end
72
+
73
+ def api_url=(value)
74
+ @api_url = value.sub /(\/)$/, "" # Remove trailing backslash
75
+ end
76
+
77
+ def api_version
78
+ @api_version || API_VERSION
13
79
  end
14
- api_url.sub! /(\/)$/, "" # Remove trailing backslash
15
- Resource.site = "#{api_url}/#{version}/"
16
- Resource.user = developer_sid
17
- Resource.password = auth_token
18
80
  end
19
81
  end
@@ -1,6 +1,6 @@
1
1
  module Poundpay
2
2
  module PaymentFixture
3
- def created_payment_attributes
3
+ def staged_payment_attributes
4
4
  {
5
5
  "amount" => 20000,
6
6
  "payer_fee_amount" => 0,
@@ -23,47 +23,15 @@ module Poundpay
23
23
  end
24
24
 
25
25
  def escrowed_payment_attributes
26
- {
27
- "amount" => 20000,
28
- "payer_fee_amount" => 0,
29
- "payer_email_address" => "goliath@example.com",
30
- "recipient_fee_amount" => 500,
31
- "recipient_email_address" => "david@example.com",
32
- "description" => "Beats by Dr. Dre",
33
- "sid" => "PY1d82752a361211e0bce31231400042c7",
34
- "status" => "ESCROWED",
35
- "amount_to_credit_developer" => 550,
36
- "updated_at" => "2011-02-11T19:07:05.332356Z",
37
- "recipient_sid" => nil,
38
- "payer_sid" => "US552595ee364111e0b18800264a09ff3c",
39
- "developer_sid" => "DV8539761e250011e0a81d1231400042c7",
40
- "poundpay_fee_amount" => 450,
41
- "created_at" => "2011-02-11T19:07:05.332356Z",
42
- "amount_to_credit_recipient" => 19500,
43
- "amount_to_charge_payer" => 20000,
44
- }
26
+ @attributes = staged_payment_attributes
27
+ @attributes["status"] = "ESCROWED"
28
+ @attributes
45
29
  end
46
30
 
47
31
  def released_payment_attributes
48
- {
49
- "amount" => 20000,
50
- "payer_fee_amount" => 0,
51
- "payer_email_address" => "goliath@example.com",
52
- "recipient_fee_amount" => 500,
53
- "recipient_email_address" => "david@example.com",
54
- "description" => "Beats by Dr. Dre",
55
- "sid" => "PY1d82752a361211e0bce31231400042c7",
56
- "status" => "RELEASED",
57
- "amount_to_credit_developer" => 550,
58
- "updated_at" => "2011-02-11T19:07:05.332356Z",
59
- "recipient_sid" => nil,
60
- "payer_sid" => "US552595ee364111e0b18800264a09ff3c",
61
- "developer_sid" => "DV8539761e250011e0a81d1231400042c7",
62
- "poundpay_fee_amount" => 450,
63
- "created_at" => "2011-02-11T19:07:05.332356Z",
64
- "amount_to_credit_recipient" => 19500,
65
- "amount_to_charge_payer" => 20000,
66
- }
32
+ @attributes = staged_payment_attributes
33
+ @attributes["status"] = "RELEASED"
34
+ @attributes
67
35
  end
68
36
  end
69
37
  end
@@ -0,0 +1,20 @@
1
+ development:
2
+ developer_sid: DV0383d447360511e0bbac00264a09ff3c
3
+ auth_token: development_auth_token
4
+ www_url: https://www-sandbox.poundpay.com
5
+ api_url: https://api-sandbox.poundpay.com
6
+
7
+
8
+ production:
9
+ developer_sid: DV8dd93f0f3c6411e0863f00264a09ff3c
10
+ auth_token: production_auth_token
11
+
12
+
13
+ future:
14
+ developer_sid: DV8dd93f0f3c6411e0863f00264a09ff3c
15
+ auth_token: d8c4ea1bafd3fcac8c1062a72c22bcdb09321deb1041df257165cd6449def0de
16
+ api_version: gold
17
+
18
+ invalid:
19
+ developer_sid:
20
+ auth_token:
@@ -12,6 +12,10 @@ describe Poundpay do
12
12
  "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a")
13
13
  end
14
14
 
15
+ after (:all) do
16
+ Poundpay.clear_config!
17
+ end
18
+
15
19
  describe ".calculate_signature" do
16
20
  it "should calculate the correct signature using HMAC-SHA1" do
17
21
  signature = Poundpay.calculate_signature(valid_callback[:url], valid_callback[:params])
@@ -14,6 +14,10 @@ describe Developer do
14
14
  "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a")
15
15
  end
16
16
 
17
+ after (:all) do
18
+ Poundpay.clear_config!
19
+ end
20
+
17
21
  describe "#me" do
18
22
  it "should return the developer's information" do
19
23
  Developer.should_receive(:find).with(Developer.user).and_return(Developer.new developer_attributes)
@@ -31,10 +35,14 @@ describe Payment do
31
35
  "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a")
32
36
  end
33
37
 
38
+ after (:all) do
39
+ Poundpay.clear_config!
40
+ end
41
+
34
42
  describe "#release" do
35
43
  it "should not be able to release a STAGED payment" do
36
- @created_payment = Payment.new created_payment_attributes
37
- expect {@created_payment.release}.to raise_error(PaymentReleaseException)
44
+ @staged_payment = Payment.new staged_payment_attributes
45
+ expect {@staged_payment.release}.to raise_error(PaymentReleaseException)
38
46
  end
39
47
 
40
48
  it "should release an ESCROWED payment" do
@@ -0,0 +1,46 @@
1
+ require 'poundpay'
2
+
3
+ describe Poundpay do
4
+ after (:each) do
5
+ Poundpay.clear_config!
6
+ end
7
+
8
+ it "should automatically load config if exists" do
9
+ module Rails
10
+ class << self
11
+ def root
12
+ Pathname(File.expand_path("../../fixtures", __FILE__))
13
+ end
14
+
15
+ def env
16
+ "development"
17
+ end
18
+ end
19
+ end
20
+
21
+ Poundpay.configured?.should be_false
22
+ load File.expand_path("../../../lib/poundpay/rails.rb", __FILE__)
23
+ Poundpay.configured?.should be_true
24
+ Poundpay::Resource.password.should == "development_auth_token"
25
+ end
26
+
27
+ it "should not do anything if config does not exist" do
28
+ module Rails
29
+ class << self
30
+ def root
31
+ Pathname(File.expand_path("wrong_directory", __FILE__))
32
+ end
33
+
34
+ def env
35
+ "development"
36
+ end
37
+ end
38
+ end
39
+
40
+ Poundpay.configured?.should be_false
41
+ load File.expand_path("../../../lib/poundpay/rails.rb", __FILE__)
42
+ Poundpay.configured?.should be_false
43
+ Poundpay::Resource.password.should == nil
44
+ end
45
+
46
+ end
@@ -1,39 +1,125 @@
1
1
  require 'poundpay'
2
2
 
3
- describe Poundpay, ".configure" do
4
- it "should require developer_sid to start with 'DV'" do
5
- expect {
6
- # Pass developer_sid and auth_token in wrong order
7
- Poundpay.configure(
8
- "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a",
9
- "DV0383d447360511e0bbac00264a09ff3c")
10
- }.to raise_error(ArgumentError, /DV/)
11
- end
3
+ describe Poundpay do
4
+ describe ".configure" do
5
+ after (:each) do
6
+ Poundpay.clear_config!
7
+ end
8
+
9
+ it "should require developer_sid and auth_token" do
10
+ expect { Poundpay.configure(nil, nil) }.to raise_error(ArgumentError, /required/)
11
+ expect { Poundpay.configure("DV0383d447360511e0bbac00264a09ff3c", nil) }.to raise_error(ArgumentError, /required/)
12
+ expect { Poundpay.configure(nil, "auth_token") }.to raise_error(ArgumentError, /required/)
13
+ end
14
+
15
+ it "should require developer_sid to start with 'DV'" do
16
+ expect {
17
+ # Pass developer_sid and auth_token in wrong order
18
+ Poundpay.configure(
19
+ "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a",
20
+ "DV0383d447360511e0bbac00264a09ff3c")
21
+ }.to raise_error(ArgumentError, /DV/)
22
+ end
12
23
 
13
- it "should be configured with default api_url and version" do
14
- developer_sid = "DV0383d447360511e0bbac00264a09ff3c"
15
- auth_token = "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a"
16
- Poundpay.configure(developer_sid, auth_token)
17
- Poundpay::Resource.user.should == developer_sid
18
- Poundpay::Resource.password.should == auth_token
19
- Poundpay::Resource.site.to_s.should == "https://api.poundpay.com/silver/"
24
+ it "should be configured with default api_url and api_version" do
25
+ developer_sid = "DV0383d447360511e0bbac00264a09ff3c"
26
+ auth_token = "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a"
27
+ Poundpay.configure(developer_sid, auth_token)
28
+ Poundpay::Resource.user.should == developer_sid
29
+ Poundpay::Resource.password.should == auth_token
30
+ Poundpay::Resource.site.to_s.should == "https://api.poundpay.com/silver/"
31
+ Poundpay.www_url.should == "https://www.poundpay.com"
32
+ Poundpay.api_url.should == "https://api.poundpay.com"
33
+ Poundpay.api_version.should == "silver"
34
+ end
35
+
36
+ it "should accept optional api_url and api_version via block" do
37
+ Poundpay.configure("DV0383d447360511e0bbac00264a09ff3c", "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a") do |c|
38
+ c.www_url = "https://www-sandbox.poundpay.com"
39
+ c.api_url = "https://api-sandbox.poundpay.com"
40
+ c.api_version = "gold"
41
+ end
42
+ Poundpay::Resource.site.to_s.should == "https://api-sandbox.poundpay.com/gold/"
43
+ Poundpay.www_url.should == "https://www-sandbox.poundpay.com"
44
+ Poundpay.api_url.should == "https://api-sandbox.poundpay.com"
45
+ Poundpay.api_version.should == "gold"
46
+ end
47
+
48
+ it "should allow api_url to have a trailing backslash" do
49
+ Poundpay.configure("DV0383d447360511e0bbac00264a09ff3c", "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a") do |c|
50
+ c.www_url = "https://www-sandbox.poundpay.com/"
51
+ c.api_url = "https://api-sandbox.poundpay.com/"
52
+ c.api_version = "gold"
53
+ end
54
+ Poundpay::Resource.site.to_s.should == "https://api-sandbox.poundpay.com/gold/"
55
+ Poundpay.www_url.should == "https://www-sandbox.poundpay.com"
56
+ Poundpay.api_url.should == "https://api-sandbox.poundpay.com"
57
+ Poundpay.api_version.should == "gold"
58
+ end
20
59
  end
21
60
 
22
- it "should accept optional api_url and version" do
23
- Poundpay.configure(
24
- "DV0383d447360511e0bbac00264a09ff3c",
25
- "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a",
26
- api_url="https://api-sandbox.poundpay.com",
27
- version="gold")
28
- Poundpay::Resource.site.to_s.should == "https://api-sandbox.poundpay.com/gold/"
61
+ describe ".configure_from_hash" do
62
+ before (:all) do
63
+ path = File.expand_path("../fixtures/poundpay.yml", __FILE__)
64
+ @config = YAML::load_file(path)
65
+ end
66
+
67
+ after (:each) do
68
+ Poundpay.clear_config!
69
+ end
70
+
71
+ it "should accept valid development configuration" do
72
+ config = @config["development"]
73
+ Poundpay.configure_from_hash config
74
+ Poundpay::Resource.user.should == config["developer_sid"]
75
+ Poundpay::Resource.password.should == config["auth_token"]
76
+ Poundpay::Resource.site.to_s.should == "https://api-sandbox.poundpay.com/silver/"
77
+ Poundpay.www_url.should == "https://www-sandbox.poundpay.com"
78
+ Poundpay.api_url.should == "https://api-sandbox.poundpay.com"
79
+ Poundpay.api_version.should == "silver"
80
+ end
81
+
82
+ it "should accept valid production configuration" do
83
+ config = @config["production"]
84
+ Poundpay.configure_from_hash config
85
+ Poundpay::Resource.user.should == config["developer_sid"]
86
+ Poundpay::Resource.password.should == config["auth_token"]
87
+ Poundpay::Resource.site.to_s.should == "https://api.poundpay.com/silver/"
88
+ Poundpay.www_url.should == "https://www.poundpay.com"
89
+ Poundpay.api_url.should == "https://api.poundpay.com"
90
+ Poundpay.api_version.should == "silver"
91
+ end
92
+
93
+ it "should accept valid future configuration" do
94
+ config = @config["future"]
95
+ Poundpay.configure_from_hash config
96
+ Poundpay::Resource.user.should == config["developer_sid"]
97
+ Poundpay::Resource.password.should == config["auth_token"]
98
+ Poundpay::Resource.site.to_s.should == "https://api.poundpay.com/gold/"
99
+ Poundpay.www_url.should == "https://www.poundpay.com"
100
+ Poundpay.api_url.should == "https://api.poundpay.com"
101
+ Poundpay.api_version.should == "gold"
102
+ end
103
+
104
+ it "should not accept an invalid configuration" do
105
+ expect { Poundpay.configure_from_hash @config["invalid"] }.to raise_error(ArgumentError)
106
+ end
29
107
  end
30
108
 
31
- it "should allow api_url to have a trailing backslash" do
32
- Poundpay.configure(
33
- "DV0383d447360511e0bbac00264a09ff3c",
34
- "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a",
35
- api_url="https://api-sandbox.poundpay.com/",
36
- version="gold")
37
- Poundpay::Resource.site.to_s.should == "https://api-sandbox.poundpay.com/gold/"
109
+ describe ".clear_config!" do
110
+ it "should clear all Poundpay configs" do
111
+ Poundpay.configured?.should be_false
112
+ Poundpay.configure("DV0383d447360511e0bbac00264a09ff3c", "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a")
113
+ Poundpay.configured?.should be_true
114
+
115
+ Poundpay.clear_config!
116
+ Poundpay.configured?.should be_false
117
+ Poundpay.www_url.should == Poundpay::WWW_URL
118
+ Poundpay.api_url.should == Poundpay::API_URL
119
+ Poundpay.api_version.should == Poundpay::API_VERSION
120
+ Poundpay::Resource.site.should == nil
121
+ Poundpay::Resource.user.should == nil
122
+ Poundpay::Resource.password.should == nil
123
+ end
38
124
  end
39
125
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 3
9
- version: 0.1.3
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matin Tamizi
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-18 00:00:00 -08:00
17
+ date: 2011-02-19 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -85,15 +85,18 @@ files:
85
85
  - lib/poundpay/callback.rb
86
86
  - lib/poundpay/elements.rb
87
87
  - lib/poundpay/formats.rb
88
+ - lib/poundpay/rails.rb
88
89
  - lib/poundpay/resource.rb
89
90
  - lib/poundpay/version.rb
90
91
  - poundpay.gemspec
91
92
  - spec/fixtures/callback.rb
92
93
  - spec/fixtures/developers.rb
93
94
  - spec/fixtures/payments.rb
95
+ - spec/fixtures/poundpay.yml
94
96
  - spec/poundpay/callback_spec.rb
95
97
  - spec/poundpay/elements_spec.rb
96
98
  - spec/poundpay/formats_spec.rb
99
+ - spec/poundpay/rails_spec.rb
97
100
  - spec/poundpay/resource_spec.rb
98
101
  - spec/poundpay_spec.rb
99
102
  has_rdoc: true
@@ -132,8 +135,10 @@ test_files:
132
135
  - spec/fixtures/callback.rb
133
136
  - spec/fixtures/developers.rb
134
137
  - spec/fixtures/payments.rb
138
+ - spec/fixtures/poundpay.yml
135
139
  - spec/poundpay/callback_spec.rb
136
140
  - spec/poundpay/elements_spec.rb
137
141
  - spec/poundpay/formats_spec.rb
142
+ - spec/poundpay/rails_spec.rb
138
143
  - spec/poundpay/resource_spec.rb
139
144
  - spec/poundpay_spec.rb