poundpay 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/poundpay/elements.rb +16 -2
- data/lib/poundpay/version.rb +1 -1
- data/spec/fixtures/payments.rb +6 -0
- data/spec/poundpay/elements_spec.rb +15 -0
- metadata +3 -3
data/lib/poundpay/elements.rb
CHANGED
@@ -2,10 +2,16 @@ require 'uri'
|
|
2
2
|
|
3
3
|
require 'poundpay/resource'
|
4
4
|
|
5
|
-
class
|
5
|
+
class PaymentException < Exception
|
6
6
|
end
|
7
7
|
|
8
|
-
class
|
8
|
+
class PaymentEscrowException < PaymentException
|
9
|
+
end
|
10
|
+
|
11
|
+
class PaymentReleaseException < PaymentException
|
12
|
+
end
|
13
|
+
|
14
|
+
class PaymentCancelException < PaymentException
|
9
15
|
end
|
10
16
|
|
11
17
|
module Poundpay
|
@@ -35,6 +41,14 @@ module Poundpay
|
|
35
41
|
end
|
36
42
|
|
37
43
|
class Payment < Resource
|
44
|
+
def escrow
|
45
|
+
unless status == 'AUTHORIZED'
|
46
|
+
raise PaymentEscrowException.new "Payment status is #{status}. Only AUTHORIZED payments may be released"
|
47
|
+
end
|
48
|
+
attributes['status'] = 'ESCROWED'
|
49
|
+
save
|
50
|
+
end
|
51
|
+
|
38
52
|
def release
|
39
53
|
unless status == 'ESCROWED'
|
40
54
|
raise PaymentReleaseException.new "Payment status is #{status}. Only ESCROWED payments may be released"
|
data/lib/poundpay/version.rb
CHANGED
data/spec/fixtures/payments.rb
CHANGED
@@ -22,6 +22,12 @@ module Poundpay
|
|
22
22
|
}
|
23
23
|
end
|
24
24
|
|
25
|
+
def authorized_payment_attributes
|
26
|
+
@attributes = staged_payment_attributes
|
27
|
+
@attributes["status"] = "AUTHORIZED"
|
28
|
+
@attributes
|
29
|
+
end
|
30
|
+
|
25
31
|
def escrowed_payment_attributes
|
26
32
|
@attributes = staged_payment_attributes
|
27
33
|
@attributes["status"] = "ESCROWED"
|
@@ -66,6 +66,21 @@ describe Payment do
|
|
66
66
|
Poundpay.clear_config!
|
67
67
|
end
|
68
68
|
|
69
|
+
describe "#escrow" do
|
70
|
+
it "should not be able to escrow a STAGED payment" do
|
71
|
+
@staged_payment = Payment.new staged_payment_attributes
|
72
|
+
expect {@staged_payment.escrow}.to raise_error(PaymentEscrowException)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should escrow an AUTHORIZED payment" do
|
76
|
+
@authorized_payment = Payment.new authorized_payment_attributes
|
77
|
+
@authorized_payment.should_receive(:save).and_return(Payment.new escrowed_payment_attributes)
|
78
|
+
|
79
|
+
@authorized_payment.escrow
|
80
|
+
@authorized_payment.status.should == 'ESCROWED'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
69
84
|
describe "#release" do
|
70
85
|
it "should not be able to release a STAGED payment" do
|
71
86
|
@staged_payment = Payment.new staged_payment_attributes
|
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
|
+
- 6
|
9
|
+
version: 0.2.6
|
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-04-
|
17
|
+
date: 2011-04-20 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|