| Index: components/payments/content/payment_request_spec.cc
|
| diff --git a/components/payments/content/payment_request_spec.cc b/components/payments/content/payment_request_spec.cc
|
| index 7509a76a1ccce6b77cc86bed05bff8cc6df22c1c..3d3211204c8199585714b466049d8bd3344d3bbb 100644
|
| --- a/components/payments/content/payment_request_spec.cc
|
| +++ b/components/payments/content/payment_request_spec.cc
|
| @@ -19,8 +19,11 @@ PaymentRequestSpec::PaymentRequestSpec(
|
| mojom::PaymentOptionsPtr options,
|
| mojom::PaymentDetailsPtr details,
|
| std::vector<mojom::PaymentMethodDataPtr> method_data,
|
| - Observer* observer)
|
| - : options_(std::move(options)), details_(std::move(details)) {
|
| + Observer* observer,
|
| + const std::string& app_locale)
|
| + : options_(std::move(options)),
|
| + details_(std::move(details)),
|
| + app_locale_(app_locale) {
|
| if (observer)
|
| AddObserver(observer);
|
| PopulateValidatedMethodData(method_data);
|
| @@ -36,6 +39,22 @@ void PaymentRequestSpec::RemoveObserver(Observer* observer) {
|
| observers_.RemoveObserver(observer);
|
| }
|
|
|
| +base::string16 PaymentRequestSpec::GetFormattedCurrencyAmount(
|
| + const std::string& amount) {
|
| + CurrencyFormatter* formatter = GetOrCreateCurrencyFormatter(
|
| + details_->total->amount->currency,
|
| + details_->total->amount->currency_system, app_locale_);
|
| + return formatter->Format(amount);
|
| +}
|
| +
|
| +std::string PaymentRequestSpec::GetFormattedCurrencyCode() {
|
| + CurrencyFormatter* formatter = GetOrCreateCurrencyFormatter(
|
| + details_->total->amount->currency,
|
| + details_->total->amount->currency_system, app_locale_);
|
| +
|
| + return formatter->formatted_currency_code();
|
| +}
|
| +
|
| void PaymentRequestSpec::PopulateValidatedMethodData(
|
| const std::vector<mojom::PaymentMethodDataPtr>& method_data) {
|
| if (method_data.empty()) {
|
| @@ -112,4 +131,15 @@ void PaymentRequestSpec::NotifyOnInvalidSpecProvided() {
|
| observer.OnInvalidSpecProvided();
|
| }
|
|
|
| +CurrencyFormatter* PaymentRequestSpec::GetOrCreateCurrencyFormatter(
|
| + const std::string& currency_code,
|
| + const std::string& currency_system,
|
| + const std::string& locale_name) {
|
| + if (!currency_formatter_) {
|
| + currency_formatter_.reset(
|
| + new CurrencyFormatter(currency_code, currency_system, locale_name));
|
| + }
|
| + return currency_formatter_.get();
|
| +}
|
| +
|
| } // namespace payments
|
|
|