Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/content/browser/wallet/wallet_client.h" | 5 #include "components/autofill/content/browser/wallet/wallet_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 kGetFullWalletRequestFormat, | 365 kGetFullWalletRequestFormat, |
| 366 net::EscapeUrlEncodedData(json_payload, true).c_str(), | 366 net::EscapeUrlEncodedData(json_payload, true).c_str(), |
| 367 base::HexEncode(&num_bits, 1).c_str(), | 367 base::HexEncode(&num_bits, 1).c_str(), |
| 368 base::HexEncode(&(one_time_pad_[0]), one_time_pad_.size()).c_str()); | 368 base::HexEncode(&(one_time_pad_[0]), one_time_pad_.size()).c_str()); |
| 369 | 369 |
| 370 MakeWalletRequest(GetGetFullWalletUrl(user_index_), | 370 MakeWalletRequest(GetGetFullWalletUrl(user_index_), |
| 371 post_body, | 371 post_body, |
| 372 kFormEncodedMimeType); | 372 kFormEncodedMimeType); |
| 373 } | 373 } |
| 374 | 374 |
| 375 void WalletClient::SaveToWallet(scoped_ptr<Instrument> instrument, | 375 void WalletClient::SaveToWallet( |
| 376 scoped_ptr<Address> address) { | 376 scoped_ptr<Instrument> instrument, |
| 377 scoped_ptr<Address> address, | |
| 378 const WalletItems::MaskedInstrument* server_instrument, | |
| 379 const Address* server_address) { | |
| 377 DCHECK(instrument || address); | 380 DCHECK(instrument || address); |
| 378 if (HasRequestInProgress()) { | 381 if (HasRequestInProgress()) { |
| 379 pending_requests_.push(base::Bind(&WalletClient::SaveToWallet, | 382 pending_requests_.push(base::Bind(&WalletClient::SaveToWallet, |
| 380 base::Unretained(this), | 383 base::Unretained(this), |
| 381 base::Passed(&instrument), | 384 base::Passed(&instrument), |
| 382 base::Passed(&address))); | 385 base::Passed(&address), |
| 386 base::Unretained(server_instrument), | |
|
Evan Stade
2013/12/12 02:33:57
this is no bueno... you need to make a copy (add a
Dan Beam
2013/12/13 04:06:24
did option 2 and updated all the other methods
| |
| 387 base::Unretained(server_address))); | |
| 383 return; | 388 return; |
| 384 } | 389 } |
| 385 | 390 |
| 386 DCHECK_EQ(NO_PENDING_REQUEST, request_type_); | 391 DCHECK_EQ(NO_PENDING_REQUEST, request_type_); |
| 387 request_type_ = SAVE_TO_WALLET; | 392 request_type_ = SAVE_TO_WALLET; |
| 388 | 393 |
| 389 base::DictionaryValue request_dict; | 394 base::DictionaryValue request_dict; |
| 390 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey()); | 395 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey()); |
| 391 request_dict.SetString(kRiskParamsKey, delegate_->GetRiskData()); | 396 request_dict.SetString(kRiskParamsKey, delegate_->GetRiskData()); |
| 392 request_dict.SetString(kMerchantDomainKey, | 397 request_dict.SetString(kMerchantDomainKey, |
| 393 source_url_.GetWithEmptyPath().spec()); | 398 source_url_.GetWithEmptyPath().spec()); |
| 394 request_dict.SetBoolean(kUseMinimalAddresses, false); | 399 request_dict.SetBoolean(kUseMinimalAddresses, false); |
| 395 request_dict.SetBoolean(kPhoneNumberRequired, true); | 400 request_dict.SetBoolean(kPhoneNumberRequired, true); |
| 396 | 401 |
| 397 std::string primary_account_number; | 402 std::string primary_account_number; |
| 398 std::string card_verification_number; | 403 std::string card_verification_number; |
| 399 if (instrument) { | 404 if (instrument) { |
| 400 primary_account_number = net::EscapeUrlEncodedData( | 405 primary_account_number = net::EscapeUrlEncodedData( |
| 401 UTF16ToUTF8(instrument->primary_account_number()), true); | 406 UTF16ToUTF8(instrument->primary_account_number()), true); |
| 402 card_verification_number = net::EscapeUrlEncodedData( | 407 card_verification_number = net::EscapeUrlEncodedData( |
| 403 UTF16ToUTF8(instrument->card_verification_number()), true); | 408 UTF16ToUTF8(instrument->card_verification_number()), true); |
| 404 | 409 |
| 405 if (instrument->object_id().empty()) { | 410 if (!server_instrument) { |
| 406 request_dict.Set(kInstrumentKey, instrument->ToDictionary().release()); | 411 request_dict.Set(kInstrumentKey, instrument->ToDictionary().release()); |
| 407 request_dict.SetString(kInstrumentPhoneNumberKey, | 412 request_dict.SetString(kInstrumentPhoneNumberKey, |
| 408 instrument->address()->phone_number()); | 413 instrument->address()->phone_number()); |
| 409 } else { | 414 } else { |
| 410 DCHECK(instrument->address() || | 415 DCHECK(!server_instrument->object_id().empty()); |
| 411 (instrument->expiration_month() > 0 && | 416 |
| 412 instrument->expiration_year() > 0)); | 417 int new_month = instrument->expiration_month(); |
| 418 int new_year = instrument->expiration_year(); | |
| 419 bool expiration_differs_from_server = | |
|
Evan Stade
2013/12/12 02:33:57
nit: expiration_date_changed
Dan Beam
2013/12/13 04:06:24
Done.
| |
| 420 new_month != server_instrument->expiration_month() || | |
| 421 new_year != server_instrument->expiration_year(); | |
| 422 | |
| 423 DCHECK(instrument->address() || expiration_differs_from_server); | |
| 413 | 424 |
| 414 request_dict.SetString(kUpgradedInstrumentIdKey, | 425 request_dict.SetString(kUpgradedInstrumentIdKey, |
| 415 instrument->object_id()); | 426 server_instrument->object_id()); |
| 416 | 427 |
| 417 if (instrument->address()) { | 428 if (instrument->address()) { |
| 418 request_dict.SetString(kInstrumentPhoneNumberKey, | 429 request_dict.SetString(kInstrumentPhoneNumberKey, |
| 419 instrument->address()->phone_number()); | 430 instrument->address()->phone_number()); |
| 420 request_dict.Set( | 431 request_dict.Set( |
| 421 kUpgradedBillingAddressKey, | 432 kUpgradedBillingAddressKey, |
| 422 instrument->address()->ToDictionaryWithoutID().release()); | 433 instrument->address()->ToDictionaryWithoutID().release()); |
| 423 } | 434 } |
| 424 | 435 |
| 425 if (instrument->expiration_month() > 0 && | 436 if (expiration_differs_from_server) { |
| 426 instrument->expiration_year() > 0) { | 437 // Updating expiration date requires a CVC. |
| 427 DCHECK(!instrument->card_verification_number().empty()); | 438 DCHECK(!instrument->card_verification_number().empty()); |
| 428 request_dict.SetInteger(kInstrumentExpMonthKey, | 439 request_dict.SetInteger(kInstrumentExpMonthKey, |
| 429 instrument->expiration_month()); | 440 instrument->expiration_month()); |
| 430 request_dict.SetInteger(kInstrumentExpYearKey, | 441 request_dict.SetInteger(kInstrumentExpYearKey, |
| 431 instrument->expiration_year()); | 442 instrument->expiration_year()); |
| 432 } | 443 } |
| 433 | 444 |
| 434 if (request_dict.HasKey(kInstrumentKey)) | 445 if (request_dict.HasKey(kInstrumentKey)) |
| 435 request_dict.SetString(kInstrumentType, "CREDIT_CARD"); | 446 request_dict.SetString(kInstrumentType, "CREDIT_CARD"); |
| 436 } | 447 } |
| 437 } | 448 } |
| 438 if (address) { | 449 if (address) { |
| 450 if (server_address) { | |
| 451 address->set_object_id(server_address->object_id()); | |
| 452 DCHECK(!address->object_id().empty()); | |
| 453 } | |
| 439 request_dict.Set(kShippingAddressKey, | 454 request_dict.Set(kShippingAddressKey, |
| 440 address->ToDictionaryWithID().release()); | 455 address->ToDictionaryWithID().release()); |
| 441 } | 456 } |
| 442 | 457 |
| 443 std::string json_payload; | 458 std::string json_payload; |
| 444 base::JSONWriter::Write(&request_dict, &json_payload); | 459 base::JSONWriter::Write(&request_dict, &json_payload); |
| 445 | 460 |
| 446 if (!card_verification_number.empty()) { | 461 if (!card_verification_number.empty()) { |
| 447 std::string post_body; | 462 std::string post_body; |
| 448 if (!primary_account_number.empty()) { | 463 if (!primary_account_number.empty()) { |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 NOTREACHED(); | 836 NOTREACHED(); |
| 822 return AutofillMetrics::UNKNOWN_API_CALL; | 837 return AutofillMetrics::UNKNOWN_API_CALL; |
| 823 } | 838 } |
| 824 | 839 |
| 825 NOTREACHED(); | 840 NOTREACHED(); |
| 826 return AutofillMetrics::UNKNOWN_API_CALL; | 841 return AutofillMetrics::UNKNOWN_API_CALL; |
| 827 } | 842 } |
| 828 | 843 |
| 829 } // namespace wallet | 844 } // namespace wallet |
| 830 } // namespace autofill | 845 } // namespace autofill |
| OLD | NEW |