129 lines
4.9 KiB
C++
129 lines
4.9 KiB
C++
#include "PayByCardBirbankScript.h"
|
||
|
||
#include <QRandomGenerator>
|
||
#include <QThread>
|
||
#include <utility>
|
||
|
||
#include "DatabaseManager.h"
|
||
#include "adb/AdbUtils.h"
|
||
#include "dao/AccountDAO.h"
|
||
#include "dao/ApplicationDAO.h"
|
||
#include "dao/DeviceDAO.h"
|
||
#include "dao/TransactionDAO.h"
|
||
#include "db/ApplicationInfo.h"
|
||
#include "db/DeviceInfo.h"
|
||
#include "time/DateUtils.h"
|
||
|
||
PayByCardBirbankScript::PayByCardBirbankScript(
|
||
AccountInfo account,
|
||
QString card,
|
||
QString fullName,
|
||
const double amount,
|
||
QObject *parent
|
||
) : CommonBirbankScript(parent),
|
||
m_account(std::move(account)), m_card(std::move(card)),
|
||
m_fullName(std::move(fullName)), m_amount(amount) {
|
||
}
|
||
|
||
PayByCardBirbankScript::~PayByCardBirbankScript() = default;
|
||
|
||
|
||
void PayByCardBirbankScript::makePayment(const DeviceInfo &device) {
|
||
// Оплата со страницы карты
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(device.id, ++m_counter));
|
||
|
||
Node cardEditText = xmlScreenParser.findEditText("Номер карты");
|
||
Node amountEditText = xmlScreenParser.findEditText("Сумма");
|
||
if (!cardEditText.isEmpty() && !amountEditText.isEmpty()) {
|
||
AdbUtils::makeTap(device.id, cardEditText.x(), cardEditText.y());
|
||
QThread::msleep(200);
|
||
AdbUtils::inputText(device.id, m_card);
|
||
|
||
AdbUtils::hideKeyboard(device.id);
|
||
|
||
AdbUtils::makeTap(device.id, amountEditText.x(), amountEditText.y());
|
||
QThread::msleep(200);
|
||
AdbUtils::inputText(device.id, QString::number(m_amount));
|
||
|
||
AdbUtils::hideKeyboard(device.id);
|
||
|
||
// дальше оплата, но хз как
|
||
|
||
|
||
} else {
|
||
m_error = "Не нашли поля ввода 'Номер карты' или 'Сумма'";
|
||
qDebug() << m_error;
|
||
}
|
||
}
|
||
|
||
void PayByCardBirbankScript::doStart() {
|
||
const DeviceInfo device = DeviceDAO::getDeviceById(m_account.deviceId);
|
||
const ApplicationInfo app = ApplicationDAO::getApplication(m_account.deviceId, m_account.appCode);
|
||
|
||
if (device.id.isEmpty() || app.id == -1) {
|
||
m_error = "Device or app not found.";
|
||
qDebug() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_account.deviceId, ++m_counter));
|
||
if (!xmlScreenParser.isHomeScreen()) {
|
||
if (!runAppAndGoToHomeScreen(device.id, app.package, app.pinCode, device.screenWidth, device.screenHeight)) {
|
||
m_error = "Не смогли дойти до домашней страницы";
|
||
qDebug() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
}
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_account.deviceId, ++m_counter));
|
||
Node closeBannerNode = xmlScreenParser.findButtonNode("Maraqlı deyil", false);
|
||
if (!closeBannerNode.isEmpty()) {
|
||
AdbUtils::makeTap(m_account.deviceId, closeBannerNode.x(), closeBannerNode.y());
|
||
QThread::msleep(1000);
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_account.deviceId, ++m_counter));
|
||
}
|
||
|
||
if (xmlScreenParser.isHomeScreen()) {
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_account.deviceId, ++m_counter));
|
||
Node cardText = xmlScreenParser.findTextNode("2480");
|
||
if (!cardText.isEmpty()) {
|
||
AdbUtils::makeTap(m_account.deviceId, cardText.x(), cardText.y());
|
||
QThread::msleep(2000);
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_account.deviceId, ++m_counter));
|
||
Node payBtn = xmlScreenParser.findTextNode("Перевести");
|
||
if (!payBtn.isEmpty()) {
|
||
AdbUtils::makeTap(m_account.deviceId, payBtn.x(), payBtn.y());
|
||
QThread::msleep(1000);
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_account.deviceId, ++m_counter));
|
||
Node payByCardBtn = xmlScreenParser.findTextNode("На карту любого банка");
|
||
if (!payByCardBtn.isEmpty()) {
|
||
AdbUtils::makeTap(m_account.deviceId, payByCardBtn.x(), payByCardBtn.y());
|
||
QThread::msleep(1000);
|
||
|
||
makePayment(device);
|
||
} else {
|
||
m_error = "Pay by card button not found: " + m_account.deviceId + " " + m_account.appCode;
|
||
qWarning() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
} else {
|
||
m_error = "Pay button not found: " + m_account.deviceId + " " + m_account.appCode;
|
||
qWarning() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!m_error.isEmpty()) {
|
||
AdbUtils::takeXmlDump(device.id, "pay_by_Card_Birbank_fail_transactions_" + QString::number(m_account.id));
|
||
}
|
||
|
||
emit finishedWithResult(m_error);
|
||
}
|