summaryrefslogtreecommitdiff
path: root/indra/newview/llbuycurrencyhtml.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llbuycurrencyhtml.cpp')
-rw-r--r--indra/newview/llbuycurrencyhtml.cpp148
1 files changed, 124 insertions, 24 deletions
diff --git a/indra/newview/llbuycurrencyhtml.cpp b/indra/newview/llbuycurrencyhtml.cpp
index e6c4d44573..f5bc3b5357 100644
--- a/indra/newview/llbuycurrencyhtml.cpp
+++ b/indra/newview/llbuycurrencyhtml.cpp
@@ -34,6 +34,8 @@
#include "llcommandhandler.h"
#include "llviewercontrol.h"
#include "llstatusbar.h"
+#include "llcorehttputil.h"
+#include "llcoros.h"
// support for secondlife:///app/buycurrencyhtml/{ACTION}/{NEXT_ACTION}/{RETURN_CODE} SLapps
class LLBuyCurrencyHTMLHandler :
@@ -86,53 +88,154 @@ public:
};
LLBuyCurrencyHTMLHandler gBuyCurrencyHTMLHandler;
+bool LLBuyCurrencyHTML::sWebFloaterEnabled = false;
+bool LLBuyCurrencyHTML::sAddPaymentEnabled = false;
+LLFetchAvatarPaymentInfo* LLBuyCurrencyHTML::sPaymentInfoRequest = NULL;
+
+////////////////////////////////////////////////////////////////////////////////
+// static
+static void checkFeatureFlag_coro(std::string check_url)
+{
+ LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+ LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
+ httpAdapter = std::make_shared<LLCoreHttpUtil::HttpCoroutineAdapter>("CheckBuyCurrencyURL", httpPolicy);
+ LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>();
+
+ LLCore::HttpOptions::ptr_t httpOptions = std::make_shared<LLCore::HttpOptions>();
+ httpOptions->setRetries(0);
+
+ LLSD result = httpAdapter->getAndSuspend(httpRequest, check_url, httpOptions);
+ LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+ LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
+
+ LLBuyCurrencyHTML::sWebFloaterEnabled = !(status.isHttpStatus() && status.getType() == 501);
+}
+
+// static
+static void checkAddPaymentFlag_coro(std::string check_url)
+{
+ LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+ LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
+ httpAdapter = std::make_shared<LLCoreHttpUtil::HttpCoroutineAdapter>("CheckBuyCurrencyAddPaymentURL", httpPolicy);
+ LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>();
+
+ // a redirect to some other page that answers 200 must not read as enabled
+ LLCore::HttpOptions::ptr_t httpOptions = std::make_shared<LLCore::HttpOptions>();
+ httpOptions->setRetries(0);
+ httpOptions->setFollowRedirects(false);
+
+ LLSD result = httpAdapter->getRawAndSuspend(httpRequest, check_url, httpOptions);
+ LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+ LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
+
+ LLBuyCurrencyHTML::sAddPaymentEnabled = status.isHttpStatus() && status.getType() == 200;
+ LL_INFOS("LLBuyCurrency") << "Add payment probe returned " << status.toString()
+ << ", in-floater add payment " << (LLBuyCurrencyHTML::sAddPaymentEnabled ? "enabled" : "disabled") << LL_ENDL;
+}
+
+// static
+void LLBuyCurrencyHTML::checkFeatureFlag()
+{
+ std::string check_url = LLFloaterBuyCurrencyHTML::buildURL();
+ LLCoros::instance().launch("checkFeatureFlag_coro",
+ [check_url]() { checkFeatureFlag_coro(check_url); });
+
+ std::string add_payment_url = gSavedSettings.getString("BuyCurrencyAddPaymentURL");
+ LLCoros::instance().launch("checkAddPaymentFlag_coro",
+ [add_payment_url]() { checkAddPaymentFlag_coro(add_payment_url); });
+}
+
////////////////////////////////////////////////////////////////////////////////
// static
// Opens the legacy XUI based floater or new HTML based one based on
-// the QuickBuyCurrency value in settings.xml - this overload is for
+// the BuyCurrencyHTML value in settings.xml - this overload is for
// the case where the amount is not requested.
void LLBuyCurrencyHTML::openCurrencyFloater()
{
- if ( gSavedSettings.getBOOL( "QuickBuyCurrency" ) )
- {
- // HTML version
- LLBuyCurrencyHTML::showDialog( false, "", 0 );
- }
- else
- {
- // legacy version
- LLFloaterBuyCurrency::buyCurrency();
- };
+ routeCurrencyRequest(false, LLStringUtil::null, 0);
}
////////////////////////////////////////////////////////////////////////////////
// static
// Opens the legacy XUI based floater or new HTML based one based on
-// the QuickBuyCurrency value in settings.xml - this overload is for
+// the BuyCurrencyHTML value in settings.xml - this overload is for
// the case where the amount and a string to display are requested.
void LLBuyCurrencyHTML::openCurrencyFloater( const std::string& message, S32 sum )
{
- if ( gSavedSettings.getBOOL( "QuickBuyCurrency" ) )
+ routeCurrencyRequest(true, message, sum);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// static
+// Without the in-floater add payment flow, the web floater is opened only for
+// residents with payment info on file; the rest go to the LindeX payment page.
+void LLBuyCurrencyHTML::routeCurrencyRequest( bool has_target, const std::string& message, S32 sum )
+{
+ if (!gSavedSettings.getBOOL("BuyCurrencyHTML") || !sWebFloaterEnabled)
{
- // HTML version
- LLBuyCurrencyHTML::showDialog( true, message, sum );
+ // legacy version, which runs its own payment info check
+ if (has_target)
+ {
+ LLFloaterBuyCurrency::buyCurrency(message, sum);
+ }
+ else
+ {
+ LLFloaterBuyCurrency::buyCurrency();
+ }
+ }
+ else if (sAddPaymentEnabled)
+ {
+ openWebFloater(has_target, message, sum);
}
else
{
- // legacy version
- LLFloaterBuyCurrency::buyCurrency( message, sum );
- };
+ delete sPaymentInfoRequest;
+ sPaymentInfoRequest = new LLFetchAvatarPaymentInfo(
+ [has_target, message, sum](bool has_piof)
+ {
+ delete sPaymentInfoRequest;
+ sPaymentInfoRequest = NULL;
+
+ if (has_piof)
+ {
+ openWebFloater(has_target, message, sum);
+ }
+ else
+ {
+ LL_INFOS("LLBuyCurrency") << "No payment info on file, opening payment method page" << LL_ENDL;
+ LLFloaterBuyCurrency::openPaymentMethodPage();
+ }
+ });
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// static
+void LLBuyCurrencyHTML::openWebFloater( bool has_target, const std::string& message, S32 sum )
+{
+ if (!has_target)
+ {
+ LLBuyCurrencyHTML::showDialog();
+ return;
+ }
+
+ LLBuyCurrencyHTML::showDialog(sum - gStatusBar->getBalance());
+ LLFloaterBuyCurrencyHTML* floater = dynamic_cast<LLFloaterBuyCurrencyHTML*>(LLFloaterReg::getInstance("buy_currency_html"));
+ if (floater)
+ {
+ floater->setFallbackContext(message, sum);
+ }
}
////////////////////////////////////////////////////////////////////////////////
// static
-void LLBuyCurrencyHTML::showDialog( bool specific_sum_requested, const std::string& message, S32 sum )
+void LLBuyCurrencyHTML::showDialog(S32 shortfall)
{
LLFloaterBuyCurrencyHTML* buy_currency_floater = dynamic_cast< LLFloaterBuyCurrencyHTML* >( LLFloaterReg::getInstance( "buy_currency_html" ) );
if ( buy_currency_floater )
{
// pass on flag indicating if we want to buy specific amount and if so, how much
- buy_currency_floater->setParams( specific_sum_requested, message, sum );
+ buy_currency_floater->setShortfall(shortfall);
// force navigate to new URL
buy_currency_floater->navigateToFinalURL();
@@ -144,7 +247,7 @@ void LLBuyCurrencyHTML::showDialog( bool specific_sum_requested, const std::stri
buy_currency_floater->setFrontmost( take_focus );
// spec calls for floater to be centered on client window
- buy_currency_floater->center();
+ //buy_currency_floater->center();
}
else
{
@@ -161,7 +264,4 @@ void LLBuyCurrencyHTML::closeDialog()
{
buy_currency_floater->closeFloater();
};
-
- // Update L$ balance in the status bar in case L$ were purchased
- LLStatusBar::sendMoneyBalanceRequest();
}