OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/autofill/wallet/full_wallet.h" | 5 #include "chrome/browser/autofill/wallet/full_wallet.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/autofill/wallet/required_action.h" | |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 const size_t kPanSize = 16; | 14 const size_t kPanSize = 16; |
14 const size_t kBinSize = 6; | 15 const size_t kBinSize = 6; |
15 const size_t kCvnSize = 3; | 16 const size_t kCvnSize = 3; |
16 | 17 |
17 } // anonymous namespace | 18 } // anonymous namespace |
18 | 19 |
19 namespace wallet { | 20 namespace wallet { |
20 | 21 |
21 FullWallet::FullWallet(int expiration_month, | 22 FullWallet::FullWallet(int expiration_month, |
22 int expiration_year, | 23 int expiration_year, |
23 const std::string& iin, | 24 const std::string& iin, |
24 const std::string& encrypted_rest, | 25 const std::string& encrypted_rest, |
25 scoped_ptr<Address> billing_address, | 26 scoped_ptr<Address> billing_address, |
26 scoped_ptr<Address> shipping_address, | 27 scoped_ptr<Address> shipping_address, |
27 const std::vector<std::string>& required_actions) | 28 const std::vector<RequiredAction>& required_actions) |
28 : expiration_month_(expiration_month), | 29 : expiration_month_(expiration_month), |
29 expiration_year_(expiration_year), | 30 expiration_year_(expiration_year), |
30 iin_(iin), | 31 iin_(iin), |
31 encrypted_rest_(encrypted_rest), | 32 encrypted_rest_(encrypted_rest), |
32 billing_address_(billing_address.Pass()), | 33 billing_address_(billing_address.Pass()), |
33 shipping_address_(shipping_address.Pass()), | 34 shipping_address_(shipping_address.Pass()), |
34 required_actions_(required_actions) { | 35 required_actions_(required_actions) { |
35 DCHECK(required_actions_.size() > 0 || billing_address_.get()); | 36 DCHECK(required_actions_.size() > 0 || billing_address_.get()); |
36 } | 37 } |
37 | 38 |
38 FullWallet::~FullWallet() {} | 39 FullWallet::~FullWallet() {} |
39 | 40 |
40 scoped_ptr<FullWallet> | 41 scoped_ptr<FullWallet> |
41 FullWallet::CreateFullWallet(const DictionaryValue& dictionary) { | 42 FullWallet::CreateFullWallet(const DictionaryValue& dictionary) { |
42 const ListValue* required_actions_list; | 43 const ListValue* required_actions_list; |
43 std::vector<std::string> required_actions; | 44 std::vector<RequiredAction> required_actions; |
44 if (dictionary.GetList("required_action", &required_actions_list)) { | 45 if (dictionary.GetList("required_action", &required_actions_list)) { |
45 for (size_t i = 0; i < required_actions_list->GetSize(); ++i) { | 46 for (size_t i = 0; i < required_actions_list->GetSize(); ++i) { |
46 std::string action; | 47 std::string action_string; |
47 if (required_actions_list->GetString(i, &action)) | 48 if (required_actions_list->GetString(i, &action_string)) { |
49 RequiredAction action = ParseRequiredActionFromString(action_string); | |
50 if (!ActionAppliesToFullWallet(action)) { | |
51 DLOG(ERROR) << "Response from Google wallet with bad required action"; | |
ahutter
2013/01/07 18:36:13
action_string would help with debugging if this ev
Dan Beam
2013/01/07 18:52:02
Done.
| |
52 return scoped_ptr<FullWallet>(); | |
53 } | |
48 required_actions.push_back(action); | 54 required_actions.push_back(action); |
55 } | |
49 } | 56 } |
50 if (required_actions.size() > 0) | 57 if (required_actions.size() > 0) { |
51 return scoped_ptr<FullWallet>(new FullWallet(-1, | 58 return scoped_ptr<FullWallet>(new FullWallet(-1, |
52 -1, | 59 -1, |
53 "", | 60 "", |
54 "", | 61 "", |
55 scoped_ptr<Address>(), | 62 scoped_ptr<Address>(), |
56 scoped_ptr<Address>(), | 63 scoped_ptr<Address>(), |
57 required_actions)); | 64 required_actions)); |
65 } | |
58 } else { | 66 } else { |
59 DVLOG(1) << "Response from Google wallet missing required actions"; | 67 DVLOG(1) << "Response from Google wallet missing required actions"; |
60 } | 68 } |
61 | 69 |
62 int expiration_month; | 70 int expiration_month; |
63 if (!dictionary.GetInteger("expiration_month", &expiration_month)) { | 71 if (!dictionary.GetInteger("expiration_month", &expiration_month)) { |
64 DLOG(ERROR) << "Response from Google wallet missing expiration month"; | 72 DLOG(ERROR) << "Response from Google wallet missing expiration month"; |
65 return scoped_ptr<FullWallet>(); | 73 return scoped_ptr<FullWallet>(); |
66 } | 74 } |
67 | 75 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); | 207 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); |
200 | 208 |
201 // Separate out the PAN from the CVN. | 209 // Separate out the PAN from the CVN. |
202 size_t split = kPanSize - kBinSize; | 210 size_t split = kPanSize - kBinSize; |
203 cvn_ = card_info.substr(split); | 211 cvn_ = card_info.substr(split); |
204 pan_ = iin_ + card_info.substr(0, split); | 212 pan_ = iin_ + card_info.substr(0, split); |
205 } | 213 } |
206 | 214 |
207 } // namespace wallet | 215 } // namespace wallet |
208 | 216 |
OLD | NEW |