Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Interfaces/Helpers/URLHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ QString URLHelper::addParameter(const QString &_url, const QString& _paramName,
return Url.toString();
}

QString URLHelper::addParameters(const QString& _url, const QVariantMap& _params) {
QUrl Url = QUrl(_url);

QUrlQuery UrlQuery = QUrlQuery(Url);

for (QVariantMap::const_iterator it = _params.constBegin();
it != _params.constEnd();
it++
) {
UrlQuery.addQueryItem(it.key(), it.value().toString());
}

Url.setQuery(UrlQuery);
return Url.toString();
}

QString URLHelper::normalize(const QString &_url) {
QUrl Url = QUrl(_url);
QString Schema = Url.scheme();
Expand Down
1 change: 1 addition & 0 deletions Interfaces/Helpers/URLHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class URLHelper
public:
static QString domain(QString _url, bool _stripProtocol = false);
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);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* Migration File: m20220717_093924_AAA_add_PaymentVerifyCallback_to_onlinePayment.sql */
/* CAUTION: don't forget to use {{dbprefix}} for schemas */

/* The next line is to prevent this file from being committed. When done, delete this and next line: */
ERROR("THIS MIGRATION FILE IS NOT READY FOR EXECUTE.")

USE `{{dbprefix}}{{Schema}}`;

ALTER TABLE `tblOnlinePayments`
Expand Down
103 changes: 57 additions & 46 deletions Modules/Account/moduleSrc/ORM/Payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,49 @@ QVariant IMPL_ORMGET(OnlinePayments) {
return this->Select(GET_METHOD_ARGS_CALL_INTERNAL_BOOM, {}, 0, fnTouchQuery);
}

/**
* this proxy received GERT and POST and make GET call to the clients callback
*/
QVariant IMPL_REST_GET_OR_POST(OnlinePayments, paymentCallback, (
APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM,
QString _paymentKey
)) {
//curl -X POST 'http://localhost:10000/rest/v1/Account/OnlinePayments/paymentCallback?paymentKey=11&q1=qv1' -H 'content-type:application/json' -d '{"d1":"dv1"}'

_paymentKey = _paymentKey.trimmed();
if (_paymentKey.isEmpty())
throw exTargomanBase("paymentKey is empty", ESTATUS_INTERNAL_SERVER_ERROR);

tblOnlinePayments::DTO OnlinePaymentDTO = OnlinePayments::instance().GetSelectQuery(APICALLBOOM_PARAM)
// .addCols(OnlinePayments::instance().SelectableColumnNames())
// .addCols(PaymentGateways::instance().SelectableColumnNames())
// .innerJoinWith("paymentGateway")
.addCol(tblOnlinePayments::Fields::onpCallbackUrl)
.where({ tblOnlinePayments::Fields::onpMD5, enuConditionOperator::Equal, _paymentKey })
.one<tblOnlinePayments::DTO>();

//-------------------------------------------------
QVariantMap ResponseParams;

QList<QPair<QString, QString>> RequestQueryParams = APICALLBOOM_PARAM.getRequestQueryParams();
foreach (auto Item, RequestQueryParams) {
// if (Item.first == "paymentKey")
// continue;
ResponseParams.insert(Item.first, Item.second);
}

QList<QPair<QString, QString>> RequestBodyParams = APICALLBOOM_PARAM.getRequestBodyParams();
foreach (auto Item, RequestBodyParams) {
ResponseParams.insert(Item.first, Item.second);
}

//-------------------------------------------------
QString Callback = OnlinePaymentDTO.onpCallbackUrl;
Callback = URLHelper::addParameters(Callback, ResponseParams);

return TAPI::ResponseRedirect_t(Callback, false).toVariant();
}

#ifdef QT_DEBUG
QVariant IMPL_REST_GET_OR_POST(OnlinePayments, devTestPayPage, (
APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM,
Expand Down Expand Up @@ -138,7 +181,8 @@ curl -v -H 'accept: application/json' -X 'GET' 'http://127.0.0.1:10000/rest/v1/A
<div style='white-space: nowrap;'>Voucher ID:</div><div>{VOUCHER_ID}</div>
<div style='white-space: nowrap;'>Wallet ID:</div><div>{WALLET_ID}</div>
<div style='white-space: nowrap;'>Amount:</div><div>{AMOUNT}</div>
<div style='white-space: nowrap;'>Callback Url:</div><div>{CALLBACK_URL}</div>
<div style='white-space: nowrap;'>API Callback Url:</div><div>{API_CALLBACK_URL}</div>
<div style='white-space: nowrap;'>UI Callback Url:</div><div>{UI_CALLBACK_URL}</div>
</div>
</div>
</body>
Expand All @@ -155,7 +199,8 @@ curl -v -H 'accept: application/json' -X 'GET' 'http://127.0.0.1:10000/rest/v1/A
.replace("{VOUCHER_ID}", QString::number(OnlinePaymentsDTO.onp_vchID).toLatin1())
.replace("{WALLET_ID}", QString::number(NULLABLE_GET_OR_DEFAULT(OnlinePaymentsDTO.onpTarget_walID, 0)).toLatin1())
.replace("{AMOUNT}", QString::number(OnlinePaymentsDTO.onpAmount).toLatin1())
.replace("{CALLBACK_URL}", _callback.toLatin1())
.replace("{API_CALLBACK_URL}", _callback.toLatin1())
.replace("{UI_CALLBACK_URL}", OnlinePaymentsDTO.onpCallbackUrl.toLatin1())
;

return TAPI::RawData_t(Content,
Expand All @@ -170,62 +215,28 @@ QVariant IMPL_REST_GET_OR_POST(OnlinePayments, devTestCallbackPage, (
QString _paymentKey,
QString _result
)) {
QVariantMap ResponseParams;
QList<QPair<QString, QString>> RequestQueryParams = APICALLBOOM_PARAM.getRequestQueryParams();
foreach (auto Item, RequestQueryParams) {
if (Item.first == "paymentKey")
continue;
ResponseParams.insert(Item.first, Item.second);
}
ResponseParams.insert("result", _result);

return RESTClientHelper::callAPI(
RESTClientHelper::POST,
"Account/approveOnlinePayment",
{},
{
{ "paymentKey", _paymentKey },
// { "domain", "dev.test" },
{ "pgResponse", QVariantMap({
{ "result", _result },
}) },
{ "pgResponse", ResponseParams },
}
);
}
#endif

QVariant IMPL_REST_GET_OR_POST(OnlinePayments, paymentCallback, (
APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM,
QString _paymentKey
)) {
//curl -X POST 'http://localhost:10000/rest/v1/Account/OnlinePayments/paymentCallback?paymentKey=11&q1=qv1' -H 'content-type:application/json' -d '{"d1":"dv1"}'

QVariantMap ResponseParams;

QList<QPair<QString, QString>> RequestQueryParams = APICALLBOOM_PARAM.getRequestQueryParams();
foreach (auto Item, RequestQueryParams) {
if (Item.first == "paymentKey")
continue;

ResponseParams.insert(Item.first, Item.second);
}

QList<QPair<QString, QString>> RequestBodyParams = APICALLBOOM_PARAM.getRequestBodyParams();
foreach (auto Item, RequestBodyParams) {
ResponseParams.insert(Item.first, Item.second);
}

return true;

// Account::instance()->apiPOSTapproveOnlinePayment(
// APICALLBOOM_PARAM,
// _paymentKey,
// ResponseParams
// );

// RESTClientHelper::callAPI(
// RESTClientHelper::POST,
// "Account/approveOnlinePayment",
// {},
// {
// { "paymentKey", _paymentKey },
//// { "domain", "dev.test" },
// { "pgResponse", ResponseParams },
// }
// );
}

/*****************************************************************\
|* OfflinePaymentClaims ******************************************|
\*****************************************************************/
Expand Down
6 changes: 3 additions & 3 deletions Modules/Account/moduleSrc/ORM/Payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace tblOnlinePayments {
TARGOMAN_CREATE_CONSTEXPR(onp_pgwID);
TARGOMAN_CREATE_CONSTEXPR(onpTrackNumber);
TARGOMAN_CREATE_CONSTEXPR(onpAmount);
// TARGOMAN_CREATE_CONSTEXPR(onpCallbackUrl);
TARGOMAN_CREATE_CONSTEXPR(onpCallbackUrl);
TARGOMAN_CREATE_CONSTEXPR(onpTarget_walID);
TARGOMAN_CREATE_CONSTEXPR(onpResult);
TARGOMAN_CREATE_CONSTEXPR(onpStatus);
Expand All @@ -89,7 +89,7 @@ namespace tblOnlinePayments {
{ Fields::onp_pgwID, S(quint32), QFV.integer().minValue(1), QRequired, UPAdmin },
{ Fields::onpTrackNumber, S(QString), QFV.allwaysValid().maxLenght(50), QNull, UPAdmin },
{ Fields::onpAmount, S(quint64), QFV.integer().minValue(1), QRequired, UPAdmin },
// { Fields::onpCallbackUrl, S(QString), QFV.allwaysValid().maxLenght(2048), QRequired, UPAdmin },
{ Fields::onpCallbackUrl, S(QString), QFV.allwaysValid().maxLenght(2048), QRequired, UPAdmin },
{ Fields::onpTarget_walID, S(quint64), QFV, QNull, UPNone },
{ Fields::onpResult, S(QString), QFV, QNull, UPAdmin, false, false },
{ Fields::onpStatus, ORM_STATUS_FIELD(Targoman::API::AccountModule::enuPaymentStatus, Targoman::API::AccountModule::enuPaymentStatus::New) },
Expand All @@ -115,7 +115,7 @@ namespace tblOnlinePayments {
SF_quint32 (onp_pgwID),
SF_QString (onpTrackNumber),
SF_quint32 (onpAmount),
// SF_QString (onpCallbackUrl),
SF_QString (onpCallbackUrl),
SF_NULLABLE_quint64 (onpTarget_walID),
SF_QString (onpResult),
SF_ORM_STATUS_FIELD (onpStatus, Targoman::API::AccountModule::enuPaymentStatus, Targoman::API::AccountModule::enuPaymentStatus::Pending),
Expand Down
12 changes: 6 additions & 6 deletions Modules/Account/moduleSrc/Payment/PaymentLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ QString PaymentLogic::createOnlinePaymentLink(
{ "iVoucherID", _vchID },
{ "iGatewayID", PaymentGatewayDTO.pgwID },
{ "iAmount", _toPay },
// { "iCallbackUrl", _paymentVerifyCallback },
{ "iCallbackUrl", _paymentVerifyCallback },
{ "iTargetWalID", _walID },
})
.spDirectOutputs()
Expand All @@ -313,12 +313,12 @@ QString PaymentLogic::createOnlinePaymentLink(
try {
_outPaymentKey = onpMD5;

// QString Callback = QString("https://%1%2Account/OnlinePayments/paymentCallback?paymentKey=%3")
// .arg(APICALLBOOM_PARAM.hostAndPort())
// .arg(ServerCommonConfigs::BasePathWithVersion)
// .arg(onpMD5);
QString Callback = QString("https://%1%2Account/OnlinePayments/paymentCallback?paymentKey=%3")
.arg(APICALLBOOM_PARAM.hostAndPort())
.arg(ServerCommonConfigs::BasePathWithVersion)
.arg(onpMD5);

QString Callback = URLHelper::addParameter(_paymentVerifyCallback, "paymentKey", onpMD5);
// QString Callback = URLHelper::addParameter(_paymentVerifyCallback, "paymentKey", onpMD5);

//4: call driver::request
auto [Response, TrackID, PaymentLink] = PaymentGatewayDriver->prepareAndRequest(
Expand Down