Keyple Card Calypso C++ Library 2.2.5.6
Reference Terminal Reader API for C++
CmdSamSvPrepareDebitOrUndebit.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2023 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 Card Calypso */
16#include "CalypsoCardAdapter.h"
17#include "CalypsoCardClass.h"
24#include "SamUtilAdapter.h"
25
26/* Keyple Core Util */
27#include "ApduUtil.h"
28#include "IllegalArgumentException.h"
29#include "IllegalStateException.h"
30#include "System.h"
31
32namespace keyple {
33namespace card {
34namespace calypso {
35
36using namespace keyple::core::util;
37using namespace keyple::core::util::cpp;
38using namespace keyple::core::util::cpp::exception;
39
40const std::map<const int, const std::shared_ptr<StatusProperties>>
41 CmdSamSvPrepareDebitOrUndebit::STATUS_TABLE = initStatusTable();
42
44 const bool isDebitCommand,
45 const std::shared_ptr<CalypsoSamAdapter> calypsoSam,
46 const std::vector<uint8_t>& svGetHeader,
47 const std::vector<uint8_t>& svGetData,
48 const std::vector<uint8_t>& svDebitOrUndebitCmdBuildData)
49: AbstractSamCommand(isDebitCommand ? CalypsoSamCommand::SV_PREPARE_DEBIT :
50 CalypsoSamCommand::SV_PREPARE_UNDEBIT,
51 -1,
52 calypsoSam)
53{
54 const uint8_t cla = SamUtilAdapter::getClassByte(calypsoSam->getProductType());
55 const uint8_t p1 = 0x01;
56 const uint8_t p2 = 0xFF;
57 std::vector<uint8_t> data(16 + svGetData.size()); /* Header(4) + SvUndebit data (12) = 16 bytes*/
58
59 System::arraycopy(svGetHeader, 0, data, 0, 4);
60 System::arraycopy(svGetData, 0, data, 4, svGetData.size());
61 System::arraycopy(svDebitOrUndebitCmdBuildData,
62 0,
63 data,
64 4 + svGetData.size(),
65 svDebitOrUndebitCmdBuildData.size());
66
68 std::make_shared<ApduRequestAdapter>(
69 ApduUtil::build(cla, getCommandRef().getInstructionByte(), p1, p2, data)));
70}
71
72const std::map<const int, const std::shared_ptr<StatusProperties>>
73 CmdSamSvPrepareDebitOrUndebit::initStatusTable()
74{
75 std::map<const int, const std::shared_ptr<StatusProperties>> m =
77
78 m.insert({0x6700,
79 std::make_shared<StatusProperties>("Incorrect Lc.",
81 m.insert({0x6985,
82 std::make_shared<StatusProperties>("Preconditions not satisfied.",
83 typeid(CalypsoSamAccessForbiddenException))});
84 m.insert({0x6A00,
85 std::make_shared<StatusProperties>("Incorrect P1 or P2",
86 typeid(CalypsoSamIllegalParameterException))});
87 m.insert({0x6A80,
88 std::make_shared<StatusProperties>("Incorrect incoming data.",
89 typeid(CalypsoSamIncorrectInputDataException))});
90 m.insert({0x6A83,
91 std::make_shared<StatusProperties>("Record not found: ciphering key not found",
92 typeid(CalypsoSamDataAccessException))});
93
94 return m;
95}
96
97const std::map<const int, const std::shared_ptr<StatusProperties>>&
99{
100 return STATUS_TABLE;
101}
102
103}
104}
105}
virtual void setApduRequest(const std::shared_ptr< ApduRequestAdapter > apduRequest) final
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
const CalypsoSamCommand & getCommandRef() const override
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
CmdSamSvPrepareDebitOrUndebit(const bool isDebitCommand, const std::shared_ptr< CalypsoSamAdapter > calypsoSam, const std::vector< uint8_t > &svGetHeader, const std::vector< uint8_t > &svGetData, const std::vector< uint8_t > &svDebitOrUndebitCmdBuildData)
static uint8_t getClassByte(const ProductType productType)