-
Notifications
You must be signed in to change notification settings - Fork 71
Begin creating RawPendingColumnTransaction and switch Column HCB codes to having the Column ID
#10704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Begin creating RawPendingColumnTransaction and switch Column HCB codes to having the Column ID
#10704
Changes from all commits
5d17da5
578e00d
a59d9bc
e400a24
66f9fe0
9931587
35cb6c1
aa31a43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,12 @@ def webhook | |||||||||||
| type = params[:type] | ||||||||||||
| if type == "ach.incoming_transfer.scheduled" | ||||||||||||
| handle_ach_incoming_transfer_scheduled | ||||||||||||
| elsif type == "ach.incoming_transfer.settled" | ||||||||||||
| handle_as_raw_pending_column_transaction | ||||||||||||
| elsif type == "wire.incoming_transfer.completed" | ||||||||||||
| handle_as_raw_pending_column_transaction | ||||||||||||
| elsif type == "swift.incoming_transfer.completed" | ||||||||||||
| handle_as_raw_pending_column_transaction | ||||||||||||
| elsif type == "ach.outgoing_transfer.returned" | ||||||||||||
| handle_ach_outgoing_transfer_returned | ||||||||||||
| elsif type == "check.outgoing_debit.settled" | ||||||||||||
|
|
@@ -50,6 +56,20 @@ def handle_ach_incoming_transfer_scheduled | |||||||||||
| # at this point, the ACH is approved! | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| def handle_as_raw_pending_column_transaction(column_event_type:) | ||||||||||||
| account_number = AccountNumber.find_by(column_id: @object[:account_number_id]) | ||||||||||||
| # we only create RawPendingColumnTransaction for transactions to | ||||||||||||
| # event-specific account numbers. | ||||||||||||
| return if account_number.nil? | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+62
to
+64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| RawPendingColumnTransaction.create!( | ||||||||||||
| amount_cents: @object["available_amount"], | ||||||||||||
| date_posted: @object["effective_at_utc"], | ||||||||||||
| column_transaction: @object, | ||||||||||||
| column_event_type: | ||||||||||||
| ) | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| def handle_ach_outgoing_transfer_returned | ||||||||||||
| AchTransfer.find_by(column_id: @object[:id])&.mark_failed!(reason: @object[:return_details].pick(:description)&.gsub(/\(trace #: \d+\)\Z/, "")&.strip) | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # == Schema Information | ||
| # | ||
| # Table name: raw_pending_column_transactions | ||
| # | ||
| # id :bigint not null, primary key | ||
| # amount_cents :integer not null | ||
| # column_event_type :integer not null | ||
| # column_transaction :jsonb not null | ||
| # date_posted :date not null | ||
| # description :text not null | ||
| # created_at :datetime not null | ||
| # updated_at :datetime not null | ||
| # column_id :string not null | ||
| # | ||
| # Indexes | ||
| # | ||
| # index_raw_pending_column_transactions_on_column_id (column_id) UNIQUE | ||
| # | ||
| class RawPendingColumnTransaction < ApplicationRecord | ||
| has_one :canonical_pending_transaction | ||
|
|
||
| after_create :create_canonical_pending_transaction, if: -> { canonical_pending_transaction.nil? } | ||
|
|
||
| enum :column_event_type, { | ||
sampoder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "swift.incoming_transfer.completed": 0, | ||
| "wire.incoming_transfer.completed": 1, | ||
| "ach.incoming_transfer.settled": 2 | ||
| } | ||
|
|
||
| def create_canonical_pending_transaction | ||
| column_account_number = Column::AccountNumber.find_by(column_id: column_transaction["account_number_id"]) | ||
| return unless column_account_number | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: When might we run into this scenario? Should we fail louder?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is common and we shouldn't fail for this - this is any time a transaction hits our main account number and can't be matched to an event. Examples include internal book transfers and all Stripe transactions. |
||
|
|
||
| # create_canonical_pending_transaction!( | ||
| # amount_cents:, | ||
| # memo:, | ||
| # date: date_posted, | ||
| # event: column_account_number.event, | ||
| # fronted: true | ||
| # ) | ||
| end | ||
|
|
||
| def memo | ||
| if column_id.start_with? "acht" | ||
| return "#{column_transaction.fetch("company_name")} #{column_transaction["company_entry_description"]}" | ||
| elsif column_id.start_with?("wire") || column_id.start_with?("swft_") | ||
| return column_transaction.fetch("originator_name") | ||
| end | ||
| end | ||
|
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| class CreateRawPendingColumnTransactions < ActiveRecord::Migration[7.2] | ||
| def change | ||
| create_table :raw_pending_column_transactions do |t| | ||
| t.string :column_id, null: false | ||
| t.integer :column_event_type, null: false | ||
| t.jsonb :column_transaction, null: false | ||
| t.text :description, null: false | ||
| t.date :date_posted, null: false | ||
| t.integer :amount_cents, null: false | ||
| t.timestamps | ||
| end | ||
| add_index :raw_pending_column_transactions, :column_id, unique: true | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| class AddRawPendingColumnTransactionIdToCanonicalPendingTransaction < ActiveRecord::Migration[7.2] | ||
| disable_ddl_transaction! | ||
|
|
||
| def change | ||
| add_reference :canonical_pending_transactions, :raw_pending_column_transaction, index: { algorithm: :concurrently, name: "index_canonical_pending_txs_on_rpct_id" } | ||
sampoder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| add_index :canonical_pending_transactions, :raw_pending_column_transaction_id, unique: true, algorithm: :concurrently | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.