Skip to content
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

add currency details to transaction.rb #73

Merged
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
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
Loading