OLD | NEW |
---|---|
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/values.h" | 7 #include "base/values.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
11 // All of these are defined here (even though most are only used once each) so | 11 // All of these are defined here (even though most are only used once each) so |
12 // the format details are easy to locate and update or compare to the spec doc. | 12 // the format details are easy to locate and update or compare to the spec doc. |
13 // (https://w3c.github.io/browser-payment-api/). | 13 // (https://w3c.github.io/browser-payment-api/). |
14 static const char kAddressCountry[] = "country"; | |
15 static const char kAddressAddressLine[] = "addressLine"; | |
16 static const char kAddressRegion[] = "region"; | |
17 static const char kAddressCity[] = "city"; | |
18 static const char kAddressDependentLocality[] = "dependentLocality"; | |
19 static const char kAddressPostalCode[] = "postalCode"; | |
20 static const char kAddressSortingCode[] = "sortingCode"; | |
21 static const char kAddressLanguageCode[] = "languageCode"; | |
22 static const char kAddressOrganization[] = "organization"; | |
23 static const char kAddressRecipient[] = "recipient"; | |
24 static const char kAddressCareOf[] = "careOf"; | |
25 static const char kAddressPhone[] = "phone"; | |
14 static const char kMethodData[] = "methodData"; | 26 static const char kMethodData[] = "methodData"; |
15 static const char kSupportedMethods[] = "supportedMethods"; | 27 static const char kSupportedMethods[] = "supportedMethods"; |
16 static const char kData[] = "data"; | 28 static const char kData[] = "data"; |
17 static const char kPaymentDetails[] = "details"; | 29 static const char kPaymentDetails[] = "details"; |
18 static const char kPaymentDetailsTotal[] = "total"; | 30 static const char kPaymentDetailsTotal[] = "total"; |
19 static const char kPaymentDetailsTotalAmount[] = "amount"; | 31 static const char kPaymentDetailsTotalAmount[] = "amount"; |
20 static const char kPaymentDetailsTotalAmountCurrency[] = "currency"; | 32 static const char kPaymentDetailsTotalAmountCurrency[] = "currency"; |
21 static const char kPaymentDetailsTotalAmountValue[] = "value"; | 33 static const char kPaymentDetailsTotalAmountValue[] = "value"; |
22 static const char kMethodName[] = "methodName"; | 34 static const char kMethodName[] = "methodName"; |
35 static const char kCardCardholderName[] = "cardholderName"; | |
36 static const char kCardCardNumber[] = "cardNumber"; | |
37 static const char kCardExpiryMonth[] = "expiryMonth"; | |
38 static const char kCardExpiryYear[] = "expiryYear"; | |
39 static const char kCardCardSecurityCode[] = "cardSecurityCode"; | |
40 static const char kCardBillingAddress[] = "billingAddress"; | |
23 | 41 |
24 } // namespace | 42 } // namespace |
25 | 43 |
26 namespace web { | 44 namespace web { |
27 | 45 |
28 PaymentAddress::PaymentAddress() {} | 46 PaymentAddress::PaymentAddress() {} |
29 PaymentAddress::PaymentAddress(const PaymentAddress& other) = default; | 47 PaymentAddress::PaymentAddress(const PaymentAddress& other) = default; |
30 PaymentAddress::~PaymentAddress() = default; | 48 PaymentAddress::~PaymentAddress() = default; |
31 | 49 |
32 bool PaymentAddress::operator==(const PaymentAddress& other) const { | 50 bool PaymentAddress::operator==(const PaymentAddress& other) const { |
33 return this->country == other.country && | 51 return this->country == other.country && |
34 this->address_line == other.address_line && | 52 this->address_line == other.address_line && |
35 this->region == other.region && this->city == other.city && | 53 this->region == other.region && this->city == other.city && |
36 this->dependent_locality == other.dependent_locality && | 54 this->dependent_locality == other.dependent_locality && |
37 this->postal_code == other.postal_code && | 55 this->postal_code == other.postal_code && |
38 this->sorting_code == other.sorting_code && | 56 this->sorting_code == other.sorting_code && |
39 this->language_code == other.language_code && | 57 this->language_code == other.language_code && |
40 this->organization == other.organization && | 58 this->organization == other.organization && |
41 this->recipient == other.recipient && this->care_of == other.care_of && | 59 this->recipient == other.recipient && this->care_of == other.care_of && |
42 this->phone == other.phone; | 60 this->phone == other.phone; |
43 } | 61 } |
44 | 62 |
45 bool PaymentAddress::operator!=(const PaymentAddress& other) const { | 63 bool PaymentAddress::operator!=(const PaymentAddress& other) const { |
46 return !(*this == other); | 64 return !(*this == other); |
47 } | 65 } |
48 | 66 |
67 void PaymentAddress::ToDictionaryValue(base::DictionaryValue* value) const { | |
68 DCHECK(value); | |
69 value->Clear(); | |
70 | |
71 if (!this->country.empty()) | |
72 value->SetString(kAddressCountry, this->country); | |
73 | |
74 if (!this->address_line.empty()) { | |
75 std::unique_ptr<base::ListValue> address_line(new base::ListValue); | |
76 for (base::string16 address_line_string : this->address_line) { | |
77 address_line->AppendString(address_line_string); | |
78 } | |
79 value->Set(kAddressAddressLine, std::move(address_line)); | |
80 } | |
81 | |
82 if (!this->region.empty()) | |
83 value->SetString(kAddressRegion, this->region); | |
84 if (!this->city.empty()) | |
85 value->SetString(kAddressCity, this->city); | |
86 if (!this->dependent_locality.empty()) | |
87 value->SetString(kAddressDependentLocality, this->dependent_locality); | |
88 if (!this->postal_code.empty()) | |
89 value->SetString(kAddressPostalCode, this->postal_code); | |
90 if (!this->sorting_code.empty()) | |
91 value->SetString(kAddressSortingCode, this->sorting_code); | |
92 if (!this->language_code.empty()) | |
93 value->SetString(kAddressLanguageCode, this->language_code); | |
94 if (!this->organization.empty()) | |
95 value->SetString(kAddressOrganization, this->organization); | |
96 if (!this->recipient.empty()) | |
97 value->SetString(kAddressRecipient, this->recipient); | |
98 if (!this->care_of.empty()) | |
99 value->SetString(kAddressCareOf, this->care_of); | |
100 if (!this->phone.empty()) | |
101 value->SetString(kAddressPhone, this->phone); | |
102 } | |
103 | |
49 PaymentMethodData::PaymentMethodData() {} | 104 PaymentMethodData::PaymentMethodData() {} |
50 PaymentMethodData::PaymentMethodData(const PaymentMethodData& other) = default; | 105 PaymentMethodData::PaymentMethodData(const PaymentMethodData& other) = default; |
51 PaymentMethodData::~PaymentMethodData() = default; | 106 PaymentMethodData::~PaymentMethodData() = default; |
52 | 107 |
53 bool PaymentMethodData::operator==(const PaymentMethodData& other) const { | 108 bool PaymentMethodData::operator==(const PaymentMethodData& other) const { |
54 return this->supported_methods == other.supported_methods && | 109 return this->supported_methods == other.supported_methods && |
55 this->data == other.data; | 110 this->data == other.data; |
56 } | 111 } |
57 | 112 |
58 bool PaymentMethodData::operator!=(const PaymentMethodData& other) const { | 113 bool PaymentMethodData::operator!=(const PaymentMethodData& other) const { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 &this->details.total.amount.value); | 265 &this->details.total.amount.value); |
211 } | 266 } |
212 } | 267 } |
213 } | 268 } |
214 | 269 |
215 // TODO(crbug.com/602666): Parse the remaining elements. | 270 // TODO(crbug.com/602666): Parse the remaining elements. |
216 | 271 |
217 return true; | 272 return true; |
218 } | 273 } |
219 | 274 |
275 BasicCardResponse::BasicCardResponse() {} | |
276 BasicCardResponse::BasicCardResponse(const BasicCardResponse& other) = default; | |
277 BasicCardResponse::~BasicCardResponse() = default; | |
278 | |
279 bool BasicCardResponse::operator==(const BasicCardResponse& other) const { | |
280 return this->cardholder_name == other.cardholder_name && | |
281 this->card_number == other.card_number && | |
282 this->expiry_month == other.expiry_month && | |
283 this->expiry_year == other.expiry_year && | |
284 this->card_security_code == other.card_security_code && | |
285 this->billing_address == other.billing_address; | |
286 } | |
287 | |
288 bool BasicCardResponse::operator!=(const BasicCardResponse& other) const { | |
289 return !(*this == other); | |
290 } | |
291 | |
292 void BasicCardResponse::ToDictionaryValue(base::DictionaryValue* value) const { | |
Evan Stade
2016/08/29 20:34:06
why does this use an outparam instead of return va
Justin Donnelly
2016/08/30 15:21:25
No good reason, just habit of using out params. Ch
| |
293 DCHECK(value); | |
294 value->Clear(); | |
295 | |
296 if (!this->cardholder_name.empty()) | |
297 value->SetString(kCardCardholderName, this->cardholder_name); | |
298 if (!this->card_number.empty()) | |
299 value->SetString(kCardCardNumber, this->card_number); | |
300 if (!this->expiry_month.empty()) | |
301 value->SetString(kCardExpiryMonth, this->expiry_month); | |
302 if (!this->expiry_year.empty()) | |
303 value->SetString(kCardExpiryYear, this->expiry_year); | |
304 if (!this->card_security_code.empty()) | |
305 value->SetString(kCardCardSecurityCode, this->card_security_code); | |
306 | |
307 std::unique_ptr<base::DictionaryValue> address(new base::DictionaryValue); | |
308 this->billing_address.ToDictionaryValue(address.get()); | |
309 value->Set(kCardBillingAddress, std::move(address)); | |
310 } | |
311 | |
220 PaymentResponse::PaymentResponse() {} | 312 PaymentResponse::PaymentResponse() {} |
313 PaymentResponse::PaymentResponse(const PaymentResponse& other) = default; | |
221 PaymentResponse::~PaymentResponse() = default; | 314 PaymentResponse::~PaymentResponse() = default; |
222 | 315 |
223 bool PaymentResponse::operator==(const PaymentResponse& other) const { | 316 bool PaymentResponse::operator==(const PaymentResponse& other) const { |
224 return this->method_name == other.method_name && | 317 return this->method_name == other.method_name && |
225 this->details == other.details; | 318 this->details == other.details; |
226 } | 319 } |
227 | 320 |
228 bool PaymentResponse::operator!=(const PaymentResponse& other) const { | 321 bool PaymentResponse::operator!=(const PaymentResponse& other) const { |
229 return !(*this == other); | 322 return !(*this == other); |
230 } | 323 } |
231 | 324 |
232 void PaymentResponse::ToDictionaryValue(base::DictionaryValue* value) const { | 325 void PaymentResponse::ToDictionaryValue(base::DictionaryValue* value) const { |
233 DCHECK(value); | 326 DCHECK(value); |
327 value->Clear(); | |
328 | |
234 if (!this->method_name.empty()) | 329 if (!this->method_name.empty()) |
235 value->SetString(kMethodName, this->method_name); | 330 value->SetString(kMethodName, this->method_name); |
236 if (!this->details.empty()) | 331 |
237 value->SetString(kPaymentDetails, this->details); | 332 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue); |
333 this->details.ToDictionaryValue(details.get()); | |
334 value->Set(kPaymentDetails, std::move(details)); | |
238 } | 335 } |
239 | 336 |
240 } // namespace web | 337 } // namespace web |
OLD | NEW |