mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Allow smartglocal to customize tokenize url.
This commit is contained in:
parent
fc50d5c30f
commit
1d345299f5
4 changed files with 17 additions and 2 deletions
|
@ -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<SmartGlocal::APIClient>(
|
||||
|
|
|
@ -95,6 +95,7 @@ struct StripePaymentMethod {
|
|||
|
||||
struct SmartGlocalPaymentMethod {
|
||||
QString publicToken;
|
||||
QString tokenizeUrl;
|
||||
};
|
||||
|
||||
struct NativePaymentMethod {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace SmartGlocal {
|
|||
|
||||
struct PaymentConfiguration {
|
||||
QString publicToken;
|
||||
QString tokenizeUrl;
|
||||
bool isTest = false;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue