| 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/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 kAddressAddressLine[] = "addressLine"; | |
| 16 static const char kAddressCity[] = "city"; | |
| 17 static const char kAddressCountry[] = "country"; | |
| 18 static const char kAddressDependentLocality[] = "dependentLocality"; | |
| 19 static const char kAddressLanguageCode[] = "languageCode"; | |
| 20 static const char kAddressOrganization[] = "organization"; | |
| 21 static const char kAddressPhone[] = "phone"; | |
| 22 static const char kAddressPostalCode[] = "postalCode"; | |
| 23 static const char kAddressRecipient[] = "recipient"; | |
| 24 static const char kAddressRegion[] = "region"; | |
| 25 static const char kAddressSortingCode[] = "sortingCode"; | |
| 26 static const char kCardBillingAddress[] = "billingAddress"; | |
| 27 static const char kCardCardholderName[] = "cardholderName"; | |
| 28 static const char kCardCardNumber[] = "cardNumber"; | |
| 29 static const char kCardCardSecurityCode[] = "cardSecurityCode"; | |
| 30 static const char kCardExpiryMonth[] = "expiryMonth"; | |
| 31 static const char kCardExpiryYear[] = "expiryYear"; | |
| 32 static const char kMethodDataData[] = "data"; | 15 static const char kMethodDataData[] = "data"; |
| 33 static const char kPaymentCurrencyAmountCurrencySystemISO4217[] = | 16 static const char kPaymentCurrencyAmountCurrencySystemISO4217[] = |
| 34 "urn:iso:std:iso:4217"; | 17 "urn:iso:std:iso:4217"; |
| 35 static const char kPaymentCurrencyAmountCurrencySystem[] = "currencySystem"; | 18 static const char kPaymentCurrencyAmountCurrencySystem[] = "currencySystem"; |
| 36 static const char kPaymentCurrencyAmountCurrency[] = "currency"; | 19 static const char kPaymentCurrencyAmountCurrency[] = "currency"; |
| 37 static const char kPaymentCurrencyAmountValue[] = "value"; | 20 static const char kPaymentCurrencyAmountValue[] = "value"; |
| 38 static const char kPaymentDetailsDisplayItems[] = "displayItems"; | 21 static const char kPaymentDetailsDisplayItems[] = "displayItems"; |
| 39 static const char kPaymentDetailsError[] = "error"; | 22 static const char kPaymentDetailsError[] = "error"; |
| 40 static const char kPaymentDetailsShippingOptions[] = "shippingOptions"; | 23 static const char kPaymentDetailsShippingOptions[] = "shippingOptions"; |
| 41 static const char kPaymentDetailsTotal[] = "total"; | 24 static const char kPaymentDetailsTotal[] = "total"; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 63 static const char kPaymentShippingOptionAmount[] = "amount"; | 46 static const char kPaymentShippingOptionAmount[] = "amount"; |
| 64 static const char kPaymentShippingOptionId[] = "id"; | 47 static const char kPaymentShippingOptionId[] = "id"; |
| 65 static const char kPaymentShippingOptionLabel[] = "label"; | 48 static const char kPaymentShippingOptionLabel[] = "label"; |
| 66 static const char kPaymentShippingOptionSelected[] = "selected"; | 49 static const char kPaymentShippingOptionSelected[] = "selected"; |
| 67 static const char kSupportedMethods[] = "supportedMethods"; | 50 static const char kSupportedMethods[] = "supportedMethods"; |
| 68 | 51 |
| 69 } // namespace | 52 } // namespace |
| 70 | 53 |
| 71 namespace web { | 54 namespace web { |
| 72 | 55 |
| 73 PaymentAddress::PaymentAddress() {} | |
| 74 PaymentAddress::PaymentAddress(const PaymentAddress& other) = default; | |
| 75 PaymentAddress::~PaymentAddress() = default; | |
| 76 | |
| 77 bool PaymentAddress::operator==(const PaymentAddress& other) const { | |
| 78 return this->country == other.country && | |
| 79 this->address_line == other.address_line && | |
| 80 this->region == other.region && this->city == other.city && | |
| 81 this->dependent_locality == other.dependent_locality && | |
| 82 this->postal_code == other.postal_code && | |
| 83 this->sorting_code == other.sorting_code && | |
| 84 this->language_code == other.language_code && | |
| 85 this->organization == other.organization && | |
| 86 this->recipient == other.recipient && this->care_of == other.care_of && | |
| 87 this->phone == other.phone; | |
| 88 } | |
| 89 | |
| 90 bool PaymentAddress::operator!=(const PaymentAddress& other) const { | |
| 91 return !(*this == other); | |
| 92 } | |
| 93 | |
| 94 std::unique_ptr<base::DictionaryValue> PaymentAddress::ToDictionaryValue() | |
| 95 const { | |
| 96 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
| 97 | |
| 98 if (!this->country.empty()) | |
| 99 result->SetString(kAddressCountry, this->country); | |
| 100 | |
| 101 if (!this->address_line.empty()) { | |
| 102 std::unique_ptr<base::ListValue> address_line(new base::ListValue); | |
| 103 for (base::string16 address_line_string : this->address_line) { | |
| 104 if (!address_line_string.empty()) | |
| 105 address_line->AppendString(address_line_string); | |
| 106 } | |
| 107 result->Set(kAddressAddressLine, std::move(address_line)); | |
| 108 } | |
| 109 | |
| 110 if (!this->region.empty()) | |
| 111 result->SetString(kAddressRegion, this->region); | |
| 112 if (!this->city.empty()) | |
| 113 result->SetString(kAddressCity, this->city); | |
| 114 if (!this->dependent_locality.empty()) | |
| 115 result->SetString(kAddressDependentLocality, this->dependent_locality); | |
| 116 if (!this->postal_code.empty()) | |
| 117 result->SetString(kAddressPostalCode, this->postal_code); | |
| 118 if (!this->sorting_code.empty()) | |
| 119 result->SetString(kAddressSortingCode, this->sorting_code); | |
| 120 if (!this->language_code.empty()) | |
| 121 result->SetString(kAddressLanguageCode, this->language_code); | |
| 122 if (!this->organization.empty()) | |
| 123 result->SetString(kAddressOrganization, this->organization); | |
| 124 if (!this->recipient.empty()) | |
| 125 result->SetString(kAddressRecipient, this->recipient); | |
| 126 if (!this->phone.empty()) | |
| 127 result->SetString(kAddressPhone, this->phone); | |
| 128 | |
| 129 return result; | |
| 130 } | |
| 131 | |
| 132 PaymentMethodData::PaymentMethodData() {} | 56 PaymentMethodData::PaymentMethodData() {} |
| 133 PaymentMethodData::PaymentMethodData(const PaymentMethodData& other) = default; | 57 PaymentMethodData::PaymentMethodData(const PaymentMethodData& other) = default; |
| 134 PaymentMethodData::~PaymentMethodData() = default; | 58 PaymentMethodData::~PaymentMethodData() = default; |
| 135 | 59 |
| 136 bool PaymentMethodData::operator==(const PaymentMethodData& other) const { | 60 bool PaymentMethodData::operator==(const PaymentMethodData& other) const { |
| 137 return this->supported_methods == other.supported_methods && | 61 return this->supported_methods == other.supported_methods && |
| 138 this->data == other.data; | 62 this->data == other.data; |
| 139 } | 63 } |
| 140 | 64 |
| 141 bool PaymentMethodData::operator!=(const PaymentMethodData& other) const { | 65 bool PaymentMethodData::operator!=(const PaymentMethodData& other) const { |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 // Parse the payment options. | 369 // Parse the payment options. |
| 446 const base::DictionaryValue* payment_options = nullptr; | 370 const base::DictionaryValue* payment_options = nullptr; |
| 447 // Options field is optional. | 371 // Options field is optional. |
| 448 if (value.GetDictionary(kPaymentRequestOptions, &payment_options)) | 372 if (value.GetDictionary(kPaymentRequestOptions, &payment_options)) |
| 449 if (!this->options.FromDictionaryValue(*payment_options)) | 373 if (!this->options.FromDictionaryValue(*payment_options)) |
| 450 return false; | 374 return false; |
| 451 | 375 |
| 452 return true; | 376 return true; |
| 453 } | 377 } |
| 454 | 378 |
| 455 BasicCardResponse::BasicCardResponse() {} | |
| 456 BasicCardResponse::BasicCardResponse(const BasicCardResponse& other) = default; | |
| 457 BasicCardResponse::~BasicCardResponse() = default; | |
| 458 | |
| 459 bool BasicCardResponse::operator==(const BasicCardResponse& other) const { | |
| 460 return this->cardholder_name == other.cardholder_name && | |
| 461 this->card_number == other.card_number && | |
| 462 this->expiry_month == other.expiry_month && | |
| 463 this->expiry_year == other.expiry_year && | |
| 464 this->card_security_code == other.card_security_code && | |
| 465 this->billing_address == other.billing_address; | |
| 466 } | |
| 467 | |
| 468 bool BasicCardResponse::operator!=(const BasicCardResponse& other) const { | |
| 469 return !(*this == other); | |
| 470 } | |
| 471 | |
| 472 std::unique_ptr<base::DictionaryValue> BasicCardResponse::ToDictionaryValue() | |
| 473 const { | |
| 474 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
| 475 | |
| 476 if (!this->cardholder_name.empty()) | |
| 477 result->SetString(kCardCardholderName, this->cardholder_name); | |
| 478 result->SetString(kCardCardNumber, this->card_number); | |
| 479 if (!this->expiry_month.empty()) | |
| 480 result->SetString(kCardExpiryMonth, this->expiry_month); | |
| 481 if (!this->expiry_year.empty()) | |
| 482 result->SetString(kCardExpiryYear, this->expiry_year); | |
| 483 if (!this->card_security_code.empty()) | |
| 484 result->SetString(kCardCardSecurityCode, this->card_security_code); | |
| 485 if (!this->billing_address.ToDictionaryValue()->empty()) | |
| 486 result->Set(kCardBillingAddress, this->billing_address.ToDictionaryValue()); | |
| 487 | |
| 488 return result; | |
| 489 } | |
| 490 | |
| 491 PaymentResponse::PaymentResponse() {} | 379 PaymentResponse::PaymentResponse() {} |
| 492 PaymentResponse::PaymentResponse(const PaymentResponse& other) = default; | 380 PaymentResponse::PaymentResponse(const PaymentResponse& other) = default; |
| 493 PaymentResponse::~PaymentResponse() = default; | 381 PaymentResponse::~PaymentResponse() = default; |
| 494 | 382 |
| 495 bool PaymentResponse::operator==(const PaymentResponse& other) const { | 383 bool PaymentResponse::operator==(const PaymentResponse& other) const { |
| 496 return this->payment_request_id == other.payment_request_id && | 384 return this->payment_request_id == other.payment_request_id && |
| 497 this->method_name == other.method_name && | 385 this->method_name == other.method_name && |
| 498 this->details == other.details && | 386 this->details == other.details && |
| 499 this->shipping_address == other.shipping_address && | 387 this->shipping_address == other.shipping_address && |
| 500 this->shipping_option == other.shipping_option && | 388 this->shipping_option == other.shipping_option && |
| (...skipping 23 matching lines...) Expand all Loading... |
| 524 result->SetString(kPaymentResponsePayerName, this->payer_name); | 412 result->SetString(kPaymentResponsePayerName, this->payer_name); |
| 525 if (!this->payer_email.empty()) | 413 if (!this->payer_email.empty()) |
| 526 result->SetString(kPaymentResponsePayerEmail, this->payer_email); | 414 result->SetString(kPaymentResponsePayerEmail, this->payer_email); |
| 527 if (!this->payer_phone.empty()) | 415 if (!this->payer_phone.empty()) |
| 528 result->SetString(kPaymentResponsePayerPhone, this->payer_phone); | 416 result->SetString(kPaymentResponsePayerPhone, this->payer_phone); |
| 529 | 417 |
| 530 return result; | 418 return result; |
| 531 } | 419 } |
| 532 | 420 |
| 533 } // namespace web | 421 } // namespace web |
| OLD | NEW |