Sha256: 481483fc0a0385e34d6a0c475c07d6c3144cd93695d0f3561d30865a7c1d9077

Contents?: true

Size: 1.39 KB

Versions: 5

Compression:

Stored size: 1.39 KB

Contents

module LedgerSync
  module Adaptors
    module QuickBooksOnline
      module Payment
        module Operations
          class Upsert < Operation::Upsert
            class Contract < LedgerSync::Adaptors::Contract
              schema do
                required(:ledger_id).maybe(:string)
                required(:amount).filled(:integer)
                required(:currency).filled(:string)
                required(:customer).hash(Types::Reference)
              end
            end

            private

            def build
              op =  if qbo_payment?
                      Update.new(adaptor: adaptor, resource: resource)
                    else
                      Create.new(adaptor: adaptor, resource: resource)
                    end

              build_customer_operation
              add_root_operation(op)
            end

            def build_customer_operation
              customer = Customer::Operations::Upsert.new(
                adaptor: adaptor,
                resource: resource.customer
              )

              add_before_operation(customer)
            end

            def find_result
              @find_result ||= Find.new(
                adaptor: adaptor,
                resource: resource
              ).perform
            end

            def qbo_payment?
              find_result.success?
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ledger_sync-1.0.10 lib/ledger_sync/adaptors/quickbooks_online/payment/operations/upsert.rb
ledger_sync-1.0.9 lib/ledger_sync/adaptors/quickbooks_online/payment/operations/upsert.rb
ledger_sync-1.0.3 lib/ledger_sync/adaptors/quickbooks_online/payment/operations/upsert.rb
ledger_sync-1.0.2 lib/ledger_sync/adaptors/quickbooks_online/payment/operations/upsert.rb
ledger_sync-1.0.0 lib/ledger_sync/adaptors/quickbooks_online/payment/operations/upsert.rb