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 std::unique_ptr<base::DictionaryValue> PaymentAddress::ToDictionaryValue() |
| 68 const { |
| 69 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 70 |
| 71 if (!this->country.empty()) |
| 72 result->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 result->Set(kAddressAddressLine, std::move(address_line)); |
| 80 } |
| 81 |
| 82 if (!this->region.empty()) |
| 83 result->SetString(kAddressRegion, this->region); |
| 84 if (!this->city.empty()) |
| 85 result->SetString(kAddressCity, this->city); |
| 86 if (!this->dependent_locality.empty()) |
| 87 result->SetString(kAddressDependentLocality, this->dependent_locality); |
| 88 if (!this->postal_code.empty()) |
| 89 result->SetString(kAddressPostalCode, this->postal_code); |
| 90 if (!this->sorting_code.empty()) |
| 91 result->SetString(kAddressSortingCode, this->sorting_code); |
| 92 if (!this->language_code.empty()) |
| 93 result->SetString(kAddressLanguageCode, this->language_code); |
| 94 if (!this->organization.empty()) |
| 95 result->SetString(kAddressOrganization, this->organization); |
| 96 if (!this->recipient.empty()) |
| 97 result->SetString(kAddressRecipient, this->recipient); |
| 98 if (!this->care_of.empty()) |
| 99 result->SetString(kAddressCareOf, this->care_of); |
| 100 if (!this->phone.empty()) |
| 101 result->SetString(kAddressPhone, this->phone); |
| 102 |
| 103 return result; |
| 104 } |
| 105 |
49 PaymentMethodData::PaymentMethodData() {} | 106 PaymentMethodData::PaymentMethodData() {} |
50 PaymentMethodData::PaymentMethodData(const PaymentMethodData& other) = default; | 107 PaymentMethodData::PaymentMethodData(const PaymentMethodData& other) = default; |
51 PaymentMethodData::~PaymentMethodData() = default; | 108 PaymentMethodData::~PaymentMethodData() = default; |
52 | 109 |
53 bool PaymentMethodData::operator==(const PaymentMethodData& other) const { | 110 bool PaymentMethodData::operator==(const PaymentMethodData& other) const { |
54 return this->supported_methods == other.supported_methods && | 111 return this->supported_methods == other.supported_methods && |
55 this->data == other.data; | 112 this->data == other.data; |
56 } | 113 } |
57 | 114 |
58 bool PaymentMethodData::operator!=(const PaymentMethodData& other) const { | 115 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); | 267 &this->details.total.amount.value); |
211 } | 268 } |
212 } | 269 } |
213 } | 270 } |
214 | 271 |
215 // TODO(crbug.com/602666): Parse the remaining elements. | 272 // TODO(crbug.com/602666): Parse the remaining elements. |
216 | 273 |
217 return true; | 274 return true; |
218 } | 275 } |
219 | 276 |
| 277 BasicCardResponse::BasicCardResponse() {} |
| 278 BasicCardResponse::BasicCardResponse(const BasicCardResponse& other) = default; |
| 279 BasicCardResponse::~BasicCardResponse() = default; |
| 280 |
| 281 bool BasicCardResponse::operator==(const BasicCardResponse& other) const { |
| 282 return this->cardholder_name == other.cardholder_name && |
| 283 this->card_number == other.card_number && |
| 284 this->expiry_month == other.expiry_month && |
| 285 this->expiry_year == other.expiry_year && |
| 286 this->card_security_code == other.card_security_code && |
| 287 this->billing_address == other.billing_address; |
| 288 } |
| 289 |
| 290 bool BasicCardResponse::operator!=(const BasicCardResponse& other) const { |
| 291 return !(*this == other); |
| 292 } |
| 293 |
| 294 std::unique_ptr<base::DictionaryValue> BasicCardResponse::ToDictionaryValue() |
| 295 const { |
| 296 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 297 |
| 298 if (!this->cardholder_name.empty()) |
| 299 result->SetString(kCardCardholderName, this->cardholder_name); |
| 300 if (!this->card_number.empty()) |
| 301 result->SetString(kCardCardNumber, this->card_number); |
| 302 if (!this->expiry_month.empty()) |
| 303 result->SetString(kCardExpiryMonth, this->expiry_month); |
| 304 if (!this->expiry_year.empty()) |
| 305 result->SetString(kCardExpiryYear, this->expiry_year); |
| 306 if (!this->card_security_code.empty()) |
| 307 result->SetString(kCardCardSecurityCode, this->card_security_code); |
| 308 result->Set(kCardBillingAddress, this->billing_address.ToDictionaryValue()); |
| 309 |
| 310 return result; |
| 311 } |
| 312 |
220 PaymentResponse::PaymentResponse() {} | 313 PaymentResponse::PaymentResponse() {} |
| 314 PaymentResponse::PaymentResponse(const PaymentResponse& other) = default; |
221 PaymentResponse::~PaymentResponse() = default; | 315 PaymentResponse::~PaymentResponse() = default; |
222 | 316 |
223 bool PaymentResponse::operator==(const PaymentResponse& other) const { | 317 bool PaymentResponse::operator==(const PaymentResponse& other) const { |
224 return this->method_name == other.method_name && | 318 return this->method_name == other.method_name && |
225 this->details == other.details; | 319 this->details == other.details; |
226 } | 320 } |
227 | 321 |
228 bool PaymentResponse::operator!=(const PaymentResponse& other) const { | 322 bool PaymentResponse::operator!=(const PaymentResponse& other) const { |
229 return !(*this == other); | 323 return !(*this == other); |
230 } | 324 } |
231 | 325 |
| 326 std::unique_ptr<base::DictionaryValue> PaymentResponse::ToDictionaryValue() |
| 327 const { |
| 328 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 329 |
| 330 if (!this->method_name.empty()) |
| 331 result->SetString(kMethodName, this->method_name); |
| 332 result->Set(kPaymentDetails, this->details.ToDictionaryValue()); |
| 333 |
| 334 return result; |
| 335 } |
| 336 |
232 void PaymentResponse::ToDictionaryValue(base::DictionaryValue* value) const { | 337 void PaymentResponse::ToDictionaryValue(base::DictionaryValue* value) const { |
233 DCHECK(value); | 338 value->MergeDictionary(ToDictionaryValue().get()); |
234 if (!this->method_name.empty()) | |
235 value->SetString(kMethodName, this->method_name); | |
236 if (!this->details.empty()) | |
237 value->SetString(kPaymentDetails, this->details); | |
238 } | 339 } |
239 | 340 |
240 } // namespace web | 341 } // namespace web |
OLD | NEW |