chargify_api_ares 1.0.1 → 1.0.2
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/chargify_api_ares.gemspec +3 -3
- data/examples/renewal_preview.rb +36 -0
- data/lib/chargify_api_ares.rb +1 -0
- data/lib/chargify_api_ares/resources/migration.rb +2 -2
- data/lib/chargify_api_ares/resources/renewal_preview.rb +18 -0
- data/spec/resources/migration_preview_spec.rb +4 -4
- data/spec/resources/migration_spec.rb +3 -3
- data/spec/resources/renewal_preview_spec.rb +40 -0
- metadata +54 -32
- checksums.yaml +0 -7
data/chargify_api_ares.gemspec
CHANGED
@@ -4,11 +4,11 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.rubygems_version = '1.3.7'
|
5
5
|
|
6
6
|
s.name = 'chargify_api_ares'
|
7
|
-
s.version = '1.0.
|
8
|
-
s.date = '
|
7
|
+
s.version = '1.0.2'
|
8
|
+
s.date = '2014-01-21'
|
9
9
|
s.summary = 'A Chargify API wrapper for Ruby using ActiveResource'
|
10
10
|
s.description = ''
|
11
|
-
s.authors = ["Michael Klett", "Nathan Verni", "
|
11
|
+
s.authors = ["Michael Klett", "Nathan Verni", "Jeremy W. Rowe", "Eric Farkas"]
|
12
12
|
s.email = 'support@chargify.com'
|
13
13
|
s.homepage = 'http://github.com/chargify/chargify_api_ares'
|
14
14
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
$: << File.expand_path(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'chargify_api_ares'
|
4
|
+
|
5
|
+
# You could load your credentials from a file...
|
6
|
+
chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'chargify.yml'))
|
7
|
+
|
8
|
+
Chargify.configure do |c|
|
9
|
+
c.subdomain = chargify_config['subdomain']
|
10
|
+
c.api_key = chargify_config['api_key']
|
11
|
+
end
|
12
|
+
|
13
|
+
# Fetch list of subscriptions
|
14
|
+
subscriptions = Chargify::Subscription.find(:all)
|
15
|
+
|
16
|
+
# Grab the first id
|
17
|
+
id = subscriptions.first.id
|
18
|
+
|
19
|
+
|
20
|
+
# Fetch a preview of the next renewal
|
21
|
+
preview = Chargify::Renewal::Preview.create(
|
22
|
+
:subscription_id => id,
|
23
|
+
)
|
24
|
+
|
25
|
+
# The next assessment date
|
26
|
+
puts preview.next_assessment_at
|
27
|
+
|
28
|
+
# The existing balance
|
29
|
+
puts preview.existing_balance_in_cents
|
30
|
+
|
31
|
+
# The total charges for the next renwal
|
32
|
+
puts preview.total_in_cents
|
33
|
+
|
34
|
+
# The total total amount due (existing balance + total)
|
35
|
+
puts preview.total_amount_due_in_cents
|
36
|
+
|
data/lib/chargify_api_ares.rb
CHANGED
@@ -10,6 +10,7 @@ require 'chargify_api_ares/resources/migration'
|
|
10
10
|
require 'chargify_api_ares/resources/payment_profile'
|
11
11
|
require 'chargify_api_ares/resources/product'
|
12
12
|
require 'chargify_api_ares/resources/product_family'
|
13
|
+
require 'chargify_api_ares/resources/renewal_preview'
|
13
14
|
require 'chargify_api_ares/resources/site'
|
14
15
|
require 'chargify_api_ares/resources/statement'
|
15
16
|
require 'chargify_api_ares/resources/subscription'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Chargify
|
2
|
+
module Renewal
|
3
|
+
class Preview < Base
|
4
|
+
self.prefix = "/subscriptions/:subscription_id/renewals/"
|
5
|
+
|
6
|
+
def create
|
7
|
+
response = post(:preview, {}, attributes.send("to_#{self.class.format.extension}", :dasherize => false))
|
8
|
+
load_attributes_from_response(response)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def custom_method_new_element_url(method_name, options = {})
|
14
|
+
"#{self.class.prefix(prefix_options)}#{method_name}.#{self.class.format.extension}#{self.class.__send__(:query_string, options)}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -2,19 +2,19 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Chargify::Migration::Preview, :fake_resource do
|
4
4
|
context "#create" do
|
5
|
-
it '
|
5
|
+
it 'creates a migration preview' do
|
6
6
|
id = generate(:subscription_id)
|
7
7
|
subscription = build(:subscription, :id => id)
|
8
8
|
subscription.stub!(:persisted?).and_return(true)
|
9
9
|
expected_response = {:migration => {:prorated_adjustment_in_cents => -12500, :charge_in_cents => 90000, :payment_due_in_cents => 77500, :credit_applied_in_cents => 0 }}.to_xml
|
10
|
-
|
10
|
+
|
11
11
|
FakeWeb.register_uri(:post, "#{test_domain}/subscriptions/#{id}/migrations/preview.xml?product_handle=upgraded-plan", :status => 201, :body => expected_response)
|
12
|
-
|
12
|
+
|
13
13
|
response = Chargify::Migration::Preview.create(:subscription_id => subscription.id, :product_handle => 'upgraded-plan')
|
14
14
|
|
15
15
|
expect(response.valid?).to be_true
|
16
16
|
expect(response.errors.any?).to be_false
|
17
17
|
expect(response).to be_a(Chargify::Migration::Preview)
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
20
20
|
end
|
@@ -7,14 +7,14 @@ describe Chargify::Migration, :fake_resource do
|
|
7
7
|
subscription = build(:subscription, :id => id)
|
8
8
|
subscription.stub!(:persisted?).and_return(true)
|
9
9
|
expected_response = [subscription.attributes].to_xml(:root => 'subscription')
|
10
|
-
|
10
|
+
|
11
11
|
FakeWeb.register_uri(:post, "#{test_domain}/subscriptions/#{id}/migrations.xml?migration%5Bproduct_handle%5D=upgraded-plan", :status => 201, :body => expected_response)
|
12
|
-
|
12
|
+
|
13
13
|
response = Chargify::Migration.create(:subscription_id => subscription.id, :product_handle => 'upgraded-plan')
|
14
14
|
|
15
15
|
expect(response.valid?).to be_true
|
16
16
|
expect(response.errors.any?).to be_false
|
17
17
|
expect(response).to be_a(Chargify::Migration)
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
20
20
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chargify::Renewal::Preview, :fake_resource do
|
4
|
+
context "#create" do
|
5
|
+
it 'creates a renewal preview' do
|
6
|
+
id = generate(:subscription_id)
|
7
|
+
subscription = build(:subscription, :id => id)
|
8
|
+
subscription.stub!(:persisted?).and_return(true)
|
9
|
+
expected_response = {
|
10
|
+
:renewal_preview => {
|
11
|
+
:next_assessment_at => DateTime.parse("2014-04-04T01:00:00-04:00"),
|
12
|
+
:subtotal_in_cents => 1000,
|
13
|
+
:total_tax_in_cents => 0,
|
14
|
+
:total_discount_in_cents => 0,
|
15
|
+
:total_in_cents => 1000,
|
16
|
+
:existing_balance_in_cents => -77,
|
17
|
+
:total_amount_due_in_cents => 923,
|
18
|
+
:line_items => [
|
19
|
+
{
|
20
|
+
:transaction_type => "charge",
|
21
|
+
:kind => "baseline",
|
22
|
+
:amount_in_cents => 1000,
|
23
|
+
:memo => "Foosball (Fri, 04 Apr 2014 01:00:00 -0400 - Sun, 04 May 2014 01:00:00 -0400)",
|
24
|
+
:discount_amount_in_cents => 0,
|
25
|
+
:taxable_amount_in_cents => 0,
|
26
|
+
}
|
27
|
+
]
|
28
|
+
}
|
29
|
+
}.to_xml
|
30
|
+
|
31
|
+
FakeWeb.register_uri(:post, "#{test_domain}/subscriptions/#{id}/renewals/preview.xml", :status => 201, :body => expected_response)
|
32
|
+
|
33
|
+
response = Chargify::Renewal::Preview.create(:subscription_id => subscription.id)
|
34
|
+
|
35
|
+
expect(response.valid?).to be_true
|
36
|
+
expect(response.errors.any?).to be_false
|
37
|
+
expect(response).to be_a(Chargify::Renewal::Preview)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,159 +1,177 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chargify_api_ares
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Michael Klett
|
8
9
|
- Nathan Verni
|
9
|
-
- Graham McIntire
|
10
10
|
- Jeremy W. Rowe
|
11
|
-
- Rodrigo Franco
|
12
|
-
- Shay Frendt
|
13
11
|
- Eric Farkas
|
14
12
|
autorequire:
|
15
13
|
bindir: bin
|
16
14
|
cert_chain: []
|
17
|
-
date:
|
15
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
18
16
|
dependencies:
|
19
17
|
- !ruby/object:Gem::Dependency
|
20
18
|
name: activeresource
|
21
19
|
requirement: !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
22
21
|
requirements:
|
23
|
-
- -
|
22
|
+
- - ! '>='
|
24
23
|
- !ruby/object:Gem::Version
|
25
24
|
version: 3.0.0
|
26
25
|
type: :runtime
|
27
26
|
prerelease: false
|
28
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
29
|
requirements:
|
30
|
-
- -
|
30
|
+
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 3.0.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rake
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
36
37
|
requirements:
|
37
|
-
- -
|
38
|
+
- - ~>
|
38
39
|
- !ruby/object:Gem::Version
|
39
40
|
version: 10.0.3
|
40
41
|
type: :development
|
41
42
|
prerelease: false
|
42
43
|
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
43
45
|
requirements:
|
44
|
-
- -
|
46
|
+
- - ~>
|
45
47
|
- !ruby/object:Gem::Version
|
46
48
|
version: 10.0.3
|
47
49
|
- !ruby/object:Gem::Dependency
|
48
50
|
name: rspec
|
49
51
|
requirement: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
50
53
|
requirements:
|
51
|
-
- -
|
54
|
+
- - ~>
|
52
55
|
- !ruby/object:Gem::Version
|
53
56
|
version: 2.12.0
|
54
57
|
type: :development
|
55
58
|
prerelease: false
|
56
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
57
61
|
requirements:
|
58
|
-
- -
|
62
|
+
- - ~>
|
59
63
|
- !ruby/object:Gem::Version
|
60
64
|
version: 2.12.0
|
61
65
|
- !ruby/object:Gem::Dependency
|
62
66
|
name: factory_girl
|
63
67
|
requirement: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
64
69
|
requirements:
|
65
|
-
- -
|
70
|
+
- - ~>
|
66
71
|
- !ruby/object:Gem::Version
|
67
72
|
version: '2.6'
|
68
73
|
type: :development
|
69
74
|
prerelease: false
|
70
75
|
version_requirements: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
71
77
|
requirements:
|
72
|
-
- -
|
78
|
+
- - ~>
|
73
79
|
- !ruby/object:Gem::Version
|
74
80
|
version: '2.6'
|
75
81
|
- !ruby/object:Gem::Dependency
|
76
82
|
name: fakeweb
|
77
83
|
requirement: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
78
85
|
requirements:
|
79
|
-
- -
|
86
|
+
- - ~>
|
80
87
|
- !ruby/object:Gem::Version
|
81
88
|
version: 1.3.0
|
82
89
|
type: :development
|
83
90
|
prerelease: false
|
84
91
|
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
85
93
|
requirements:
|
86
|
-
- -
|
94
|
+
- - ~>
|
87
95
|
- !ruby/object:Gem::Version
|
88
96
|
version: 1.3.0
|
89
97
|
- !ruby/object:Gem::Dependency
|
90
98
|
name: faker
|
91
99
|
requirement: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
92
101
|
requirements:
|
93
|
-
- -
|
102
|
+
- - ~>
|
94
103
|
- !ruby/object:Gem::Version
|
95
104
|
version: 1.1.2
|
96
105
|
type: :development
|
97
106
|
prerelease: false
|
98
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
99
109
|
requirements:
|
100
|
-
- -
|
110
|
+
- - ~>
|
101
111
|
- !ruby/object:Gem::Version
|
102
112
|
version: 1.1.2
|
103
113
|
- !ruby/object:Gem::Dependency
|
104
114
|
name: guard-rspec
|
105
115
|
requirement: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
106
117
|
requirements:
|
107
|
-
- -
|
118
|
+
- - ~>
|
108
119
|
- !ruby/object:Gem::Version
|
109
120
|
version: 2.4.0
|
110
121
|
type: :development
|
111
122
|
prerelease: false
|
112
123
|
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
113
125
|
requirements:
|
114
|
-
- -
|
126
|
+
- - ~>
|
115
127
|
- !ruby/object:Gem::Version
|
116
128
|
version: 2.4.0
|
117
129
|
- !ruby/object:Gem::Dependency
|
118
130
|
name: growl
|
119
131
|
requirement: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
120
133
|
requirements:
|
121
|
-
- -
|
134
|
+
- - ~>
|
122
135
|
- !ruby/object:Gem::Version
|
123
136
|
version: 1.0.3
|
124
137
|
type: :development
|
125
138
|
prerelease: false
|
126
139
|
version_requirements: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
127
141
|
requirements:
|
128
|
-
- -
|
142
|
+
- - ~>
|
129
143
|
- !ruby/object:Gem::Version
|
130
144
|
version: 1.0.3
|
131
145
|
- !ruby/object:Gem::Dependency
|
132
146
|
name: rb-fsevent
|
133
147
|
requirement: !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
134
149
|
requirements:
|
135
|
-
- -
|
150
|
+
- - ~>
|
136
151
|
- !ruby/object:Gem::Version
|
137
152
|
version: 0.9.2
|
138
153
|
type: :development
|
139
154
|
prerelease: false
|
140
155
|
version_requirements: !ruby/object:Gem::Requirement
|
156
|
+
none: false
|
141
157
|
requirements:
|
142
|
-
- -
|
158
|
+
- - ~>
|
143
159
|
- !ruby/object:Gem::Version
|
144
160
|
version: 0.9.2
|
145
161
|
- !ruby/object:Gem::Dependency
|
146
162
|
name: pry
|
147
163
|
requirement: !ruby/object:Gem::Requirement
|
164
|
+
none: false
|
148
165
|
requirements:
|
149
|
-
- -
|
166
|
+
- - ~>
|
150
167
|
- !ruby/object:Gem::Version
|
151
168
|
version: 0.9.12
|
152
169
|
type: :development
|
153
170
|
prerelease: false
|
154
171
|
version_requirements: !ruby/object:Gem::Requirement
|
172
|
+
none: false
|
155
173
|
requirements:
|
156
|
-
- -
|
174
|
+
- - ~>
|
157
175
|
- !ruby/object:Gem::Version
|
158
176
|
version: 0.9.12
|
159
177
|
description: ''
|
@@ -162,8 +180,8 @@ executables: []
|
|
162
180
|
extensions: []
|
163
181
|
extra_rdoc_files: []
|
164
182
|
files:
|
165
|
-
-
|
166
|
-
-
|
183
|
+
- .gitignore
|
184
|
+
- .travis.yml
|
167
185
|
- Gemfile
|
168
186
|
- Gemfile.lock
|
169
187
|
- Guardfile
|
@@ -178,6 +196,7 @@ files:
|
|
178
196
|
- examples/metered_components.rb
|
179
197
|
- examples/migrations.rb
|
180
198
|
- examples/products.rb
|
199
|
+
- examples/renewal_preview.rb
|
181
200
|
- examples/subscriptions.rb
|
182
201
|
- examples/transactions.rb
|
183
202
|
- lib/chargify_api_ares.rb
|
@@ -192,6 +211,7 @@ files:
|
|
192
211
|
- lib/chargify_api_ares/resources/payment_profile.rb
|
193
212
|
- lib/chargify_api_ares/resources/product.rb
|
194
213
|
- lib/chargify_api_ares/resources/product_family.rb
|
214
|
+
- lib/chargify_api_ares/resources/renewal_preview.rb
|
195
215
|
- lib/chargify_api_ares/resources/site.rb
|
196
216
|
- lib/chargify_api_ares/resources/statement.rb
|
197
217
|
- lib/chargify_api_ares/resources/subscription.rb
|
@@ -212,6 +232,7 @@ files:
|
|
212
232
|
- spec/resources/product_family_component_spec.rb
|
213
233
|
- spec/resources/product_family_spec.rb
|
214
234
|
- spec/resources/product_spec.rb
|
235
|
+
- spec/resources/renewal_preview_spec.rb
|
215
236
|
- spec/resources/subscription_component_spec.rb
|
216
237
|
- spec/resources/subscription_spec.rb
|
217
238
|
- spec/resources/usage_spec.rb
|
@@ -220,24 +241,25 @@ files:
|
|
220
241
|
- spec/support/fake_resource.rb
|
221
242
|
homepage: http://github.com/chargify/chargify_api_ares
|
222
243
|
licenses: []
|
223
|
-
metadata: {}
|
224
244
|
post_install_message:
|
225
245
|
rdoc_options: []
|
226
246
|
require_paths:
|
227
247
|
- lib
|
228
248
|
required_ruby_version: !ruby/object:Gem::Requirement
|
249
|
+
none: false
|
229
250
|
requirements:
|
230
|
-
- -
|
251
|
+
- - ! '>='
|
231
252
|
- !ruby/object:Gem::Version
|
232
253
|
version: '0'
|
233
254
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
255
|
+
none: false
|
234
256
|
requirements:
|
235
|
-
- -
|
257
|
+
- - ! '>='
|
236
258
|
- !ruby/object:Gem::Version
|
237
259
|
version: '0'
|
238
260
|
requirements: []
|
239
261
|
rubyforge_project:
|
240
|
-
rubygems_version:
|
262
|
+
rubygems_version: 1.8.23
|
241
263
|
signing_key:
|
242
264
|
specification_version: 3
|
243
265
|
summary: A Chargify API wrapper for Ruby using ActiveResource
|
@@ -255,10 +277,10 @@ test_files:
|
|
255
277
|
- spec/resources/product_family_component_spec.rb
|
256
278
|
- spec/resources/product_family_spec.rb
|
257
279
|
- spec/resources/product_spec.rb
|
280
|
+
- spec/resources/renewal_preview_spec.rb
|
258
281
|
- spec/resources/subscription_component_spec.rb
|
259
282
|
- spec/resources/subscription_spec.rb
|
260
283
|
- spec/resources/usage_spec.rb
|
261
284
|
- spec/spec.opts
|
262
285
|
- spec/spec_helper.rb
|
263
286
|
- spec/support/fake_resource.rb
|
264
|
-
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 9c648cb6bdbeedc16d78144cfe42a749dcd70467
|
4
|
-
data.tar.gz: 4ba920a8a9193d4eedca12e720eef1ac5c5eb663
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: d50afab5688335aece9ee206c818a85f80792b9d60e6b42b83c54fb03bb286baf89e61893902c97c72e48a83ce83225c1d0ed0c5f123ba8635683f23086baa4b
|
7
|
-
data.tar.gz: d34c1eb71a65f8f53aa3fa34d1ef0dfbf51ce78215776ba734a6062c2e2a1891b0ce4f95ec731d6af36f15b21ce493c68c1a9fc37908d3f3ffdac99f9081e868
|