Allow smartglocal to customize tokenize url.

This commit is contained in:
John Preston 2023-12-22 20:51:50 -04:00
parent fc50d5c30f
commit 1d345299f5
4 changed files with 17 additions and 2 deletions

View File

@ -675,6 +675,7 @@ void Form::fillSmartGlocalNativeMethod(QJsonObject object) {
_paymentMethod.native = NativePaymentMethod{ _paymentMethod.native = NativePaymentMethod{
.data = SmartGlocalPaymentMethod{ .data = SmartGlocalPaymentMethod{
.publicToken = key, .publicToken = key,
.tokenizeUrl = value(u"tokenize_url").toString(),
}, },
}; };
_paymentMethod.ui.native = Ui::NativeMethodDetails{ _paymentMethod.ui.native = Ui::NativeMethodDetails{
@ -1011,6 +1012,7 @@ void Form::validateCard(
} }
auto configuration = SmartGlocal::PaymentConfiguration{ auto configuration = SmartGlocal::PaymentConfiguration{
.publicToken = method.publicToken, .publicToken = method.publicToken,
.tokenizeUrl = method.tokenizeUrl,
.isTest = _invoice.isTest, .isTest = _invoice.isTest,
}; };
_smartglocal = std::make_unique<SmartGlocal::APIClient>( _smartglocal = std::make_unique<SmartGlocal::APIClient>(

View File

@ -95,6 +95,7 @@ struct StripePaymentMethod {
struct SmartGlocalPaymentMethod { struct SmartGlocalPaymentMethod {
QString publicToken; QString publicToken;
QString tokenizeUrl;
}; };
struct NativePaymentMethod { struct NativePaymentMethod {

View File

@ -44,10 +44,21 @@ namespace {
}).toJson(QJsonDocument::Compact); }).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 } // namespace
APIClient::APIClient(PaymentConfiguration configuration) APIClient::APIClient(PaymentConfiguration configuration)
: _apiUrl("https://" + APIURLBase(configuration.isTest)) : _apiUrl(ComputeApiUrl(configuration))
, _configuration(configuration) { , _configuration(configuration) {
_additionalHttpHeaders = { _additionalHttpHeaders = {
{ "X-PUBLIC-TOKEN", _configuration.publicToken }, { "X-PUBLIC-TOKEN", _configuration.publicToken },
@ -67,7 +78,7 @@ void APIClient::createTokenWithCard(
void APIClient::createTokenWithData( void APIClient::createTokenWithData(
QByteArray data, QByteArray data,
TokenCompletionCallback completion) { TokenCompletionCallback completion) {
const auto url = QUrl(_apiUrl + '/' + TokenEndpoint()); const auto url = QUrl(_apiUrl);
auto request = QNetworkRequest(url); auto request = QNetworkRequest(url);
request.setHeader( request.setHeader(
QNetworkRequest::ContentTypeHeader, QNetworkRequest::ContentTypeHeader,

View File

@ -19,6 +19,7 @@ namespace SmartGlocal {
struct PaymentConfiguration { struct PaymentConfiguration {
QString publicToken; QString publicToken;
QString tokenizeUrl;
bool isTest = false; bool isTest = false;
}; };