rewrite for eet 2.0 api version v4
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
#include "eetv4soap.h"
|
||||
|
||||
#include "eetv4xml.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
namespace
|
||||
{
|
||||
QByteArray withoutXmlDeclaration(const QByteArray &xml)
|
||||
{
|
||||
const int declarationEnd = xml.indexOf("?>");
|
||||
return declarationEnd >= 0 ? xml.mid(declarationEnd + 2).trimmed() : xml.trimmed();
|
||||
}
|
||||
|
||||
bool isValidBodyId(const QByteArray &bodyId)
|
||||
{
|
||||
static const QRegularExpression expression(QStringLiteral("^[A-Za-z_][A-Za-z0-9_.-]{0,63}$"));
|
||||
return expression.match(QString::fromLatin1(bodyId)).hasMatch();
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray EetV4Soap::serializeUnsigned(const EetV4SaleRequest &request,
|
||||
const QByteArray &bodyId,
|
||||
QString *error)
|
||||
{
|
||||
if (!isValidBodyId(bodyId))
|
||||
{
|
||||
if (error != nullptr)
|
||||
{
|
||||
*error = QStringLiteral("SOAP Body ID has an invalid format.");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
QString saleError;
|
||||
const QByteArray saleXml = EetV4Xml::serializeSale(request, &saleError);
|
||||
if (saleXml.isEmpty())
|
||||
{
|
||||
if (error != nullptr)
|
||||
{
|
||||
*error = saleError;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
QByteArray output;
|
||||
output.reserve(saleXml.size() + 512);
|
||||
output.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
output.append("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\""
|
||||
" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\""
|
||||
" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">");
|
||||
output.append("<soap:Header/>");
|
||||
output.append("<soap:Body wsu:Id=\"");
|
||||
output.append(bodyId);
|
||||
output.append("\">");
|
||||
output.append(withoutXmlDeclaration(saleXml));
|
||||
output.append("</soap:Body></soap:Envelope>");
|
||||
|
||||
if (output.size() > MaximumMessageSize)
|
||||
{
|
||||
if (error != nullptr)
|
||||
{
|
||||
*error = QStringLiteral("SOAP message exceeds the 12 KiB EET limit.");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
return output;
|
||||
}
|
||||
Reference in New Issue
Block a user