Sha256: e06ef60db6f5e93bba764c83fc1a24476173365bb596d9cee6a27d1f47faee36

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'savon'
require 'logger'

module Cetustek
  module Services
    class InvoiceService
      def initialize(xml, order_id = nil)
        @xml = xml
        @order_id = order_id
      end

      def create
        client = build_soap_client
        response = call_create_invoice(client)
        log_response(response)
        response
      end

      private

      def build_soap_client
        Savon.client(
          wsdl: Cetustek.config.url,
          open_timeout: 300,
          read_timeout: 300
        )
      end

      def call_create_invoice(client)
        client.call(:create_invoice_v3, message: {
          invoicexml: @xml,
          source: Cetustek.config.site_id + Cetustek.config.password,
          rentid: Cetustek.config.username,
          hastax: 1
        })
      end

      def log_response(response)
        return unless defined?(Rails)

        logger = Logger.new(Rails.root.join('log/invoice.log'))
        logger.debug("#{@order_id} - #{response.body}") if @order_id
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cetustek-0.2.0 lib/cetustek/services/invoice_service.rb