Index: components/autofill/core/browser/payments/payments_client.cc |
diff --git a/components/autofill/core/browser/payments/payments_client.cc b/components/autofill/core/browser/payments/payments_client.cc |
index b34ad10a996fd51eb440a591320f2e2ca37fee4f..4ac8e3f7e9a08546bc6b465e2818050348cc4cc0 100644 |
--- a/components/autofill/core/browser/payments/payments_client.cc |
+++ b/components/autofill/core/browser/payments/payments_client.cc |
@@ -6,6 +6,7 @@ |
#include <memory> |
#include <utility> |
+#include <vector> |
#include "base/command_line.h" |
#include "base/json/json_reader.h" |
@@ -110,14 +111,20 @@ void AppendStringIfNotEmpty(const AutofillProfile& profile, |
list->AppendString(value); |
} |
+// Returns a dictionary with the structure expected by Payments RPCs, containing |
+// each of the fields in |profile|, formatted according to |app_locale|. If |
+// |include_recipient_name| is false, the name in |profile| is not included. |
std::unique_ptr<base::DictionaryValue> BuildAddressDictionary( |
const AutofillProfile& profile, |
- const std::string& app_locale) { |
+ const std::string& app_locale, |
+ bool include_recipient_name) { |
std::unique_ptr<base::DictionaryValue> postal_address( |
new base::DictionaryValue()); |
- SetStringIfNotEmpty(profile, NAME_FULL, app_locale, "recipient_name", |
- postal_address.get()); |
+ if (include_recipient_name) { |
+ SetStringIfNotEmpty(profile, NAME_FULL, app_locale, |
+ PaymentsClient::kRecipientName, postal_address.get()); |
+ } |
std::unique_ptr<base::ListValue> address_lines(new base::ListValue()); |
AppendStringIfNotEmpty(profile, ADDRESS_HOME_LINE1, app_locale, |
@@ -209,8 +216,9 @@ class UnmaskCardRequest : public PaymentsRequest { |
class GetUploadDetailsRequest : public PaymentsRequest { |
public: |
- GetUploadDetailsRequest(const std::string& app_locale) |
- : app_locale_(app_locale) {} |
+ GetUploadDetailsRequest(const std::vector<AutofillProfile>& addresses, |
+ const std::string& app_locale) |
+ : addresses_(addresses), app_locale_(app_locale) {} |
~GetUploadDetailsRequest() override {} |
std::string GetRequestUrlPath() override { |
@@ -225,6 +233,12 @@ class GetUploadDetailsRequest : public PaymentsRequest { |
context->SetString("language_code", app_locale_); |
request_dict.Set("context", std::move(context)); |
+ std::unique_ptr<base::ListValue> addresses(new base::ListValue()); |
+ for (const AutofillProfile& profile : addresses_) { |
+ addresses->Append(BuildAddressDictionary(profile, app_locale_, false)); |
+ } |
+ request_dict.Set("address", std::move(addresses)); |
+ |
std::string request_content; |
base::JSONWriter::Write(request_dict, &request_content); |
VLOG(3) << "getdetailsforsavecard request body: " << request_content; |
@@ -249,6 +263,7 @@ class GetUploadDetailsRequest : public PaymentsRequest { |
} |
private: |
+ std::vector<AutofillProfile> addresses_; |
std::string app_locale_; |
base::string16 context_token_; |
std::unique_ptr<base::DictionaryValue> legal_message_; |
@@ -283,7 +298,7 @@ class UploadCardRequest : public PaymentsRequest { |
std::unique_ptr<base::ListValue> addresses(new base::ListValue()); |
for (const AutofillProfile& profile : request_details_.profiles) { |
- addresses->Append(BuildAddressDictionary(profile, app_locale)); |
+ addresses->Append(BuildAddressDictionary(profile, app_locale, true)); |
} |
request_dict.Set("address", std::move(addresses)); |
@@ -330,6 +345,8 @@ class UploadCardRequest : public PaymentsRequest { |
} // namespace |
+const std::string PaymentsClient::kRecipientName = "recipient_name"; |
+ |
PaymentsClient::UnmaskRequestDetails::UnmaskRequestDetails() {} |
PaymentsClient::UnmaskRequestDetails::~UnmaskRequestDetails() {} |
@@ -360,8 +377,11 @@ void PaymentsClient::UnmaskCard( |
IssueRequest(base::MakeUnique<UnmaskCardRequest>(request_details), true); |
} |
-void PaymentsClient::GetUploadDetails(const std::string& app_locale) { |
- IssueRequest(base::MakeUnique<GetUploadDetailsRequest>(app_locale), false); |
+void PaymentsClient::GetUploadDetails( |
+ const std::vector<AutofillProfile>& addresses, |
+ const std::string& app_locale) { |
+ IssueRequest(base::MakeUnique<GetUploadDetailsRequest>(addresses, app_locale), |
+ false); |
} |
void PaymentsClient::UploadCard( |