Commit dc4e7f52 authored by Mohamad Ahmadi's avatar Mohamad Ahmadi Committed by Commit Bot

[Payment Request] Fixes a bug with the serialized PaymentResponse.details

PaymentResponse.details was being JSON-escaped twice.

Bug: 602666
Change-Id: I0b574654353b25ed16d3baf143ac12ac14526953
Reviewed-on: https://chromium-review.googlesource.com/565008
Commit-Queue: mahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarMathieu Perreault <mathp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485373}
parent 1da87bbb
......@@ -4,6 +4,7 @@
#include "ios/web/public/payments/payment_request.h"
#include "base/json/json_reader.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
......@@ -362,7 +363,13 @@ std::unique_ptr<base::DictionaryValue> PaymentResponse::ToDictionaryValue()
result->SetString(kPaymentRequestId, this->payment_request_id);
result->SetString(kPaymentResponseMethodName, this->method_name);
result->SetString(kPaymentResponseDetails, this->details);
// |this.details| is a json-serialized string. Parse it to a base::Value so
// that when |this| is converted to a JSON string, |this.details| won't get
// json-escaped.
std::unique_ptr<base::Value> details =
base::JSONReader().ReadToValue(this->details);
if (details)
result->Set(kPaymentResponseDetails, std::move(details));
if (!this->shipping_address.ToDictionaryValue()->empty()) {
result->Set(kPaymentResponseShippingAddress,
this->shipping_address.ToDictionaryValue());
......
......@@ -264,7 +264,6 @@ TEST(PaymentRequestTest, ParsingFullyPopulatedRequestDictionarySucceeds) {
TEST(PaymentRequestTest, EmptyResponseDictionary) {
base::DictionaryValue expected_value;
expected_value.SetString("details", "");
expected_value.SetString("paymentRequestID", "");
expected_value.SetString("methodName", "");
......@@ -288,9 +287,7 @@ TEST(PaymentRequestTest, PopulatedResponseDictionary) {
new base::DictionaryValue);
billing_address->SetString("postalCode", "90210");
details->Set("billingAddress", std::move(billing_address));
std::string stringified_details;
base::JSONWriter::Write(*details, &stringified_details);
expected_value.SetString("details", stringified_details);
expected_value.Set("details", std::move(details));
expected_value.SetString("paymentRequestID", "12345");
expected_value.SetString("methodName", "American Express");
std::unique_ptr<base::DictionaryValue> shipping_address(
......
......@@ -262,8 +262,8 @@ class PaymentResponse {
// to fulfil the transaction.
base::string16 method_name;
// A credit card response object used by the merchant to process the
// transaction and determine successful fund transfer.
// The json-serialized stringified details of the payment method. Used by the
// merchant to process the transaction and determine successful fund transfer.
std::string details;
// If request_shipping was set to true in the PaymentOptions passed to the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment