Skip to content

Commit

Permalink
add currency details to transaction.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekcieslar authored and tobischo committed Jan 15, 2025
1 parent 7117b1f commit 68121e3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
16 changes: 16 additions & 0 deletions lib/camt_parser/general/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ def reference
@reference ||= xml_data.xpath('Refs/InstrId/text()').text
end

def original_currency_amount # May be missing
@original_currency_amount ||= CamtParser::Misc.to_amount(parse_original_currency_amount)
end

def original_currency # May be missing
@original_currency ||= xml_data.xpath('AmtDtls/InstdAmt/Amt/@Ccy').text
end

def exchange_rate # May be missing
@exchange_rate ||= xml_data.xpath('AmtDtls/TxAmt/CcyXchg/XchgRate/text()').text
end

def bank_reference # May be missing
@bank_reference ||= xml_data.xpath('Refs/AcctSvcrRef/text()').text
end
Expand Down Expand Up @@ -118,6 +130,10 @@ def reason_code # May be missing

private

def parse_original_currency_amount
xml_data.xpath('AmtDtls/InstdAmt/Amt/text()').text
end

def parse_amount
if xml_data.xpath('Amt').any?
xml_data.xpath('Amt/text()').text
Expand Down
16 changes: 12 additions & 4 deletions spec/fixtures/053/valid_example_v8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
<AddtlNtryInf>Credit Creditor Reference</AddtlNtryInf>
</Ntry>
<Ntry>
<Amt Ccy="CHF">19.69</Amt>
<Amt Ccy="EUR">20.97</Amt>
<CdtDbtInd>DBIT</CdtDbtInd>
<Sts>
<Cd>BOOK</Cd>
Expand Down Expand Up @@ -286,7 +286,11 @@
<Amt Ccy="CHF">19.69</Amt>
</InstdAmt>
<TxAmt>
<Amt Ccy="CHF">19.69</Amt>
<Amt Ccy="EUR">20.97</Amt>
<CcyXchg>
<SrcCcy>CHF</SrcCcy>
<XchgRate>0.9433</XchgRate>
</CcyXchg>
</TxAmt>
</AmtDtls>
<NtryDtls>
Expand All @@ -298,14 +302,18 @@
<InstrId>373502949-1208481</InstrId>
<EndToEndId>1208481</EndToEndId>
</Refs>
<Amt Ccy="CHF">19.69</Amt>
<Amt Ccy="EUR">20.97</Amt>
<CdtDbtInd>DBIT</CdtDbtInd>
<AmtDtls>
<InstdAmt>
<Amt Ccy="CHF">19.69</Amt>
</InstdAmt>
<TxAmt>
<Amt Ccy="CHF">19.69</Amt>
<Amt Ccy="EUR">20.97</Amt>
<CcyXchg>
<SrcCcy>CHF</SrcCcy>
<XchgRate>0.9433</XchgRate>
</CcyXchg>
</TxAmt>
</AmtDtls>
<BkTxCd>
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/camt_parser/general/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@
specify { expect(ex_transaction.amount_in_cents).to eq(8885) }
end

context 'transaction with different currency' do
let(:ex_transaction) { transactions[0] }
let(:ex_entry) { entries[2] }

context '#amount' do
specify { expect(ex_transaction.amount).to be_kind_of(BigDecimal) }
specify { expect(ex_transaction.amount).to eq(BigDecimal('20.97')) }
specify { expect(ex_transaction.amount_in_cents).to eq(2097) }
end

context '#original_currency_amount' do
specify { expect(ex_transaction.original_currency_amount).to be_kind_of(BigDecimal) }
specify { expect(ex_transaction.original_currency_amount).to eq(BigDecimal('19.69')) }
end

specify { expect(ex_transaction.currency).to eq('EUR') }
specify { expect(ex_transaction.original_currency).to eq('CHF') }
specify { expect(ex_transaction.exchange_rate).to eq('0.9433') }
end


specify { expect(ex_transaction.name).to eq("Finanz AG") }
specify { expect(ex_transaction.creditor_reference).to eq("RF38000000000000000000552") }
Expand Down

0 comments on commit 68121e3

Please sign in to comment.