From e89b4e67067d49ff8f6c7a2c042d59d2e5f58fcb Mon Sep 17 00:00:00 2001 From: kambizzandi Date: Mon, 18 Jul 2022 16:08:19 +0430 Subject: [PATCH 1/3] callback url encoded and decoded by percent sign --- Interfaces/DBM/QueryBuilders.cpp | 4 ++++ Interfaces/Helpers/URLHelper.cpp | 8 +++++++ Interfaces/Helpers/URLHelper.h | 2 ++ .../Account/functionalTest/testAccount.hpp | 22 ++++++++++++++++++- Modules/Account/moduleSrc/ORM/UserWallets.cpp | 2 ++ .../moduleSrc/Payment/Gateways/gtwDevTest.cpp | 3 ++- 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Interfaces/DBM/QueryBuilders.cpp b/Interfaces/DBM/QueryBuilders.cpp index 40365a0a..c1ce406b 100644 --- a/Interfaces/DBM/QueryBuilders.cpp +++ b/Interfaces/DBM/QueryBuilders.cpp @@ -2836,7 +2836,11 @@ QVariantMap ORMSelectQuery::one(QVariantMap _args) { .toJson(true, this->Data->Table.Converters); if (Result.object().isEmpty()) +#ifdef QT_DEBUG throw exHTTPNotFound(QString("No item could be found in table (%1.%2)").arg(PrependSchema(this->Data->Table.Schema)).arg(this->Data->Table.Name)); +#else + throw exHTTPNotFound("No item could be found"); +#endif // qDebug() << "--- ORMSelectQuery::one()" << __FILE__ << __LINE__ << Result; // qDebug() << "--- ORMSelectQuery::one() {tovariant}" << __FILE__ << __LINE__ << Result.toVariant(); diff --git a/Interfaces/Helpers/URLHelper.cpp b/Interfaces/Helpers/URLHelper.cpp index 69927b98..72d29069 100644 --- a/Interfaces/Helpers/URLHelper.cpp +++ b/Interfaces/Helpers/URLHelper.cpp @@ -86,4 +86,12 @@ QString URLHelper::normalize(const QString &_url) { return Result; } +QString URLHelper::encode(const QString &_url) { + return QUrl::toPercentEncoding(_url); +} + +QString URLHelper::decode(const QString &_url) { + return QUrl::fromPercentEncoding(_url.toLatin1()); +} + } //namespace Targoman::API::Helpers diff --git a/Interfaces/Helpers/URLHelper.h b/Interfaces/Helpers/URLHelper.h index 12b8ebb2..e7aede61 100644 --- a/Interfaces/Helpers/URLHelper.h +++ b/Interfaces/Helpers/URLHelper.h @@ -36,6 +36,8 @@ class URLHelper static QString addParameter(const QString& _url, const QString& _paramName, const QVariant& _value); static QString addParameters(const QString& _url, const QVariantMap& _params); static QString normalize(const QString &_url); + static QString encode(const QString &_url); + static QString decode(const QString &_url); }; } //namespace Targoman::API::Helpers diff --git a/Modules/Account/functionalTest/testAccount.hpp b/Modules/Account/functionalTest/testAccount.hpp index 17eedd7a..421172be 100644 --- a/Modules/Account/functionalTest/testAccount.hpp +++ b/Modules/Account/functionalTest/testAccount.hpp @@ -274,6 +274,26 @@ private slots: /***************************************************************************************/ /* tests *******************************************************************************/ /***************************************************************************************/ +// void checkUrl() { +// QString u = QUrl::toPercentEncoding("https://callback.com?a=1&b=2"); +// qDebug() << 1 << u; + +// u = QUrl::toPercentEncoding(u); +// qDebug() << 2 << u; + +// u = QUrl::fromPercentEncoding(u.toLatin1()); +// qDebug() << 3 << u; + +// u = QUrl::fromPercentEncoding(u.toLatin1()); +// qDebug() << 4 << u; + +// u = QUrl::fromPercentEncoding(u.toLatin1()); +// qDebug() << 5 << u; + +// u = QUrl::fromPercentEncoding(u.toLatin1()); +// qDebug() << 6 << u; +// } +//private: void NormalizePhoneNumber() { try { QVariant Result = callUserAPI( @@ -889,7 +909,7 @@ private slots: { { "amount", 10'000 }, { "gatewayType", "_DeveloperTest" }, - { "domain", "dev.test" }, +// { "domain", "dev.test" }, { "walID", 0 }, { "paymentVerifyCallback", "http://127.0.0.1:10000/rest/v1/Account/OnlinePayments/devTestCallbackPage" } } diff --git a/Modules/Account/moduleSrc/ORM/UserWallets.cpp b/Modules/Account/moduleSrc/ORM/UserWallets.cpp index c5ddc7e5..a75b1671 100644 --- a/Modules/Account/moduleSrc/ORM/UserWallets.cpp +++ b/Modules/Account/moduleSrc/ORM/UserWallets.cpp @@ -145,6 +145,8 @@ Targoman::API::AAA::stuVoucher IMPL_REST_CREATE(UserWallets, requestIncrease, ( Voucher.Info.ToPay = _amount; Voucher.Info.Sign = QString(sign(Voucher.Info)); + Voucher.Remained = _amount; + Voucher.ID = Voucher::instance().Create( APICALLBOOM_PARAM, TAPI::ORMFields_t({ diff --git a/Modules/Account/moduleSrc/Payment/Gateways/gtwDevTest.cpp b/Modules/Account/moduleSrc/Payment/Gateways/gtwDevTest.cpp index f4558332..a680307e 100644 --- a/Modules/Account/moduleSrc/Payment/Gateways/gtwDevTest.cpp +++ b/Modules/Account/moduleSrc/Payment/Gateways/gtwDevTest.cpp @@ -22,6 +22,7 @@ */ #include "gtwDevTest.h" +#include "Interfaces/Helpers/URLHelper.h" #include "Interfaces/Helpers/RESTClientHelper.h" using namespace Targoman::API::Helpers; #include "Interfaces/Server/ServerCommon.h" @@ -66,7 +67,7 @@ std::tuple gtwDevTest::prepareAndRequest( .arg(ServerUrl) //ClientConfigs::RESTServerAddress.value()) .arg(_paymentKey) .arg(TrackID) - .arg(_callback) + .arg(URLHelper::encode(_callback)) ; return { From 3f9801d15ecd8992ac169b0109f3772bd611b543 Mon Sep 17 00:00:00 2001 From: kambizzandi Date: Tue, 19 Jul 2022 12:37:03 +0430 Subject: [PATCH 2/3] fix bug in test account --- Modules/Account/functionalTest/testAccount.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Account/functionalTest/testAccount.hpp b/Modules/Account/functionalTest/testAccount.hpp index 421172be..8e9c77ad 100644 --- a/Modules/Account/functionalTest/testAccount.hpp +++ b/Modules/Account/functionalTest/testAccount.hpp @@ -948,7 +948,7 @@ private slots: void approveOnlinePayment_for_requestIncrease_DEVTEST_with_domain() { if (this->Voucher.PaymentKey.isEmpty() == false) { QT_TRY { - QVariant Result = callUserAPI( + QVariant Result = callAdminAPI( RESTClientHelper::POST, "Account/approveOnlinePayment", {}, @@ -1067,7 +1067,7 @@ private slots: void claimOfflinePayment_NO_VOUCHER_2_approveOfflinePayment() { if (this->OfflinePaymentClaimID > 0) { QT_TRY { - QVariant Result = callUserAPI( + QVariant Result = callAdminAPI( RESTClientHelper::POST, "Account/approveOfflinePayment", {}, From deda978e72373973614f665dd9aa54def4e65a68 Mon Sep 17 00:00:00 2001 From: kambizzandi Date: Tue, 19 Jul 2022 12:40:54 +0430 Subject: [PATCH 3/3] decode callback --- Modules/Account/moduleSrc/ORM/Payments.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Modules/Account/moduleSrc/ORM/Payments.cpp b/Modules/Account/moduleSrc/ORM/Payments.cpp index c911d38c..538d1312 100644 --- a/Modules/Account/moduleSrc/ORM/Payments.cpp +++ b/Modules/Account/moduleSrc/ORM/Payments.cpp @@ -137,8 +137,10 @@ curl -v -H 'accept: application/json' -X 'GET' 'http://127.0.0.1:10000/rest/v1/A .arg(ServerUrl) //ClientConfigs::RESTServerAddress.value()) .arg(_paymentKey) ; - else + else { + _callback = URLHelper::decode(_callback); _callback = URLHelper::addParameter(_callback, "paymentKey", _paymentKey); + } QByteArray Content = R"(