Skip to content

Commit

Permalink
added rate plan charges to subscribe request to specify quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
mdemin914 committed Oct 9, 2012
1 parent 0931942 commit a7b4973
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/zuora/objects/subscribe_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class SubscribeRequest < Base
attr_accessor :payment_method
attr_accessor :sold_to_contact
attr_accessor :product_rate_plans
attr_accessor :rate_plan_charges

attr_accessor :validation_errors

Expand Down Expand Up @@ -82,6 +83,15 @@ def create
rpd.__send__(zns, :RatePlan) do |rp|
rp.__send__(ons, :ProductRatePlanId, product_rate_plan.id)
end

rate_plan_charges.each do |product_rate_plan_charge|
rpd.__send__(zns, :RatePlanChargeData) do |rpcd|
rpcd.__send__(zns, :RatePlanCharge) do |rpc|
rpc.__send__(ons, :ProductRatePlanChargeId, product_rate_plan_charge.product_rate_plan_charge_id)
rpc.__send__(ons, :Quantity, product_rate_plan_charge.quantity)
end
end
end unless rate_plan_charges.nil?
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions spec/zuora/objects/subscribe_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,23 @@
with_value(true)
end

it "supports specifiying the charges quantity" do
MockResponse.responds_with(:subscribe_request_success) do
rpc = Zuora::Objects::RatePlanCharge.new
rpc.quantity = 12
rpc.product_rate_plan_charge_id = '123'
charges = Array.new
charges << rpc
subject.rate_plan_charges = charges
subject.should be_valid
sub_resp = subject.create
sub_resp[:success].should == true
end
xml = Zuora::Api.instance.last_request
xml.should have_xml("//env:Body/#{zns}:subscribe/#{zns}:subscribes/#{zns}:SubscriptionData/#{zns}:RatePlanData/#{zns}:RatePlanChargeData/#{zns}:RatePlanCharge/#{ons}:Quantity").
with_value("12")
end

it "applies valid response data to the proper nested objects and resets dirty" do
MockResponse.responds_with(:subscribe_request_success) do
subject.should be_valid
Expand Down

0 comments on commit a7b4973

Please sign in to comment.