rspreedly 0.1.4 → 0.1.5

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -19,8 +19,6 @@ module RSpreedly
19
19
  begin
20
20
  create!
21
21
  rescue RSpreedly::Error::Base
22
- # gulp those errors down
23
- # TODO - set self.errors or something?
24
22
  nil
25
23
  end
26
24
  end
@@ -54,9 +52,18 @@ module RSpreedly
54
52
  # Pay an Invoice (more)
55
53
  # PUT /api/v4/[short site name]/invoices/[invoice token]/pay.xml
56
54
  def pay(payment)
55
+ begin
56
+ pay!(payment)
57
+ rescue RSpreedly::Error::Base
58
+ nil
59
+ end
60
+ end
61
+
62
+ def pay!(payment)
57
63
  result = api_request(:put, "/invoices/#{self.token}/pay.xml", :body => payment.to_xml(:outer => 'payment'))
58
64
  self.attributes = result["invoice"]
59
- true
65
+ true
60
66
  end
67
+
61
68
  end
62
69
  end
data/rspreedly.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rspreedly}
5
- s.version = "0.1.4"
5
+ s.version = "0.1.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Richard Livsey"]
data/spec/invoice_spec.rb CHANGED
@@ -80,7 +80,7 @@ describe RSpreedly::Invoice do
80
80
 
81
81
 
82
82
  describe "#pay" do
83
-
83
+
84
84
  before(:each) do
85
85
  @invoice = RSpreedly::Invoice.new(:token => "5b1f186651dd988865c6573921ec87fa4bec23b8")
86
86
  @payment = RSpreedly::PaymentMethod::CreditCard.new(:number => "4222222222222",
@@ -97,39 +97,64 @@ describe RSpreedly::Invoice do
97
97
  @invoice.pay(@payment).should be_true
98
98
  end
99
99
 
100
+ it "should return nil if not successful" do
101
+ stub_http_with_fixture("payment_not_found.xml", 404)
102
+ @invoice.pay(@payment).should be_nil
103
+ end
104
+
105
+ end
106
+
107
+ describe "#pay!" do
108
+
109
+ before(:each) do
110
+ @invoice = RSpreedly::Invoice.new(:token => "5b1f186651dd988865c6573921ec87fa4bec23b8")
111
+ @payment = RSpreedly::PaymentMethod::CreditCard.new(:number => "4222222222222",
112
+ :card_type => "visa",
113
+ :verification_value => "234",
114
+ :month => 1,
115
+ :year => 2011,
116
+ :first_name => "Joe",
117
+ :last_name => "Bob")
118
+ end
119
+
120
+ it "should return true if successful" do
121
+ stub_http_with_fixture("payment_success.xml", 200)
122
+ @invoice.pay!(@payment).should be_true
123
+ end
124
+
100
125
  it "should update the Invoice if successful" do
101
126
  stub_http_with_fixture("payment_success.xml", 200)
102
127
 
103
128
  lambda{
104
- @invoice.pay(@payment)
129
+ @invoice.pay!(@payment)
105
130
  }.should change(@invoice, :closed).to(true)
106
131
  end
107
132
 
108
133
  it "should raise NotFound if the invoice doesn't exist" do
109
134
  stub_http_with_fixture("payment_not_found.xml", 404)
110
135
  lambda{
111
- @invoice.pay(@payment)
136
+ @invoice.pay!(@payment)
112
137
  }.should raise_error(RSpreedly::Error::NotFound)
113
138
  end
114
139
 
115
140
  it "should raise GatewayTimeout if the payment gateway times out" do
116
141
  stub_http_with_code(504)
117
142
  lambda{
118
- @invoice.pay(@payment)
143
+ @invoice.pay!(@payment)
119
144
  }.should raise_error(RSpreedly::Error::GatewayTimeout)
120
145
  end
121
146
 
122
147
  it "should raise BadRequest if the payment method is invalid" do
123
148
  stub_http_with_fixture("payment_invalid.xml", 422)
124
149
  lambda{
125
- @invoice.pay(@payment)
150
+ @invoice.pay!(@payment)
126
151
  }.should raise_error(RSpreedly::Error::BadRequest)
127
152
  end
128
153
 
129
154
  it "should raise Forbidden if the invoice is already paid" do
130
155
  stub_http_with_fixture("payment_already_paid.xml", 403)
131
156
  lambda{
132
- @invoice.pay(@payment)
157
+ @invoice.pay!(@payment)
133
158
  }.should raise_error(RSpreedly::Error::Forbidden)
134
159
  end
135
160
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspreedly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Livsey