Sha256: 21c23b19ded72655bcc5c6da4f2a6369eeb75cb8ca907886150f851c1bddb572

Contents?: true

Size: 685 Bytes

Versions: 2

Compression:

Stored size: 685 Bytes

Contents

module SpreeAvataxOfficial
  module Transactions
    class FindOrderTransactionService < SpreeAvataxOfficial::Base
      def call(order:)
        return success(true)  if order.avatax_sales_invoice_transaction.present?
        return failure(false) if get_transaction(order).failure?

        order.create_avatax_sales_invoice_transaction(code: order.number)

        # ensure taxable items have avatax_uuid
        order.taxable_items.each { |item| item.update(avatax_uuid: SecureRandom.uuid) }

        success(true)
      end

      private

      def get_transaction(order)
        SpreeAvataxOfficial::Transactions::GetByCodeService.call(order: order)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_avatax_official-1.8.0 app/services/spree_avatax_official/transactions/find_order_transaction_service.rb
spree_avatax_official-1.7.1 app/services/spree_avatax_official/transactions/find_order_transaction_service.rb