OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/autofill/wallet/full_wallet.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" |
| 10 |
| 11 namespace wallet { |
| 12 |
| 13 FullWallet::FullWallet(int expiration_month, |
| 14 int expiration_year, |
| 15 const std::string& iin, |
| 16 const std::string& rest, |
| 17 Address* billing_address, |
| 18 Address* shipping_address, |
| 19 std::vector<std::string> required_actions) |
| 20 : expiration_month_(expiration_month), |
| 21 expiration_year_(expiration_year), |
| 22 iin_(iin), |
| 23 rest_(rest), |
| 24 billing_address_(billing_address), |
| 25 shipping_address_(shipping_address), |
| 26 required_actions_(required_actions) {} |
| 27 |
| 28 FullWallet::~FullWallet() { |
| 29 } |
| 30 |
| 31 scoped_ptr<FullWallet> FullWallet::FromDictionary(DictionaryValue* dictionary) { |
| 32 int expiration_month; |
| 33 int expiration_year; |
| 34 std::string iin; |
| 35 std::string rest; |
| 36 DictionaryValue* billing_address_dict; |
| 37 DictionaryValue* shipping_address_dict; |
| 38 ListValue* required_actions_list; |
| 39 if (!dictionary->GetInteger("expiration_month", &expiration_month)) { |
| 40 LOG(ERROR) << "Response from Google wallet missing expiration month"; |
| 41 return scoped_ptr<FullWallet>(); |
| 42 } |
| 43 if (!dictionary->GetInteger("expiration_year", &expiration_year)) { |
| 44 LOG(ERROR) << "Response from Google wallet missing expiration year"; |
| 45 return scoped_ptr<FullWallet>(); |
| 46 } |
| 47 if (!dictionary->GetString("iin", &iin)) { |
| 48 LOG(ERROR) << "Response from Google wallet missing iin"; |
| 49 return scoped_ptr<FullWallet>(); |
| 50 } |
| 51 if (!dictionary->GetString("rest", &rest)) { |
| 52 LOG(ERROR) << "Response from Google wallet missing rest"; |
| 53 return scoped_ptr<FullWallet>(); |
| 54 } |
| 55 if (!dictionary->GetDictionary("billing_address", &billing_address_dict)) { |
| 56 LOG(ERROR) << "Response from Google wallet missing billing address"; |
| 57 return scoped_ptr<FullWallet>(); |
| 58 } |
| 59 scoped_ptr<Address> billing_address = |
| 60 Address::FromWalletDictionary(billing_address_dict); |
| 61 scoped_ptr<Address> shipping_address(NULL); |
| 62 if (dictionary->GetDictionary("shipping_address", &shipping_address_dict)) { |
| 63 shipping_address = Address::FromWalletDictionary(shipping_address_dict); |
| 64 } else { |
| 65 VLOG(1) << "Response from Google wallet missing shipping address"; |
| 66 } |
| 67 |
| 68 std::vector<std::string> required_actions; |
| 69 if (dictionary->GetList("required_action", &required_actions_list)) { |
| 70 for (size_t i = 0; i < required_actions_list->GetSize(); i++) { |
| 71 std::string action; |
| 72 if (required_actions_list->GetString(i, &action)) |
| 73 required_actions.push_back(action); |
| 74 } |
| 75 } else { |
| 76 VLOG(1) << "Response from Google wallet missing required actions"; |
| 77 } |
| 78 |
| 79 return scoped_ptr<FullWallet>(new FullWallet(expiration_month, |
| 80 expiration_year, |
| 81 iin, |
| 82 rest, |
| 83 billing_address.release(), |
| 84 shipping_address.release(), |
| 85 required_actions)); |
| 86 } |
| 87 |
| 88 bool FullWallet::operator==(const FullWallet& other) const { |
| 89 if (expiration_month_ != other.expiration_month_) |
| 90 return false; |
| 91 if (expiration_year_ != other.expiration_year_) |
| 92 return false; |
| 93 if (iin_.compare(other.iin_) != 0) |
| 94 return false; |
| 95 if (rest_.compare(other.rest_) != 0) |
| 96 return false; |
| 97 if (billing_address_.get() && other.billing_address_.get()) { |
| 98 if (*billing_address_.get() != *other.billing_address_.get()) |
| 99 return false; |
| 100 } else if (billing_address_.get() || other.billing_address_.get()) { |
| 101 return false; |
| 102 } |
| 103 if (shipping_address_.get() && other.shipping_address_.get()) { |
| 104 if (*shipping_address_.get() != *other.shipping_address_.get()) |
| 105 return false; |
| 106 } else if (shipping_address_.get() || other.shipping_address_.get()) { |
| 107 return false; |
| 108 } |
| 109 if (required_actions_ != other.required_actions_) |
| 110 return false; |
| 111 return true; |
| 112 } |
| 113 |
| 114 bool FullWallet::operator!=(const FullWallet& other) const { |
| 115 return !(*this == other); |
| 116 } |
| 117 |
| 118 std::ostream& operator<<(std::ostream& o, |
| 119 const FullWallet& full_wallet) { |
| 120 o << "Expiration month : " << full_wallet.expiration_month_ << std::endl; |
| 121 o << "Expiration year : " << full_wallet.expiration_year_ << std::endl; |
| 122 o << "Iin : " << full_wallet.iin_ << std::endl; |
| 123 o << "Rest : " << full_wallet.rest_ << std::endl; |
| 124 o << "Billing address : " << full_wallet.billing_address_ << std::endl; |
| 125 o << "Shipping address : " << full_wallet.shipping_address_ << std::endl; |
| 126 // o << "Required actions : " << full_wallet.required_actions_ << std::endl; |
| 127 return o; |
| 128 } |
| 129 |
| 130 const std::string FullWallet::GetPAN(long otp) const { |
| 131 return "123"; |
| 132 } |
| 133 |
| 134 const std::string FullWallet::GetCVN(long otp) const { |
| 135 return "123"; |
| 136 } |
| 137 |
| 138 } // end wallet namespace |
OLD | NEW |