Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: third_party/WebKit/Source/modules/payments/PaymentResponse.cpp

Issue 2491513002: [Payment] Clean up PaymentResponse::toJSONForBinding (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "modules/payments/PaymentResponse.h" 5 #include "modules/payments/PaymentResponse.h"
6 6
7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
8 #include "bindings/core/v8/V8ObjectBuilder.h" 8 #include "bindings/core/v8/V8ObjectBuilder.h"
9 #include "modules/payments/PaymentAddress.h" 9 #include "modules/payments/PaymentAddress.h"
10 #include "modules/payments/PaymentCompleter.h" 10 #include "modules/payments/PaymentCompleter.h"
(...skipping 23 matching lines...) Expand all
34 V8ObjectBuilder result(scriptState); 34 V8ObjectBuilder result(scriptState);
35 result.addString("methodName", methodName()); 35 result.addString("methodName", methodName());
36 result.add("details", details(scriptState, ASSERT_NO_EXCEPTION)); 36 result.add("details", details(scriptState, ASSERT_NO_EXCEPTION));
37 37
38 if (shippingAddress()) 38 if (shippingAddress())
39 result.add("shippingAddress", 39 result.add("shippingAddress",
40 shippingAddress()->toJSONForBinding(scriptState)); 40 shippingAddress()->toJSONForBinding(scriptState));
41 else 41 else
42 result.addNull("shippingAddress"); 42 result.addNull("shippingAddress");
43 43
44 if (shippingOption().isNull()) 44 result.addStringOrNull("shippingOption", shippingOption())
45 result.addNull("shippingOption"); 45 .addStringOrNull("payerName", payerName())
46 else 46 .addStringOrNull("payerEmail", payerEmail())
47 result.addString("shippingOption", shippingOption()); 47 .addStringOrNull("payerPhone", payerPhone());
48
49 if (payerName().isNull())
50 result.addNull("payerName");
51 else
52 result.addString("payerName", payerName());
53
54 if (payerEmail().isNull())
55 result.addNull("payerEmail");
56 else
57 result.addString("payerEmail", payerEmail());
58
59 if (payerPhone().isNull())
60 result.addNull("payerPhone");
61 else
62 result.addString("payerPhone", payerPhone());
63 48
64 return result.scriptValue(); 49 return result.scriptValue();
65 } 50 }
66 51
67 ScriptValue PaymentResponse::details(ScriptState* scriptState, 52 ScriptValue PaymentResponse::details(ScriptState* scriptState,
68 ExceptionState& exceptionState) const { 53 ExceptionState& exceptionState) const {
69 return ScriptValue( 54 return ScriptValue(
70 scriptState, fromJSONString(scriptState->isolate(), m_stringifiedDetails, 55 scriptState, fromJSONString(scriptState->isolate(), m_stringifiedDetails,
71 exceptionState)); 56 exceptionState));
72 } 57 }
73 58
74 ScriptPromise PaymentResponse::complete(ScriptState* scriptState, 59 ScriptPromise PaymentResponse::complete(ScriptState* scriptState,
75 const String& result) { 60 const String& result) {
76 PaymentCompleter::PaymentComplete convertedResult = PaymentCompleter::Unknown; 61 PaymentCompleter::PaymentComplete convertedResult = PaymentCompleter::Unknown;
77 if (result == "success") 62 if (result == "success")
78 convertedResult = PaymentCompleter::Success; 63 convertedResult = PaymentCompleter::Success;
79 else if (result == "fail") 64 else if (result == "fail")
80 convertedResult = PaymentCompleter::Fail; 65 convertedResult = PaymentCompleter::Fail;
81 return m_paymentCompleter->complete(scriptState, convertedResult); 66 return m_paymentCompleter->complete(scriptState, convertedResult);
82 } 67 }
83 68
84 DEFINE_TRACE(PaymentResponse) { 69 DEFINE_TRACE(PaymentResponse) {
85 visitor->trace(m_shippingAddress); 70 visitor->trace(m_shippingAddress);
86 visitor->trace(m_paymentCompleter); 71 visitor->trace(m_paymentCompleter);
87 } 72 }
88 73
89 } // namespace blink 74 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698