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
3 changes: 2 additions & 1 deletion Modules/Account/moduleSrc/Payment/Gateways/ActiveGateways.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#define TARGOMAN_API_MODULES_ACCOUNT_PAYMENT_GATEWAYS_ACTIVEGATEWAYS_H

#include "gtwDevTest.h"
#include "gtwMellatBank.h"
#include "gtwZibal.h"
#include "gtwTarjomyarPay.h"
#include "gtwMellatBank.h"

#endif // TARGOMAN_API_MODULES_ACCOUNT_PAYMENT_GATEWAYS_ACTIVEGATEWAYS_H
12 changes: 4 additions & 8 deletions Modules/Account/moduleSrc/Payment/Gateways/gtwDevTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,11 @@ std::tuple<QString, QString, QString> gtwDevTest::prepareAndRequest(
// [Response, refNumber]
std::tuple<QString, QString> gtwDevTest::verifyAndSettle(
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
const ORM::tblPaymentGateways::DTO &_paymentGateway,
const ORM::tblOnlinePayments::DTO &_onlinePayment,
const TAPI::JSON_t &_pgResponse
Q_DECL_UNUSED const ORM::tblPaymentGateways::DTO &_paymentGateway,
Q_DECL_UNUSED const ORM::tblOnlinePayments::DTO &_onlinePaymentDTO,
Q_DECL_UNUSED const TAPI::JSON_t &_pgResponse
// const QString &_domain
) {
Q_UNUSED(_paymentGateway);
Q_UNUSED(_onlinePayment);
Q_UNUSED(_pgResponse);

#ifdef QT_DEBUG
if (_pgResponse.isObject() == false)
throw exPayment("Invalid response from gateway.");
Expand All @@ -103,7 +99,7 @@ std::tuple<QString, QString> gtwDevTest::verifyAndSettle(

return {
"",
"ref_" + _onlinePayment.onpMD5
"ref_" + _onlinePaymentDTO.onpMD5
};

#else
Expand Down
5 changes: 3 additions & 2 deletions Modules/Account/moduleSrc/Payment/Gateways/gtwDevTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ namespace Targoman::API::AccountModule::Payment::Gateways {
class gtwDevTest : public intfPaymentGateway
{
TARGOMAN_DEFINE_API_PAYMENT_GATEWAY(
Targoman::API::AccountModule::enuPaymentGatewayType::_DeveloperTest,
gtwDevTest)
gtwDevTest,
Targoman::API::AccountModule::enuPaymentGatewayType::_DeveloperTest
);

public:
constexpr static char Name[] = "DevTest";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ std::tuple<QString, QString, QString> gtwMellatBank::prepareAndRequest(
std::tuple<QString, QString> gtwMellatBank::verifyAndSettle(
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
const ORM::tblPaymentGateways::DTO &_paymentGateway,
const ORM::tblOnlinePayments::DTO &_onlinePayment,
Q_DECL_UNUSED const ORM::tblOnlinePayments::DTO &_onlinePaymentDTO,
const TAPI::JSON_t& _pgResponse
// const QString& _domain
) {
Expand Down
7 changes: 4 additions & 3 deletions Modules/Account/moduleSrc/Payment/Gateways/gtwMellatBank.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ class gtwMellatBank : public intfPaymentGateway
public:
constexpr static char Name[] = "MellatBank";

TARGOMAN_DEFINE_API_PAYMENT_GATEWAY(
Targoman::API::AccountModule::enuPaymentGatewayType::IranBank,
gtwMellatBank)
TARGOMAN_DEFINE_API_PAYMENT_GATEWAY(
gtwMellatBank,
Targoman::API::AccountModule::enuPaymentGatewayType::IranBank
);

private:
virtual QString errorString(int _errCode);
Expand Down
169 changes: 169 additions & 0 deletions Modules/Account/moduleSrc/Payment/Gateways/gtwTarjomyarPay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/******************************************************************************
# TargomanAPI: REST API for Targoman
#
# Copyright 2014-2020 by Targoman Intelligent Processing <http://tip.co.ir>
#
# TargomanAPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# TargomanAPI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU AFFERO GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
# along with Targoman. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/**
* @author S. Mehran M. Ziabary <ziabary@targoman.com>
* @author Kambiz Zandi <kambizzandi@gmail.com>
*/

#include "gtwTarjomyarPay.h"

namespace Targoman::API::AccountModule::Payment::Gateways {

TARGOMAN_IMPL_API_PAYMENT_GATEWAY(gtwTarjomyarPay)

// [Response, TrackID, PaymentLink]
std::tuple<QString, QString, QString> gtwTarjomyarPay::prepareAndRequest(
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
const ORM::tblPaymentGateways::DTO &_paymentGateway,
TAPI::MD5_t _paymentKey,
qint64 _amount,
const QString& _callback,
const QString& _desc
) {
// TAPI::JSON_t MetaInfo = NULLABLE_GET_OR_DEFAULT(_paymentGateway.pgwMetaInfo, TAPI::JSON_t());
QString Token = _paymentGateway.pgwMetaInfo[gtwTarjomyarPay::METAINFO_KEY_TOKEN].toString();

PaymentLogic::log(gtwTarjomyarPay::Name, __FUNCTION__, __LINE__, { _paymentKey, _amount, _callback, _desc });

try {
QJsonDocument Json = intfPaymentGateway::postJsonWithCurl(
gtwTarjomyarPay::URL_GTW_REQUEST,
QJsonDocument(QJsonObject({
{ "token" , Token },
{ "amount" , _amount },
{ "cb" , _callback },
{ "desc" , _desc },
}))
);

PaymentLogic::log(gtwTarjomyarPay::Name, __FUNCTION__, __LINE__, { Json });

if (Json.isObject() == false)
throw exPayment("JsonObject expected as TarjomyarPay response");

QJsonObject Response = Json.object();
/*
{
"ordID":"b5a73777f32bcb814062c6f96f8a1d9d",
"url":"https:\/\/tarjomyar.ir\/paymentGW.html
?ref=b5a73777f32bcb814062c6f96f8a1d9d
&cb=https%3A%2F%2Ffreepaper.me%2FpaymentResponse.html"
}
*/

if (Response.contains("ordID") == false)
throw exPayment("The ordID is missing");
if (Response.value("ordID").toString().isEmpty())
throw exPayment("The ordID is empty");

if (Response.contains("url") == false)
throw exPayment("The url is missing");
if (Response.value("url").toString().isEmpty())
throw exPayment("The url is empty");

return {
Json.toJson(QJsonDocument::Compact),
Response.value("ordID").toString(),
Response.value("url").toString()
};

} catch (std::exception &e) {
PaymentLogic::log(gtwTarjomyarPay::Name, __FUNCTION__, __LINE__, { e.what() });
throw;
}
}

// [Response, refNumber]
std::tuple<QString, QString> gtwTarjomyarPay::verifyAndSettle(
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
const ORM::tblPaymentGateways::DTO &_paymentGateway,
Q_DECL_UNUSED const ORM::tblOnlinePayments::DTO &_onlinePaymentDTO,
const TAPI::JSON_t& _pgResponse
// const QString& _domain
) {
QString Token = _paymentGateway.pgwMetaInfo[gtwTarjomyarPay::METAINFO_KEY_TOKEN].toString();

PaymentLogic::log(gtwTarjomyarPay::Name, __FUNCTION__, __LINE__, { _pgResponse/*, _domain*/ });

try {
if (_pgResponse.isObject() == false)
throw exPayment("Invalid response from gateway.");

QJsonObject PGResponse = _pgResponse.object();

//error
if (PGResponse.contains("err")) {
QString Error = PGResponse.value("err").toString();
throw exPayment(QString("Error:%1")
.arg(Error));
}

//ok
if (PGResponse.contains("approval") == false)
throw exPayment("The approval is missing");
if (PGResponse.value("approval").toString().isEmpty())
throw exPayment("The approval is empty");

QString Approval = PGResponse.value("approval").toString();

QJsonDocument Json = intfPaymentGateway::postJsonWithCurl(
gtwTarjomyarPay::URL_GTW_VERIFY,
QJsonDocument(QJsonObject({
{ "token", Token },
{ "ordID", Approval },
}))
);

PaymentLogic::log(gtwTarjomyarPay::Name, __FUNCTION__, __LINE__, { Json });

if (Json.isObject() == false)
throw exPayment("JsonObject expected as TarjomyarPay response.");

QJsonObject Response = Json.object();

//
QString RespStatus;
if (Response.contains("status"))
RespStatus = Response.value("status").toString();
else if (Response.contains("bitStatus"))
RespStatus = Response.value("bitStatus").toString();
else
throw exPayment("The response has no status field");

QString RespAmount;
if (Response.contains("amount"))
RespAmount = Response.value("amount").toString();
else if (Response.contains("bitAmount"))
RespAmount = Response.value("bitAmount").toString();
else
throw exPayment("The response has no amount field");

//
return {
Json.toJson(QJsonDocument::Compact),
Approval
};

} catch (std::exception &e) {
PaymentLogic::log(gtwTarjomyarPay::Name, __FUNCTION__, __LINE__, { e.what() });
throw;
}
}

} //namespace Targoman::API::AccountModule::Payment::Gateways
59 changes: 59 additions & 0 deletions Modules/Account/moduleSrc/Payment/Gateways/gtwTarjomyarPay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/******************************************************************************
# TargomanAPI: REST API for Targoman
#
# Copyright 2014-2020 by Targoman Intelligent Processing <http://tip.co.ir>
#
# TargomanAPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# TargomanAPI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU AFFERO GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
# along with Targoman. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/**
* @author S. Mehran M. Ziabary <ziabary@targoman.com>
* @author Kambiz Zandi <kambizzandi@gmail.com>
*/

#ifndef TARGOMAN_API_MODULES_ACCOUNT_PGTW_TARJOMYARPAY_H
#define TARGOMAN_API_MODULES_ACCOUNT_PGTW_TARJOMYARPAY_H

#include "../intfPaymentGateway.h"
#include "../PaymentLogic.h"

/**
* CAUTION:
* place #include "gtwTarjomyarPay.h" in ActivePayments.h for proper driver registration
*/

namespace Targoman::API::AccountModule::Payment::Gateways {

class gtwTarjomyarPay : public intfPaymentGateway
{
TARGOMAN_DEFINE_API_PAYMENT_GATEWAY(
gtwTarjomyarPay,
Targoman::API::AccountModule::enuPaymentGatewayType::IranIntermediateGateway
);

public:
constexpr static char Name[] = "TarjomyarPay";

private:
constexpr static char METAINFO_KEY_TOKEN[] = "token";

//($token, $amount, $cb, $desc)
constexpr static char URL_GTW_REQUEST[] = "https://api.targoman.ir/svn/Branch/NGT/rest/Affiliates/requestPayment";

//($token, $ordID)
constexpr static char URL_GTW_VERIFY[] = "https://api.targoman.ir/svn/Branch/NGT/rest/Affiliates/approvePayment";
};

} //namespace Targoman::API::AccountModule::Payment::Gateways

#endif // TARGOMAN_API_MODULES_ACCOUNT_PGTW_TARJOMYARPAY_H
2 changes: 1 addition & 1 deletion Modules/Account/moduleSrc/Payment/Gateways/gtwZibal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ std::tuple<QString, QString, QString> gtwZibal::prepareAndRequest(
std::tuple<QString, QString> gtwZibal::verifyAndSettle(
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
const ORM::tblPaymentGateways::DTO &_paymentGateway,
const ORM::tblOnlinePayments::DTO &_onlinePayment,
Q_DECL_UNUSED const ORM::tblOnlinePayments::DTO &_onlinePaymentDTO,
const TAPI::JSON_t& _pgResponse
// const QString& _domain
) {
Expand Down
5 changes: 3 additions & 2 deletions Modules/Account/moduleSrc/Payment/Gateways/gtwZibal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ namespace Targoman::API::AccountModule::Payment::Gateways {
class gtwZibal : public intfPaymentGateway
{
TARGOMAN_DEFINE_API_PAYMENT_GATEWAY(
Targoman::API::AccountModule::enuPaymentGatewayType::IranIntermediateGateway,
gtwZibal)
gtwZibal,
Targoman::API::AccountModule::enuPaymentGatewayType::IranIntermediateGateway
);

public:
constexpr static char Name[] = "Zibal";
Expand Down
26 changes: 13 additions & 13 deletions Modules/Account/moduleSrc/Payment/intfPaymentGateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ namespace Payment {
static _class* Instance = nullptr; return (Q_LIKELY(Instance) ? Instance : (Instance = new _class)); \
}

#define TARGOMAN_DEFINE_API_PAYMENT_GATEWAY(_gtwType, _gatewayClassName) \
#define TARGOMAN_DEFINE_API_PAYMENT_GATEWAY(_name, _type) \
public: \
instanceGetterPtr(_gatewayClassName); \
instanceGetterPtr(_name); \
protected: \
virtual Targoman::API::AccountModule::enuPaymentGatewayType::Type getType() { return _gtwType; }; \
virtual Targoman::API::AccountModule::enuPaymentGatewayType::Type getType() { return _type; }; \
virtual /*[Response, TrackID, PaymentLink]*/std::tuple<QString, QString, QString> prepareAndRequest( \
INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM, \
const Targoman::API::AccountModule::ORM::tblPaymentGateways::DTO &_paymentGateway, \
Expand All @@ -122,17 +122,17 @@ protected: \
); \
friend Targoman::API::AccountModule::Payment::PaymentLogic; \
private: \
_gatewayClassName(); \
TAPI_DISABLE_COPY(_gatewayClassName); \
TARGOMAN_BEGIN_STATIC_CTOR(_gatewayClassName) \
Targoman::API::AccountModule::Payment::PaymentLogic::registerGateway(_gatewayClassName::Name, _gatewayClassName::instancePtr()); \
TARGOMAN_END_STATIC_CTOR(_gatewayClassName)
_name(); \
TAPI_DISABLE_COPY(_name); \
TARGOMAN_BEGIN_STATIC_CTOR(_name) \
Targoman::API::AccountModule::Payment::PaymentLogic::registerGateway(_name::Name, _name::instancePtr()); \
TARGOMAN_END_STATIC_CTOR(_name)

//PaymentLogic::registerGateway<_gatewayClassName>(_gatewayClassName::Name, _gatewayClassName::instancePtr());
//PaymentLogic::registerGateway<_gatewayClassName>(_gatewayClassName::Name);
//PaymentLogic::registerGateway<_name>(_name::Name, _name::instancePtr());
//PaymentLogic::registerGateway<_name>(_name::Name);

#define TARGOMAN_IMPL_API_PAYMENT_GATEWAY(_gatewayClassName) \
_gatewayClassName::_gatewayClassName() { ; }
#define TARGOMAN_IMPL_API_PAYMENT_GATEWAY(_name) \
_name::_name() { ; }

/**
* @brief The intfPaymentGateway class is base class of gateway drivers
Expand All @@ -159,7 +159,7 @@ class intfPaymentGateway
virtual std::tuple<QString, QString> verifyAndSettle(
INTFAPICALLBOOM_DECL &APICALLBOOM_PARAM,
const ORM::tblPaymentGateways::DTO &_paymentGateway,
const ORM::tblOnlinePayments::DTO &_onlinePayment,
Q_DECL_UNUSED const ORM::tblOnlinePayments::DTO &_onlinePaymentDTO,
const TAPI::JSON_t &_pgResponse
// const QString &_domain
) = 0;
Expand Down
10 changes: 6 additions & 4 deletions Modules/Account/moduleSrc/moduleSrc.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ HEADERS += \
Payment/PaymentLogic.h \
Payment/intfPaymentGateway.h \
Payment/Gateways/gtwDevTest.h \
Payment/Gateways/gtwMellatBank.h \
Payment/Gateways/gtwZibal.h
Payment/Gateways/gtwZibal.h \
Payment/Gateways/gtwTarjomyarPay.h \
Payment/Gateways/gtwMellatBank.h

SOURCES += \
Account.cpp \
Expand All @@ -57,8 +58,9 @@ SOURCES += \
Payment/PaymentLogic.cpp \
Payment/intfPaymentGateway.cpp \
Payment/Gateways/gtwDevTest.cpp \
Payment/Gateways/gtwMellatBank.cpp \
Payment/Gateways/gtwZibal.cpp
Payment/Gateways/gtwZibal.cpp \
Payment/Gateways/gtwTarjomyarPay.cpp \
Payment/Gateways/gtwMellatBank.cpp

OTHER_FILES +=

Expand Down