Commit bf96868c authored by Sujie Zhu's avatar Sujie Zhu Committed by Commit Bot

[Autofill local card migration] Add billable service field in GetUploadDetailRequest

We add billable service field in the GetUploadDetailRequest context. In order to do that, we pass the billable service number when we call the GetUploadDetail().

Add unittests to verify the request content.

Bug: 852904
Change-Id: I104c193ee5c94d17f5af1b873f1ee71ad391dcf0
Reviewed-on: https://chromium-review.googlesource.com/1164173
Commit-Queue: Sujie Zhu <sujiezhu@google.com>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Cr-Commit-Position: refs/heads/master@{#582154}
parent b54dd1eb
......@@ -181,7 +181,8 @@ void CreditCardSaveManager::AttemptToOfferCardUploadSave(
.substr(0, 6),
upload_request_.active_experiments, app_locale_,
base::BindOnce(&CreditCardSaveManager::OnDidGetUploadDetails,
weak_ptr_factory_.GetWeakPtr()));
weak_ptr_factory_.GetWeakPtr()),
payments::kUploadCardBillableServiceNumber);
}
bool CreditCardSaveManager::IsCreditCardUploadEnabled() {
......
......@@ -100,7 +100,8 @@ void LocalCardMigrationManager::AttemptToOfferLocalCardMigration() {
/*pan_first_six=*/std::string(), upload_request_.active_experiments,
app_locale_,
base::BindOnce(&LocalCardMigrationManager::OnDidGetUploadDetails,
weak_ptr_factory_.GetWeakPtr()));
weak_ptr_factory_.GetWeakPtr()),
payments::kMigrateCardBillableServiceNumber);
}
// TODO(crbug.com/852904): Pops up a larger, modal dialog showing the local
......
......@@ -64,9 +64,6 @@ const char kTokenFetchId[] = "wallet_client";
const char kPaymentsOAuth2Scope[] =
"https://www.googleapis.com/auth/wallet.chrome";
const int kUnmaskCardBillableServiceNumber = 70154;
const int kUploadCardBillableServiceNumber = 70073;
GURL GetRequestUrl(const std::string& path) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch("sync-url")) {
if (IsPaymentsProductionEnabled()) {
......@@ -274,13 +271,15 @@ class GetUploadDetailsRequest : public PaymentsRequest {
const std::string& app_locale,
base::OnceCallback<void(AutofillClient::PaymentsRpcResult,
const base::string16&,
std::unique_ptr<base::DictionaryValue>)> callback)
std::unique_ptr<base::DictionaryValue>)> callback,
const int billable_service_number)
: addresses_(addresses),
detected_values_(detected_values),
pan_first_six_(pan_first_six),
active_experiments_(active_experiments),
app_locale_(app_locale),
callback_(std::move(callback)) {}
callback_(std::move(callback)),
billable_service_number_(billable_service_number) {}
~GetUploadDetailsRequest() override {}
std::string GetRequestUrlPath() override {
......@@ -293,6 +292,7 @@ class GetUploadDetailsRequest : public PaymentsRequest {
base::DictionaryValue request_dict;
std::unique_ptr<base::DictionaryValue> context(new base::DictionaryValue());
context->SetString("language_code", app_locale_);
context->SetInteger("billable_service", billable_service_number_);
request_dict.Set("context", std::move(context));
std::unique_ptr<base::ListValue> addresses(new base::ListValue());
......@@ -352,6 +352,7 @@ class GetUploadDetailsRequest : public PaymentsRequest {
callback_;
base::string16 context_token_;
std::unique_ptr<base::DictionaryValue> legal_message_;
const int billable_service_number_;
};
class UploadCardRequest : public PaymentsRequest {
......@@ -506,10 +507,12 @@ void PaymentsClient::GetUploadDetails(
const std::string& app_locale,
base::OnceCallback<void(AutofillClient::PaymentsRpcResult,
const base::string16&,
std::unique_ptr<base::DictionaryValue>)> callback) {
IssueRequest(std::make_unique<GetUploadDetailsRequest>(
addresses, detected_values, pan_first_six,
active_experiments, app_locale, std::move(callback)),
std::unique_ptr<base::DictionaryValue>)> callback,
const int billable_service_number) {
IssueRequest(
std::make_unique<GetUploadDetailsRequest>(
addresses, detected_values, pan_first_six, active_experiments,
app_locale, std::move(callback), billable_service_number),
false);
}
......
......@@ -32,6 +32,12 @@ namespace autofill {
namespace payments {
// Billable service number is defined in Payments server to distinguish
// different requests.
const int kUnmaskCardBillableServiceNumber = 70154;
const int kUploadCardBillableServiceNumber = 70073;
const int kMigrateCardBillableServiceNumber = 70264;
class PaymentsRequest;
// PaymentsClient issues Payments RPCs and manages responses and failure
......@@ -112,9 +118,11 @@ class PaymentsClient {
// CreditCardSaveManager::DetectedValue values that relays what data is
// actually available for upload in order to make more informed upload
// decisions. |callback| is the callback function when get response from
// server. If the conditions are met, the legal message will be returned via
// |callback|. |active_experiments| is used by Payments server to track
// requests that were triggered by enabled features.
// server. |billable_service_number| is used to set the billable service
// number in the GetUploadDetails request. If the conditions are met, the
// legal message will be returned via |callback|. |active_experiments| is used
// by Payments server to track requests that were triggered by enabled
// features.
virtual void GetUploadDetails(
const std::vector<AutofillProfile>& addresses,
const int detected_values,
......@@ -123,8 +131,8 @@ class PaymentsClient {
const std::string& app_locale,
base::OnceCallback<void(AutofillClient::PaymentsRpcResult,
const base::string16&,
std::unique_ptr<base::DictionaryValue>)>
callback);
std::unique_ptr<base::DictionaryValue>)> callback,
const int billable_service_number);
// The user has indicated that they would like to upload a card with the given
// cvc. This request will fail server-side if a successful call to
......
......@@ -145,7 +145,8 @@ class PaymentsClientTest : public testing::Test {
/*pan_first_six=*/"411111", std::vector<const char*>(),
"language-LOCALE",
base::BindOnce(&PaymentsClientTest::OnDidGetUploadDetails,
weak_ptr_factory_.GetWeakPtr()));
weak_ptr_factory_.GetWeakPtr()),
/*billable_service_number=*/12345);
}
void StartUploading(bool include_cvc) {
......@@ -435,6 +436,14 @@ TEST_F(PaymentsClientTest,
std::string::npos);
}
TEST_F(PaymentsClientTest, GetDetailsIncludeBillableServiceNumber) {
StartGettingUploadDetails();
// Verify that billable service number was included in the request.
EXPECT_TRUE(GetUploadData().find("\"billable_service\":12345") !=
std::string::npos);
}
TEST_F(PaymentsClientTest, UploadSuccessWithoutServerId) {
StartUploading(/*include_cvc=*/true);
IssueOAuthToken();
......
......@@ -26,7 +26,8 @@ void TestPaymentsClient::GetUploadDetails(
const std::string& app_locale,
base::OnceCallback<void(AutofillClient::PaymentsRpcResult,
const base::string16&,
std::unique_ptr<base::DictionaryValue>)> callback) {
std::unique_ptr<base::DictionaryValue>)> callback,
const int billable_service_number) {
upload_details_addresses_ = addresses;
detected_values_ = detected_values;
pan_first_six_ = pan_first_six;
......
......@@ -34,8 +34,8 @@ class TestPaymentsClient : public payments::PaymentsClient {
const std::string& app_locale,
base::OnceCallback<void(AutofillClient::PaymentsRpcResult,
const base::string16&,
std::unique_ptr<base::DictionaryValue>)> callback)
override;
std::unique_ptr<base::DictionaryValue>)> callback,
const int billable_service_number) override;
void UploadCard(
const payments::PaymentsClient::UploadRequestDetails& request_details,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment