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
9 changes: 8 additions & 1 deletion Interfaces/Helpers/URLHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace Targoman::API::Helpers {

QString URLHelper::domain(QString _url) {
QString URLHelper::domain(QString _url, bool _stripProtocol) {
if (!_url.startsWith("http://") && !_url.startsWith("https://") && (_url.indexOf("://") < 0))
_url = "http://" + _url;

Expand All @@ -39,6 +39,13 @@ QString URLHelper::domain(QString _url) {
if (Domain.endsWith("/"))
Domain.chop(1);

if (_stripProtocol) {
if (_url.startsWith("http://"))
Domain = Domain.mid(7);
else if (_url.startsWith("https://"))
Domain = Domain.mid(8);
}

return Domain;
};

Expand Down
2 changes: 1 addition & 1 deletion Interfaces/Helpers/URLHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Targoman::API::Helpers {
class URLHelper
{
public:
static QString domain(QString _url);
static QString domain(QString _url, bool _stripProtocol = false);
static QString addParameter(const QString& _url, const QString& _paramName, const QVariant& _value);
static QString normalize(const QString &_url);
};
Expand Down
43 changes: 26 additions & 17 deletions Modules/Account/moduleSrc/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "Interfaces/Helpers/RESTClientHelper.h"
#include "Interfaces/Helpers/FixtureHelper.h"
#include "Interfaces/Helpers/IteratorHelper.hpp"
#include "Interfaces/Helpers/URLHelper.h"
using namespace Targoman::API::Helpers;

using namespace Targoman::API::AAA;
Expand Down Expand Up @@ -738,6 +739,8 @@ Targoman::API::AAA::stuVoucher IMPL_REST_POST(Account, finalizeBasket, (
QString _paymentVerifyCallback,
bool _allowChargeWallet
)) {
_domain = URLHelper::domain(_domain, true);

///scenario:
///1: create main expense voucher
///?: create pending vouchers per item
Expand Down Expand Up @@ -1009,17 +1012,20 @@ Targoman::API::AAA::stuVoucher IMPL_REST_POST(Account, finalizeBasket, (
.where({ tblPaymentGatewayTypes::Fields::pgtType, enuConditionOperator::Equal, _gatewayType })
.one<tblPaymentGatewayTypes::DTO>();
stuVoucher Voucher;
quint64 MustPay = 0;

if (NULLABLE_HAS_VALUE(PaymentGatewayTypesDTO.pgtMaxRequestAmount)
&& (RemainingAfterWallet > NULLABLE_VALUE(PaymentGatewayTypesDTO.pgtMaxRequestAmount))
) {
if (_allowChargeWallet == false)
throw exHTTPInternalServerError("Permission to charge the wallet is not given");

MustPay = NULLABLE_VALUE(PaymentGatewayTypesDTO.pgtMaxRequestAmount);

Voucher.Info.UserID = CurrentUserID;
Voucher.Info.Items.append(Targoman::API::AAA::stuVoucherItem(VOUCHER_ITEM_NAME_INC_WALLET, 0 /*_walID*/));
Voucher.Info.Summary = "Increase wallet";
Voucher.Info.ToPay = NULLABLE_VALUE(PaymentGatewayTypesDTO.pgtMaxRequestAmount);
Voucher.Info.ToPay = MustPay;
Voucher.Info.Sign = QString(voucherSign(QJsonDocument(Voucher.Info.toJson()).toJson()).toBase64());

Voucher.ID = Voucher::instance().Create(
Expand All @@ -1036,11 +1042,9 @@ Targoman::API::AAA::stuVoucher IMPL_REST_POST(Account, finalizeBasket, (
Voucher.Remained = Voucher.Info.ToPay;
Voucher.Payed = 0;
} else {
Voucher.Info = _preVoucher;
MustPay = RemainingAfterWallet;
Voucher.ID = _preVoucher.VoucherID;

Voucher.Remained = RemainingAfterWallet;
Voucher.Payed = Voucher.Info.ToPay - Voucher.Remained;
Voucher.Info = _preVoucher;
}

//freeze MustFreeze
Expand All @@ -1062,15 +1066,18 @@ Targoman::API::AAA::stuVoucher IMPL_REST_POST(Account, finalizeBasket, (
_domain,
Voucher.ID,
Voucher.Info.Summary,
Voucher.Remained, //Info.ToPay,
MustPay,
_paymentVerifyCallback,
PaymentKey,
0 /* _walID */
);

Voucher.PaymentKey = PaymentKey;

//send master voucher info back to the client
Voucher.Info = _preVoucher;
Voucher.Remained = RemainingAfterWallet;
Voucher.Payed = Voucher.Info.ToPay - Voucher.Remained;

Voucher.PaymentKey = PaymentKey;

return Voucher;
}
Expand Down Expand Up @@ -1198,10 +1205,12 @@ Targoman::API::AAA::stuVoucher Account::payAndProcessBasket(
*/
Targoman::API::AAA::stuVoucher IMPL_REST_POST(Account, approveOnlinePayment, (
APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM,
const QString _paymentKey,
const QString _domain,
QString _paymentKey,
QString _domain,
TAPI::JSON_t _pgResponse
)) {
_domain = URLHelper::domain(_domain, true);

auto [PaymentID, VoucherID, TargetWalletID] = PaymentLogic::approveOnlinePayment(
APICALLBOOM_PARAM,
_paymentKey,
Expand Down Expand Up @@ -1321,8 +1330,8 @@ Targoman::API::AAA::stuVoucher IMPL_REST_POST(Account, approveOnlinePayment, (
if (RemainingAfterWallet > 0) {
stuVoucher Voucher;

// Voucher.ID = MainExpenseVoucherID;
Voucher.ID = VoucherID;
Voucher.ID = MainExpenseVoucherID;
// Voucher.ID = VoucherID;
// Voucher.Info : stuPreVoucher
// Voucher.PaymentLink
// Voucher.PaymentKey
Expand Down Expand Up @@ -1392,13 +1401,13 @@ Targoman::API::AAA::stuVoucher IMPL_REST_POST(Account, approveOnlinePayment, (
*/
quint64 IMPL_REST_POST(Account, claimOfflinePayment, (
APICALLBOOM_TYPE_JWT_IMPL &APICALLBOOM_PARAM,
const QString &_bank,
const QString &_receiptCode,
QString _bank,
QString _receiptCode,
TAPI::Date_t _receiptDate,
quint32 _amount,
// NULLABLE_TYPE(quint64) voucherID,
quint64 _walID,
const QString &_note
QString _note
)) {
/*if (NULLABLE_HAS_VALUE(voucherID)) {
QJsonObject VoucherInfo = QJsonObject::fromVariantMap(SelectQuery(Voucher::instance())
Expand Down Expand Up @@ -2035,7 +2044,7 @@ quint64 IMPL_REST_POST(Account, addPrizeTo, (
APICALLBOOM_TYPE_JWT_IMPL &APICALLBOOM_PARAM,
quint64 _targetUsrID,
quint64 _amount,
const QString &_desc
QString _desc
)) {
qint64 Limit = Authorization::getPrivValue(_APICALLBOOM, "AAA:addPrizeTo:maxAmount", -1).toLongLong();
if (Limit == 0)
Expand Down Expand Up @@ -2066,7 +2075,7 @@ quint64 IMPL_REST_POST(Account, addIncomeTo, (
APICALLBOOM_TYPE_JWT_IMPL &APICALLBOOM_PARAM,
quint64 _targetUsrID,
quint64 _amount,
const QString &_desc
QString _desc
)) {
qint64 Limit = Authorization::getPrivValue(_APICALLBOOM, "AAA:addIncomeTo:maxAmount", -1).toLongLong();
if (Limit == 0)
Expand Down
14 changes: 7 additions & 7 deletions Modules/Account/moduleSrc/Account.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ private slots:
approveOnlinePayment,
(
APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM,
const QString _paymentKey,
const QString _domain,
QString _paymentKey,
QString _domain,
TAPI::JSON_t _pgResponse
),
"approve payment back from payment gateway"
Expand All @@ -385,13 +385,13 @@ private slots:
claimOfflinePayment,
(
APICALLBOOM_TYPE_JWT_DECL &APICALLBOOM_PARAM,
const QString& _bank,
const QString& _receiptCode,
QString _bank,
QString _receiptCode,
TAPI::Date_t _receiptDate,
quint32 _amount,
// NULLABLE_TYPE(quint64) _voucherID = NULLABLE_NULL_VALUE,
quint64 _walID = 0,
const QString& _note = {}
QString _note = {}
),
"Claim offline payment by user."
"Set vchID to null just for charging wallet, otherwise after increasing the wallet, the voucher will be paid"
Expand Down Expand Up @@ -442,7 +442,7 @@ private slots:
APICALLBOOM_TYPE_JWT_DECL &APICALLBOOM_PARAM,
quint64 _targetUsrID,
quint64 _amount,
const QString &_desc
QString _desc
),
"Add prize to a user by priviledged user"
)
Expand All @@ -453,7 +453,7 @@ private slots:
APICALLBOOM_TYPE_JWT_DECL &APICALLBOOM_PARAM,
quint64 _targetUsrID,
quint64 _amount,
const QString &_desc
QString _desc
),
"Add income to a user by priviledged user"
)
Expand Down
2 changes: 2 additions & 0 deletions Modules/Account/moduleSrc/ORM/PaymentGateways.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ QVariantList IMPL_REST_GET_OR_POST(PaymentGateways, availableGatewayTypes, (
quint32 _amount,
QString _domain
)) {
_domain = URLHelper::domain(_domain, true);

if (_amount == 0)
throw exHTTPBadRequest("amount is zero");

Expand Down
2 changes: 1 addition & 1 deletion Modules/Account/moduleSrc/ORM/Payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ curl -v -H 'accept: application/json' -X 'GET' 'http://127.0.0.1:10000/rest/v1/A

if (_callback.isEmpty())
_callback = QString("%1/Account/OnlinePayments/devTestCallbackPage?paymentKey=%2")
.arg("https://newapi.targoman.ir/rest/v1/") //ClientConfigs::RESTServerAddress.value())
.arg("https://newapi.targoman.ir/rest/v1") //ClientConfigs::RESTServerAddress.value())
.arg(_paymentKey)
;
else
Expand Down
3 changes: 3 additions & 0 deletions Modules/Account/moduleSrc/ORM/UserWallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "Voucher.h"
#include "Payment/PaymentLogic.h"
#include "Interfaces/Helpers/PhoneHelper.h"
#include "Interfaces/Helpers/URLHelper.h"
using namespace Targoman::API::Helpers;

TAPI_REGISTER_TARGOMAN_ENUM(Targoman::API::AccountModule, enuUserWalletStatus);
Expand Down Expand Up @@ -130,6 +131,8 @@ Targoman::API::AAA::stuVoucher IMPL_REST_CREATE(UserWallets, requestIncrease, (
QString _paymentVerifyCallback,
quint64 _walID
)) {
_domain = URLHelper::domain(_domain, true);

if (_gatewayType == Targoman::API::AccountModule::enuPaymentGatewayType::COD)
throw exHTTPBadRequest("requestIncrease is just for Online payments. For offline increase use claimOfflinePayment");

Expand Down
2 changes: 1 addition & 1 deletion Modules/Account/moduleSrc/Payment/Gateways/gtwDevTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ std::tuple<QString, QString, QString> gtwDevTest::prepareAndRequest(
QString TrackID = "track_" + _paymentKey;

QString PaymentLink = QString("%1/Account/OnlinePayments/devTestPayPage?paymentKey=%2&trackID=%3&callback=%4")
.arg("https://newapi.targoman.ir/rest/v1/") //ClientConfigs::RESTServerAddress.value())
.arg("https://newapi.targoman.ir/rest/v1") //ClientConfigs::RESTServerAddress.value())
.arg(_paymentKey)
.arg(TrackID)
.arg(_callback)
Expand Down
16 changes: 10 additions & 6 deletions Modules/Account/moduleSrc/Payment/PaymentLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ intfPaymentGateway* PaymentLogic::getDriver(const QString& _driverName) {
QVariantList PaymentLogic::findAvailableGatewayTypes(
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
quint32 _amount,
const QString& _domain
QString _domain
) {
QString Domain = URLHelper::domain(_domain);
QString Domain = URLHelper::domain(_domain, true);

SelectQuery qry = SelectQuery(PaymentGatewayTypes::instance())
.addCol(tblPaymentGatewayTypes::Fields::pgtType)
Expand Down Expand Up @@ -190,7 +190,7 @@ const ORM::tblPaymentGateways::DTO PaymentLogic::findBestPaymentGateway(
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
quint32 _amount,
enuPaymentGatewayType::Type _gatewayType,
const QString& _domain
QString _domain
) {
// QString CSVGatewayTypes = enuPaymentGatewayTypeToCSV(_gatewayTypes, "'");

Expand All @@ -199,7 +199,7 @@ const ORM::tblPaymentGateways::DTO PaymentLogic::findBestPaymentGateway(
throw exPayment("DeveloperTest is not allowed in non debug mode");
#endif

QString Domain = URLHelper::domain(_domain);
QString Domain = URLHelper::domain(_domain, true);

SelectQuery qry = SelectQuery(PaymentGateways::instance())
.addCols(PaymentGateways::instance().SelectableColumnNames())
Expand Down Expand Up @@ -261,14 +261,16 @@ const ORM::tblPaymentGateways::DTO PaymentLogic::findBestPaymentGateway(
QString PaymentLogic::createOnlinePaymentLink(
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
enuPaymentGatewayType::Type _gatewayType,
const QString& _domain,
QString _domain,
quint64 _vchID,
const QString& _invDesc,
quint32 _toPay,
const QString _paymentVerifyCallback,
/*OUT*/ TAPI::MD5_t& _outPaymentKey,
quint64 _walID
) {
_domain = URLHelper::domain(_domain, true);

///scenario:
///1: find best payment gateway
///2: get payment gateway driver
Expand Down Expand Up @@ -365,8 +367,10 @@ std::tuple<quint64, quint64, quint64> PaymentLogic::approveOnlinePayment(
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
const QString& _paymentKey,
const TAPI::JSON_t& _pgResponse,
const QString& _domain
QString _domain
) {
_domain = URLHelper::domain(_domain, true);

if (_paymentKey.isEmpty())
throw exPayment("paymentKey is empty");

Expand Down
8 changes: 4 additions & 4 deletions Modules/Account/moduleSrc/Payment/PaymentLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ class PaymentLogic
static QVariantList findAvailableGatewayTypes(
INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM,
quint32 _amount,
const QString& _domain
QString _domain
);

static const ORM::tblPaymentGateways::DTO findBestPaymentGateway(
INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM,
quint32 _amount,
enuPaymentGatewayType::Type _gatewayType,
const QString& _domain
QString _domain
);

static QString createOnlinePaymentLink(
INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM,
enuPaymentGatewayType::Type _gatewayType,
const QString& _domain,
QString _domain,
quint64 _vchID,
const QString& _invDesc,
quint32 _toPay,
Expand All @@ -80,7 +80,7 @@ class PaymentLogic
INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM,
const QString& _paymentKey,
const TAPI::JSON_t& _pgResponse,
const QString& _domain
QString _domain
);

public:
Expand Down