| 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"; | |
| 26 static const char kMethodData[] = "methodData"; | 14 static const char kMethodData[] = "methodData"; |
| 27 static const char kSupportedMethods[] = "supportedMethods"; | 15 static const char kSupportedMethods[] = "supportedMethods"; |
| 28 static const char kData[] = "data"; | 16 static const char kData[] = "data"; |
| 29 static const char kPaymentDetails[] = "details"; | 17 static const char kPaymentDetails[] = "details"; |
| 30 static const char kPaymentDetailsTotal[] = "total"; | 18 static const char kPaymentDetailsTotal[] = "total"; |
| 31 static const char kPaymentDetailsTotalAmount[] = "amount"; | 19 static const char kPaymentDetailsTotalAmount[] = "amount"; |
| 32 static const char kPaymentDetailsTotalAmountCurrency[] = "currency"; | 20 static const char kPaymentDetailsTotalAmountCurrency[] = "currency"; |
| 33 static const char kPaymentDetailsTotalAmountValue[] = "value"; | 21 static const char kPaymentDetailsTotalAmountValue[] = "value"; |
| 34 static const char kMethodName[] = "methodName"; | 22 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"; | |
| 41 | 23 |
| 42 } // namespace | 24 } // namespace |
| 43 | 25 |
| 44 namespace web { | 26 namespace web { |
| 45 | 27 |
| 46 PaymentAddress::PaymentAddress() {} | 28 PaymentAddress::PaymentAddress() {} |
| 47 PaymentAddress::PaymentAddress(const PaymentAddress& other) = default; | 29 PaymentAddress::PaymentAddress(const PaymentAddress& other) = default; |
| 48 PaymentAddress::~PaymentAddress() = default; | 30 PaymentAddress::~PaymentAddress() = default; |
| 49 | 31 |
| 50 bool PaymentAddress::operator==(const PaymentAddress& other) const { | 32 bool PaymentAddress::operator==(const PaymentAddress& other) const { |
| 51 return this->country == other.country && | 33 return this->country == other.country && |
| 52 this->address_line == other.address_line && | 34 this->address_line == other.address_line && |
| 53 this->region == other.region && this->city == other.city && | 35 this->region == other.region && this->city == other.city && |
| 54 this->dependent_locality == other.dependent_locality && | 36 this->dependent_locality == other.dependent_locality && |
| 55 this->postal_code == other.postal_code && | 37 this->postal_code == other.postal_code && |
| 56 this->sorting_code == other.sorting_code && | 38 this->sorting_code == other.sorting_code && |
| 57 this->language_code == other.language_code && | 39 this->language_code == other.language_code && |
| 58 this->organization == other.organization && | 40 this->organization == other.organization && |
| 59 this->recipient == other.recipient && this->care_of == other.care_of && | 41 this->recipient == other.recipient && this->care_of == other.care_of && |
| 60 this->phone == other.phone; | 42 this->phone == other.phone; |
| 61 } | 43 } |
| 62 | 44 |
| 63 bool PaymentAddress::operator!=(const PaymentAddress& other) const { | 45 bool PaymentAddress::operator!=(const PaymentAddress& other) const { |
| 64 return !(*this == other); | 46 return !(*this == other); |
| 65 } | 47 } |
| 66 | 48 |
| 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 | |
| 106 PaymentMethodData::PaymentMethodData() {} | 49 PaymentMethodData::PaymentMethodData() {} |
| 107 PaymentMethodData::PaymentMethodData(const PaymentMethodData& other) = default; | 50 PaymentMethodData::PaymentMethodData(const PaymentMethodData& other) = default; |
| 108 PaymentMethodData::~PaymentMethodData() = default; | 51 PaymentMethodData::~PaymentMethodData() = default; |
| 109 | 52 |
| 110 bool PaymentMethodData::operator==(const PaymentMethodData& other) const { | 53 bool PaymentMethodData::operator==(const PaymentMethodData& other) const { |
| 111 return this->supported_methods == other.supported_methods && | 54 return this->supported_methods == other.supported_methods && |
| 112 this->data == other.data; | 55 this->data == other.data; |
| 113 } | 56 } |
| 114 | 57 |
| 115 bool PaymentMethodData::operator!=(const PaymentMethodData& other) const { | 58 bool PaymentMethodData::operator!=(const PaymentMethodData& other) const { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 &this->details.total.amount.value); | 210 &this->details.total.amount.value); |
| 268 } | 211 } |
| 269 } | 212 } |
| 270 } | 213 } |
| 271 | 214 |
| 272 // TODO(crbug.com/602666): Parse the remaining elements. | 215 // TODO(crbug.com/602666): Parse the remaining elements. |
| 273 | 216 |
| 274 return true; | 217 return true; |
| 275 } | 218 } |
| 276 | 219 |
| 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 | |
| 313 PaymentResponse::PaymentResponse() {} | 220 PaymentResponse::PaymentResponse() {} |
| 314 PaymentResponse::PaymentResponse(const PaymentResponse& other) = default; | |
| 315 PaymentResponse::~PaymentResponse() = default; | 221 PaymentResponse::~PaymentResponse() = default; |
| 316 | 222 |
| 317 bool PaymentResponse::operator==(const PaymentResponse& other) const { | 223 bool PaymentResponse::operator==(const PaymentResponse& other) const { |
| 318 return this->method_name == other.method_name && | 224 return this->method_name == other.method_name && |
| 319 this->details == other.details; | 225 this->details == other.details; |
| 320 } | 226 } |
| 321 | 227 |
| 322 bool PaymentResponse::operator!=(const PaymentResponse& other) const { | 228 bool PaymentResponse::operator!=(const PaymentResponse& other) const { |
| 323 return !(*this == other); | 229 return !(*this == other); |
| 324 } | 230 } |
| 325 | 231 |
| 326 std::unique_ptr<base::DictionaryValue> PaymentResponse::ToDictionaryValue() | 232 void PaymentResponse::ToDictionaryValue(base::DictionaryValue* value) const { |
| 327 const { | 233 DCHECK(value); |
| 328 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
| 329 | |
| 330 if (!this->method_name.empty()) | 234 if (!this->method_name.empty()) |
| 331 result->SetString(kMethodName, this->method_name); | 235 value->SetString(kMethodName, this->method_name); |
| 332 result->Set(kPaymentDetails, this->details.ToDictionaryValue()); | 236 if (!this->details.empty()) |
| 333 | 237 value->SetString(kPaymentDetails, this->details); |
| 334 return result; | |
| 335 } | |
| 336 | |
| 337 void PaymentResponse::ToDictionaryValue(base::DictionaryValue* value) const { | |
| 338 value->MergeDictionary(ToDictionaryValue().get()); | |
| 339 } | 238 } |
| 340 | 239 |
| 341 } // namespace web | 240 } // namespace web |
| OLD | NEW |