Sha256: 6742bcadc7624ec569e0839f4b6b8b2721825a9e49fab6dd41781af726af9fc6

Contents?: true

Size: 1.57 KB

Versions: 9

Compression:

Stored size: 1.57 KB

Contents

module ActiveZuora
  module BillingPreview

    # This is meant to be included onto an BillingPreviewRequest class.
    # Returns a BillingPreviewResponse object on success.
    # Result hash is stored in #result.
    # If failure, errors will be present on object.

    extend ActiveSupport::Concern

    included do
      include Base
      attr_accessor :result
    end

    def billing_preview
      self.result = self.class.connection.request(:billing_preview) do |soap|
        soap.body do |xml|
          build_xml(xml, soap,
            :namespace => soap.namespace,
            :element_name => :requests,
            :force_type => true)
        end
      end[:billing_preview_response][:results]

      if result[:success]
        clear_changed_attributes
        filtered_invoice_items = self.result[:invoice_item].map do |invoice_item|
          #Filter out data in the return value that are not valid invoice item fields such as
          #    :"@xmlns:ns2"=>"http://object.api.zuora.com/",
          #    :"@xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
          #    :"@xsi:type"=>"ns2:InvoiceItem"
          invoice_item.select{|key, v| ActiveZuora::InvoiceItem.field_names.include?(key)}
        end
        ActiveZuora::BillingPreviewResult.new(self.result.merge(invoice_item: filtered_invoice_items))
      else
        add_zuora_errors(result[:errors])
        false
      end
    end

    def billing_preview!
      billing_preview.tap do |preview|
        raise "Could not billing preview: #{errors.full_messages.join ', '}" unless preview
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
active_zuora-2.6.0 lib/active_zuora/billing_preview.rb
active_zuora-2.5.4 lib/active_zuora/billing_preview.rb
active_zuora-2.5.3 lib/active_zuora/billing_preview.rb
active_zuora-2.5.2 lib/active_zuora/billing_preview.rb
active_zuora-2.5.1 lib/active_zuora/billing_preview.rb
active_zuora-2.5.0 lib/active_zuora/billing_preview.rb
active_zuora-2.4.1 lib/active_zuora/billing_preview.rb
active_zuora-2.4.0 lib/active_zuora/billing_preview.rb
active_zuora-2.3.1 lib/active_zuora/billing_preview.rb