Home | History | Annotate | Download | only in wallet
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "components/autofill/content/browser/wallet/wallet_service_url.h"
      6 
      7 #include <string>
      8 
      9 #include "base/command_line.h"
     10 #include "base/metrics/field_trial.h"
     11 #include "components/autofill/core/common/autofill_switches.h"
     12 #include "google_apis/gaia/gaia_urls.h"
     13 #include "net/base/url_util.h"
     14 #include "url/gurl.h"
     15 
     16 namespace autofill {
     17 namespace {
     18 
     19 const char kProdWalletServiceUrl[] = "https://wallet.google.com/";
     20 
     21 // TODO(ahutter): Remove this once production is ready.
     22 const char kSandboxWalletServiceUrl[] =
     23     "https://payments-form-dogfood.sandbox.google.com/";
     24 
     25 // TODO(ahutter): Remove this once production is ready.
     26 const char kSandboxWalletSecureServiceUrl[] =
     27     "https://wallet-web.sandbox.google.com/";
     28 
     29 bool IsWalletProductionEnabled() {
     30   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
     31   return command_line.HasSwitch(switches::kWalletServiceUseProd) ||
     32       base::FieldTrialList::FindFullName("WalletProductionService") == "Yes" ||
     33       base::FieldTrialList::FindFullName("Autocheckout") == "Yes";
     34 }
     35 
     36 GURL GetWalletHostUrl() {
     37   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
     38   std::string wallet_service_hostname =
     39       command_line.GetSwitchValueASCII(switches::kWalletServiceUrl);
     40   if (!wallet_service_hostname.empty())
     41     return GURL(wallet_service_hostname);
     42   if (IsWalletProductionEnabled())
     43     return GURL(kProdWalletServiceUrl);
     44   return GURL(kSandboxWalletServiceUrl);
     45 }
     46 
     47 GURL GetBaseWalletUrl() {
     48   return GetWalletHostUrl().Resolve("online/v2/");
     49 }
     50 
     51 GURL GetBaseAutocheckoutUrl() {
     52   return GetBaseWalletUrl().Resolve("wallet/autocheckout/v1/");
     53 }
     54 
     55 GURL GetBaseSecureUrl() {
     56   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
     57   std::string wallet_secure_url =
     58       command_line.GetSwitchValueASCII(switches::kWalletSecureServiceUrl);
     59   if (!wallet_secure_url.empty())
     60     return GURL(wallet_secure_url);
     61   if (IsWalletProductionEnabled())
     62     return GURL(kProdWalletServiceUrl);
     63   return GURL(kSandboxWalletSecureServiceUrl);
     64 }
     65 
     66 GURL GetBaseEncryptedFrontendUrl() {
     67   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
     68   // TODO(ahutter): Stop checking these switches once we switch over to prod.
     69   GURL base_url = IsWalletProductionEnabled() ||
     70       command_line.HasSwitch(switches::kWalletServiceUrl) ?
     71           GetWalletHostUrl() : GetBaseSecureUrl();
     72   return base_url.Resolve("online-secure/v2/autocheckout/v1/");
     73 }
     74 
     75 }  // namespace
     76 
     77 namespace wallet {
     78 
     79 GURL GetGetWalletItemsUrl() {
     80   return GetBaseAutocheckoutUrl().Resolve("getWalletItemsJwtless");
     81 }
     82 
     83 GURL GetGetFullWalletUrl() {
     84   return GetBaseEncryptedFrontendUrl().Resolve("getFullWalletJwtless?s7e=otp");
     85 }
     86 
     87 GURL GetManageInstrumentsUrl() {
     88   return GetBaseSecureUrl().Resolve("manage/paymentMethods");
     89 }
     90 
     91 GURL GetManageAddressesUrl() {
     92   return GetBaseSecureUrl().Resolve("manage/settings/addresses");
     93 }
     94 
     95 GURL GetAcceptLegalDocumentsUrl() {
     96   return GetBaseAutocheckoutUrl().Resolve("acceptLegalDocument");
     97 }
     98 
     99 GURL GetAuthenticateInstrumentUrl() {
    100   return GetBaseEncryptedFrontendUrl()
    101       .Resolve("authenticateInstrument?s7e=cvn");
    102 }
    103 
    104 GURL GetSendStatusUrl() {
    105   return GetBaseAutocheckoutUrl().Resolve("reportStatus");
    106 }
    107 
    108 GURL GetSaveToWalletNoEscrowUrl() {
    109   return GetBaseAutocheckoutUrl().Resolve("saveToWallet");
    110 }
    111 
    112 GURL GetSaveToWalletUrl() {
    113   return GetBaseEncryptedFrontendUrl()
    114       .Resolve("saveToWallet?s7e=card_number%3Bcvn");
    115 }
    116 
    117 GURL GetPassiveAuthUrl() {
    118   return GetBaseWalletUrl().Resolve("passiveauth?isChromePayments=true");
    119 }
    120 
    121 GURL GetSignInUrl() {
    122   GURL url(GaiaUrls::GetInstance()->service_login_url());
    123   url = net::AppendQueryParameter(url, "service", "toolbar");
    124   url = net::AppendQueryParameter(url, "nui", "1");
    125   url = net::AppendQueryParameter(url,
    126                                   "continue",
    127                                   GetSignInContinueUrl().spec());
    128   return url;
    129 }
    130 
    131 // The continue url portion of the sign-in URL.
    132 GURL GetSignInContinueUrl() {
    133   return GetPassiveAuthUrl();
    134 }
    135 
    136 bool IsSignInContinueUrl(const GURL& url) {
    137   GURL final_url = wallet::GetSignInContinueUrl();
    138   return url.SchemeIsSecure() &&
    139          url.host() == final_url.host() &&
    140          url.path() == final_url.path();
    141 }
    142 
    143 bool IsUsingProd() {
    144   return GetWalletHostUrl() == GURL(kProdWalletServiceUrl);
    145 }
    146 
    147 }  // namespace wallet
    148 }  // namespace autofill
    149