Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1993)

Unified Diff: chrome/browser/autofill/wallet/full_wallet.cc

Issue 11293078: Integrating Online Wallet into Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More unit tests and functionality Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/wallet/full_wallet.cc
diff --git a/chrome/browser/autofill/wallet/full_wallet.cc b/chrome/browser/autofill/wallet/full_wallet.cc
new file mode 100644
index 0000000000000000000000000000000000000000..86215cf3dd659e010fd1696f4db3a0a950c6738e
--- /dev/null
+++ b/chrome/browser/autofill/wallet/full_wallet.cc
@@ -0,0 +1,138 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/autofill/wallet/full_wallet.h"
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+
+namespace wallet {
+
+FullWallet::FullWallet(int expiration_month,
+ int expiration_year,
+ const std::string& iin,
+ const std::string& rest,
+ Address* billing_address,
+ Address* shipping_address,
+ std::vector<std::string> required_actions)
+ : expiration_month_(expiration_month),
+ expiration_year_(expiration_year),
+ iin_(iin),
+ rest_(rest),
+ billing_address_(billing_address),
+ shipping_address_(shipping_address),
+ required_actions_(required_actions) {}
+
+FullWallet::~FullWallet() {
+}
+
+scoped_ptr<FullWallet> FullWallet::FromDictionary(DictionaryValue* dictionary) {
+ int expiration_month;
+ int expiration_year;
+ std::string iin;
+ std::string rest;
+ DictionaryValue* billing_address_dict;
+ DictionaryValue* shipping_address_dict;
+ ListValue* required_actions_list;
+ if (!dictionary->GetInteger("expiration_month", &expiration_month)) {
+ LOG(ERROR) << "Response from Google wallet missing expiration month";
+ return scoped_ptr<FullWallet>();
+ }
+ if (!dictionary->GetInteger("expiration_year", &expiration_year)) {
+ LOG(ERROR) << "Response from Google wallet missing expiration year";
+ return scoped_ptr<FullWallet>();
+ }
+ if (!dictionary->GetString("iin", &iin)) {
+ LOG(ERROR) << "Response from Google wallet missing iin";
+ return scoped_ptr<FullWallet>();
+ }
+ if (!dictionary->GetString("rest", &rest)) {
+ LOG(ERROR) << "Response from Google wallet missing rest";
+ return scoped_ptr<FullWallet>();
+ }
+ if (!dictionary->GetDictionary("billing_address", &billing_address_dict)) {
+ LOG(ERROR) << "Response from Google wallet missing billing address";
+ return scoped_ptr<FullWallet>();
+ }
+ scoped_ptr<Address> billing_address =
+ Address::FromWalletDictionary(billing_address_dict);
+ scoped_ptr<Address> shipping_address(NULL);
+ if (dictionary->GetDictionary("shipping_address", &shipping_address_dict)) {
+ shipping_address = Address::FromWalletDictionary(shipping_address_dict);
+ } else {
+ VLOG(1) << "Response from Google wallet missing shipping address";
+ }
+
+ std::vector<std::string> required_actions;
+ if (dictionary->GetList("required_action", &required_actions_list)) {
+ for (size_t i = 0; i < required_actions_list->GetSize(); i++) {
+ std::string action;
+ if (required_actions_list->GetString(i, &action))
+ required_actions.push_back(action);
+ }
+ } else {
+ VLOG(1) << "Response from Google wallet missing required actions";
+ }
+
+ return scoped_ptr<FullWallet>(new FullWallet(expiration_month,
+ expiration_year,
+ iin,
+ rest,
+ billing_address.release(),
+ shipping_address.release(),
+ required_actions));
+}
+
+bool FullWallet::operator==(const FullWallet& other) const {
+ if (expiration_month_ != other.expiration_month_)
+ return false;
+ if (expiration_year_ != other.expiration_year_)
+ return false;
+ if (iin_.compare(other.iin_) != 0)
+ return false;
+ if (rest_.compare(other.rest_) != 0)
+ return false;
+ if (billing_address_.get() && other.billing_address_.get()) {
+ if (*billing_address_.get() != *other.billing_address_.get())
+ return false;
+ } else if (billing_address_.get() || other.billing_address_.get()) {
+ return false;
+ }
+ if (shipping_address_.get() && other.shipping_address_.get()) {
+ if (*shipping_address_.get() != *other.shipping_address_.get())
+ return false;
+ } else if (shipping_address_.get() || other.shipping_address_.get()) {
+ return false;
+ }
+ if (required_actions_ != other.required_actions_)
+ return false;
+ return true;
+}
+
+bool FullWallet::operator!=(const FullWallet& other) const {
+ return !(*this == other);
+}
+
+std::ostream& operator<<(std::ostream& o,
+ const FullWallet& full_wallet) {
+ o << "Expiration month : " << full_wallet.expiration_month_ << std::endl;
+ o << "Expiration year : " << full_wallet.expiration_year_ << std::endl;
+ o << "Iin : " << full_wallet.iin_ << std::endl;
+ o << "Rest : " << full_wallet.rest_ << std::endl;
+ o << "Billing address : " << full_wallet.billing_address_ << std::endl;
+ o << "Shipping address : " << full_wallet.shipping_address_ << std::endl;
+// o << "Required actions : " << full_wallet.required_actions_ << std::endl;
+ return o;
+}
+
+const std::string FullWallet::GetPAN(long otp) const {
+ return "123";
+}
+
+const std::string FullWallet::GetCVN(long otp) const {
+ return "123";
+}
+
+} // end wallet namespace

Powered by Google App Engine
This is Rietveld 408576698