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

Unified Diff: chrome/browser/autofill/wallet/wallet_items.h

Issue 11293078: Integrating Online Wallet into Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed linter issue Created 8 years 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/wallet_items.h
diff --git a/chrome/browser/autofill/wallet/wallet_items.h b/chrome/browser/autofill/wallet/wallet_items.h
new file mode 100644
index 0000000000000000000000000000000000000000..3e2dacbf42a700a9a256bace88229e6d5b28b1d0
--- /dev/null
+++ b/chrome/browser/autofill/wallet/wallet_items.h
@@ -0,0 +1,198 @@
+// 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.
+
+#ifndef CHROME_BROWSER_AUTOFILL_WALLET_WALLET_ITEMS_H_
+#define CHROME_BROWSER_AUTOFILL_WALLET_WALLET_ITEMS_H_
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
+#include "chrome/browser/autofill/wallet/wallet_address.h"
+
+namespace base {
+class DictionaryValue;
+}
+
+namespace wallet {
+
+// WalletItems primarily serves as a container for the user's instruments and
+// address, however, it also provides a transaction id which must be used
+// throughout all API calls being made using this data. Additionally, user
+// actions may be required before a purchase can be completed using Online
+// Wallet and those actions are present in the object as well.
+class WalletItems {
+ public:
+ // Container for all information about a credit card except for it's card
+ // verfication number (CVN) and it's complete primary account number (PAN).
+ class MaskedInstrument {
+ public:
+ enum Type {
+ AMEX,
+ DISCOVER,
+ MAESTRO,
+ MASTER_CARD,
+ SOLO,
+ SWITCH,
+ UNKNOWN, // Catch all type.
+ VISA,
+ };
+ enum Status {
+ BILLING_INCOMPLETE,
+ DECLINED,
+ EXPIRED,
+ INAPPLICABLE, // Catch all status.
+ PENDING,
+ UNSUPPORTED_COUNTRY,
+ VALID,
+ };
+
+ // This constructor is only public for unit testing.
Ilya Sherman 2012/12/14 04:56:43 Please reduce the visibility of this constructor a
ahutter 2012/12/15 01:06:31 Done.
+ MaskedInstrument(const std::string& descriptve_name,
+ const Type& type,
+ std::vector<std::string> supported_currencies,
Ilya Sherman 2012/12/14 04:56:43 nit: Pass by const reference
ahutter 2012/12/15 01:06:31 Done.
+ const std::string& last_four_digits,
+ int expiration_month,
+ int expiration_year,
+ const std::string& brand,
+ Address* address,
Ilya Sherman 2012/12/14 04:56:43 nit: Pass a scoped_ptr
ahutter 2012/12/15 01:06:31 Done.
+ const Status& status,
+ const std::string& object_id);
+
+ ~MaskedInstrument();
+
+ // Returns null if input is invalid or a valid masked instrument. Caller
+ // owns returned pointer.
+ static MaskedInstrument* CreateMaskedInstrument(
+ const base::DictionaryValue& dictionary);
+
+ bool operator==(const MaskedInstrument& other) const;
+ bool operator!=(const MaskedInstrument& other) const;
+
+ const std::string descriptive_name() const { return descriptive_name_; }
Ilya Sherman 2012/12/14 04:56:43 nit: Return by const reference
ahutter 2012/12/15 01:06:31 Done.
+ Type type() const { return type_; }
+ const std::vector<std::string> supported_currencies() const {
+ return supported_currencies_;
+ }
Ilya Sherman 2012/12/14 04:56:43 nit: Return by const reference
ahutter 2012/12/15 01:06:31 Done.
+ const std::string last_four_digits() const { return last_four_digits_; }
Ilya Sherman 2012/12/14 04:56:43 nit: Return by const reference
ahutter 2012/12/15 01:06:31 Done.
+ int expiration_month() const { return expiration_month_; }
+ int expiration_year() const { return expiration_year_; }
+ const std::string brand() const { return brand_; }
Ilya Sherman 2012/12/14 04:56:43 nit: Return by const reference
ahutter 2012/12/15 01:06:31 Done.
+ const Address* address() const { return address_.get(); }
Ilya Sherman 2012/12/14 04:56:43 nit: Return by const reference
ahutter 2012/12/15 01:06:31 Done.
+ Status status() const { return status_; }
+ const std::string object_id() const { return object_id_; }
Ilya Sherman 2012/12/14 04:56:43 nit: Return by const reference
ahutter 2012/12/15 01:06:31 Done.
+
+ private:
+ static Type TypeFromString(const std::string& type_string);
+ static Status StatusFromString(const std::string& status_string);
Ilya Sherman 2012/12/14 04:56:43 nit: Please tuck these into an anonymous namespace
ahutter 2012/12/15 01:06:31 Done.
+ std::string descriptive_name_;
+ Type type_;
+ std::vector<std::string> supported_currencies_;
+ std::string last_four_digits_;
+ int expiration_month_;
+ int expiration_year_;
+ std::string brand_;
+ scoped_ptr<Address> address_;
+ Status status_;
+ std::string object_id_;
+ DISALLOW_COPY_AND_ASSIGN(MaskedInstrument);
+ };
+
+ // Class representing a legal document that the user must accept before they
+ // can use Online Wallet.
+ class LegalDocument {
+ public:
+ // This constructor is only public for unit testing.
+ LegalDocument(const std::string& document_id,
+ const std::string& display_name,
+ const std::string& document_body);
+
+ ~LegalDocument();
+
+ // Returns null if input is invalid or a valid legal document. Caller owns
+ // returned pointer.
+ static LegalDocument* CreateLegalDocument(
+ const base::DictionaryValue& dictionary);
+
+ bool operator==(const LegalDocument& other) const;
+ bool operator!=(const LegalDocument& other) const;
+
+ const std::string document_id() const { return document_id_; }
+ const std::string display_name() const { return display_name_; }
+ const std::string document_body() const { return document_body_; }
+
+ private:
+ std::string document_id_;
+ std::string display_name_;
+ std::string document_body_;
+ DISALLOW_COPY_AND_ASSIGN(LegalDocument);
+ };
+
+ // This constructor is only public for unit testing.
+ WalletItems(const std::vector<std::string>& required_actions,
+ const std::string& google_transaction_id,
+ const std::string& default_instrument_id,
+ const std::string& default_address_id);
+
+ ~WalletItems();
+
+ // Returns null on invalid input, an empty wallet items with required
+ // actions if any are present, and a populated wallet items otherwise. Caller
+ // owns returned pointer.
Ilya Sherman 2012/12/14 04:56:43 Please return a scoped_ptr<> rather than a raw poi
ahutter 2012/12/15 01:06:31 Done.
+ static WalletItems* CreateWalletItems(
+ const base::DictionaryValue& dictionary);
+
+ bool operator==(const WalletItems& other) const;
+ bool operator!=(const WalletItems& other) const;
+
+ void AddInstrument(MaskedInstrument* instrument) {
Ilya Sherman 2012/12/14 04:56:43 Please pass this in as a scoped_ptr<>. Ditto for
ahutter 2012/12/15 01:06:31 Done.
+ DCHECK(instrument);
+ instruments_.push_back(instrument);
+ }
+ void AddAddress(Address* address) {
+ DCHECK(address);
+ addresses_.push_back(address);
+ }
+ void AddLegalDocument(LegalDocument* legal_document) {
+ DCHECK(legal_document);
+ legal_documents_.push_back(legal_document);
+ }
+ const std::vector<std::string> required_actions() const {
+ return required_actions_;
+ }
+ const std::string google_transaction_id() const {
+ return google_transaction_id_;
+ }
+ const std::vector<MaskedInstrument*> instruments() const {
+ return instruments_.get();
+ }
+ const std::string default_instrument_id() const {
+ return default_instrument_id_;
+ }
+ const std::vector<Address*> addresses() const { return addresses_.get(); }
+ const std::string default_address_id() const {
+ return default_address_id_;
+ }
+ const std::vector<LegalDocument*> legal_documents() const {
+ return legal_documents_.get();
+ }
+
+ private:
+ std::vector<std::string> required_actions_;
+ std::string google_transaction_id_;
+ std::string default_instrument_id_;
+ std::string default_address_id_;
+ ScopedVector<MaskedInstrument> instruments_;
+ ScopedVector<Address> addresses_;
+ ScopedVector<LegalDocument> legal_documents_;
+ DISALLOW_COPY_AND_ASSIGN(WalletItems);
+};
+
+} // end namespace wallet
+
+#endif // CHROME_BROWSER_AUTOFILL_WALLET_WALLET_ITEMS_H_
+

Powered by Google App Engine
This is Rietveld 408576698