diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp index 5eea983534..9ff737d1ca 100644 --- a/Telegram/SourceFiles/payments/payments_form.cpp +++ b/Telegram/SourceFiles/payments/payments_form.cpp @@ -675,6 +675,7 @@ void Form::fillSmartGlocalNativeMethod(QJsonObject object) { _paymentMethod.native = NativePaymentMethod{ .data = SmartGlocalPaymentMethod{ .publicToken = key, + .tokenizeUrl = value(u"tokenize_url").toString(), }, }; _paymentMethod.ui.native = Ui::NativeMethodDetails{ @@ -1011,6 +1012,7 @@ void Form::validateCard( } auto configuration = SmartGlocal::PaymentConfiguration{ .publicToken = method.publicToken, + .tokenizeUrl = method.tokenizeUrl, .isTest = _invoice.isTest, }; _smartglocal = std::make_unique( diff --git a/Telegram/SourceFiles/payments/payments_form.h b/Telegram/SourceFiles/payments/payments_form.h index bd95e68eaf..414eb0b021 100644 --- a/Telegram/SourceFiles/payments/payments_form.h +++ b/Telegram/SourceFiles/payments/payments_form.h @@ -95,6 +95,7 @@ struct StripePaymentMethod { struct SmartGlocalPaymentMethod { QString publicToken; + QString tokenizeUrl; }; struct NativePaymentMethod { diff --git a/Telegram/SourceFiles/payments/smartglocal/smartglocal_api_client.cpp b/Telegram/SourceFiles/payments/smartglocal/smartglocal_api_client.cpp index 0fca1b7f05..690438c085 100644 --- a/Telegram/SourceFiles/payments/smartglocal/smartglocal_api_client.cpp +++ b/Telegram/SourceFiles/payments/smartglocal/smartglocal_api_client.cpp @@ -44,10 +44,21 @@ namespace { }).toJson(QJsonDocument::Compact); } +[[nodiscard]] QString ComputeApiUrl(PaymentConfiguration configuration) { + const auto url = configuration.tokenizeUrl; + if (url.startsWith("https://") + && url.endsWith(".smart-glocal.com/cds/v1/tokenize/card")) { + return url; + } + return QString("https://%1/%2") + .arg(APIURLBase(configuration.isTest)) + .arg(TokenEndpoint()); +} + } // namespace APIClient::APIClient(PaymentConfiguration configuration) -: _apiUrl("https://" + APIURLBase(configuration.isTest)) +: _apiUrl(ComputeApiUrl(configuration)) , _configuration(configuration) { _additionalHttpHeaders = { { "X-PUBLIC-TOKEN", _configuration.publicToken }, @@ -67,7 +78,7 @@ void APIClient::createTokenWithCard( void APIClient::createTokenWithData( QByteArray data, TokenCompletionCallback completion) { - const auto url = QUrl(_apiUrl + '/' + TokenEndpoint()); + const auto url = QUrl(_apiUrl); auto request = QNetworkRequest(url); request.setHeader( QNetworkRequest::ContentTypeHeader, diff --git a/Telegram/SourceFiles/payments/smartglocal/smartglocal_api_client.h b/Telegram/SourceFiles/payments/smartglocal/smartglocal_api_client.h index b418188cb0..3166b386da 100644 --- a/Telegram/SourceFiles/payments/smartglocal/smartglocal_api_client.h +++ b/Telegram/SourceFiles/payments/smartglocal/smartglocal_api_client.h @@ -19,6 +19,7 @@ namespace SmartGlocal { struct PaymentConfiguration { QString publicToken; + QString tokenizeUrl; bool isTest = false; };