Chromium Code Reviews| Index: ios/web/payments/payment_request.cc |
| diff --git a/ios/web/payments/payment_request.cc b/ios/web/payments/payment_request.cc |
| index f0579371be0c66cf5615c26c1a96efcebdf3bda4..f5da1639acb7634f19a3559cf0b9f784bc28e81c 100644 |
| --- a/ios/web/payments/payment_request.cc |
| +++ b/ios/web/payments/payment_request.cc |
| @@ -11,6 +11,18 @@ namespace { |
| // All of these are defined here (even though most are only used once each) so |
| // the format details are easy to locate and update or compare to the spec doc. |
| // (https://w3c.github.io/browser-payment-api/). |
| +static const char kAddressCountry[] = "country"; |
| +static const char kAddressAddressLine[] = "addressLine"; |
| +static const char kAddressRegion[] = "region"; |
| +static const char kAddressCity[] = "city"; |
| +static const char kAddressDependentLocality[] = "dependentLocality"; |
| +static const char kAddressPostalCode[] = "postalCode"; |
| +static const char kAddressSortingCode[] = "sortingCode"; |
| +static const char kAddressLanguageCode[] = "languageCode"; |
| +static const char kAddressOrganization[] = "organization"; |
| +static const char kAddressRecipient[] = "recipient"; |
| +static const char kAddressCareOf[] = "careOf"; |
| +static const char kAddressPhone[] = "phone"; |
| static const char kMethodData[] = "methodData"; |
| static const char kSupportedMethods[] = "supportedMethods"; |
| static const char kData[] = "data"; |
| @@ -20,6 +32,12 @@ static const char kPaymentDetailsTotalAmount[] = "amount"; |
| static const char kPaymentDetailsTotalAmountCurrency[] = "currency"; |
| static const char kPaymentDetailsTotalAmountValue[] = "value"; |
| static const char kMethodName[] = "methodName"; |
| +static const char kCardCardholderName[] = "cardholderName"; |
| +static const char kCardCardNumber[] = "cardNumber"; |
| +static const char kCardExpiryMonth[] = "expiryMonth"; |
| +static const char kCardExpiryYear[] = "expiryYear"; |
| +static const char kCardCardSecurityCode[] = "cardSecurityCode"; |
| +static const char kCardBillingAddress[] = "billingAddress"; |
| } // namespace |
| @@ -46,6 +64,43 @@ bool PaymentAddress::operator!=(const PaymentAddress& other) const { |
| return !(*this == other); |
| } |
| +void PaymentAddress::ToDictionaryValue(base::DictionaryValue* value) const { |
| + DCHECK(value); |
| + value->Clear(); |
| + |
| + if (!this->country.empty()) |
| + value->SetString(kAddressCountry, this->country); |
| + |
| + if (!this->address_line.empty()) { |
| + std::unique_ptr<base::ListValue> address_line(new base::ListValue); |
| + for (base::string16 address_line_string : this->address_line) { |
| + address_line->AppendString(address_line_string); |
| + } |
| + value->Set(kAddressAddressLine, std::move(address_line)); |
| + } |
| + |
| + if (!this->region.empty()) |
| + value->SetString(kAddressRegion, this->region); |
| + if (!this->city.empty()) |
| + value->SetString(kAddressCity, this->city); |
| + if (!this->dependent_locality.empty()) |
| + value->SetString(kAddressDependentLocality, this->dependent_locality); |
| + if (!this->postal_code.empty()) |
| + value->SetString(kAddressPostalCode, this->postal_code); |
| + if (!this->sorting_code.empty()) |
| + value->SetString(kAddressSortingCode, this->sorting_code); |
| + if (!this->language_code.empty()) |
| + value->SetString(kAddressLanguageCode, this->language_code); |
| + if (!this->organization.empty()) |
| + value->SetString(kAddressOrganization, this->organization); |
| + if (!this->recipient.empty()) |
| + value->SetString(kAddressRecipient, this->recipient); |
| + if (!this->care_of.empty()) |
| + value->SetString(kAddressCareOf, this->care_of); |
| + if (!this->phone.empty()) |
| + value->SetString(kAddressPhone, this->phone); |
| +} |
| + |
| PaymentMethodData::PaymentMethodData() {} |
| PaymentMethodData::PaymentMethodData(const PaymentMethodData& other) = default; |
| PaymentMethodData::~PaymentMethodData() = default; |
| @@ -217,7 +272,45 @@ bool PaymentRequest::FromDictionaryValue(const base::DictionaryValue& value) { |
| return true; |
| } |
| +BasicCardResponse::BasicCardResponse() {} |
| +BasicCardResponse::BasicCardResponse(const BasicCardResponse& other) = default; |
| +BasicCardResponse::~BasicCardResponse() = default; |
| + |
| +bool BasicCardResponse::operator==(const BasicCardResponse& other) const { |
| + return this->cardholder_name == other.cardholder_name && |
| + this->card_number == other.card_number && |
| + this->expiry_month == other.expiry_month && |
| + this->expiry_year == other.expiry_year && |
| + this->card_security_code == other.card_security_code && |
| + this->billing_address == other.billing_address; |
| +} |
| + |
| +bool BasicCardResponse::operator!=(const BasicCardResponse& other) const { |
| + return !(*this == other); |
| +} |
| + |
| +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
|
| + DCHECK(value); |
| + value->Clear(); |
| + |
| + if (!this->cardholder_name.empty()) |
| + value->SetString(kCardCardholderName, this->cardholder_name); |
| + if (!this->card_number.empty()) |
| + value->SetString(kCardCardNumber, this->card_number); |
| + if (!this->expiry_month.empty()) |
| + value->SetString(kCardExpiryMonth, this->expiry_month); |
| + if (!this->expiry_year.empty()) |
| + value->SetString(kCardExpiryYear, this->expiry_year); |
| + if (!this->card_security_code.empty()) |
| + value->SetString(kCardCardSecurityCode, this->card_security_code); |
| + |
| + std::unique_ptr<base::DictionaryValue> address(new base::DictionaryValue); |
| + this->billing_address.ToDictionaryValue(address.get()); |
| + value->Set(kCardBillingAddress, std::move(address)); |
| +} |
| + |
| PaymentResponse::PaymentResponse() {} |
| +PaymentResponse::PaymentResponse(const PaymentResponse& other) = default; |
| PaymentResponse::~PaymentResponse() = default; |
| bool PaymentResponse::operator==(const PaymentResponse& other) const { |
| @@ -231,10 +324,14 @@ bool PaymentResponse::operator!=(const PaymentResponse& other) const { |
| void PaymentResponse::ToDictionaryValue(base::DictionaryValue* value) const { |
| DCHECK(value); |
| + value->Clear(); |
| + |
| if (!this->method_name.empty()) |
| value->SetString(kMethodName, this->method_name); |
| - if (!this->details.empty()) |
| - value->SetString(kPaymentDetails, this->details); |
| + |
| + std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue); |
| + this->details.ToDictionaryValue(details.get()); |
| + value->Set(kPaymentDetails, std::move(details)); |
| } |
| } // namespace web |