Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/f2ynab/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module F2ynab
VERSION = "0.1.3"
VERSION = "0.1.4"
end
5 changes: 3 additions & 2 deletions lib/f2ynab/webhooks/monzo.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module F2ynab
module Webhooks
class Monzo
def initialize(ynab_client, webhook, skip_tags: false, skip_foreign_currency_flag: false, skip_emoji: false)
def initialize(ynab_client, webhook, skip_tags: false, skip_foreign_currency_flag: false, skip_emoji: false, omit_import_id: false)
@ynab_client = ynab_client
@webhook = webhook
@skip_tags = skip_tags
@skip_foreign_currency_flag = skip_foreign_currency_flag
@skip_emoji = skip_emoji
@omit_import_id = omit_import_id
end

def import
Expand Down Expand Up @@ -44,7 +45,7 @@ def import

::F2ynab::YNAB::TransactionCreator.new(
@ynab_client,
id: @webhook[:data][:id],
id: @omit_import_id ? nil : @webhook[:data][:id],
date: Time.parse(@webhook[:data][:created]).to_date,
amount: @webhook[:data][:amount] * 10,
payee_name: payee_name,
Expand Down
5 changes: 3 additions & 2 deletions lib/f2ynab/webhooks/starling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ class Starling
INTEREST_CHARGE
]

def initialize(ynab_client, webhook, skip_foreign_currency_flag: false)
def initialize(ynab_client, webhook, skip_foreign_currency_flag: false, omit_import_id: false)
@webhook = webhook
@ynab_client = ynab_client
@skip_foreign_currency_flag = skip_foreign_currency_flag
@omit_import_id = omit_import_id
end

def import
Expand All @@ -54,7 +55,7 @@ def import

::F2ynab::YNAB::TransactionCreator.new(
@ynab_client,
id: "S:#{@webhook[:content][:transactionUid]}",
id: @omit_import_id ? nil : "S:#{@webhook[:content][:transactionUid]}",
date: Time.parse(@webhook[:timestamp]).to_date,
amount: amount,
payee_name: payee_name,
Expand Down
24 changes: 13 additions & 11 deletions lib/f2ynab/ynab/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ def transactions(since_date: nil, account_id: nil)
end

def create_transaction(id: nil, payee_id: nil, payee_name: nil, amount: nil, cleared: nil, date: nil, memo: nil, flag: nil)
transaction_params = {
account_id: selected_account_id,
date: date.to_s,
amount: amount,
payee_id: payee_id,
payee_name: payee_name,
cleared: cleared ? "Cleared" : 'Uncleared',
memo: memo,
flag_color: flag,
}
transaction_params[:import_id] = id unless id.nil? || id.empty?

client.transactions.create_transaction(
selected_budget_id,
transaction: {
account_id: selected_account_id,
date: date.to_s,
amount: amount,
payee_id: payee_id,
payee_name: payee_name,
cleared: cleared ? "Cleared" : 'Uncleared',
memo: memo,
flag_color: flag,
import_id: id,
},
transaction: transaction_params,
).data.transaction
rescue StandardError => e
Rails.logger.error('YNAB::Client.create_transaction failure')
Expand Down