Keyple Card Calypso C++ Library 2.2.2
Reference Terminal Reader API for C++
SvDebitLogRecordAdapter.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2022 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information regarding *
5 * copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the terms of the Eclipse *
8 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
9 * *
10 * SPDX-License-Identifier: EPL-2.0 *
11 **************************************************************************************************/
12
14
15/* Keyple Core Util */
16#include "ByteArrayUtil.h"
17#include "HexUtil.h"
18#include "KeypleStd.h"
19#include "System.h"
20
21namespace keyple {
22namespace card {
23namespace calypso {
24
25using namespace keyple::core::util;
26using namespace keyple::core::util::cpp;
27
29 const std::vector<uint8_t>& cardResponse, const int offset)
30: mOffset(offset), mCardResponse(cardResponse) {}
31
32const std::vector<uint8_t>& SvDebitLogRecordAdapter::getRawData() const
33{
34 return mCardResponse;
35}
36
38{
39 return ByteArrayUtil::extractInt(mCardResponse, mOffset, 2, true);
40}
41
43{
44 return ByteArrayUtil::extractInt(mCardResponse, mOffset + 14, 3, true);
45}
46
47const std::vector<uint8_t> SvDebitLogRecordAdapter::getDebitTime() const
48{
49 std::vector<uint8_t> loadTime(2);
50 loadTime[0] = mCardResponse[mOffset + 4];
51 loadTime[1] = mCardResponse[mOffset + 5];
52
53 return loadTime;
54}
55
56const std::vector<uint8_t> SvDebitLogRecordAdapter::getDebitDate() const
57{
58 std::vector<uint8_t> loadDate(2);
59 loadDate[0] = mCardResponse[mOffset + 2];
60 loadDate[1] = mCardResponse[mOffset + 3];
61
62 return loadDate;
63}
64
66{
67 return mCardResponse[mOffset + 6];
68}
69
70const std::vector<uint8_t> SvDebitLogRecordAdapter::getSamId() const
71{
72 std::vector<uint8_t> samId(4);
73 System::arraycopy(mCardResponse, mOffset + 7, samId, 0, 4);
74
75 return samId;
76}
77
79{
80 std::vector<uint8_t> tnNum(2);
81 tnNum[0] = mCardResponse[mOffset + 17];
82 tnNum[1] = mCardResponse[mOffset + 18];
83
84 return ByteArrayUtil::extractInt(tnNum, 0, 2, false);
85}
86
88{
89 std::vector<uint8_t> samTNum(3);
90 System::arraycopy(mCardResponse, mOffset + 11, samTNum, 0, 3);
91
92 return ByteArrayUtil::extractInt(samTNum, 0, 3, false);
93}
94
95std::ostream& operator<<(std::ostream& os, const SvDebitLogRecordAdapter& ra)
96{
97 os << "SV_DEBIT_LOG_RECORD_ADAPTER: {"
98 << "AMOUNT: " << ra.getAmount() << ", "
99 << "BALANCE: " << ra.getBalance() << ", "
100 << "DEBIT_DATE: " << ra.getDebitDate() << ", "
101 << "LOAD_TIME: " << ra.getDebitDate() << ", "
102 << "KVC: " << ra.getKvc() << ", "
103 << "SAM_ID: " << ra.getSamId() << ", "
104 << "SV_TRANSACTION_NUMBER: " << ra.getSvTNum() << ", "
105 << "SV_SAM_TRANSACTION_NUMBER: " << ra.getSamTNum()
106 << "}";
107
108 return os;
109}
110
111std::ostream& operator<<(std::ostream& os, const std::shared_ptr<SvDebitLogRecordAdapter> ra)
112{
113 if (ra == nullptr) {
114 os << "SV_DEBIT_LOG_RECORD_ADAPTER: null";
115 } else {
116 os << *ra.get();
117 }
118
119 return os;
120}
121
123{
124 return "{" \
125 "\"amount\":" + std::to_string(getAmount()) + ", " \
126 "\"balance\":" + std::to_string(getBalance()) + ", " \
127 "\"debitDate\":" + HexUtil::toHex(getDebitDate()) + ", " \
128 "\"loadTime\":" + HexUtil::toHex(getDebitDate()) + ", " \
129 "\"kvc\":" + std::to_string(getKvc()) + ", " \
130 "\"samId\": \"" + HexUtil::toHex(getSamId()) + "\", " \
131 "\"svTransactionNumber\":" + std::to_string(getSvTNum()) + ", " \
132 "\"svSamTransactionNumber\":" + std::to_string(getSamTNum()) + "" \
133 "}";
134}
135
136}
137}
138}
const std::vector< uint8_t > & getRawData() const override
SvDebitLogRecordAdapter(const std::vector< uint8_t > &cardResponse, const int offset)
const std::vector< uint8_t > getDebitDate() const override
const std::vector< uint8_t > getSamId() const override
const std::vector< uint8_t > getDebitTime() const override
std::ostream & operator<<(std::ostream &os, const std::shared_ptr< ApduRequestAdapter > ara)