Sha256: c1c683c39fda71b181a82cb49158b8c4cb481c08cdaf67a70e5455bba11a72fe

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

module LedgerSync
  module Adaptors
    module QuickBooksOnline
      module Transfer
        module Operations
          class Create < Operation::Create
            class Contract < LedgerSync::Adaptors::Contract
              params do
                required(:ledger_id).value(:nil)
                required(:from_account).hash(Types::Reference)
                required(:to_account).hash(Types::Reference)
                required(:amount).filled(:integer)
                required(:currency).filled(:string)
                required(:memo).filled(:string)
                required(:transaction_date).filled(:date?)
              end
            end

            private

            def operate
              response = adaptor.post(
                resource: 'transfer',
                payload: local_resource_data
              )

              resource.ledger_id = response.dig('Id')
              success(response: response)
            end

            def local_resource_data
              {
                'CurrencyRef' => {
                  'value' => resource.currency,
                },
                'Amount' => resource.amount,
                'TxnDate' => resource.transaction_date.to_s, # Format: YYYY-MM-DD
                'PrivateNote' => resource.memo,
                'FromAccountRef' => {
                  'value' => resource.from_account.ledger_id
                },
                'ToAccountRef' => {
                  'value' => resource.to_account.ledger_id
                }
              }
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ledger_sync-1.1.1 lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/create.rb