poundpay 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -1
- data/examples/marketplace/application.rb +3 -6
- data/lib/poundpay/elements.rb +17 -17
- data/lib/poundpay/rails.rb +10 -4
- data/lib/poundpay/resource.rb +17 -13
- data/lib/poundpay/version.rb +1 -1
- data/poundpay.gemspec +2 -2
- data/spec/fixtures/payments.rb +10 -10
- data/spec/fixtures/poundpay.yml +2 -2
- data/spec/fixtures/poundpay.yml.erb +5 -0
- data/spec/poundpay/elements_spec.rb +28 -20
- data/spec/poundpay/rails_spec.rb +28 -31
- metadata +72 -41
data/Rakefile
CHANGED
@@ -71,7 +71,7 @@ class Payment < SimpleController
|
|
71
71
|
|
72
72
|
def authorize request
|
73
73
|
if request.POST['sid'].kind_of?(Array)
|
74
|
-
payments = Poundpay::Payment.batch_update(:sid => request.POST['sid'], :
|
74
|
+
payments = Poundpay::Payment.batch_update(:sid => request.POST['sid'], :state => 'authorized')
|
75
75
|
payments = payments.collect! {|p| p.schema }
|
76
76
|
return PP.pp(payments, ''), "text/html"
|
77
77
|
else
|
@@ -85,26 +85,23 @@ class Payment < SimpleController
|
|
85
85
|
def release request
|
86
86
|
payment = Poundpay::Payment.find(request.POST['sid'])
|
87
87
|
payment.release
|
88
|
-
payment.save
|
89
88
|
return PP.pp(payment.schema, ''), "text/html"
|
90
89
|
end
|
91
90
|
|
92
91
|
def cancel request
|
93
92
|
payment = Poundpay::Payment.find(request.POST['sid'])
|
94
93
|
payment.cancel
|
95
|
-
payment.save
|
96
94
|
return PP.pp(payment.schema, ''), "text/html"
|
97
95
|
end
|
98
96
|
|
99
97
|
def escrow request
|
100
98
|
if request.POST['sid'].kind_of?(Array)
|
101
|
-
payments = Poundpay::Payment.batch_update(:sid => request.POST['sid'], :
|
99
|
+
payments = Poundpay::Payment.batch_update(:sid => request.POST['sid'], :state => 'escrowed')
|
102
100
|
payments = payments.collect! {|p| p.schema }
|
103
101
|
return PP.pp(payments, ''), "text/html"
|
104
102
|
else
|
105
103
|
payment = Poundpay::Payment.find(request.POST['sid'])
|
106
104
|
payment.escrow
|
107
|
-
payment.save
|
108
105
|
return PP.pp(payment.schema, ''), "text/html"
|
109
106
|
end
|
110
107
|
end
|
@@ -181,4 +178,4 @@ class ChargePermission < SimpleController
|
|
181
178
|
return PP.pp(charge_permission.schema, ''), 'text/plain'
|
182
179
|
end
|
183
180
|
|
184
|
-
end
|
181
|
+
end
|
data/lib/poundpay/elements.rb
CHANGED
@@ -78,40 +78,40 @@ module Poundpay
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def authorize
|
81
|
-
unless
|
82
|
-
raise PaymentAuthorizeException.new "Payment
|
81
|
+
unless state == 'CREATED'
|
82
|
+
raise PaymentAuthorizeException.new "Payment state is #{state}. Only CREATED payments may be AUTHORIZED."
|
83
83
|
end
|
84
|
-
attributes['
|
84
|
+
attributes['state'] = 'AUTHORIZED'
|
85
85
|
save
|
86
86
|
end
|
87
87
|
|
88
88
|
def escrow
|
89
|
-
unless
|
90
|
-
raise PaymentEscrowException.new "Payment
|
89
|
+
unless state == 'AUTHORIZED'
|
90
|
+
raise PaymentEscrowException.new "Payment state is #{state}. Only AUTHORIZED payments may be ESCROWED."
|
91
91
|
end
|
92
|
-
attributes['
|
92
|
+
attributes['state'] = 'ESCROWED'
|
93
93
|
save
|
94
94
|
end
|
95
95
|
|
96
96
|
def release
|
97
|
-
|
98
|
-
unless
|
99
|
-
raise PaymentReleaseException.new "Payment
|
97
|
+
states = ['ESCROWED']
|
98
|
+
unless states.include?(state)
|
99
|
+
raise PaymentReleaseException.new "Payment state is #{state}. Only ESCROWED payments may be RELEASED."
|
100
100
|
end
|
101
|
-
# Tried setting
|
102
|
-
# Setting the
|
103
|
-
attributes['
|
101
|
+
# Tried setting state with state=, but save still had state == 'ESCROWED'.
|
102
|
+
# Setting the state through the attributes, however, does work.
|
103
|
+
attributes['state'] = 'RELEASED'
|
104
104
|
save
|
105
105
|
end
|
106
106
|
|
107
107
|
def cancel
|
108
|
-
|
109
|
-
unless
|
110
|
-
raise PaymentCancelException.new "Payment
|
111
|
-
"#{
|
108
|
+
states = ['CREATED', 'AUTHORIZED', 'ESCROWED']
|
109
|
+
unless states.include?(state)
|
110
|
+
raise PaymentCancelException.new "Payment state is #{state}. Only payments with states " \
|
111
|
+
"#{states.join(', ')} may be canceled"
|
112
112
|
end
|
113
113
|
|
114
|
-
attributes['
|
114
|
+
attributes['state'] = 'CANCELED'
|
115
115
|
save
|
116
116
|
end
|
117
117
|
end
|
data/lib/poundpay/rails.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
if defined? Rails
|
2
|
+
require 'erb'
|
3
|
+
|
2
4
|
module Poundpay
|
3
5
|
def self.configure_from_yaml(path)
|
4
|
-
pathname =
|
5
|
-
raise ArgumentError
|
6
|
-
|
6
|
+
pathname = Rails.root.join(path)
|
7
|
+
raise ArgumentError, "File does not exist: #{pathname}" unless pathname.exist?
|
8
|
+
|
9
|
+
config = pathname.read
|
10
|
+
config = ERB.new(config).result if pathname.extname == '.erb'
|
11
|
+
config = YAML.load(config)[Rails.env]
|
12
|
+
|
7
13
|
Poundpay.configure_from_hash(config)
|
8
14
|
end
|
9
15
|
end
|
10
|
-
end
|
16
|
+
end
|
data/lib/poundpay/resource.rb
CHANGED
@@ -7,7 +7,11 @@ module Poundpay
|
|
7
7
|
self.format = Formats::UrlencodedJsonFormat
|
8
8
|
|
9
9
|
class << self
|
10
|
-
|
10
|
+
attr_writer :primary_key
|
11
|
+
|
12
|
+
def primary_key
|
13
|
+
@primary_key ||= 'sid'
|
14
|
+
end
|
11
15
|
|
12
16
|
# Modified default to not use an extension
|
13
17
|
def element_path(id, prefix_options = {}, query_options = nil)
|
@@ -41,9 +45,9 @@ module Poundpay
|
|
41
45
|
end
|
42
46
|
|
43
47
|
protected
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
def remove_extension(path)
|
49
|
+
path.sub /(\.#{format.extension})/, ""
|
50
|
+
end
|
47
51
|
end
|
48
52
|
|
49
53
|
# Poundpay accepts urlencoded form parameters
|
@@ -57,14 +61,14 @@ module Poundpay
|
|
57
61
|
end
|
58
62
|
|
59
63
|
protected
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
}.join("&")
|
64
|
+
def self.urlencode(params)
|
65
|
+
params.to_a.collect! { |k, v|
|
66
|
+
if v.kind_of?(Array)
|
67
|
+
v.collect! { |x| "#{k}=#{CGI.escape(x.to_s)}" }.join("&")
|
68
|
+
else
|
69
|
+
"#{k}=#{CGI.escape(v.to_s)}"
|
68
70
|
end
|
71
|
+
}.join("&")
|
72
|
+
end
|
69
73
|
end
|
70
|
-
end
|
74
|
+
end
|
data/lib/poundpay/version.rb
CHANGED
data/poundpay.gemspec
CHANGED
@@ -14,9 +14,9 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.rubyforge_project = "poundpay"
|
16
16
|
|
17
|
-
s.add_dependency("activeresource", "~> 3.
|
17
|
+
s.add_dependency("activeresource", "~> 3.1")
|
18
18
|
|
19
|
-
s.add_development_dependency("rspec", "
|
19
|
+
s.add_development_dependency("rspec", "~> 2.0")
|
20
20
|
s.add_development_dependency("wirble")
|
21
21
|
|
22
22
|
s.files = `git ls-files`.split("\n")
|
data/spec/fixtures/payments.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Poundpay
|
2
2
|
module PaymentFixture
|
3
|
-
def
|
3
|
+
def created_payment_attributes
|
4
4
|
{
|
5
5
|
"amount" => 20000,
|
6
6
|
"payer_fee_amount" => 0,
|
@@ -9,7 +9,7 @@ module Poundpay
|
|
9
9
|
"recipient_email_address" => "david@example.com",
|
10
10
|
"description" => "Beats by Dr. Dre",
|
11
11
|
"sid" => "PY1d82752a361211e0bce31231400042c7",
|
12
|
-
"
|
12
|
+
"state" => "CREATED",
|
13
13
|
"amount_to_credit_developer" => 550,
|
14
14
|
"updated_at" => "2011-02-11T19:07:05.332356Z",
|
15
15
|
"recipient_sid" => nil,
|
@@ -23,26 +23,26 @@ module Poundpay
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def authorized_payment_attributes
|
26
|
-
@attributes =
|
27
|
-
@attributes["
|
26
|
+
@attributes = created_payment_attributes
|
27
|
+
@attributes["state"] = "AUTHORIZED"
|
28
28
|
@attributes
|
29
29
|
end
|
30
30
|
|
31
31
|
def escrowed_payment_attributes
|
32
|
-
@attributes =
|
33
|
-
@attributes["
|
32
|
+
@attributes = created_payment_attributes
|
33
|
+
@attributes["state"] = "ESCROWED"
|
34
34
|
@attributes
|
35
35
|
end
|
36
36
|
|
37
37
|
def released_payment_attributes
|
38
|
-
@attributes =
|
39
|
-
@attributes["
|
38
|
+
@attributes = created_payment_attributes
|
39
|
+
@attributes["state"] = "RELEASED"
|
40
40
|
@attributes
|
41
41
|
end
|
42
42
|
|
43
43
|
def canceled_payment_attributes
|
44
|
-
@attributes =
|
45
|
-
@attributes["
|
44
|
+
@attributes = created_payment_attributes
|
45
|
+
@attributes["state"] = "CANCELED"
|
46
46
|
@attributes
|
47
47
|
end
|
48
48
|
end
|
data/spec/fixtures/poundpay.yml
CHANGED
@@ -68,24 +68,24 @@ describe Payment do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
describe "#authorize" do
|
71
|
-
it "should not be able to authorize a non
|
72
|
-
@
|
73
|
-
expect {@
|
71
|
+
it "should not be able to authorize a non CREATED payment" do
|
72
|
+
@non_created_payment = Payment.new authorized_payment_attributes
|
73
|
+
expect {@non_created_payment.authorize}.to raise_error(PaymentAuthorizeException)
|
74
74
|
end
|
75
75
|
|
76
|
-
it "should authorize a
|
77
|
-
@
|
78
|
-
@
|
76
|
+
it "should authorize a CREATED payment" do
|
77
|
+
@created_payment = Payment.new created_payment_attributes
|
78
|
+
@created_payment.should_receive(:save).and_return(Payment.new authorized_payment_attributes)
|
79
79
|
|
80
|
-
@
|
81
|
-
@
|
80
|
+
@created_payment.authorize
|
81
|
+
@created_payment.state.should == 'AUTHORIZED'
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
85
|
describe "#escrow" do
|
86
|
-
it "should not be able to escrow a
|
87
|
-
@
|
88
|
-
expect {@
|
86
|
+
it "should not be able to escrow a CREATED payment" do
|
87
|
+
@created_payment = Payment.new created_payment_attributes
|
88
|
+
expect {@created_payment.escrow}.to raise_error(PaymentEscrowException)
|
89
89
|
end
|
90
90
|
|
91
91
|
it "should escrow an AUTHORIZED payment" do
|
@@ -93,14 +93,14 @@ describe Payment do
|
|
93
93
|
@authorized_payment.should_receive(:save).and_return(Payment.new escrowed_payment_attributes)
|
94
94
|
|
95
95
|
@authorized_payment.escrow
|
96
|
-
@authorized_payment.
|
96
|
+
@authorized_payment.state.should == 'ESCROWED'
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
100
|
describe "#release" do
|
101
|
-
it "should not be able to release a
|
102
|
-
@
|
103
|
-
expect {@
|
101
|
+
it "should not be able to release a CREATED payment" do
|
102
|
+
@created_payment = Payment.new created_payment_attributes
|
103
|
+
expect {@created_payment.release}.to raise_error(PaymentReleaseException)
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should release an ESCROWED payment" do
|
@@ -108,14 +108,14 @@ describe Payment do
|
|
108
108
|
@escrowed_payment.should_receive(:save).and_return(Payment.new released_payment_attributes)
|
109
109
|
|
110
110
|
@escrowed_payment.release
|
111
|
-
@escrowed_payment.
|
111
|
+
@escrowed_payment.state.should == 'RELEASED'
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
115
|
describe "#cancel" do
|
116
|
-
it "should not be able to cancel a
|
117
|
-
@
|
118
|
-
expect {@
|
116
|
+
it "should not be able to cancel a RELEASED payment" do
|
117
|
+
@released_payment = Payment.new released_payment_attributes
|
118
|
+
expect {@released_payment.cancel}.to raise_error(PaymentCancelException)
|
119
119
|
end
|
120
120
|
|
121
121
|
it "should cancel an ESCROWED payment" do
|
@@ -123,7 +123,15 @@ describe Payment do
|
|
123
123
|
@escrowed_payment.should_receive(:save).and_return(Payment.new canceled_payment_attributes)
|
124
124
|
|
125
125
|
@escrowed_payment.cancel
|
126
|
-
@escrowed_payment.
|
126
|
+
@escrowed_payment.state.should == 'CANCELED'
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should cancel a CREATED payment" do
|
130
|
+
@created_payment = Payment.new created_payment_attributes
|
131
|
+
@created_payment.should_receive(:save).and_return(Payment.new canceled_payment_attributes)
|
132
|
+
|
133
|
+
@created_payment.cancel
|
134
|
+
@created_payment.state.should == 'CANCELED'
|
127
135
|
end
|
128
136
|
end
|
129
137
|
end
|
data/spec/poundpay/rails_spec.rb
CHANGED
@@ -2,48 +2,45 @@ require 'poundpay'
|
|
2
2
|
|
3
3
|
describe Poundpay do
|
4
4
|
module Rails
|
5
|
+
def self.root
|
6
|
+
Pathname(File.expand_path("../../fixtures", __FILE__))
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.env
|
10
|
+
"development"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
load File.expand_path("../../../lib/poundpay/rails.rb", __FILE__)
|
15
|
+
|
16
|
+
before do
|
17
|
+
Poundpay.should_not be_configured
|
5
18
|
end
|
6
19
|
|
7
|
-
after
|
20
|
+
after do
|
8
21
|
Poundpay.clear_config!
|
9
22
|
end
|
10
23
|
|
11
24
|
it "should automatically load config if exists" do
|
12
|
-
|
25
|
+
Poundpay.configure_from_yaml "poundpay.yml"
|
13
26
|
|
14
|
-
|
15
|
-
def self.root
|
16
|
-
Pathname(File.expand_path("../../fixtures", __FILE__))
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.env
|
20
|
-
"development"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
Poundpay.configured?.should be_false
|
25
|
-
Poundpay.configure_from_yaml "config/poundpay.yml"
|
26
|
-
Poundpay.configured?.should be_true
|
27
|
+
Poundpay.should be_configured
|
27
28
|
Poundpay::Resource.password.should == "development_auth_token"
|
28
29
|
end
|
29
30
|
|
30
|
-
it "
|
31
|
-
|
31
|
+
it "configures using ERB files to allow ENV variables" do
|
32
|
+
Poundpay.configure_from_yaml "poundpay.yml.erb"
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
34
|
+
Poundpay.should be_configured
|
35
|
+
Poundpay::Resource.password.should == "erb_development_auth_token"
|
36
|
+
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
it "should raise argument error and configure nothing if config does not exist" do
|
39
|
+
expect {
|
40
|
+
Poundpay.configure_from_yaml "wrong_path"
|
41
|
+
}.to raise_error(ArgumentError, /wrong_path/)
|
42
42
|
|
43
|
-
Poundpay.
|
44
|
-
|
45
|
-
Poundpay.configured?.should be_false
|
46
|
-
Poundpay::Resource.password.should == nil
|
43
|
+
Poundpay.should_not be_configured
|
44
|
+
Poundpay::Resource.password.should_not be
|
47
45
|
end
|
48
|
-
|
49
|
-
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,55 +1,75 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: poundpay
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Matin Tamizi
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2012-03-16 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: activeresource
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
25
|
+
requirements:
|
19
26
|
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 5
|
29
|
+
segments:
|
30
|
+
- 3
|
31
|
+
- 1
|
32
|
+
version: "3.1"
|
22
33
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
26
36
|
name: rspec
|
27
|
-
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 2
|
46
|
+
- 0
|
47
|
+
version: "2.0"
|
33
48
|
type: :development
|
34
|
-
|
35
|
-
|
36
|
-
- !ruby/object:Gem::Dependency
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
37
51
|
name: wirble
|
38
|
-
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
54
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
44
62
|
type: :development
|
45
|
-
|
46
|
-
version_requirements: *24259020
|
63
|
+
version_requirements: *id003
|
47
64
|
description: Payments platform for marketplaces
|
48
65
|
email: devsupport@poundpay.com
|
49
66
|
executables: []
|
67
|
+
|
50
68
|
extensions: []
|
69
|
+
|
51
70
|
extra_rdoc_files: []
|
52
|
-
|
71
|
+
|
72
|
+
files:
|
53
73
|
- .autotest
|
54
74
|
- .gitignore
|
55
75
|
- .gitmodules
|
@@ -79,6 +99,7 @@ files:
|
|
79
99
|
- spec/fixtures/developers.rb
|
80
100
|
- spec/fixtures/payments.rb
|
81
101
|
- spec/fixtures/poundpay.yml
|
102
|
+
- spec/fixtures/poundpay.yml.erb
|
82
103
|
- spec/poundpay/callback_spec.rb
|
83
104
|
- spec/poundpay/elements_spec.rb
|
84
105
|
- spec/poundpay/exceptions_spec.rb
|
@@ -88,26 +109,36 @@ files:
|
|
88
109
|
- spec/poundpay_spec.rb
|
89
110
|
homepage: http://github.com/poundpay/poundpay-ruby
|
90
111
|
licenses: []
|
112
|
+
|
91
113
|
post_install_message:
|
92
114
|
rdoc_options: []
|
93
|
-
|
115
|
+
|
116
|
+
require_paths:
|
94
117
|
- lib
|
95
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
119
|
none: false
|
97
|
-
requirements:
|
98
|
-
- -
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
|
101
|
-
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 3
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
version: "0"
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
128
|
none: false
|
103
|
-
requirements:
|
104
|
-
- -
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
hash: 3
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
version: "0"
|
107
136
|
requirements: []
|
137
|
+
|
108
138
|
rubyforge_project: poundpay
|
109
139
|
rubygems_version: 1.8.10
|
110
140
|
signing_key:
|
111
141
|
specification_version: 3
|
112
142
|
summary: Poundpay Ruby library
|
113
143
|
test_files: []
|
144
|
+
|