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

Side by Side Diff: components/payments/core/basic_card_response.cc

Issue 2733953003: [Payments] Return a basic card response (Closed)
Patch Set: addressed comments from anthony Created 3 years, 9 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 "components/payments/core/basic_card_response.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h"
10
11 namespace payments {
12
13 namespace {
14
15 // These are defined as part of the spec at:
16 // https://w3c.github.io/webpayments-methods-card/#basiccardresponse
17 static const char kCardBillingAddress[] = "billingAddress";
18 static const char kCardCardholderName[] = "cardholderName";
19 static const char kCardCardNumber[] = "cardNumber";
20 static const char kCardCardSecurityCode[] = "cardSecurityCode";
21 static const char kCardExpiryMonth[] = "expiryMonth";
22 static const char kCardExpiryYear[] = "expiryYear";
23
24 } // namespace
25
26 BasicCardResponse::BasicCardResponse() {}
27 BasicCardResponse::BasicCardResponse(const BasicCardResponse& other) = default;
28 BasicCardResponse::~BasicCardResponse() = default;
29
30 bool BasicCardResponse::operator==(const BasicCardResponse& other) const {
31 return this->cardholder_name == other.cardholder_name &&
32 this->card_number == other.card_number &&
33 this->expiry_month == other.expiry_month &&
34 this->expiry_year == other.expiry_year &&
35 this->card_security_code == other.card_security_code &&
36 this->billing_address == other.billing_address;
37 }
38
39 bool BasicCardResponse::operator!=(const BasicCardResponse& other) const {
40 return !(*this == other);
41 }
42
43 std::unique_ptr<base::DictionaryValue> BasicCardResponse::ToDictionaryValue()
44 const {
45 std::unique_ptr<base::DictionaryValue> result =
46 base::MakeUnique<base::DictionaryValue>();
47
48 if (!this->cardholder_name.empty())
49 result->SetString(kCardCardholderName, this->cardholder_name);
50 result->SetString(kCardCardNumber, this->card_number);
51 if (!this->expiry_month.empty())
52 result->SetString(kCardExpiryMonth, this->expiry_month);
53 if (!this->expiry_year.empty())
54 result->SetString(kCardExpiryYear, this->expiry_year);
55 if (!this->card_security_code.empty())
56 result->SetString(kCardCardSecurityCode, this->card_security_code);
57 if (!this->billing_address.ToDictionaryValue()->empty())
58 result->Set(kCardBillingAddress, this->billing_address.ToDictionaryValue());
59
60 return result;
61 }
62
63 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/basic_card_response.h ('k') | components/payments/core/basic_card_response_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698