-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiyzipayresource.cpp
More file actions
130 lines (98 loc) · 3.71 KB
/
iyzipayresource.cpp
File metadata and controls
130 lines (98 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "iyzipayresource.h"
#include <QTime>
#include <qjson/parser.h>
#include <qjson/qobjecthelper.h>
#include <qjson/serializer.h>
const QString IyzipayResource::AUTHORIZATION = "Authorization";
const QString IyzipayResource::RANDOM_HEADER_NAME = "x-iyzi-rnd";
const QString IyzipayResource::CLIENT_VERSION_HEADER_NAME = "x-iyzi-client-version";
const QString IyzipayResource::IYZIWS_HEADER_NAME = "IYZWS ";
const QString IyzipayResource::CLIENT_VERSION = "1.0.0";
const QString IyzipayResource::CLIENT_TITLE = "iyzipay-cpp";
const QString IyzipayResource::COLON = ":";
const int IyzipayResource::RANDOM_STRING_SIZE = 8;
IyzipayResource::IyzipayResource(QObject *parent) : QObject(parent)
{
qsrand(QTime::currentTime().msec());
connect(&httpClient, SIGNAL(dataReady(QNetworkReply*)), this, SLOT(onDataReady(QNetworkReply*)));
}
QString IyzipayResource::status() {
return m_status;
}
void IyzipayResource::setStatus(const QString& status) {
this->m_status = status;
}
QString IyzipayResource::errorCode() {
return m_errorCode;
}
void IyzipayResource::setErrorCode(const QString& errorCode) {
this->m_errorCode = errorCode;
}
QString IyzipayResource::errorMessage() {
return m_errorMessage;
}
void IyzipayResource::setErrorMessage(const QString& errorMessage) {
this->m_errorMessage = errorMessage;
}
QString IyzipayResource::errorGroup() {
return m_errorGroup;
}
void IyzipayResource::setErrorGroup(const QString& errorGroup) {
this->m_errorGroup = errorGroup;
}
QString IyzipayResource::locale() {
return m_locale;
}
void IyzipayResource::setLocale(const QString& locale) {
this->m_locale = locale;
}
long IyzipayResource::systemTime() {
return m_systemTime;
}
void IyzipayResource::setSystemTime(long systemTime) {
this->m_systemTime = systemTime;
}
QString IyzipayResource::conversationId() {
return m_conversationId;
}
void IyzipayResource::setConversationId(const QString& conversationId) {
this->m_conversationId = conversationId;
}
QMap<QString, QString> IyzipayResource::getHttpHeaders(Request* request, Options* options) {
QMap<QString, QString> headers;
QString randomString = QString::number(QDateTime::currentMSecsSinceEpoch());
randomString.append(RandomStringUtility::GetRandomString(RANDOM_STRING_SIZE));
headers.insert(RANDOM_HEADER_NAME, randomString);
headers.insert(AUTHORIZATION, IyzipayResource::prepareAuthorizationString(request, randomString, options));
if (!CLIENT_VERSION.isEmpty() && !CLIENT_TITLE.isEmpty()) {
headers.insert(CLIENT_VERSION_HEADER_NAME, CLIENT_TITLE + "-" + CLIENT_VERSION);
}
return headers;
}
QString IyzipayResource::prepareAuthorizationString(Request *request, const QString& randomString, Options* options) {
QString hash = HashGenerator::generateHash(options->getApiKey(), options->getSecretKey(), randomString, request);
QString result (IYZIWS_HEADER_NAME + options->getApiKey() + COLON + hash);
return result;
}
QByteArray IyzipayResource::toJsonData(){
QStringList ignoreList(QString(QLatin1String("objectName")));
ignoreList.append(QString(QLatin1String("httpClient")));
QVariantMap variant = QJson::QObjectHelper::qobject2qvariant(this, ignoreList );
QJson::Serializer serializer;
return serializer.serialize( variant);
}
QString IyzipayResource::toString(){
QString str = this->toJsonData();
return str;
}
void IyzipayResource::onDataReady(QNetworkReply* reply){
QNetworkReply::NetworkError error_type = reply->error();
QString response;
if (error_type == QNetworkReply::NoError) {
response = QString::fromUtf8(reply->readAll());
}
else {
response = reply->errorString();
}
emit responseReady(response);
}