Skip to content

Commit

Permalink
support multiple product rate plans in subscribe requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoline committed Jun 18, 2012
1 parent bd97d1e commit a9a6e32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions lib/zuora/objects/subscribe_request.rb
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/zuora/objects/subscribe_request_spec.rb
Expand Up @@ -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)
Expand Down

0 comments on commit a9a6e32

Please sign in to comment.