chargify_api_ares 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.7
1
+ 0.3.8
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{chargify_api_ares}
8
- s.version = "0.3.7"
8
+ s.version = "0.3.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Michael Klett", "The Lab Rats @ Phase Two Labs", "Brian Rose", "Nathan Verni"]
12
- s.date = %q{2010-11-11}
11
+ s.authors = ["Michael Klett", "Nathan Verni", "The Lab Rats @ Phase Two Labs", "Brian Rose"]
12
+ s.date = %q{2011-2-20}
13
13
  s.description = %q{}
14
14
  s.email = %q{mklett@grasshopper.com}
15
15
  s.extra_rdoc_files = [
@@ -63,6 +63,7 @@ module Chargify
63
63
 
64
64
  Base.site = site
65
65
  Subscription::Component.site = site + "/subscriptions/:subscription_id"
66
+ Subscription::Transaction.site = site + "/subscriptions/:subscription_id"
66
67
  end
67
68
  end
68
69
 
@@ -78,8 +79,8 @@ module Chargify
78
79
  end
79
80
 
80
81
  class Site < Base
81
- def self.clear_data!
82
- post(:clear_data)
82
+ def self.clear_data!(params = {})
83
+ post(:clear_data, params)
83
84
  end
84
85
  end
85
86
 
@@ -134,15 +135,15 @@ module Chargify
134
135
  # For more information, please see the one-time charge API docs available
135
136
  # at: http://support.chargify.com/faqs/api/api-charges
136
137
  def charge(attrs = {})
137
- post :charges, :charge => attrs
138
+ post :charges, {}, attrs.to_xml(:root => :charge)
138
139
  end
139
140
 
140
141
  def credit(attrs = {})
141
- post :credits, :credit => attrs
142
+ post :credits, {}, attrs.to_xml(:root => :credit)
142
143
  end
143
144
 
144
145
  def refund(attrs = {})
145
- post :refunds, :refund => attrs
146
+ post :refunds, {}, attrs.to_xml(:root => :refund)
146
147
  end
147
148
 
148
149
  def reactivate(params = {})
@@ -157,8 +158,9 @@ module Chargify
157
158
  post :migrations, :migration => attrs
158
159
  end
159
160
 
160
- def transactions()
161
- Transaction.find(:all, :params =>{:subscription_id => self.id})
161
+ def transactions(params = {})
162
+ params.merge!(:subscription_id => self.id)
163
+ Transaction.find(:all, :params => params)
162
164
  end
163
165
 
164
166
  class Component < Base
@@ -167,6 +169,22 @@ module Chargify
167
169
  self.component_id
168
170
  end
169
171
  end
172
+
173
+ class Transaction < Base
174
+ def full_refund(attrs = {})
175
+ return false if self.transaction_type != 'payment'
176
+
177
+ attrs.merge!(:amount_in_cents => self.amount_in_cents)
178
+ self.refund(attrs)
179
+ end
180
+
181
+ def refund(attrs = {})
182
+ return false if self.transaction_type != 'payment'
183
+
184
+ attrs.merge!(:payment_id => self.id)
185
+ Subscription.find(self.prefix_options[:subscription_id]).refund(attrs)
186
+ end
187
+ end
170
188
  end
171
189
 
172
190
  class Product < Base
@@ -212,6 +230,19 @@ module Chargify
212
230
  end
213
231
 
214
232
  class Transaction < Base
233
+ def full_refund(attrs = {})
234
+ return false if self.transaction_type != 'payment'
235
+
236
+ attrs.merge!(:amount_in_cents => self.amount_in_cents)
237
+ self.refund(attrs)
238
+ end
239
+
240
+ def refund(attrs = {})
241
+ return false if self.transaction_type != 'payment'
242
+
243
+ attrs.merge!(:payment_id => self.id)
244
+ Subscription.find(self.subscription_id).refund(attrs)
245
+ end
215
246
  end
216
247
 
217
248
  class PaymentProfile < Base
@@ -251,7 +251,7 @@ if run_remote_tests?
251
251
  lambda{
252
252
  @subscription.credit(:amount => 7, :memo => 'credit')
253
253
  }.should change{@subscription.reload.transactions.size}.by(1)
254
- @subscription.transactions.first.amount_in_cents.should == 700
254
+ @subscription.transactions.first.amount_in_cents.should == -700
255
255
  end
256
256
  end
257
257
 
@@ -277,6 +277,50 @@ if run_remote_tests?
277
277
  @subscription.transactions.first.amount_in_cents.should == 700
278
278
  @subscription.transactions.first.transaction_type.should == 'refund'
279
279
  end
280
+
281
+ context "via subscription payment (Chargify::Subscription::Transaction)" do
282
+ before :each do
283
+ @payment = @subscription.transactions.first
284
+ end
285
+
286
+ it "creates a refund" do
287
+ lambda{
288
+ @payment.refund :amount => 7, :memo => 'Refunding One Time Charge'
289
+ }.should change{@subscription.reload.transactions.size}.by(1)
290
+ @subscription.transactions.first.amount_in_cents.should == 700
291
+ @subscription.transactions.first.transaction_type.should == 'refund'
292
+ end
293
+
294
+ it "creates a full refund" do
295
+ lambda{
296
+ @payment.full_refund :memo => 'Refunding One Time Charge'
297
+ }.should change{@subscription.reload.transactions.size}.by(1)
298
+ @subscription.transactions.first.amount_in_cents.should == 700
299
+ @subscription.transactions.first.transaction_type.should == 'refund'
300
+ end
301
+ end
302
+
303
+ context "via site payment (Chargify::Transaction)" do
304
+ before :each do
305
+ @site_payment = Chargify::Transaction.find(:first)
306
+ end
307
+
308
+ it "creates a refund" do
309
+ lambda{
310
+ @site_payment.refund :amount => 7, :memo => 'Refunding One Time Charge'
311
+ }.should change{@subscription.reload.transactions.size}.by(1)
312
+ @subscription.transactions.first.amount_in_cents.should == 700
313
+ @subscription.transactions.first.transaction_type.should == 'refund'
314
+ end
315
+
316
+ it "creates a full refund" do
317
+ lambda{
318
+ @site_payment.full_refund :memo => 'Refunding One Time Charge'
319
+ }.should change{@subscription.reload.transactions.size}.by(1)
320
+ @subscription.transactions.first.amount_in_cents.should == 700
321
+ @subscription.transactions.first.transaction_type.should == 'refund'
322
+ end
323
+ end
280
324
  end
281
325
 
282
326
  def already_cleared_site_data?
@@ -467,4 +511,4 @@ if run_remote_tests?
467
511
  end
468
512
 
469
513
  end
470
- end
514
+ end
metadata CHANGED
@@ -1,24 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chargify_api_ares
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 7
10
- version: 0.3.7
9
+ - 8
10
+ version: 0.3.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Klett
14
+ - Nathan Verni
14
15
  - The Lab Rats @ Phase Two Labs
15
16
  - Brian Rose
16
- - Nathan Verni
17
17
  autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-11-11 00:00:00 -05:00
21
+ date: 2011-02-20 00:00:00 -05:00
22
22
  default_executable:
23
23
  dependencies: []
24
24