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