mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Support additional payment methods.
This commit is contained in:
parent
de0eef8cc6
commit
bb251627a9
5 changed files with 68 additions and 4 deletions
|
@ -318,6 +318,9 @@ void Form::processForm(const MTPDpayments_paymentForm &data) {
|
||||||
processSavedCredentials(data);
|
processSavedCredentials(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (const auto additional = data.vadditional_methods()) {
|
||||||
|
processAdditionalPaymentMethods(additional->v);
|
||||||
|
}
|
||||||
fillPaymentMethodInformation();
|
fillPaymentMethodInformation();
|
||||||
_updates.fire(FormReady{});
|
_updates.fire(FormReady{});
|
||||||
}
|
}
|
||||||
|
@ -470,6 +473,18 @@ void Form::processSavedCredentials(
|
||||||
refreshPaymentMethodDetails();
|
refreshPaymentMethodDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Form::processAdditionalPaymentMethods(
|
||||||
|
const QVector<MTPPaymentFormMethod> &list) {
|
||||||
|
_paymentMethod.ui.additionalMethods = ranges::views::all(
|
||||||
|
list
|
||||||
|
) | ranges::views::transform([](const MTPPaymentFormMethod &method) {
|
||||||
|
return Ui::PaymentMethodAdditional{
|
||||||
|
.title = qs(method.data().vtitle()),
|
||||||
|
.url = qs(method.data().vurl()),
|
||||||
|
};
|
||||||
|
}) | ranges::to_vector;
|
||||||
|
}
|
||||||
|
|
||||||
void Form::refreshPaymentMethodDetails() {
|
void Form::refreshPaymentMethodDetails() {
|
||||||
const auto &saved = _paymentMethod.savedCredentials;
|
const auto &saved = _paymentMethod.savedCredentials;
|
||||||
const auto &entered = _paymentMethod.newCredentials;
|
const auto &entered = _paymentMethod.newCredentials;
|
||||||
|
|
|
@ -256,6 +256,8 @@ private:
|
||||||
void processSavedInformation(const MTPDpaymentRequestedInfo &data);
|
void processSavedInformation(const MTPDpaymentRequestedInfo &data);
|
||||||
void processSavedCredentials(
|
void processSavedCredentials(
|
||||||
const MTPDpaymentSavedCredentialsCard &data);
|
const MTPDpaymentSavedCredentialsCard &data);
|
||||||
|
void processAdditionalPaymentMethods(
|
||||||
|
const QVector<MTPPaymentFormMethod> &list);
|
||||||
void processShippingOptions(const QVector<MTPShippingOption> &data);
|
void processShippingOptions(const QVector<MTPShippingOption> &data);
|
||||||
void fillPaymentMethodInformation();
|
void fillPaymentMethodInformation();
|
||||||
void fillStripeNativeMethod(QJsonObject object);
|
void fillStripeNativeMethod(QJsonObject object);
|
||||||
|
|
|
@ -443,6 +443,26 @@ void Panel::showEditPaymentMethod(const PaymentMethodDetails &method) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Panel::showAdditionalMethod(
|
||||||
|
const QString &provider,
|
||||||
|
const PaymentMethodAdditional &method) {
|
||||||
|
auto bottomText = tr::lng_payments_processed_by(
|
||||||
|
lt_provider,
|
||||||
|
rpl::single(provider));
|
||||||
|
setTitle(rpl::single(method.title));
|
||||||
|
if (!showWebview(method.url, true, std::move(bottomText))) {
|
||||||
|
const auto available = Webview::Availability();
|
||||||
|
if (available.error != Webview::Available::Error::None) {
|
||||||
|
showWebviewError(
|
||||||
|
tr::lng_payments_webview_no_use(tr::now),
|
||||||
|
available);
|
||||||
|
} else {
|
||||||
|
showCriticalError({ "Error: Could not initialize WebView." });
|
||||||
|
}
|
||||||
|
_widget->setBackAllowed(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Panel::showWebviewProgress() {
|
void Panel::showWebviewProgress() {
|
||||||
if (_webviewProgress && _progress && _progress->shown) {
|
if (_webviewProgress && _progress && _progress->shown) {
|
||||||
return;
|
return;
|
||||||
|
@ -572,20 +592,37 @@ postEvent: function(eventType, eventData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::choosePaymentMethod(const PaymentMethodDetails &method) {
|
void Panel::choosePaymentMethod(const PaymentMethodDetails &method) {
|
||||||
if (!method.ready) {
|
const auto hasSaved = method.ready;
|
||||||
|
if (!hasSaved && method.additionalMethods.empty()) {
|
||||||
showEditPaymentMethod(method);
|
showEditPaymentMethod(method);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
showBox(Box([=](not_null<GenericBox*> box) {
|
showBox(Box([=](not_null<GenericBox*> box) {
|
||||||
const auto save = [=](int option) {
|
const auto save = [=](int option) {
|
||||||
if (option) {
|
const auto basic = hasSaved ? 1 : 0;
|
||||||
|
if (option > basic) {
|
||||||
|
const auto index = option - basic - 1;
|
||||||
|
Assert(index < method.additionalMethods.size());
|
||||||
|
showAdditionalMethod(
|
||||||
|
method.provider,
|
||||||
|
method.additionalMethods[index]);
|
||||||
|
} else if (!option) {
|
||||||
showEditPaymentMethod(method);
|
showEditPaymentMethod(method);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
auto options = std::vector{
|
||||||
|
tr::lng_payments_new_card(tr::now),
|
||||||
|
};
|
||||||
|
if (hasSaved) {
|
||||||
|
options.push_back(method.title);
|
||||||
|
}
|
||||||
|
for (const auto &additional : method.additionalMethods) {
|
||||||
|
options.push_back(additional.title);
|
||||||
|
}
|
||||||
SingleChoiceBox(box, {
|
SingleChoiceBox(box, {
|
||||||
.title = tr::lng_payments_payment_method(),
|
.title = tr::lng_payments_payment_method(),
|
||||||
.options = { method.title, tr::lng_payments_new_card(tr::now) },
|
.options = std::move(options),
|
||||||
.initialSelection = 0,
|
.initialSelection = hasSaved ? 1 : -1,
|
||||||
.callback = save,
|
.callback = save,
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -36,6 +36,7 @@ class FormSummary;
|
||||||
class EditInformation;
|
class EditInformation;
|
||||||
class EditCard;
|
class EditCard;
|
||||||
struct PaymentMethodDetails;
|
struct PaymentMethodDetails;
|
||||||
|
struct PaymentMethodAdditional;
|
||||||
struct NativeMethodDetails;
|
struct NativeMethodDetails;
|
||||||
|
|
||||||
class Panel final {
|
class Panel final {
|
||||||
|
@ -61,6 +62,9 @@ public:
|
||||||
const RequestedInformation ¤t,
|
const RequestedInformation ¤t,
|
||||||
InformationField field);
|
InformationField field);
|
||||||
void showEditPaymentMethod(const PaymentMethodDetails &method);
|
void showEditPaymentMethod(const PaymentMethodDetails &method);
|
||||||
|
void showAdditionalMethod(
|
||||||
|
const QString &provider,
|
||||||
|
const PaymentMethodAdditional &method);
|
||||||
void showEditCard(
|
void showEditCard(
|
||||||
const NativeMethodDetails &native,
|
const NativeMethodDetails &native,
|
||||||
CardField field);
|
CardField field);
|
||||||
|
|
|
@ -160,9 +160,15 @@ struct NativeMethodDetails {
|
||||||
bool canSaveInformation = false;
|
bool canSaveInformation = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct PaymentMethodAdditional {
|
||||||
|
QString title;
|
||||||
|
QString url;
|
||||||
|
};
|
||||||
|
|
||||||
struct PaymentMethodDetails {
|
struct PaymentMethodDetails {
|
||||||
QString title;
|
QString title;
|
||||||
NativeMethodDetails native;
|
NativeMethodDetails native;
|
||||||
|
std::vector<PaymentMethodAdditional> additionalMethods;
|
||||||
QString url;
|
QString url;
|
||||||
QString provider;
|
QString provider;
|
||||||
bool ready = false;
|
bool ready = false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue