mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 07:07:08 +02:00
Processed payments form with API scheme on layer 181.
This commit is contained in:
parent
39e03c3ca7
commit
ac2f35f12b
2 changed files with 72 additions and 53 deletions
Telegram/SourceFiles/payments
|
@ -359,12 +359,7 @@ void Form::requestForm() {
|
|||
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json))
|
||||
)).done([=](const MTPpayments_PaymentForm &result) {
|
||||
hideProgress();
|
||||
result.match([&](const MTPDpayments_paymentForm &data) {
|
||||
processForm(data);
|
||||
}, [&](const MTPDpayments_paymentFormStars &data) {
|
||||
// #TODO stars
|
||||
_updates.fire(Error{ Error::Type::Form });
|
||||
});
|
||||
processForm(result);
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
hideProgress();
|
||||
_updates.fire(Error{ Error::Type::Form, error.type() });
|
||||
|
@ -390,33 +385,44 @@ void Form::requestReceipt() {
|
|||
}).send();
|
||||
}
|
||||
|
||||
void Form::processForm(const MTPDpayments_paymentForm &data) {
|
||||
_session->data().processUsers(data.vusers());
|
||||
void Form::processForm(const MTPpayments_PaymentForm &result) {
|
||||
using TLForm = MTPDpayments_paymentForm;
|
||||
using TLCredits = MTPDpayments_paymentFormStars;
|
||||
result.match([&](const auto &data) {
|
||||
_session->data().processUsers(data.vusers());
|
||||
|
||||
data.vinvoice().match([&](const auto &data) {
|
||||
processInvoice(data);
|
||||
});
|
||||
processDetails(data);
|
||||
if (const auto info = data.vsaved_info()) {
|
||||
info->match([&](const auto &data) {
|
||||
processSavedInformation(data);
|
||||
data.vinvoice().match([&](const auto &data) {
|
||||
processInvoice(data);
|
||||
});
|
||||
}
|
||||
_paymentMethod.savedCredentials.clear();
|
||||
_paymentMethod.savedCredentialsIndex = 0;
|
||||
if (const auto credentials = data.vsaved_credentials()) {
|
||||
_paymentMethod.savedCredentials.reserve(credentials->v.size());
|
||||
for (const auto &saved : credentials->v) {
|
||||
_paymentMethod.savedCredentials.push_back({
|
||||
.id = qs(saved.data().vid()),
|
||||
.title = qs(saved.data().vtitle()),
|
||||
});
|
||||
|
||||
processDetails(result);
|
||||
result.match([&](const TLForm &data) {
|
||||
if (const auto info = data.vsaved_info()) {
|
||||
info->match([&](const auto &data) {
|
||||
processSavedInformation(data);
|
||||
});
|
||||
}
|
||||
refreshPaymentMethodDetails();
|
||||
}
|
||||
if (const auto additional = data.vadditional_methods()) {
|
||||
processAdditionalPaymentMethods(additional->v);
|
||||
}
|
||||
}, [](const TLCredits &) {
|
||||
});
|
||||
_paymentMethod.savedCredentials.clear();
|
||||
_paymentMethod.savedCredentialsIndex = 0;
|
||||
result.match([&](const TLForm &data) {
|
||||
if (const auto credentials = data.vsaved_credentials()) {
|
||||
_paymentMethod.savedCredentials.reserve(credentials->v.size());
|
||||
for (const auto &saved : credentials->v) {
|
||||
_paymentMethod.savedCredentials.push_back({
|
||||
.id = qs(saved.data().vid()),
|
||||
.title = qs(saved.data().vtitle()),
|
||||
});
|
||||
}
|
||||
refreshPaymentMethodDetails();
|
||||
}
|
||||
if (const auto additional = data.vadditional_methods()) {
|
||||
processAdditionalPaymentMethods(additional->v);
|
||||
}
|
||||
}, [](const TLCredits &) {
|
||||
});
|
||||
fillPaymentMethodInformation();
|
||||
_updates.fire(FormReady{});
|
||||
}
|
||||
|
@ -479,31 +485,44 @@ void Form::processInvoice(const MTPDinvoice &data) {
|
|||
};
|
||||
}
|
||||
|
||||
void Form::processDetails(const MTPDpayments_paymentForm &data) {
|
||||
const auto nativeParams = data.vnative_params();
|
||||
auto nativeParamsJson = nativeParams
|
||||
? nativeParams->match(
|
||||
[&](const MTPDdataJSON &data) { return data.vdata().v; })
|
||||
: QByteArray();
|
||||
_details = FormDetails{
|
||||
.formId = data.vform_id().v,
|
||||
.url = qs(data.vurl()),
|
||||
.nativeProvider = qs(data.vnative_provider().value_or_empty()),
|
||||
.nativeParamsJson = std::move(nativeParamsJson),
|
||||
.botId = data.vbot_id().v,
|
||||
.providerId = data.vprovider_id().v,
|
||||
.canSaveCredentials = data.is_can_save_credentials(),
|
||||
.passwordMissing = data.is_password_missing(),
|
||||
};
|
||||
_invoice.cover.title = qs(data.vtitle());
|
||||
void Form::processDetails(const MTPpayments_PaymentForm &result) {
|
||||
using TLForm = MTPDpayments_paymentForm;
|
||||
using TLCredits = MTPDpayments_paymentFormStars;
|
||||
_details = result.match([&](const TLForm &data) {
|
||||
const auto nativeParams = data.vnative_params();
|
||||
auto nativeParamsJson = nativeParams
|
||||
? nativeParams->match(
|
||||
[&](const MTPDdataJSON &data) { return data.vdata().v; })
|
||||
: QByteArray();
|
||||
return FormDetails{
|
||||
.formId = data.vform_id().v,
|
||||
.url = qs(data.vurl()),
|
||||
.nativeProvider = qs(data.vnative_provider().value_or_empty()),
|
||||
.nativeParamsJson = std::move(nativeParamsJson),
|
||||
.botId = data.vbot_id().v,
|
||||
.providerId = data.vprovider_id().v,
|
||||
.canSaveCredentials = data.is_can_save_credentials(),
|
||||
.passwordMissing = data.is_password_missing(),
|
||||
};
|
||||
}, [](const TLCredits &data) {
|
||||
return FormDetails{
|
||||
.formId = data.vform_id().v,
|
||||
.botId = data.vbot_id().v,
|
||||
};
|
||||
});
|
||||
_invoice.cover.title = result.match([](const auto &data) {
|
||||
return qs(data.vtitle());
|
||||
});
|
||||
_invoice.cover.description = TextUtilities::ParseEntities(
|
||||
qs(data.vdescription()),
|
||||
result.match([](const auto &d) { return qs(d.vdescription()); }),
|
||||
TextParseLinks | TextParseMultiline);
|
||||
if (_invoice.cover.thumbnail.isNull() && !_thumbnailLoadProcess) {
|
||||
if (const auto photo = data.vphoto()) {
|
||||
loadThumbnail(
|
||||
_session->data().photoFromWeb(*photo, ImageLocation()));
|
||||
}
|
||||
result.match([&](const auto &data) {
|
||||
if (const auto photo = data.vphoto()) {
|
||||
loadThumbnail(
|
||||
_session->data().photoFromWeb(*photo, ImageLocation()));
|
||||
}
|
||||
});
|
||||
}
|
||||
if (const auto botId = _details.botId) {
|
||||
if (const auto bot = _session->data().userLoaded(botId)) {
|
||||
|
|
|
@ -285,10 +285,10 @@ private:
|
|||
|
||||
void requestForm();
|
||||
void requestReceipt();
|
||||
void processForm(const MTPDpayments_paymentForm &data);
|
||||
void processForm(const MTPpayments_PaymentForm &result);
|
||||
void processReceipt(const MTPDpayments_paymentReceipt &data);
|
||||
void processInvoice(const MTPDinvoice &data);
|
||||
void processDetails(const MTPDpayments_paymentForm &data);
|
||||
void processDetails(const MTPpayments_PaymentForm &result);
|
||||
void processDetails(const MTPDpayments_paymentReceipt &data);
|
||||
void processSavedInformation(const MTPDpaymentRequestedInfo &data);
|
||||
void processAdditionalPaymentMethods(
|
||||
|
|
Loading…
Add table
Reference in a new issue