Skip to content

Commit 1d34529

Browse files
committed
Allow smartglocal to customize tokenize url.
1 parent fc50d5c commit 1d34529

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

Telegram/SourceFiles/payments/payments_form.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ void Form::fillSmartGlocalNativeMethod(QJsonObject object) {
675675
_paymentMethod.native = NativePaymentMethod{
676676
.data = SmartGlocalPaymentMethod{
677677
.publicToken = key,
678+
.tokenizeUrl = value(u"tokenize_url").toString(),
678679
},
679680
};
680681
_paymentMethod.ui.native = Ui::NativeMethodDetails{
@@ -1011,6 +1012,7 @@ void Form::validateCard(
10111012
}
10121013
auto configuration = SmartGlocal::PaymentConfiguration{
10131014
.publicToken = method.publicToken,
1015+
.tokenizeUrl = method.tokenizeUrl,
10141016
.isTest = _invoice.isTest,
10151017
};
10161018
_smartglocal = std::make_unique<SmartGlocal::APIClient>(

Telegram/SourceFiles/payments/payments_form.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct StripePaymentMethod {
9595

9696
struct SmartGlocalPaymentMethod {
9797
QString publicToken;
98+
QString tokenizeUrl;
9899
};
99100

100101
struct NativePaymentMethod {

Telegram/SourceFiles/payments/smartglocal/smartglocal_api_client.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,21 @@ namespace {
4444
}).toJson(QJsonDocument::Compact);
4545
}
4646

47+
[[nodiscard]] QString ComputeApiUrl(PaymentConfiguration configuration) {
48+
const auto url = configuration.tokenizeUrl;
49+
if (url.startsWith("https://")
50+
&& url.endsWith(".smart-glocal.com/cds/v1/tokenize/card")) {
51+
return url;
52+
}
53+
return QString("https://%1/%2")
54+
.arg(APIURLBase(configuration.isTest))
55+
.arg(TokenEndpoint());
56+
}
57+
4758
} // namespace
4859

4960
APIClient::APIClient(PaymentConfiguration configuration)
50-
: _apiUrl("https://" + APIURLBase(configuration.isTest))
61+
: _apiUrl(ComputeApiUrl(configuration))
5162
, _configuration(configuration) {
5263
_additionalHttpHeaders = {
5364
{ "X-PUBLIC-TOKEN", _configuration.publicToken },
@@ -67,7 +78,7 @@ void APIClient::createTokenWithCard(
6778
void APIClient::createTokenWithData(
6879
QByteArray data,
6980
TokenCompletionCallback completion) {
70-
const auto url = QUrl(_apiUrl + '/' + TokenEndpoint());
81+
const auto url = QUrl(_apiUrl);
7182
auto request = QNetworkRequest(url);
7283
request.setHeader(
7384
QNetworkRequest::ContentTypeHeader,

Telegram/SourceFiles/payments/smartglocal/smartglocal_api_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace SmartGlocal {
1919

2020
struct PaymentConfiguration {
2121
QString publicToken;
22+
QString tokenizeUrl;
2223
bool isTest = false;
2324
};
2425

0 commit comments

Comments
 (0)