Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

fix(trade-republic): import unmapped card, stamp duty and bonus events (#4038)

Simone8f161967bbdd
diff --git a/app/models/provider/trade_republic_client.rb b/app/models/provider/trade_republic_client.rb
index 1ba03ae246..d69559aad1 100644
--- a/app/models/provider/trade_republic_client.rb
+++ b/app/models/provider/trade_republic_client.rb
@@ -57,7 +57,10 @@ class Provider::TradeRepublicClient
TRADE_DETAIL_EVENT_TYPES = %w[
SAVEBACK_AGGREGATE
SPARE_CHANGE_AGGREGATE
+ ACQUISITION_TRADE_PERK
].freeze
+ # A stock bonus is titled "Stock Bonus"; its asset row names the stock.
+ STOCK_PERK_EVENT_TYPE = "ACQUISITION_TRADE_PERK"
# New dividends also fetch timelineDetailV2 so provider_detail keeps the
# ISIN, share count, dividend per share and withholding tax. The imported
# cash amount still comes from the timeline list.
@@ -1586,7 +1589,7 @@ class Provider::TradeRepublicClient
{
"isin" => find_isin(item) || find_isin(raw) || find_logo_isin(raw),
- "name" => item&.dig("title") || find_asset_name(raw),
+ "name" => detail_name(item, raw),
"quantity" => decimal_string(quantity),
"price" => decimal_string(price),
"amount" => decimal_string(amount&.abs),
@@ -1663,6 +1666,12 @@ class Provider::TradeRepublicClient
isin
end
+ def detail_name(item, raw)
+ return find_asset_name(raw) || item&.dig("title") if item&.dig("eventType") == STOCK_PERK_EVENT_TYPE
+
+ item&.dig("title") || find_asset_name(raw)
+ end
+
def find_asset_name(raw)
rows = collect_sections(raw).flat_map { |section| Array(section["data"]) }
row = rows.find { |candidate| %w[wertpapier asset vermögenswert security].include?(candidate["title"].to_s.downcase) }
diff --git a/app/models/provider/trade_republic_timeline_event.rb b/app/models/provider/trade_republic_timeline_event.rb
index 193c1c5ac3..73cfdfa241 100644
--- a/app/models/provider/trade_republic_timeline_event.rb
+++ b/app/models/provider/trade_republic_timeline_event.rb
@@ -33,6 +33,7 @@ module Provider::TradeRepublicTimelineEvent
"PAYMENT_INBOUND_SEPA_DIRECT_DEBIT" => "PAYMENT_RECEIVED",
"PAYMENT_INBOUND_APPLE_PAY" => "PAYMENT_RECEIVED",
"PAYMENT_INBOUND_GOOGLE_PAY" => "PAYMENT_RECEIVED",
+ "PAYMENT_INBOUND_CREDIT_CARD" => "PAYMENT_RECEIVED",
"BANK_TRANSACTION_OUTGOING" => "POC_CREATED",
"BANK_TRANSACTION_OUTGOING_DIRECT_DEBIT" => "POC_CREATED",
"OUTGOING_TRANSFER" => "POC_CREATED",
@@ -48,8 +49,19 @@ module Provider::TradeRepublicTimelineEvent
"CARD_REFUND" => "PAYMENT_RECEIVED",
"SPARE_CHANGE_AGGREGATE" => "POC_CREATED",
"SAVEBACK_AGGREGATE" => "POC_CREATED",
+ "ACQUISITION_TRADE_PERK" => "POC_CREATED",
"BANK_TRANSACTION_OUTGOING_SCHEDULED" => "POC_CREATED",
"CARD_ATM_WITHDRAWAL" => "POC_CREATED",
+ # Card-funded transfers out (Account Funding Transaction), e.g. topping up
+ # PayPal, Revolut or Paysafecard with the Trade Republic card.
+ "CARD_AFT" => "POC_CREATED",
+ # Card-funded credits (Original Credit Transaction), e.g. a merchant
+ # refund pushed to the card.
+ "CARD_OCT" => "PAYMENT_RECEIVED",
+ # Italian stamp duty (imposta di bollo) on cash and portfolio. A
+ # cancellation arrives with the same event type and is turned into a
+ # credit by the activities processor.
+ "STAMP_DUTY_TAX_PAID" => "POC_CREATED",
"SSP_CORPORATE_ACTION_CASH" => "DIVIDEND",
"ssp_corporate_action_invoice_cash" => "DIVIDEND",
"SSP_CORPORATE_ACTION_CASH_NON_DIVIDEND" => "PAYMENT_RECEIVED",
@@ -78,6 +90,8 @@ module Provider::TradeRepublicTimelineEvent
DOCUMENTS_CREATED
EX_POST_COST_REPORT_CREATED
TAX_YEAR_END_REPORT_CREATED
+ TAX_YEAR_END_REPORT_CORRECTED
+ AML_SOURCE_OF_WEALTH_RESPONSE_EXECUTED
QUARTERLY_REPORT
QUARTERLY_NET_WORTH_STATEMENT_CREATED
CARD_VERIFICATION
@@ -113,6 +127,8 @@ module Provider::TradeRepublicTimelineEvent
].freeze
DECLINED_SUBTITLE_PATTERN = /declin|failed|reject|cancel/i
+ STAMP_DUTY_EVENT_TYPE = "STAMP_DUTY_TAX_PAID"
+ STAMP_DUTY_CANCELLATION_PATTERN = /cancellation/i
LIFECYCLE_KEYS = %w[status deleted hidden badge].freeze
class << self
@@ -175,6 +191,17 @@ module Provider::TradeRepublicTimelineEvent
nil
end
+ # Trade Republic reports a stamp duty refund as a STAMP_DUTY_TAX_PAID
+ # event whose subtitle says it is a cancellation. It is a real credit,
+ # not a cancelled event.
+ def stamp_duty_cancellation?(event)
+ return false unless event.is_a?(Hash)
+
+ event = event.with_indifferent_access
+ event[:eventType].to_s == STAMP_DUTY_EVENT_TYPE &&
+ event[:subtitle].to_s.match?(STAMP_DUTY_CANCELLATION_PATTERN)
+ end
+
def resolved_category(event)
event = event.with_indifferent_access
event[:category].to_s.presence || EVENT_TYPE_CATEGORIES[event[:eventType].to_s]
@@ -208,9 +235,13 @@ module Provider::TradeRepublicTimelineEvent
# Only subtitle/badge — never title. Titles are often security or
# merchant names and can contain substrings like "cancel" without
- # meaning the event itself failed.
+ # meaning the event itself failed. A stamp duty cancellation's
+ # subtitle names the refund, so only its badge counts.
def declined_subtitle?(event)
- [ event[:subtitle], event[:badge] ].compact.any? do |value|
+ values = [ event[:badge] ]
+ values << event[:subtitle] unless stamp_duty_cancellation?(event)
+
+ values.compact.any? do |value|
value.to_s.match?(DECLINED_SUBTITLE_PATTERN)
end
end
diff --git a/app/models/trade_republic_account/activities_processor.rb b/app/models/trade_republic_account/activities_processor.rb
index 8abf1135f0..9476650064 100644
--- a/app/models/trade_republic_account/activities_processor.rb
+++ b/app/models/trade_republic_account/activities_processor.rb
@@ -2,6 +2,9 @@ class TradeRepublicAccount::ActivitiesProcessor
include TradeRepublicAccount::DataHelpers
SAVEBACK_EVENT_TYPE = "SAVEBACK_AGGREGATE"
+ STOCK_PERK_EVENT_TYPE = "ACQUISITION_TRADE_PERK"
+ # Shares Trade Republic pays for: a trade only, without a cash leg.
+ BROKER_FUNDED_TRADE_EVENT_TYPES = [ SAVEBACK_EVENT_TYPE, STOCK_PERK_EVENT_TYPE ].freeze
ROUND_UP_EVENT_TYPE = "SPARE_CHANGE_AGGREGATE"
SAVINGS_PLAN_INVOICE_EVENT_TYPE = "SAVINGS_PLAN_INVOICE_CREATED"
SAVINGS_PLAN_EXECUTION_EVENT_TYPES = %w[TRADING_SAVINGSPLAN_EXECUTED SAVINGS_PLAN_EXECUTED].freeze
@@ -144,11 +147,12 @@ class TradeRepublicAccount::ActivitiesProcessor
.to_set
end
- # Saveback and Round Up stay classified as POC_CREATED at the client
- # boundary so other cash withdrawals are unchanged. Routing happens here
- # by eventType: Saveback is a trade only; Round Up is a trade plus cash
- # outflow when both accounts are linked. Crypto trades go to the Crypto
- # account once it is linked, except a portfolio copy the user edited.
+ # Saveback, stock bonuses and Round Up stay classified as POC_CREATED at
+ # the client boundary so other cash withdrawals are unchanged. Routing
+ # happens here by eventType: Saveback and stock bonuses are a trade only;
+ # Round Up is a trade plus cash outflow when both accounts are linked.
+ # Crypto trades go to the Crypto account once it is linked, except a
+ # portfolio copy the user edited.
def processable_event?(event)
event_type = event[:eventType].to_s
@@ -157,7 +161,7 @@ class TradeRepublicAccount::ActivitiesProcessor
return false if @trade_republic_account.crypto? && protected_portfolio_trade?(event)
end
- return @trade_republic_account.holds_securities? if saveback_event?(event_type)
+ return @trade_republic_account.holds_securities? if broker_funded_trade_event?(event_type)
return true if round_up_event?(event_type)
category = event[:category].to_s
@@ -183,7 +187,7 @@ class TradeRepublicAccount::ActivitiesProcessor
detail = event[:detail] || {}
event_type = event[:eventType].to_s
- return process_saveback(event, detail, external_id, date) if saveback_event?(event_type)
+ return process_broker_funded_trade(event, detail, external_id, date) if broker_funded_trade_event?(event_type)
return process_round_up(event, detail, external_id, date) if round_up_event?(event_type)
case event_category(event)
@@ -214,10 +218,12 @@ class TradeRepublicAccount::ActivitiesProcessor
nil
end
- def process_saveback(event, detail, external_id, date)
+ # Trade Republic pays for Saveback and stock bonuses: no cash moves
+ # anywhere, so the trade must not move the portfolio's cash either.
+ def process_broker_funded_trade(event, detail, external_id, date)
return nil unless @trade_republic_account.holds_securities?
- import_order_execution(event, detail, external_id, date) ? :trade : nil
+ import_order_execution(event, detail, external_id, date, moves_cash: false) ? :trade : nil
end
def process_round_up(event, detail, external_id, date)
@@ -266,15 +272,15 @@ class TradeRepublicAccount::ActivitiesProcessor
[ detail[:isin].to_s, date, parse_decimal(detail[:quantity])&.abs ]
end
- def saveback_event?(event_type)
- event_type == SAVEBACK_EVENT_TYPE
+ def broker_funded_trade_event?(event_type)
+ BROKER_FUNDED_TRADE_EVENT_TYPES.include?(event_type)
end
def round_up_event?(event_type)
event_type == ROUND_UP_EVENT_TYPE
end
- def import_order_execution(event, detail, external_id, date)
+ def import_order_execution(event, detail, external_id, date, moves_cash: true)
isin = detail[:isin].to_s
quantity = parse_decimal(detail[:quantity])
@@ -326,7 +332,9 @@ class TradeRepublicAccount::ActivitiesProcessor
security: security,
quantity: signed_quantity,
price: price,
- amount: signed_amount,
+ # Without a cash leg the value lives in qty and price, which is all
+ # the cost basis needs.
+ amount: moves_cash ? signed_amount : 0,
fee: fee,
currency: detail[:currency].presence || currency,
date: date,
@@ -586,20 +594,25 @@ class TradeRepublicAccount::ActivitiesProcessor
def event_category(event)
signed_amount = parse_decimal(event.dig(:detail, :signed_amount) || event.dig(:detail, :amount))
return CATEGORY_WITHDRAWAL if event[:eventType].to_s == "CARD_CASH_BACK" && signed_amount&.negative?
+ # Trade Republic reports a stamp duty cancellation with the same event
+ # type and sign as the charge; it is a refund to the account.
+ return CATEGORY_DEPOSIT if Provider::TradeRepublicTimelineEvent.stamp_duty_cancellation?(event)
event[:category].to_s.presence ||
Provider::TradeRepublicClient::EVENT_TYPE_CATEGORIES[event[:eventType].to_s].to_s
end
def cash_label_key(event, default:)
+ return "tax_refund" if Provider::TradeRepublicTimelineEvent.stamp_duty_cancellation?(event)
+
case event[:eventType].to_s
- when "CARD_TRANSACTION", "card_successful_transaction", "CARD_CASH_BACK"
+ when "CARD_TRANSACTION", "card_successful_transaction", "CARD_CASH_BACK", "CARD_AFT"
"card_payment"
when "CARD_ATM_WITHDRAWAL"
"cash_withdrawal"
when "CARD_ORDER_FEE"
"card_fee"
- when "card_refund", "CARD_REFUND"
+ when "card_refund", "CARD_REFUND", "CARD_OCT"
"card_refund"
when "TAX_REFUND", "SSP_TAX_CORRECTION", "ssp_tax_correction_invoice"
"tax_refund"
diff --git a/app/models/trade_republic_account/data_helpers.rb b/app/models/trade_republic_account/data_helpers.rb
index 0f62c89d2b..dedf54d84a 100644
--- a/app/models/trade_republic_account/data_helpers.rb
+++ b/app/models/trade_republic_account/data_helpers.rb
@@ -9,6 +9,7 @@ module TradeRepublicAccount::DataHelpers
PAYMENT_INBOUND PAYMENT_OUTBOUND INCOMING_TRANSFER OUTGOING_TRANSFER
INCOMING_TRANSFER_DELEGATION OUTGOING_TRANSFER_DELEGATION
PAYMENT_INBOUND_SEPA_DIRECT_DEBIT PAYMENT_INBOUND_APPLE_PAY PAYMENT_INBOUND_GOOGLE_PAY
+ PAYMENT_INBOUND_CREDIT_CARD
].freeze
class << self
diff --git a/test/models/trade_republic_account_activities_processor_test.rb b/test/models/trade_republic_account_activities_processor_test.rb
index 134f6df445..d5e9b32fda 100644
--- a/test/models/trade_republic_account_activities_processor_test.rb
+++ b/test/models/trade_republic_account_activities_processor_test.rb
@@ -341,6 +341,115 @@ class TradeRepublicAccountActivitiesProcessorTest < ActiveSupport::TestCase
assert_equal "Card purchase", entry.transaction.extra.dig("trade_republic", "subtitle")
end
+ test "card funding transactions are imported as card payments" do
+ import_event({
+ id: "evt_card_aft",
+ timestamp: "2026-02-21T11:13:04Z",
+ eventType: "CARD_AFT",
+ title: "Revolut",
+ status: "EXECUTED",
+ detail: { amount: -100.0, signed_amount: -100.0, currency: "EUR" }
+ })
+
+ entry = Entry.find_by!(external_id: "trade_republic_event_evt_card_aft")
+ assert_equal BigDecimal("100.0"), entry.amount
+ assert_equal "Revolut", entry.name
+ end
+
+ test "card credit transactions are imported as money in" do
+ import_event({
+ id: "evt_card_oct",
+ timestamp: "2026-03-16T18:01:01Z",
+ eventType: "CARD_OCT",
+ title: "Refund Globalblue.com",
+ status: "EXECUTED",
+ detail: { amount: 2.96, signed_amount: 2.96, currency: "EUR" }
+ })
+
+ assert_equal BigDecimal("-2.96"), Entry.find_by!(external_id: "trade_republic_event_evt_card_oct").amount
+ end
+
+ test "credit card top-ups are imported as money in" do
+ import_event({
+ id: "evt_credit_card_cash_in",
+ timestamp: "2024-12-11T10:00:00Z",
+ eventType: "PAYMENT_INBOUND_CREDIT_CARD",
+ title: "Cash In",
+ status: "EXECUTED",
+ detail: { amount: 500.0, signed_amount: 500.0, currency: "EUR" }
+ })
+
+ assert_equal BigDecimal("-500"), Entry.find_by!(external_id: "trade_republic_event_evt_credit_card_cash_in").amount
+ end
+
+ test "stamp duty is imported as a charge and its cancellation as a refund" do
+ @tr_account.update!(raw_timeline_payload: [
+ {
+ id: "evt_stamp_duty",
+ timestamp: "2026-02-18T14:34:02Z",
+ eventType: "STAMP_DUTY_TAX_PAID",
+ title: "Stamp duty (Portfolio)",
+ status: "EXECUTED",
+ detail: { amount: -22.24, signed_amount: -22.24, currency: "EUR" }
+ },
+ {
+ id: "evt_stamp_duty_cancel",
+ timestamp: "2026-02-18T09:37:01Z",
+ eventType: "STAMP_DUTY_TAX_PAID",
+ title: "Stamp duty (Portfolio)",
+ subtitle: "Cancellation of stamp duty",
+ status: "EXECUTED",
+ detail: { amount: -20.99, signed_amount: -20.99, currency: "EUR" }
+ }
+ ])
+ TradeRepublicAccount::ActivitiesProcessor.new(@tr_account.reload).process
+
+ assert_equal BigDecimal("22.24"), Entry.find_by!(external_id: "trade_republic_event_evt_stamp_duty").amount
+ assert_equal BigDecimal("-20.99"), Entry.find_by!(external_id: "trade_republic_event_evt_stamp_duty_cancel").amount
+ end
+
+ test "stamp duty cancellation without a status is still imported as a refund" do
+ import_event({
+ id: "evt_stamp_duty_cancel_no_status",
+ timestamp: "2026-02-18T09:37:01Z",
+ eventType: "STAMP_DUTY_TAX_PAID",
+ title: "Stamp duty (Portfolio)",
+ subtitle: "Cancellation of stamp duty",
+ detail: { amount: -20.99, signed_amount: -20.99, currency: "EUR" }
+ })
+
+ assert_equal BigDecimal("-20.99"), Entry.find_by!(external_id: "trade_republic_event_evt_stamp_duty_cancel_no_status").amount
+ end
+
+ test "a stamp duty refund on a portfolio account is not booked as a contribution" do
+ import_event({
+ id: "evt_stamp_duty_refund",
+ timestamp: "2026-02-18T09:37:01Z",
+ eventType: "STAMP_DUTY_TAX_PAID",
+ title: "Stamp duty (Portfolio)",
+ subtitle: "Cancellation of stamp duty",
+ status: "EXECUTED",
+ detail: { amount: -20.99, signed_amount: -20.99, currency: "EUR" }
+ })
+
+ transaction = Entry.find_by!(external_id: "trade_republic_event_evt_stamp_duty_refund").transaction
+ assert_nil transaction.investment_activity_label
+ assert_equal "standard", transaction.kind
+ end
+
+ test "a voided stamp duty charge is not imported as a refund" do
+ import_event({
+ id: "evt_stamp_duty_voided",
+ timestamp: "2026-02-18T09:37:01Z",
+ eventType: "STAMP_DUTY_TAX_PAID",
+ title: "Stamp duty (Portfolio)",
+ subtitle: "Cancelled",
+ detail: { amount: -20.99, signed_amount: -20.99, currency: "EUR" }
+ })
+
+ assert_nil Entry.find_by(external_id: "trade_republic_event_evt_stamp_duty_voided")
+ end
+
test "category direction wins over the provider signed amount" do
import_event({
id: "evt_incoming_signed",
@@ -568,12 +677,38 @@ class TradeRepublicAccountActivitiesProcessorTest < ActiveSupport::TestCase
assert_equal "Trade", trade.entryable_type
assert_equal BigDecimal("0.09329"), trade.entryable.qty
assert_equal "Buy", trade.entryable.investment_activity_label
- assert_equal BigDecimal("3.74"), trade.amount
+ # Trade Republic pays for Saveback, so the portfolio's cash must not move;
+ # the value stays in the price for the cost basis.
+ assert_equal 0, trade.amount
+ assert_in_delta BigDecimal("3.74"), trade.entryable.qty * trade.entryable.price, BigDecimal("0.01")
assert_equal "SAVEBACK_AGGREGATE", trade.entryable.extra.dig("trade_republic", "event_type")
assert_not Entry.exists?(account: cash_sure, external_id: "trade_republic_event_evt_saveback")
end
+ test "a stock bonus imports as a portfolio trade without a cash leg" do
+ cash_account, cash_sure = create_linked_cash_account!
+
+ bonus = stock_bonus_event
+ @tr_account.update!(raw_timeline_payload: [ bonus ])
+ cash_account.update!(raw_timeline_payload: [ bonus ])
+
+ TradeRepublicAccount::ActivitiesProcessor.new(@tr_account.reload).process
+ TradeRepublicAccount::ActivitiesProcessor.new(cash_account.reload).process
+
+ trade = find_trade("trade_republic_event_evt_stock_bonus")
+ assert_equal "Trade", trade.entryable_type
+ assert_equal BigDecimal("0.055"), trade.entryable.qty
+ # No cash moved, so the portfolio's cash must not move either; the value
+ # stays in the price for the cost basis.
+ assert_equal 0, trade.amount
+ assert_in_delta BigDecimal("10.04"), trade.entryable.qty * trade.entryable.price, BigDecimal("0.01")
+ assert_equal "ACQUISITION_TRADE_PERK", trade.entryable.extra.dig("trade_republic", "event_type")
+
+ assert_not Entry.exists?(account: cash_sure, external_id: "trade_republic_event_evt_stock_bonus")
+ assert_not @account.entries.exists?(external_id: "trade_republic_settlement_evt_stock_bonus")
+ end
+
test "round up imports as a portfolio trade and a cash outflow when split" do
cash_account, cash_sure = create_linked_cash_account!
@@ -1682,6 +1817,25 @@ class TradeRepublicAccountActivitiesProcessorTest < ActiveSupport::TestCase
}
end
+ # Shaped like a stored stock bonus: no status, no amount on the timeline,
+ # shares and value from the detail.
+ def stock_bonus_event
+ {
+ id: "evt_stock_bonus",
+ timestamp: "2025-06-25T14:52:12.282+0000",
+ eventType: "ACQUISITION_TRADE_PERK",
+ title: "Stock Bonus",
+ subtitle: "Redeemed",
+ detail: {
+ amount: "10.04",
+ currency: "EUR",
+ quantity: "0.055",
+ isin: "US0231351067",
+ name: "Amazon.com"
+ }
+ }
+ end
+
def round_up_event
{
id: "evt_round_up",
diff --git a/test/models/trade_republic_client_test.rb b/test/models/trade_republic_client_test.rb
index 69d6fe1f34..775808650b 100644
--- a/test/models/trade_republic_client_test.rb
+++ b/test/models/trade_republic_client_test.rb
@@ -1097,6 +1097,83 @@ class TradeRepublicClientTest < ActiveSupport::TestCase
)
end
+ test "maps card funding, card credit and stamp duty events to cash categories" do
+ categories = Provider::TradeRepublicClient::EVENT_TYPE_CATEGORIES
+ assert_equal "POC_CREATED", categories["CARD_AFT"]
+ assert_equal "PAYMENT_RECEIVED", categories["CARD_OCT"]
+ assert_equal "POC_CREATED", categories["STAMP_DUTY_TAX_PAID"]
+
+ %w[CARD_AFT CARD_OCT STAMP_DUTY_TAX_PAID].each do |event_type|
+ assert_equal :financial, Provider::TradeRepublicTimelineEvent.classify("eventType" => event_type), event_type
+ end
+ end
+
+ test "maps credit card top-ups and stock bonuses" do
+ categories = Provider::TradeRepublicClient::EVENT_TYPE_CATEGORIES
+ assert_equal "PAYMENT_RECEIVED", categories["PAYMENT_INBOUND_CREDIT_CARD"]
+ assert_equal "POC_CREATED", categories["ACQUISITION_TRADE_PERK"]
+
+ %w[PAYMENT_INBOUND_CREDIT_CARD ACQUISITION_TRADE_PERK].each do |event_type|
+ assert_equal :financial, Provider::TradeRepublicTimelineEvent.classify("eventType" => event_type), event_type
+ end
+ assert Provider::TradeRepublicClient.requires_trade_detail?("eventType" => "ACQUISITION_TRADE_PERK")
+ end
+
+ test "normalize_event_detail names a stock bonus after its asset" do
+ detail = @client.send(:normalize_event_detail, stock_bonus_detail,
+ item: { "title" => "Stock Bonus", "subtitle" => "Redeemed", "eventType" => "ACQUISITION_TRADE_PERK" })
+
+ assert_equal "US0231351067", detail["isin"]
+ assert_equal "Amazon.com", detail["name"]
+ assert_equal "0.055", detail["quantity"]
+ assert_equal "10.04", detail["amount"]
+ end
+
+ test "stamp duty cancellations are not treated as declined events" do
+ cancellation = {
+ "eventType" => "STAMP_DUTY_TAX_PAID",
+ "title" => "Stamp duty (Portfolio)",
+ "subtitle" => "Cancellation of stamp duty"
+ }
+
+ assert Provider::TradeRepublicTimelineEvent.stamp_duty_cancellation?(cancellation)
+ assert_not Provider::TradeRepublicTimelineEvent.lifecycle_blocks_import?(cancellation)
+ assert Provider::TradeRepublicTimelineEvent.lifecycle_blocks_import?(cancellation.merge("status" => "CANCELED"))
+ assert Provider::TradeRepublicTimelineEvent.lifecycle_blocks_import?(
+ "eventType" => "CARD_TRANSACTION", "subtitle" => "Cancelled"
+ )
+ end
+
+ test "a voided stamp duty charge is blocked, not treated as a cancellation" do
+ voided = {
+ "eventType" => "STAMP_DUTY_TAX_PAID",
+ "title" => "Stamp duty (Portfolio)",
+ "subtitle" => "Cancelled"
+ }
+
+ assert_not Provider::TradeRepublicTimelineEvent.stamp_duty_cancellation?(voided)
+ assert Provider::TradeRepublicTimelineEvent.lifecycle_blocks_import?(voided)
+ assert_not Provider::TradeRepublicTimelineEvent.importable?(voided)
+ end
+
+ test "a failed badge still blocks a stamp duty cancellation" do
+ cancellation = {
+ "eventType" => "STAMP_DUTY_TAX_PAID",
+ "title" => "Stamp duty (Portfolio)",
+ "subtitle" => "Cancellation of stamp duty"
+ }
+
+ assert Provider::TradeRepublicTimelineEvent.lifecycle_blocks_import?(cancellation.merge("badge" => "Failed"))
+ assert Provider::TradeRepublicTimelineEvent.lifecycle_blocks_import?(cancellation.merge("badge" => "Declined"))
+ assert_not Provider::TradeRepublicTimelineEvent.importable?(cancellation.merge("badge" => "Failed"))
+ end
+
+ test "ignores tax report corrections and source of wealth checks" do
+ %w[TAX_YEAR_END_REPORT_CORRECTED AML_SOURCE_OF_WEALTH_RESPONSE_EXECUTED].each do |event_type|
+ assert_equal :ignored, Provider::TradeRepublicTimelineEvent.classify("eventType" => event_type), event_type
+ end
+ end
+
test "ignores Legal documents timeline rows without an event type" do
assert_equal :ignored, Provider::TradeRepublicTimelineEvent.classify(
"title" => "Legal documents",
@@ -2237,6 +2314,32 @@ class TradeRepublicClientTest < ActiveSupport::TestCase
private
+ # Trimmed from a real Trade Republic stock bonus (ACQUISITION_TRADE_PERK).
+ def stock_bonus_detail
+ row = ->(title, text) { { "title" => title, "detail" => { "text" => text, "type" => "text" }, "style" => "plain" } }
+
+ {
+ "id" => "stock-bonus",
+ "sections" => [
+ {
+ "title" => "Amazon.com stock bonus",
+ "type" => "header",
+ "data" => { "icon" => { "asset" => "logos/US0231351067/v2", "badge" => nil }, "status" => "executed" }
+ },
+ { "title" => "Overview", "type" => "table", "data" => [
+ { "title" => "Buy", "detail" => { "text" => "Completed", "functionalStyle" => "EXECUTED", "type" => "status" } },
+ row.call("Asset", "Amazon.com"),
+ {
+ "title" => "Transaction",
+ "detail" => { "text" => "0.055 × € 182.46", "displayValue" => { "text" => "€ 182.46", "prefix" => "0.055 ×" }, "type" => "text" }
+ },
+ row.call("Fee", "Free"),
+ row.call("Total", "€ 10.04")
+ ] }
+ ]
+ }
+ end
+
def timeline_pass(events, newest_event_id, outcome: :finished)
Provider::TradeRepublicClient::TimelinePass.new(events: events, newest_event_id: newest_event_id, warnings: [], outcome: outcome, cursor: nil)
end