Chromium Code Reviews| 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); | |
|
Eugene But (OOO till 7-30)
2016/08/26 00:52:06
Do you want to clear the dictionary before filling
Justin Donnelly
2016/08/29 19:52:59
Good idea, thanks. Done.
| |
| 69 if (!this->country.empty()) | |
|
Eugene But (OOO till 7-30)
2016/08/26 00:52:07
Why do you want to use |this->| everywhere?
Justin Donnelly
2016/08/29 19:52:59
Removing them seems less clear to me. If I were ca
| |
| 70 value->SetString(kAddressCountry, this->country); | |
| 71 | |
| 72 if (!this->address_line.empty()) { | |
| 73 std::unique_ptr<base::ListValue> address_line(new base::ListValue); | |
| 74 for (base::string16 address_line_string : this->address_line) { | |
| 75 address_line->AppendString(address_line_string); | |
| 76 } | |
| 77 value->Set(kAddressAddressLine, std::move(address_line)); | |
| 78 } | |
| 79 | |
| 80 if (!this->region.empty()) | |
| 81 value->SetString(kAddressRegion, this->region); | |
| 82 if (!this->city.empty()) | |
| 83 value->SetString(kAddressCity, this->city); | |
| 84 if (!this->dependent_locality.empty()) | |
| 85 value->SetString(kAddressDependentLocality, this->dependent_locality); | |
| 86 if (!this->postal_code.empty()) | |
| 87 value->SetString(kAddressPostalCode, this->postal_code); | |
| 88 if (!this->sorting_code.empty()) | |
| 89 value->SetString(kAddressSortingCode, this->sorting_code); | |
| 90 if (!this->language_code.empty()) | |
| 91 value->SetString(kAddressLanguageCode, this->language_code); | |
| 92 if (!this->organization.empty()) | |
| 93 value->SetString(kAddressOrganization, this->organization); | |
| 94 if (!this->recipient.empty()) | |
| 95 value->SetString(kAddressRecipient, this->recipient); | |
| 96 if (!this->care_of.empty()) | |
| 97 value->SetString(kAddressCareOf, this->care_of); | |
| 98 if (!this->phone.empty()) | |
| 99 value->SetString(kAddressPhone, this->phone); | |
| 100 } | |
| 101 | |
| 49 PaymentMethodData::PaymentMethodData() {} | 102 PaymentMethodData::PaymentMethodData() {} |
| 50 PaymentMethodData::PaymentMethodData(const PaymentMethodData& other) = default; | 103 PaymentMethodData::PaymentMethodData(const PaymentMethodData& other) = default; |
| 51 PaymentMethodData::~PaymentMethodData() = default; | 104 PaymentMethodData::~PaymentMethodData() = default; |
| 52 | 105 |
| 53 bool PaymentMethodData::operator==(const PaymentMethodData& other) const { | 106 bool PaymentMethodData::operator==(const PaymentMethodData& other) const { |
| 54 return this->supported_methods == other.supported_methods && | 107 return this->supported_methods == other.supported_methods && |
| 55 this->data == other.data; | 108 this->data == other.data; |
| 56 } | 109 } |
| 57 | 110 |
| 58 bool PaymentMethodData::operator!=(const PaymentMethodData& other) const { | 111 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); | 263 &this->details.total.amount.value); |
| 211 } | 264 } |
| 212 } | 265 } |
| 213 } | 266 } |
| 214 | 267 |
| 215 // TODO(crbug.com/602666): Parse the remaining elements. | 268 // TODO(crbug.com/602666): Parse the remaining elements. |
| 216 | 269 |
| 217 return true; | 270 return true; |
| 218 } | 271 } |
| 219 | 272 |
| 273 BasicCardResponse::BasicCardResponse() {} | |
| 274 BasicCardResponse::BasicCardResponse(const BasicCardResponse& other) = default; | |
| 275 BasicCardResponse::~BasicCardResponse() = default; | |
| 276 | |
| 277 bool BasicCardResponse::operator==(const BasicCardResponse& other) const { | |
| 278 return this->cardholder_name == other.cardholder_name && | |
| 279 this->card_number == other.card_number && | |
| 280 this->expiry_month == other.expiry_month && | |
| 281 this->expiry_year == other.expiry_year && | |
| 282 this->card_security_code == other.card_security_code && | |
| 283 this->billing_address == other.billing_address; | |
| 284 } | |
| 285 | |
| 286 bool BasicCardResponse::operator!=(const BasicCardResponse& other) const { | |
| 287 return !(*this == other); | |
| 288 } | |
| 289 | |
| 290 void BasicCardResponse::ToDictionaryValue(base::DictionaryValue* value) const { | |
| 291 DCHECK(value); | |
| 292 if (!this->cardholder_name.empty()) | |
| 293 value->SetString(kCardCardholderName, this->cardholder_name); | |
| 294 if (!this->card_number.empty()) | |
| 295 value->SetString(kCardCardNumber, this->card_number); | |
| 296 if (!this->expiry_month.empty()) | |
| 297 value->SetString(kCardExpiryMonth, this->expiry_month); | |
| 298 if (!this->expiry_year.empty()) | |
| 299 value->SetString(kCardExpiryYear, this->expiry_year); | |
| 300 if (!this->card_security_code.empty()) | |
| 301 value->SetString(kCardCardSecurityCode, this->card_security_code); | |
| 302 | |
| 303 std::unique_ptr<base::DictionaryValue> address(new base::DictionaryValue); | |
| 304 this->billing_address.ToDictionaryValue(address.get()); | |
| 305 value->Set(kCardBillingAddress, std::move(address)); | |
| 306 } | |
| 307 | |
| 220 PaymentResponse::PaymentResponse() {} | 308 PaymentResponse::PaymentResponse() {} |
| 309 PaymentResponse::PaymentResponse(const PaymentResponse& other) = default; | |
| 221 PaymentResponse::~PaymentResponse() = default; | 310 PaymentResponse::~PaymentResponse() = default; |
| 222 | 311 |
| 223 bool PaymentResponse::operator==(const PaymentResponse& other) const { | 312 bool PaymentResponse::operator==(const PaymentResponse& other) const { |
| 224 return this->method_name == other.method_name && | 313 return this->method_name == other.method_name && |
| 225 this->details == other.details; | 314 this->details == other.details; |
| 226 } | 315 } |
| 227 | 316 |
| 228 bool PaymentResponse::operator!=(const PaymentResponse& other) const { | 317 bool PaymentResponse::operator!=(const PaymentResponse& other) const { |
| 229 return !(*this == other); | 318 return !(*this == other); |
| 230 } | 319 } |
| 231 | 320 |
| 232 void PaymentResponse::ToDictionaryValue(base::DictionaryValue* value) const { | 321 void PaymentResponse::ToDictionaryValue(base::DictionaryValue* value) const { |
| 233 DCHECK(value); | 322 DCHECK(value); |
| 234 if (!this->method_name.empty()) | 323 if (!this->method_name.empty()) |
| 235 value->SetString(kMethodName, this->method_name); | 324 value->SetString(kMethodName, this->method_name); |
| 236 if (!this->details.empty()) | 325 |
| 237 value->SetString(kPaymentDetails, this->details); | 326 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue); |
| 327 this->details.ToDictionaryValue(details.get()); | |
| 328 value->Set(kPaymentDetails, std::move(details)); | |
| 238 } | 329 } |
| 239 | 330 |
| 240 } // namespace web | 331 } // namespace web |
| OLD | NEW |