mirror of
https://github.com/we-promise/sure.git
synced 2026-04-18 11:34:13 +00:00
Fix "invisible" merchants (#262)
- Fix display issues on the settings -> merchants page. Currently it was showing only user created merchants, not provider created ones. - SimpleFin had its own MerchantDetector class that directly called ProviderMerchant.find_or_create_by! - This was inconsistent with Plaid and Lunchflow which use the centralized import_adapter.find_or_create_merchant method - Different unique keys: SimpleFin used source + name, others used source + provider_merchant_id
This commit is contained in:
@@ -4,7 +4,8 @@ class FamilyMerchantsController < ApplicationController
|
||||
def index
|
||||
@breadcrumbs = [ [ "Home", root_path ], [ "Merchants", nil ] ]
|
||||
|
||||
@family_merchants = Current.family.merchants.alphabetically
|
||||
# Show all merchants assigned to transactions (both FamilyMerchant and ProviderMerchant)
|
||||
@family_merchants = Current.family.assigned_merchants.alphabetically
|
||||
|
||||
render layout: "settings"
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
require "digest/md5"
|
||||
|
||||
class SimplefinEntry::Processor
|
||||
# simplefin_transaction is the raw hash fetched from SimpleFin API and converted to JSONB
|
||||
def initialize(simplefin_transaction, simplefin_account:)
|
||||
@@ -100,6 +102,22 @@ class SimplefinEntry::Processor
|
||||
|
||||
|
||||
def merchant
|
||||
@merchant ||= SimplefinAccount::Transactions::MerchantDetector.new(data).detect_merchant
|
||||
# Use SimpleFin's clean payee data for merchant detection
|
||||
payee = data[:payee]&.strip
|
||||
return nil unless payee.present?
|
||||
|
||||
@merchant ||= import_adapter.find_or_create_merchant(
|
||||
provider_merchant_id: generate_merchant_id(payee),
|
||||
name: payee,
|
||||
source: "simplefin"
|
||||
)
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
Rails.logger.error "SimplefinEntry::Processor - Failed to create merchant '#{payee}': #{e.message}"
|
||||
nil
|
||||
end
|
||||
|
||||
def generate_merchant_id(merchant_name)
|
||||
# Generate a consistent ID for merchants without explicit IDs
|
||||
"simplefin_#{Digest::MD5.hexdigest(merchant_name.downcase)}"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user