Skip to content

Commit d23e259

Browse files
committed
feat: add statement meta info
enrich the statement with the info if the statement in not yet confirmed by the bank (expected) or if a statement is reversal of a previous transaction
1 parent 5e7375b commit d23e259

File tree

17 files changed

+247
-21
lines changed

17 files changed

+247
-21
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ruby "3.3.2"
66

77
gem "activesupport"
88
gem "camt_parser", git: "https://github.com/railslove/camt_parser.git"
9-
gem "cmxl", git: "https://github.com/railslove/cmxl"
9+
gem "cmxl"
1010
gem "epics"
1111
gem "faraday"
1212
gem "grape"

Gemfile.lock

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ GIT
55
camt_parser (1.0.2)
66
nokogiri
77

8-
GIT
9-
remote: https://github.com/railslove/cmxl
10-
revision: b92aea3de958426119d76d043a886233a313f43f
11-
specs:
12-
cmxl (1.5.0)
13-
rchardet
14-
158
GIT
169
remote: https://github.com/railslove/king_dtaus_ruby_3.git
1710
revision: 28b077aa6b2cf5590e322d0d207236adccf2d543
@@ -45,6 +38,8 @@ GEM
4538
base64 (0.2.0)
4639
bigdecimal (3.1.8)
4740
builder (3.3.0)
41+
cmxl (2.0)
42+
rchardet
4843
coderay (1.1.3)
4944
concurrent-ruby (1.3.4)
5045
connection_pool (2.4.1)
@@ -160,7 +155,7 @@ GEM
160155
rack (>= 1.0, < 3)
161156
rainbow (3.1.1)
162157
rake (13.2.1)
163-
rchardet (1.8.0)
158+
rchardet (1.9.0)
164159
redis (4.8.1)
165160
regexp_parser (2.9.2)
166161
rest-client (2.1.0)
@@ -261,7 +256,7 @@ DEPENDENCIES
261256
airborne
262257
barnes
263258
camt_parser!
264-
cmxl!
259+
cmxl
265260
database_cleaner-sequel
266261
dotenv
267262
epics

box/apis/v2/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Statement Created:
8484
account_id,
8585
statement: {
8686
id, account (iban), name, bic, iban, type, amount (cents), date,
87-
remittance_information
87+
remittance_information, expected, reversal
8888
}
8989
}
9090
```

box/business_processes/import_statements.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ def self.statement_attributes_from_bank_transaction(transaction, bank_statement)
112112
mref: transaction.respond_to?(:mref) ? transaction.mref : transaction.sepa["MREF"],
113113
svwz: transaction.respond_to?(:svwz) ? transaction.svwz : transaction.sepa["SVWZ"],
114114
tx_id: transaction.try(:transaction_id),
115-
creditor_identifier: transaction.respond_to?(:creditor_identifier) ? transaction.creditor_identifier : transaction.sepa["CRED"]
115+
creditor_identifier: transaction.respond_to?(:creditor_identifier) ? transaction.creditor_identifier : transaction.sepa["CRED"],
116+
expected: transaction.expected?,
117+
reversal: transaction.reversal?
116118
}
117119
end
118120
end

box/entities/statement.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Statement < Grape::Entity
1111
expose :name
1212
expose :bic
1313
expose :iban
14-
expose :type
14+
expose :expected, documentation: {type: "Boolean", desc: "Expected statement are not yet confirmed"}
15+
expose :reversal, documentation: {type: "Boolean", desc: "Reversal of a previous transaction"}
1516
expose :amount, documentation: {type: "Integer", desc: "Amount in cents"}
1617
expose :date
1718
expose(:remittance_information, documentation: {type: "String", desc: "Wire transfer reference"}) { |statement| statement[:svwz] || statement[:information] }

box/entities/v2/transaction.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class Transaction < Grape::Entity
1212
expose :iban
1313
expose :bic
1414
expose :type
15+
expose :expected
16+
expose :reversal
1517
expose :amount, as: "amount_in_cents"
1618
expose :date, as: "executed_on"
1719
expose(:settled_at) { |trx| trx.settled ? trx.date : nil }

box/models/statement.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ def credit?
8181
end
8282

8383
def debit?
84-
debit
84+
end
85+
86+
def reversal?
87+
reversal
88+
end
89+
90+
def expected?
91+
!!expected
8592
end
8693

8794
def type
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
Sequel.migration do
4+
change do
5+
add_column :statements, :expected, :boolean
6+
add_column :statements, :reversal, :boolean
7+
end
8+
end

db/schema.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@
117117
column :settled, "boolean", :default=>true
118118
column :sha, "text"
119119
column :tx_id, "text"
120+
column :expected, "boolean"
121+
column :reversal, "boolean"
120122

121123
index [:sha], :name=>:statements_sha2_index, :unique=>true
122124
index [:sha_bak], :name=>:statements_sha_key, :unique=>true

spec/apis/v2/transactions_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module Box
1616
amount_in_cents: :integer,
1717
executed_on: :date,
1818
type: :string,
19+
expected: :boolean,
20+
reversal: :boolean,
1921
reference: :string,
2022
end_to_end_reference: :string,
2123
settled_at: :string

0 commit comments

Comments
 (0)