Skip to content

Commit

Permalink
fixing subscribe request
Browse files Browse the repository at this point in the history
  • Loading branch information
mdemin914 committed Apr 2, 2015
1 parent 45ed72a commit 08296bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/zuora/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def self.configure(opts={})
class Api
include Singleton

I18n.enforce_available_locales = false

# @return [Savon::Client]
def client
@client ||= make_client
Expand Down Expand Up @@ -80,7 +82,6 @@ def request(method, options={}, &block)
yield xml
options[:message] = xml.target!
end

client.call(method, options)
rescue Savon::SOAPFault, IOError => e
raise Zuora::Fault.new(:message => e.message)
Expand Down
24 changes: 18 additions & 6 deletions lib/zuora/objects/subscribe_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class SubscribeRequest < Base
attr_accessor :product_rate_plans

store_accessors :subscribe_options
store_accessors :preview_options

validate do |request|
request.must_have_usable(:account)
Expand Down Expand Up @@ -39,17 +40,13 @@ def must_have_usable(ref)

# Generate a subscription request
def create
return false unless valid?
#return false unless valid?
result = Zuora::Api.instance.request(:subscribe) do |xml|
xml.__send__(zns, :subscribes) do |s|
s.__send__(zns, :Account) do |a|
generate_object(a, account)
end

s.__send__(zns, :SubscribeOptions) do |so|
generate_subscribe_options(so)
end unless subscribe_options.blank?

s.__send__(zns, :PaymentMethod) do |pm|
generate_object(pm, payment_method)
end
Expand All @@ -58,10 +55,18 @@ def create
generate_object(btc, bill_to_contact)
end

s.__send__(zns, :PreviewOptions) do |po|
generate_preview_options(po)
end unless preview_options.blank?

s.__send__(zns, :SoldToContact) do |btc|
generate_object(btc, sold_to_contact)
end unless sold_to_contact.nil?

s.__send__(zns, :SubscribeOptions) do |so|
generate_subscribe_options(so)
end unless subscribe_options.blank?

s.__send__(zns, :SubscriptionData) do |sd|
sd.__send__(zns, :Subscription) do |sub|
generate_subscription(sub)
Expand All @@ -77,6 +82,7 @@ def create
end
end
end

apply_response(result.to_hash, :subscribe_response)
end

Expand Down Expand Up @@ -120,7 +126,13 @@ def generate_subscription(builder)

def generate_subscribe_options(builder)
subscribe_options.each do |k,v|
builder.__send__(ons, k.to_s.zuora_camelize.to_sym, v)
builder.__send__(zns, k.to_s.zuora_camelize.to_sym, v)
end
end

def generate_preview_options(builder)
preview_options.each do |k,v|
builder.__send__(zns, k.to_s.zuora_camelize.to_sym, v)
end
end

Expand Down

0 comments on commit 08296bb

Please sign in to comment.