poundpay 0.2.8 → 0.2.9
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 +9 -4
- data/lib/poundpay/elements.rb +26 -5
- data/lib/poundpay/version.rb +1 -1
- data/poundpay.gemspec +1 -1
- data/spec/fixtures/payments.rb +7 -1
- data/spec/poundpay/elements_spec.rb +47 -2
- metadata +6 -5
data/README.rdoc
CHANGED
@@ -66,7 +66,11 @@ Poundpay is a payments platform for marketplaces
|
|
66
66
|
payment_sid: "<%= @payment.sid %>",
|
67
67
|
success: handlePaymentSuccess,
|
68
68
|
error: handlePaymentError,
|
69
|
-
|
69
|
+
name: "Fred Nietzsche", // Optional
|
70
|
+
address_street: "330 Townsend St", // Optional
|
71
|
+
address_city: "San Francisco", // Optional
|
72
|
+
address_state: "California", // Optional
|
73
|
+
address_zip: "94107", // Optional
|
70
74
|
server: "<%= Poundpay.www_url %>"
|
71
75
|
});
|
72
76
|
</script>
|
@@ -75,6 +79,7 @@ Poundpay is a payments platform for marketplaces
|
|
75
79
|
== Payment methods
|
76
80
|
|
77
81
|
payment = Poundpay::Payment.find(payment_sid)
|
78
|
-
payment.escrow
|
79
|
-
payment.
|
80
|
-
payment.
|
82
|
+
payment.escrow # AUTHORIZED -> ESCROWED. Credit card is charged
|
83
|
+
payment.partially_release(amount) # ESCROWED or PARTIALLY_RELEASED -> PARTIALLY_RELEASED or PARTIALLY_RELEASED. Recipieint recieves a portion of funds.
|
84
|
+
payment.release # ESCROWED or PARTIALLY_RELEASED -> RELEASED. Recipient receives money
|
85
|
+
payment.cancel # ESCROWED or PARTIALLY_RELEASED -> CANCELED. Payer receives refund
|
data/lib/poundpay/elements.rb
CHANGED
@@ -8,6 +8,9 @@ end
|
|
8
8
|
class PaymentEscrowException < PaymentException
|
9
9
|
end
|
10
10
|
|
11
|
+
class PaymentPartiallyReleaseException < PaymentException
|
12
|
+
end
|
13
|
+
|
11
14
|
class PaymentReleaseException < PaymentException
|
12
15
|
end
|
13
16
|
|
@@ -40,6 +43,9 @@ module Poundpay
|
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
46
|
+
class User < Resource
|
47
|
+
end
|
48
|
+
|
43
49
|
class Payment < Resource
|
44
50
|
def escrow
|
45
51
|
unless status == 'AUTHORIZED'
|
@@ -49,9 +55,23 @@ module Poundpay
|
|
49
55
|
save
|
50
56
|
end
|
51
57
|
|
58
|
+
def partially_release(amount_to_release)
|
59
|
+
statuses = ['ESCROWED', 'PARTIALLY_RELEASED']
|
60
|
+
unless statuses.include?(status)
|
61
|
+
raise PaymentPartiallyReleaseException.new "Payment status is #{status}. Only ESCROWED or PARTIALLY_RELEASED payments may be released"
|
62
|
+
end
|
63
|
+
# Tried setting status with status=, but save still had status == 'ESCROWED'.
|
64
|
+
# Setting the status through the attributes, however, does work.
|
65
|
+
attributes['status'] = 'PARTIALLY_RELEASED'
|
66
|
+
attributes['amount_to_release'] = amount_to_release
|
67
|
+
save
|
68
|
+
attributes.delete('amount_to_release')
|
69
|
+
end
|
70
|
+
|
52
71
|
def release
|
53
|
-
|
54
|
-
|
72
|
+
statuses = ['ESCROWED', 'PARTIALLY_RELEASED']
|
73
|
+
unless statuses.include?(status)
|
74
|
+
raise PaymentReleaseException.new "Payment status is #{status}. Only ESCROWED or PARTIALLY_RELASED payments may be released"
|
55
75
|
end
|
56
76
|
# Tried setting status with status=, but save still had status == 'ESCROWED'.
|
57
77
|
# Setting the status through the attributes, however, does work.
|
@@ -60,12 +80,13 @@ module Poundpay
|
|
60
80
|
end
|
61
81
|
|
62
82
|
def cancel
|
63
|
-
|
64
|
-
|
83
|
+
statuses = ['ESCROWED', 'PARTIALLY_RELEASED']
|
84
|
+
unless statuses.include?(status)
|
85
|
+
raise PaymentCancelException.new "Payment status is #{status}. Only ESCROWED or PARTIALLY_RELEASED payments may be canceled"
|
65
86
|
end
|
66
87
|
|
67
88
|
attributes['status'] = 'CANCELED'
|
68
89
|
save
|
69
90
|
end
|
70
91
|
end
|
71
|
-
end
|
92
|
+
end
|
data/lib/poundpay/version.rb
CHANGED
data/poundpay.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.rubyforge_project = "poundpay"
|
16
16
|
|
17
|
-
s.add_dependency("activeresource", "
|
17
|
+
s.add_dependency("activeresource", "~> 3.0.0")
|
18
18
|
|
19
19
|
s.add_development_dependency("rspec", ">= 2.0")
|
20
20
|
s.add_development_dependency("wirble")
|
data/spec/fixtures/payments.rb
CHANGED
@@ -34,6 +34,12 @@ module Poundpay
|
|
34
34
|
@attributes
|
35
35
|
end
|
36
36
|
|
37
|
+
def partially_released_payment_attributes
|
38
|
+
@attributes = staged_payment_attributes
|
39
|
+
@attributes["status"] = "PARTIALLY_RELEASED"
|
40
|
+
@attributes
|
41
|
+
end
|
42
|
+
|
37
43
|
def released_payment_attributes
|
38
44
|
@attributes = staged_payment_attributes
|
39
45
|
@attributes["status"] = "RELEASED"
|
@@ -46,4 +52,4 @@ module Poundpay
|
|
46
52
|
@attributes
|
47
53
|
end
|
48
54
|
end
|
49
|
-
end
|
55
|
+
end
|
@@ -94,20 +94,65 @@ describe Payment do
|
|
94
94
|
@escrowed_payment.release
|
95
95
|
@escrowed_payment.status.should == 'RELEASED'
|
96
96
|
end
|
97
|
+
|
98
|
+
it "should release a PARTIALLY_RELEASED payment" do
|
99
|
+
@escrowed_payment = Payment.new partially_released_payment_attributes
|
100
|
+
@escrowed_payment.should_receive(:save).and_return(Payment.new partially_released_payment_attributes)
|
101
|
+
|
102
|
+
@escrowed_payment.release
|
103
|
+
@escrowed_payment.status.should == 'RELEASED'
|
104
|
+
end
|
97
105
|
end
|
98
106
|
|
107
|
+
describe "#partially_release" do
|
108
|
+
it "should not be able to partially release a STAGED payment" do
|
109
|
+
@staged_payment = Payment.new staged_payment_attributes
|
110
|
+
expect {@staged_payment.release}.to raise_error(PaymentReleaseException)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should partially release an ESCROWED payment" do
|
114
|
+
@escrowed_payment = Payment.new escrowed_payment_attributes
|
115
|
+
@escrowed_payment.should_receive(:save).and_return(Payment.new released_payment_attributes)
|
116
|
+
|
117
|
+
@escrowed_payment.partially_release(123)
|
118
|
+
@escrowed_payment.status.should == 'PARTIALLY_RELEASED'
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should partially release a PARTIALLY_RELEASED payment" do
|
122
|
+
@escrowed_payment = Payment.new partially_released_payment_attributes
|
123
|
+
@escrowed_payment.should_receive(:save).and_return(Payment.new partially_released_payment_attributes)
|
124
|
+
|
125
|
+
@escrowed_payment.partially_release(123)
|
126
|
+
@escrowed_payment.status.should == 'PARTIALLY_RELEASED'
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should not be able to partially release a RELEASED payment" do
|
130
|
+
@staged_payment = Payment.new staged_payment_attributes
|
131
|
+
expect {@staged_payment.partially_release(123)}.to raise_error(PaymentPartiallyReleaseException)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
|
99
136
|
describe "#cancel" do
|
100
137
|
it "should not be able to cancel a STAGED payment" do
|
101
138
|
@staged_payment = Payment.new staged_payment_attributes
|
102
139
|
expect {@staged_payment.cancel}.to raise_error(PaymentCancelException)
|
103
140
|
end
|
104
141
|
|
105
|
-
it "should
|
142
|
+
it "should cancel an ESCROWED payment" do
|
106
143
|
@escrowed_payment = Payment.new escrowed_payment_attributes
|
107
144
|
@escrowed_payment.should_receive(:save).and_return(Payment.new canceled_payment_attributes)
|
108
145
|
|
109
146
|
@escrowed_payment.cancel
|
110
147
|
@escrowed_payment.status.should == 'CANCELED'
|
111
148
|
end
|
149
|
+
|
150
|
+
it "should cancel a PARTIALLY_RELEASED payment" do
|
151
|
+
@escrowed_payment = Payment.new partially_released_payment_attributes
|
152
|
+
@escrowed_payment.should_receive(:save).and_return(Payment.new partially_released_payment_attributes)
|
153
|
+
|
154
|
+
@escrowed_payment.cancel
|
155
|
+
@escrowed_payment.status.should == 'CANCELED'
|
156
|
+
end
|
112
157
|
end
|
113
|
-
end
|
158
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 9
|
9
|
+
version: 0.2.9
|
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-
|
17
|
+
date: 2011-10-12 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -23,12 +23,13 @@ dependencies:
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
29
|
- 3
|
30
30
|
- 0
|
31
|
-
|
31
|
+
- 0
|
32
|
+
version: 3.0.0
|
32
33
|
type: :runtime
|
33
34
|
version_requirements: *id001
|
34
35
|
- !ruby/object:Gem::Dependency
|