Permalink
Browse files

support multiple product rate plans in subscribe requests

  • Loading branch information...
jmoline committed Jun 18, 2012
1 parent bd97d1e commit a9a6e3288064eb14c5d330c962addca66d1f81fb
Showing with 14 additions and 9 deletions.
  1. +13 −8 lib/zuora/objects/subscribe_request.rb
  2. +1 −1 spec/zuora/objects/subscribe_request_spec.rb
@@ -5,15 +5,15 @@ class SubscribeRequest < Base
attr_accessor :bill_to_contact
attr_accessor :payment_method
attr_accessor :sold_to_contact
- attr_accessor :product_rate_plan
+ attr_accessor :product_rate_plans
store_accessors :subscribe_options
validate do |request|
request.must_have_usable(:account)
request.must_have_usable(:payment_method)
request.must_have_usable(:bill_to_contact)
- request.must_have_usable(:product_rate_plan)
+ request.must_have_usable(:product_rate_plans)
request.must_have_new(:subscription)
end
@@ -28,9 +28,12 @@ def must_have_new(ref)
# used to validate nested objects
def must_have_usable(ref)
obj = self.send(ref)
- return errors[ref] << "must be provided" if obj.nil?
- if obj.new_record? || obj.changed?
- errors[ref] << "is invalid" unless obj.valid?
+ return errors[ref] << "must be provided" if obj.blank?
+ obj = obj.is_a?(Array) ? obj : [obj]
+ obj.each do |object|
+ if object.new_record? || object.changed?
+ errors[ref] << "is invalid" unless object.valid?
+ end
end
end
@@ -64,9 +67,11 @@ def create
generate_subscription(sub)
end
- sd.__send__(zns, :RatePlanData) do |rpd|
- rpd.__send__(zns, :RatePlan) do |rp|
- rp.__send__(ons, :ProductRatePlanId, product_rate_plan.id)
+ product_rate_plans.each do |product_rate_plan|
+ sd.__send__(zns, :RatePlanData) do |rpd|
+ rpd.__send__(zns, :RatePlan) do |rp|
+ rp.__send__(ons, :ProductRatePlanId, product_rate_plan.id)
+ end
end
end
end
@@ -25,7 +25,7 @@
end
MockResponse.responds_with(:payment_method_credit_card_find_success) do
- subject.product_rate_plan = Zuora::Objects::ProductRatePlan.find('stub')
+ subject.product_rate_plans = [Zuora::Objects::ProductRatePlan.find('stub')]
end
subject.subscription = FactoryGirl.build(:subscription)

0 comments on commit a9a6e32

Please sign in to comment.