active_zuora 2.1.4 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +1 -0
- data/README.md +13 -0
- data/lib/active_zuora.rb +2 -0
- data/lib/active_zuora/batch_subscribe.rb +53 -0
- data/lib/active_zuora/collection_proxy.rb +38 -0
- data/lib/active_zuora/generator.rb +1 -0
- data/lib/active_zuora/version.rb +1 -1
- data/spec/collection_proxy_spec.rb +28 -0
- data/spec/subscribe_integration_spec.rb +115 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a193209e8dc321e159f45d360a0b1b5a0f4458f
|
4
|
+
data.tar.gz: 5994cf1d464ebde4d2e674763eee752c8f6c6f13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcc832f90122ccc3e4d12bba198d83d28cee4c8fba77fcdbb6b42c86d1761fe69c032d175a1e520800ca71f0db4db528136cbfcd3b47026cf162d845d4469431
|
7
|
+
data.tar.gz: be5417128f8bce2c3d484c9a2403482472854b424a90e2b92ed3f7aef3db312158e25b828ca8eed941181b166f2b46b15c545bf68a55336df138c182a8f04aa5
|
data/CHANGELOG.markdown
CHANGED
data/README.md
CHANGED
@@ -33,6 +33,11 @@ fields to a list of filtered fields.
|
|
33
33
|
:wsdl => 'path/to/zuora.wsdl'
|
34
34
|
)
|
35
35
|
```
|
36
|
+
Override the default endpoint or host loaded from the wsdl
|
37
|
+
|
38
|
+
```
|
39
|
+
ActiveZuora::Base.connection.soap_client.wsdl.endpoint.host = "www.zuora.com" if Rails.env.production?
|
40
|
+
````
|
36
41
|
|
37
42
|
## Defining Classes
|
38
43
|
|
@@ -156,6 +161,14 @@ You can also delete all records matching a query as well. The method returns th
|
|
156
161
|
|
157
162
|
ActiveZuora::Account.where(:status => "Draft").delete_all # 56
|
158
163
|
|
164
|
+
## Batch Subscribe
|
165
|
+
|
166
|
+
You can submit up to 50 subscribe requests on a single subscribe call per the Zuora documentation. To batch subscribe requests, use the CollectionProxy to build a collection of subscribe requests, then call batch_subscribe
|
167
|
+
|
168
|
+
ActiveZuora::CollectionProxy.new([ActiveZuora::SubscribeRequest.new({account: {}, bill_to: {}, subscription_data:{}}),
|
169
|
+
ActiveZuora::SubscribeRequest.new({account: {}, bill_to: {}, subscription_data:{}})]).batch_subscribe
|
170
|
+
|
171
|
+
|
159
172
|
## License
|
160
173
|
|
161
174
|
Active Zuora is released under the MIT license:
|
data/lib/active_zuora.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
module ActiveZuora
|
2
|
+
module BatchSubscribe
|
3
|
+
|
4
|
+
# This is meant to be included onto the CollectionProxy class.
|
5
|
+
# Returns true if every SubscribeRequest was a success
|
6
|
+
# Returns false if any single subsciption Request fails
|
7
|
+
# Result hash of each subscribe request is stored in the Subscribe Request #result.
|
8
|
+
# If success, the subscription id and account id will be set in those objects.
|
9
|
+
# If failure, errors will be present on the request object(s) that had error(s).
|
10
|
+
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
include Base
|
15
|
+
attr_accessor :result
|
16
|
+
end
|
17
|
+
|
18
|
+
def batch_subscribe
|
19
|
+
raise "object must be an ActiveZuora::CollectionProxy object instance" unless self.zuora_object_name == "CollectionProxy"
|
20
|
+
self.result = self.class.connection.request(:subscribe) do |soap|
|
21
|
+
soap.body do |xml|
|
22
|
+
inject(xml) do |memo, el|
|
23
|
+
el.build_xml(xml, soap,
|
24
|
+
:namespace => soap.namespace,
|
25
|
+
:element_name => :subscribes,
|
26
|
+
:force_type => true)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end[:subscribe_response][:result]
|
30
|
+
|
31
|
+
self.result = [result] unless result.is_a?(Array)
|
32
|
+
result.each_with_index do |result, i|
|
33
|
+
self.records[i].result = result
|
34
|
+
if result[:success]
|
35
|
+
#we assume order is maintained by zuora. is it?
|
36
|
+
self.records[i].account.id = result[:account_id]
|
37
|
+
self.records[i].subscription_data.subscription.id = result[:subscription_id]
|
38
|
+
self.records[i].clear_changed_attributes
|
39
|
+
@status = true
|
40
|
+
else
|
41
|
+
add_zuora_errors(result[:errors])
|
42
|
+
@status = false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
@status
|
46
|
+
end
|
47
|
+
|
48
|
+
def batch_subscribe!
|
49
|
+
raise "Could not batch subscribe: #{errors.full_messages.join ', '}" unless batch_subscribe
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ActiveZuora
|
2
|
+
class CollectionProxy
|
3
|
+
|
4
|
+
include ZObject
|
5
|
+
include Enumerable
|
6
|
+
include BatchSubscribe
|
7
|
+
|
8
|
+
attr_reader :records, :zobject_class
|
9
|
+
|
10
|
+
def initialize(ary = [])
|
11
|
+
unless ary.empty?
|
12
|
+
raise "objects in collection must be ActiveZuora object instances" unless class_names = ary.map{|object| object.zuora_object_name}.uniq
|
13
|
+
raise "objects in collection must be ActiveZuora object instances of the same class" unless class_names.length == 1
|
14
|
+
@zobject_class = class_names.first
|
15
|
+
end
|
16
|
+
@records = ary
|
17
|
+
end
|
18
|
+
|
19
|
+
def add object
|
20
|
+
raise "object must be an ActiveZuora object instance" unless object.zuora_object_name
|
21
|
+
if records.empty?
|
22
|
+
@zobject_class = object.zuora_object_name
|
23
|
+
else
|
24
|
+
raise "object must be must be ActiveZuora object instances of the same class as other elements in the Collection" unless object.zuora_object_name == zobject_class
|
25
|
+
end
|
26
|
+
@records.push object
|
27
|
+
end
|
28
|
+
|
29
|
+
def each
|
30
|
+
records.each { |r| yield r }
|
31
|
+
end
|
32
|
+
|
33
|
+
def empty?
|
34
|
+
records.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -8,6 +8,7 @@ module ActiveZuora
|
|
8
8
|
@document = document
|
9
9
|
@classes = []
|
10
10
|
@class_nesting = options[:inside] || ActiveZuora
|
11
|
+
@class_nesting.const_set("CollectionProxy", CollectionProxy) unless @class_nesting.constants.include?(:CollectionProxy)
|
11
12
|
end
|
12
13
|
|
13
14
|
def generate_classes
|
data/lib/active_zuora/version.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "ActiveZuora::CollectionProxy" do
|
4
|
+
|
5
|
+
it "should initialize" do
|
6
|
+
cp = Z::CollectionProxy.new
|
7
|
+
expect(cp).to be_empty
|
8
|
+
cp = Z::CollectionProxy.new([Z::SubscribeRequest.new])
|
9
|
+
expect(cp).not_to be_empty
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should respond to enumerable methods" do
|
13
|
+
cp = Z::CollectionProxy.new([Z::SubscribeRequest.new])
|
14
|
+
cp.each do |cp|
|
15
|
+
expect(cp)
|
16
|
+
end
|
17
|
+
cp.inject do |memo,cp|
|
18
|
+
expect(memo)
|
19
|
+
expect(cp)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should respond to the batch_subscribe method" do
|
24
|
+
cp = Z::CollectionProxy.new([Z::SubscribeRequest.new])
|
25
|
+
expect(cp.respond_to?(:batch_subscribe)).to eq(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -39,8 +39,9 @@ describe "Subscribe" do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
after do
|
42
|
-
@account.delete
|
43
42
|
@product.delete
|
43
|
+
@account.delete
|
44
|
+
@account_2.delete if !!@account_2
|
44
45
|
end
|
45
46
|
|
46
47
|
it "Can successfully subscribe and amend using a new account" do
|
@@ -214,5 +215,118 @@ describe "Subscribe" do
|
|
214
215
|
expect(invoice.account_id).to eq(subscribe_request.account.id)
|
215
216
|
end
|
216
217
|
|
218
|
+
it "Can successfully batch subscribe from a collection proxy of subscribe requests and generate an invoice for the first subscription" do
|
219
|
+
subscribe_request_1 = Z::SubscribeRequest.new(
|
220
|
+
:account => {
|
221
|
+
:name => "Joe Customer",
|
222
|
+
:currency => Tenant.currency,
|
223
|
+
:bill_cycle_day => 1,
|
224
|
+
:payment_term => "Due Upon Receipt",
|
225
|
+
:batch => "Batch1"
|
226
|
+
},
|
227
|
+
:payment_method => {
|
228
|
+
:type => "CreditCard",
|
229
|
+
:credit_card_holder_name => "Robert Paulson",
|
230
|
+
:credit_card_type => "MasterCard",
|
231
|
+
:credit_card_number => "4111111111111111",
|
232
|
+
:credit_card_expiration_month => 1,
|
233
|
+
:credit_card_expiration_year => (Date.today.year + 1)
|
234
|
+
},
|
235
|
+
:bill_to_contact => {
|
236
|
+
:first_name => "Conny",
|
237
|
+
:last_name => "Client",
|
238
|
+
:work_email => "conny.client@example.com",
|
239
|
+
:country => "AU"
|
240
|
+
},
|
241
|
+
:subscription_data => {
|
242
|
+
:subscription => {
|
243
|
+
:contract_effective_date => Date.today,
|
244
|
+
:service_activation_date => Date.today,
|
245
|
+
:initial_term => 12,
|
246
|
+
:renewal_term => 12,
|
247
|
+
:term_type => 'TERMED'
|
248
|
+
},
|
249
|
+
:rate_plan_data => {
|
250
|
+
:rate_plan => {
|
251
|
+
:product_rate_plan_id => @product_rate_plan.id,
|
252
|
+
},
|
253
|
+
:rate_plan_charge_data => {
|
254
|
+
:rate_plan_charge => {
|
255
|
+
:product_rate_plan_charge_id => @product_rate_plan_charge.id,
|
256
|
+
:price => 45.00
|
257
|
+
}
|
258
|
+
}
|
259
|
+
}
|
260
|
+
}
|
261
|
+
)
|
262
|
+
|
263
|
+
subscribe_request_2 = Z::SubscribeRequest.new(
|
264
|
+
:account => {
|
265
|
+
:name => "Joe Customer",
|
266
|
+
:currency => Tenant.currency,
|
267
|
+
:bill_cycle_day => 1,
|
268
|
+
:payment_term => "Due Upon Receipt",
|
269
|
+
:batch => "Batch1"
|
270
|
+
},
|
271
|
+
:payment_method => {
|
272
|
+
:type => "CreditCard",
|
273
|
+
:credit_card_holder_name => "Robert Paulson",
|
274
|
+
:credit_card_type => "MasterCard",
|
275
|
+
:credit_card_number => "4111111111111111",
|
276
|
+
:credit_card_expiration_month => 1,
|
277
|
+
:credit_card_expiration_year => (Date.today.year + 1)
|
278
|
+
},
|
279
|
+
:bill_to_contact => {
|
280
|
+
:first_name => "Conny",
|
281
|
+
:last_name => "Client",
|
282
|
+
:work_email => "conny.client@example.com",
|
283
|
+
:country => "AU"
|
284
|
+
},
|
285
|
+
:subscription_data => {
|
286
|
+
:subscription => {
|
287
|
+
:contract_effective_date => Date.today,
|
288
|
+
:service_activation_date => Date.today,
|
289
|
+
:initial_term => 12,
|
290
|
+
:renewal_term => 12,
|
291
|
+
:term_type => 'TERMED'
|
292
|
+
},
|
293
|
+
:rate_plan_data => {
|
294
|
+
:rate_plan => {
|
295
|
+
:product_rate_plan_id => @product_rate_plan.id,
|
296
|
+
},
|
297
|
+
:rate_plan_charge_data => {
|
298
|
+
:rate_plan_charge => {
|
299
|
+
:product_rate_plan_charge_id => @product_rate_plan_charge.id,
|
300
|
+
:price => 45.00
|
301
|
+
}
|
302
|
+
}
|
303
|
+
}
|
304
|
+
}
|
305
|
+
)
|
306
|
+
|
307
|
+
collection = Z::CollectionProxy.new([subscribe_request_1,subscribe_request_2])
|
308
|
+
collection.batch_subscribe!
|
309
|
+
|
310
|
+
#subscribe reqeust 1
|
311
|
+
@account = subscribe_request_1.account
|
312
|
+
expect(subscribe_request_1.new_record?).to be_falsey
|
313
|
+
expect(subscribe_request_1changed?).to be_falsey
|
314
|
+
expect(subscribe_request_1.subscription_data.subscription.new_record?).to be_falsey
|
315
|
+
expect(subscribe_request_1.subscription_data.subscription.rate_plans.first.
|
316
|
+
rate_plan_charges.first.
|
317
|
+
product_rate_plan_charge).to eq(@product_rate_plan_charge)
|
318
|
+
expect(subscribe_request_1.result).to be_present
|
319
|
+
|
320
|
+
#subscribe reqeust 2
|
321
|
+
@account_2 = subscribe_request_2.account
|
322
|
+
expect(subscribe_request_2.new_record?).to be_falsey
|
323
|
+
expect(subscribe_request_2changed?).to be_falsey
|
324
|
+
expect(subscribe_request_2.subscription_data.subscription.new_record?).to be_falsey
|
325
|
+
expect(subscribe_request_2.subscription_data.subscription.rate_plans.first.
|
326
|
+
rate_plan_charges.first.
|
327
|
+
product_rate_plan_charge).to eq(@product_rate_plan_charge)
|
328
|
+
expect(subscribe_request_2.result).to be_present
|
329
|
+
end
|
330
|
+
|
217
331
|
end
|
218
332
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_zuora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ed Lebert
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-02-
|
12
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: savon
|
@@ -117,7 +117,9 @@ files:
|
|
117
117
|
- lib/active_zuora.rb
|
118
118
|
- lib/active_zuora/amend.rb
|
119
119
|
- lib/active_zuora/base.rb
|
120
|
+
- lib/active_zuora/batch_subscribe.rb
|
120
121
|
- lib/active_zuora/belongs_to_associations.rb
|
122
|
+
- lib/active_zuora/collection_proxy.rb
|
121
123
|
- lib/active_zuora/connection.rb
|
122
124
|
- lib/active_zuora/fields.rb
|
123
125
|
- lib/active_zuora/fields/array_field_decorator.rb
|
@@ -141,6 +143,7 @@ files:
|
|
141
143
|
- spec/account_integration_spec.rb
|
142
144
|
- spec/base_spec.rb
|
143
145
|
- spec/belongs_to_associations_spec.rb
|
146
|
+
- spec/collection_proxy_spec.rb
|
144
147
|
- spec/connection_spec.rb
|
145
148
|
- spec/has_many_integration_spec.rb
|
146
149
|
- spec/spec_helper.rb
|
@@ -175,6 +178,7 @@ test_files:
|
|
175
178
|
- spec/account_integration_spec.rb
|
176
179
|
- spec/base_spec.rb
|
177
180
|
- spec/belongs_to_associations_spec.rb
|
181
|
+
- spec/collection_proxy_spec.rb
|
178
182
|
- spec/connection_spec.rb
|
179
183
|
- spec/has_many_integration_spec.rb
|
180
184
|
- spec/spec_helper.rb
|