mirror of
https://github.com/we-promise/sure.git
synced 2026-07-21 09:15:23 +00:00
- Add WiseItem/WiseAccount models with full sync pipeline (importer, syncer, processor) - Detect income vs expense using targetAccount == recipientId from borderless accounts API - Support JAR (SAVINGS) accounts with totalWorth balance and savings subtype - Fetch JAR activity via profile activities API (INTERBALANCE, BALANCE_CASHBACK, BALANCE_ASSET_FEE) - Route INTERBALANCE activities to both JAR and STANDARD accounts and link as Transfer records - Add provider connection status registration, routes, views, and i18n - Add migration for wise_items and wise_accounts tables - Add tests for WiseAccount, WiseEntry::Processor, WiseActivity::Processor, WiseItem::Importer, and WiseItem#link_jar_transfers!
45 lines
1.3 KiB
Ruby
45 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class WiseAccount::Processor
|
|
attr_reader :wise_account
|
|
|
|
def initialize(wise_account)
|
|
@wise_account = wise_account
|
|
end
|
|
|
|
def process
|
|
unless wise_account.current_account.present?
|
|
Rails.logger.info "WiseAccount::Processor - No linked account for wise_account #{wise_account.id}, skipping"
|
|
return
|
|
end
|
|
|
|
process_account!
|
|
process_transactions
|
|
rescue StandardError => e
|
|
Rails.logger.error "WiseAccount::Processor - Failed to process account #{wise_account.id}: #{e.message}"
|
|
Sentry.capture_exception(e) { |s| s.set_tags(wise_account_id: wise_account.id) }
|
|
raise
|
|
end
|
|
|
|
private
|
|
|
|
def process_account!
|
|
account = wise_account.current_account
|
|
balance = wise_account.current_balance || 0
|
|
|
|
account.update!(
|
|
balance: balance,
|
|
cash_balance: balance,
|
|
currency: wise_account.currency
|
|
)
|
|
end
|
|
|
|
def process_transactions
|
|
WiseAccount::Transactions::Processor.new(wise_account).process
|
|
rescue StandardError => e
|
|
Rails.logger.error "WiseAccount::Processor - Failed to process transactions for wise_account #{wise_account.id}: #{e.message}"
|
|
Rails.logger.error Array(e.backtrace).first(10).join("\n")
|
|
Sentry.capture_exception(e) { |s| s.set_tags(wise_account_id: wise_account.id) }
|
|
end
|
|
end
|