mirror of
https://github.com/we-promise/sure.git
synced 2026-04-14 01:24:06 +00:00
* First pass lunch flow * Fixes - Fix apikey not being saved properly due to provider no reload support - Fix proper messages if we try to link existing accounts. * Fix better error handling * Filter existing transactions and skip duplicates * FIX messaging * Branding :) * Fix XSS and linter * FIX provider concern - also fix code duplication * FIX md5 digest * Updated determine_sync_start_date to be account-aware * Review fixes * Broaden error catch to not crash UI * Fix buttons styling * FIX process account error handling * FIX account cap and url parsing * Lunch Flow brand * Found orphan i18n strings * Remove per conversation with @sokie --------- Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
32 lines
1009 B
Ruby
32 lines
1009 B
Ruby
require "digest/md5"
|
|
|
|
# Detects and creates merchant records from SimpleFin transaction data
|
|
# SimpleFin provides clean payee data that works well for merchant identification
|
|
class SimplefinAccount::Transactions::MerchantDetector
|
|
def initialize(transaction_data)
|
|
@transaction_data = transaction_data.with_indifferent_access
|
|
end
|
|
|
|
def detect_merchant
|
|
# SimpleFin provides clean payee data - use it directly
|
|
payee = (transaction_data[:payee] || transaction_data["payee"])&.strip
|
|
return nil unless payee.present?
|
|
|
|
# Find or create merchant record using payee data
|
|
ProviderMerchant.find_or_create_by!(
|
|
source: "simplefin",
|
|
name: payee
|
|
) do |merchant|
|
|
merchant.provider_merchant_id = generate_merchant_id(payee)
|
|
end
|
|
end
|
|
|
|
private
|
|
attr_reader :transaction_data
|
|
|
|
def generate_merchant_id(merchant_name)
|
|
# Generate a consistent ID for merchants without explicit IDs
|
|
"simplefin_#{Digest::MD5.hexdigest(merchant_name.downcase)}"
|
|
end
|
|
end
|