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

Side by Side Diff: ios/web/payments/payment_request.cc

Issue 2797633002: [Payments] Move PaymentMethodData to components/payments/core (Closed)
Patch Set: clean Created 3 years, 8 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ios/web/public/payments/payment_request.h" 5 #include "ios/web/public/payments/payment_request.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 9
10 namespace { 10 namespace {
11 11
12 // All of these are defined here (even though most are only used once each) so 12 // All of these are defined here (even though most are only used once each) so
13 // the format details are easy to locate and update or compare to the spec doc. 13 // the format details are easy to locate and update or compare to the spec doc.
14 // (https://w3c.github.io/browser-payment-api/). 14 // (https://w3c.github.io/browser-payment-api/).
15 static const char kMethodDataData[] = "data";
16 static const char kPaymentCurrencyAmountCurrencySystemISO4217[] = 15 static const char kPaymentCurrencyAmountCurrencySystemISO4217[] =
17 "urn:iso:std:iso:4217"; 16 "urn:iso:std:iso:4217";
18 static const char kPaymentCurrencyAmountCurrencySystem[] = "currencySystem"; 17 static const char kPaymentCurrencyAmountCurrencySystem[] = "currencySystem";
19 static const char kPaymentCurrencyAmountCurrency[] = "currency"; 18 static const char kPaymentCurrencyAmountCurrency[] = "currency";
20 static const char kPaymentCurrencyAmountValue[] = "value"; 19 static const char kPaymentCurrencyAmountValue[] = "value";
21 static const char kPaymentDetailsDisplayItems[] = "displayItems"; 20 static const char kPaymentDetailsDisplayItems[] = "displayItems";
22 static const char kPaymentDetailsError[] = "error"; 21 static const char kPaymentDetailsError[] = "error";
23 static const char kPaymentDetailsShippingOptions[] = "shippingOptions"; 22 static const char kPaymentDetailsShippingOptions[] = "shippingOptions";
24 static const char kPaymentDetailsTotal[] = "total"; 23 static const char kPaymentDetailsTotal[] = "total";
25 static const char kPaymentItemAmount[] = "amount"; 24 static const char kPaymentItemAmount[] = "amount";
(...skipping 14 matching lines...) Expand all
40 static const char kPaymentResponseMethodName[] = "methodName"; 39 static const char kPaymentResponseMethodName[] = "methodName";
41 static const char kPaymentResponsePayerEmail[] = "payerEmail"; 40 static const char kPaymentResponsePayerEmail[] = "payerEmail";
42 static const char kPaymentResponsePayerName[] = "payerName"; 41 static const char kPaymentResponsePayerName[] = "payerName";
43 static const char kPaymentResponsePayerPhone[] = "payerPhone"; 42 static const char kPaymentResponsePayerPhone[] = "payerPhone";
44 static const char kPaymentResponseShippingAddress[] = "shippingAddress"; 43 static const char kPaymentResponseShippingAddress[] = "shippingAddress";
45 static const char kPaymentResponseShippingOption[] = "shippingOption"; 44 static const char kPaymentResponseShippingOption[] = "shippingOption";
46 static const char kPaymentShippingOptionAmount[] = "amount"; 45 static const char kPaymentShippingOptionAmount[] = "amount";
47 static const char kPaymentShippingOptionId[] = "id"; 46 static const char kPaymentShippingOptionId[] = "id";
48 static const char kPaymentShippingOptionLabel[] = "label"; 47 static const char kPaymentShippingOptionLabel[] = "label";
49 static const char kPaymentShippingOptionSelected[] = "selected"; 48 static const char kPaymentShippingOptionSelected[] = "selected";
50 static const char kSupportedMethods[] = "supportedMethods";
51 49
52 } // namespace 50 } // namespace
53 51
54 namespace web { 52 namespace web {
55 53
56 PaymentMethodData::PaymentMethodData() {}
57 PaymentMethodData::PaymentMethodData(const PaymentMethodData& other) = default;
58 PaymentMethodData::~PaymentMethodData() = default;
59
60 bool PaymentMethodData::operator==(const PaymentMethodData& other) const {
61 return this->supported_methods == other.supported_methods &&
62 this->data == other.data;
63 }
64
65 bool PaymentMethodData::operator!=(const PaymentMethodData& other) const {
66 return !(*this == other);
67 }
68
69 bool PaymentMethodData::FromDictionaryValue(
70 const base::DictionaryValue& value) {
71 this->supported_methods.clear();
72
73 const base::ListValue* supported_methods_list = nullptr;
74 // At least one supported method is required.
75 if (!value.GetList(kSupportedMethods, &supported_methods_list) ||
76 supported_methods_list->GetSize() == 0) {
77 return false;
78 }
79 for (size_t i = 0; i < supported_methods_list->GetSize(); ++i) {
80 base::string16 supported_method;
81 if (!supported_methods_list->GetString(i, &supported_method)) {
82 return false;
83 }
84 this->supported_methods.push_back(supported_method);
85 }
86
87 // Data is optional.
88 value.GetString(kMethodDataData, &this->data);
89
90 return true;
91 }
92
93 PaymentCurrencyAmount::PaymentCurrencyAmount() 54 PaymentCurrencyAmount::PaymentCurrencyAmount()
94 // By default, the currency is defined by [ISO4217]. For example, USD for 55 // By default, the currency is defined by [ISO4217]. For example, USD for
95 // US Dollars. 56 // US Dollars.
96 : currency_system( 57 : currency_system(
97 base::ASCIIToUTF16(kPaymentCurrencyAmountCurrencySystemISO4217)) {} 58 base::ASCIIToUTF16(kPaymentCurrencyAmountCurrencySystemISO4217)) {}
98 59
99 PaymentCurrencyAmount::~PaymentCurrencyAmount() = default; 60 PaymentCurrencyAmount::~PaymentCurrencyAmount() = default;
100 61
101 bool PaymentCurrencyAmount::operator==( 62 bool PaymentCurrencyAmount::operator==(
102 const PaymentCurrencyAmount& other) const { 63 const PaymentCurrencyAmount& other) const {
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 // At least one method is required. 307 // At least one method is required.
347 if (!value.GetList(kPaymentRequestMethodData, &method_data_list) || 308 if (!value.GetList(kPaymentRequestMethodData, &method_data_list) ||
348 method_data_list->GetSize() == 0) { 309 method_data_list->GetSize() == 0) {
349 return false; 310 return false;
350 } 311 }
351 for (size_t i = 0; i < method_data_list->GetSize(); ++i) { 312 for (size_t i = 0; i < method_data_list->GetSize(); ++i) {
352 const base::DictionaryValue* method_data_dict; 313 const base::DictionaryValue* method_data_dict;
353 if (!method_data_list->GetDictionary(i, &method_data_dict)) 314 if (!method_data_list->GetDictionary(i, &method_data_dict))
354 return false; 315 return false;
355 316
356 PaymentMethodData method_data; 317 payments::PaymentMethodData method_data;
357 if (!method_data.FromDictionaryValue(*method_data_dict)) 318 if (!method_data.FromDictionaryValue(*method_data_dict))
358 return false; 319 return false;
359 this->method_data.push_back(method_data); 320 this->method_data.push_back(method_data);
360 } 321 }
361 322
362 // Parse the payment details. 323 // Parse the payment details.
363 const base::DictionaryValue* payment_details_dict = nullptr; 324 const base::DictionaryValue* payment_details_dict = nullptr;
364 if (!value.GetDictionary(kPaymentRequestDetails, &payment_details_dict) || 325 if (!value.GetDictionary(kPaymentRequestDetails, &payment_details_dict) ||
365 !this->details.FromDictionaryValue(*payment_details_dict)) { 326 !this->details.FromDictionaryValue(*payment_details_dict)) {
366 return false; 327 return false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 result->SetString(kPaymentResponsePayerName, this->payer_name); 373 result->SetString(kPaymentResponsePayerName, this->payer_name);
413 if (!this->payer_email.empty()) 374 if (!this->payer_email.empty())
414 result->SetString(kPaymentResponsePayerEmail, this->payer_email); 375 result->SetString(kPaymentResponsePayerEmail, this->payer_email);
415 if (!this->payer_phone.empty()) 376 if (!this->payer_phone.empty())
416 result->SetString(kPaymentResponsePayerPhone, this->payer_phone); 377 result->SetString(kPaymentResponsePayerPhone, this->payer_phone);
417 378
418 return result; 379 return result;
419 } 380 }
420 381
421 } // namespace web 382 } // namespace web
OLDNEW
« no previous file with comments | « ios/chrome/browser/payments/payment_request_util.mm ('k') | ios/web/payments/payment_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698