Skip to content

Commit

Permalink
add #booking_datetime and #value_datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpuglisi committed Jul 6, 2023
1 parent 27aa99b commit 1b76675
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GEM
remote: https://rubygems.org/
specs:
builder (3.2.2)
diff-lcs (1.2.5)
diff-lcs (1.5.0)
mini_portile2 (2.8.1)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
Expand Down
17 changes: 13 additions & 4 deletions lib/camt_parser/general/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ def debit

# @return [Date]
def value_date
@value_date ||= Date.parse(@xml_data.xpath('ValDt/Dt/text()').text)
@value_date ||= ((date = @xml_data.xpath('ValDt/Dt/text()').text).empty? ? nil : Date.parse(date))
end

# @return [Date]
def booking_date
@booking_date ||= Date.parse(@xml_data.xpath('BookgDt/Dt/text()').text)
@booking_date ||= ((date = @xml_data.xpath('BookgDt/Dt/text()').text).empty? ? nil : Date.parse(date))
end

# @return [DateTime]
def value_datetime
@value_datetime ||= ((datetime = @xml_data.xpath('ValDt/DtTm/text()').text).empty? ? nil : DateTime.parse(datetime))
end

# @return [DateTime]
def booking_datetime
@booking_datetime ||= ((datetime = @xml_data.xpath('BookgDt/DtTm/text()').text).empty? ? nil : DateTime.parse(datetime))
end

# @return [String]
Expand Down Expand Up @@ -81,7 +91,7 @@ def charges
# @return [CamtParser::BatchDetail, nil]
def batch_detail
@batch_detail ||= @xml_data.xpath('NtryDtls/Btch').empty? ? nil : CamtParser::BatchDetail.new(@xml_data.xpath('NtryDtls/Btch'))
end
end

private

Expand All @@ -98,6 +108,5 @@ def parse_transactions

@xml_data.xpath('NtryDtls/TxDtls').map { |x| Transaction.new(x, debit?, amt, ccy) }
end

end
end
1 change: 1 addition & 0 deletions lib/camt_parser/register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## CAMT053
CamtParser::Xml.register('urn:iso:std:iso:20022:tech:xsd:camt.053.001.02', :camt053)
CamtParser::Xml.register('urn:iso:std:iso:20022:tech:xsd:camt.053.001.04', :camt053)
CamtParser::Xml.register('urn:iso:std:iso:20022:tech:xsd:camt.053.001.10', :camt053)

## CAMT054
CamtParser::Xml.register('urn:iso:std:iso:20022:tech:xsd:camt.054.001.02', :camt054)
Expand Down
112 changes: 112 additions & 0 deletions spec/fixtures/053/valid_example_with_datetime.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.10">
<BkToCstmrStmt>
<GrpHdr>
<MsgId>1234567-1234567891000</MsgId>
<CreDtTm>2023-07-06T10:27:07.213294607Z</CreDtTm>
</GrpHdr>
<Stmt>
<Id>7301750-38631543-1688639227213</Id>
<CreDtTm>2023-07-06T10:27:07.213294607Z</CreDtTm>
<FrToDt>
<FrDtTm>2022-07-07T00:00:00+02:00</FrDtTm>
<ToDtTm>2023-07-07T00:00:00+02:00</ToDtTm>
</FrToDt>
<Acct>
<Id>
<Othr>
<Id>11111111</Id>
<SchmeNm>
<Prtry>Wise Account ID</Prtry>
</SchmeNm>
<Issr>Wise Payments Ltd.</Issr>
</Othr>
</Id>
<Ccy>USD</Ccy>
<Ownr>
<Nm>Max Muster</Nm>
<PstlAdr>
<AdrTp>
<Cd>ADDR</Cd>
</AdrTp>
<PstCd>4410</PstCd>
<TwnNm>Liestal</TwnNm>
<AdrLine>Beispielstrasse 10</AdrLine>
</PstlAdr>
<Id>
<PrvtId>
<Othr>
<Id>1111111</Id>
<SchmeNm>
<Cd>CUST</Cd>
</SchmeNm>
</Othr>
</PrvtId>
</Id>
</Ownr>
<Svcr>
<FinInstnId>
<Nm>Wise Payments Ltd.</Nm>
<PstlAdr>
<AdrTp>
<Cd>ADDR</Cd>
</AdrTp>
<PstCd>E1 6JJ</PstCd>
<TwnNm>London</TwnNm>
<AdrLine>6th Floor, The Tea Building, 56 Shoreditch High Street</AdrLine>
</PstlAdr>
</FinInstnId>
</Svcr>
</Acct>
<Bal>
<Tp>
<CdOrPrtry>
<Cd>CLBD</Cd>
</CdOrPrtry>
</Tp>
<Amt Ccy="USD">606.80</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<Dt>
<DtTm>2023-07-07T00:00:00+02:00</DtTm>
</Dt>
</Bal>
<TxsSummry>
<TtlNtries>
<NbOfNtries>14</NbOfNtries>
<Sum>606.80</Sum>
<TtlNetNtry>
<Amt>606.80</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
</TtlNetNtry>
</TtlNtries>
<TtlCdtNtries>
<NbOfNtries>4</NbOfNtries>
<Sum>1115.92</Sum>
</TtlCdtNtries>
<TtlDbtNtries>
<NbOfNtries>10</NbOfNtries>
<Sum>-509.12</Sum>
</TtlDbtNtries>
</TxsSummry>
<Ntry>
<NtryRef>Test Buchung</NtryRef>
<Amt Ccy="USD">195.86</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<Sts>
<Cd>BOOK</Cd>
</Sts>
<BookgDt>
<DtTm>2023-06-21T12:35:33.115965+00:00</DtTm>
</BookgDt>
<BkTxCd>
<Prtry>
<Cd>TRANSFER-123456789</Cd>
</Prtry>
</BkTxCd>
<Chrgs>
<TtlChrgsAndTaxAmt Ccy="USD">4.14</TtlChrgsAndTaxAmt>
</Chrgs>
</Ntry>
</Stmt>
</BkToCstmrStmt>
</Document>
7 changes: 7 additions & 0 deletions spec/lib/camt_parser/general/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
specify { expect(ex_entry.sign).to eq(-1) }
specify { expect(ex_entry.transactions).to all(be_kind_of(CamtParser::Transaction)) }
specify { expect(ex_entry.bank_reference).to eq('2013122710583450000') }

context 'datetime' do
let(:camt) { CamtParser::File.parse('spec/fixtures/053/valid_example_with_datetime.xml') }
specify { expect(ex_entry.booking_datetime).to be_kind_of(DateTime) }
specify { expect(ex_entry.booking_datetime).to eq(DateTime.new(2023, 06, 21, 12, 35, 33.115965)) }
specify { expect(ex_entry.value_datetime).to eq(nil) }
end
end

0 comments on commit 1b76675

Please sign in to comment.