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

Side by Side Diff: components/payments/core/autofill_payment_instrument.cc

Issue 2779283002: [Web Payments] Implement the CVC Unmask dialog. (Closed)
Patch Set: Update AutofillPaymentInstrument's credit_card_ after unmasking. Created 3 years, 8 months 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/payments/core/autofill_payment_instrument.h" 5 #include "components/payments/core/autofill_payment_instrument.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "components/autofill/core/browser/autofill_data_util.h" 10 #include "components/autofill/core/browser/autofill_data_util.h"
11 #include "components/payments/core/basic_card_response.h" 11 #include "components/payments/core/basic_card_response.h"
12 #include "components/payments/core/payment_request_data_util.h" 12 #include "components/payments/core/payment_request_data_util.h"
13 13
14 namespace payments { 14 namespace payments {
15 15
16 AutofillPaymentInstrument::AutofillPaymentInstrument( 16 AutofillPaymentInstrument::AutofillPaymentInstrument(
17 const std::string& method_name, 17 const std::string& method_name,
18 const autofill::CreditCard& card, 18 const autofill::CreditCard& card,
19 const std::vector<autofill::AutofillProfile*>& billing_profiles, 19 const std::vector<autofill::AutofillProfile*>& billing_profiles,
20 const std::string& app_locale) 20 const std::string& app_locale,
21 FullCardRequestDelegate* full_card_request_delegate)
21 : PaymentInstrument( 22 : PaymentInstrument(
22 method_name, 23 method_name,
23 /* label= */ card.TypeAndLastFourDigits(), 24 /* label= */ card.TypeAndLastFourDigits(),
24 /* sublabel= */ 25 /* sublabel= */
25 card.GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), 26 card.GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
26 app_locale), 27 app_locale),
27 autofill::data_util::GetPaymentRequestData(card.type()) 28 autofill::data_util::GetPaymentRequestData(card.type())
28 .icon_resource_id), 29 .icon_resource_id),
29 credit_card_(card), 30 credit_card_(card),
30 billing_profiles_(billing_profiles), 31 billing_profiles_(billing_profiles),
31 app_locale_(app_locale) {} 32 app_locale_(app_locale),
33 delegate_(nullptr),
34 full_card_request_delegate_(full_card_request_delegate),
35 weak_ptr_factory_(this) {}
32 AutofillPaymentInstrument::~AutofillPaymentInstrument() {} 36 AutofillPaymentInstrument::~AutofillPaymentInstrument() {}
33 37
34 void AutofillPaymentInstrument::InvokePaymentApp( 38 void AutofillPaymentInstrument::InvokePaymentApp(
35 PaymentInstrument::Delegate* delegate) { 39 PaymentInstrument::Delegate* delegate) {
36 DCHECK(delegate); 40 DCHECK(delegate);
please use gerrit instead 2017/03/30 13:14:09 DCHECK(!delegate_);
anthonyvd 2017/03/30 15:43:41 I don't think that's correct. For example, we coul
please use gerrit instead 2017/03/31 14:41:14 If the user hits back, then "delegate_ = null" cod
anthonyvd 2017/04/04 13:25:22 Makes sense, done.
37 std::string stringified_details; 41 delegate_ = delegate;
38 // TODO(mathp): Show the CVC dialog and use the data instead of the 42
39 // placeholder string. 43 full_card_request_delegate_->DoFullCardRequest(
40 std::unique_ptr<base::DictionaryValue> response_value = 44 credit_card_, weak_ptr_factory_.GetWeakPtr());
41 payments::data_util::GetBasicCardResponseFromAutofillCreditCard(
42 credit_card_, base::ASCIIToUTF16("123"), billing_profiles_,
43 app_locale_)
44 .ToDictionaryValue();
45 base::JSONWriter::Write(*response_value, &stringified_details);
46 delegate->OnInstrumentDetailsReady(method_name(), stringified_details);
47 } 45 }
48 46
49 bool AutofillPaymentInstrument::IsValid() { 47 bool AutofillPaymentInstrument::IsValid() {
50 return credit_card_.IsValid(); 48 return credit_card_.IsValid();
51 } 49 }
52 50
51 void AutofillPaymentInstrument::OnFullCardRequestSucceeded(
52 const autofill::CreditCard& card,
53 const base::string16& cvc) {
54 DCHECK(delegate_);
55 credit_card_ = card;
56 std::string stringified_details;
57 std::unique_ptr<base::DictionaryValue> response_value =
58 payments::data_util::GetBasicCardResponseFromAutofillCreditCard(
59 credit_card_, cvc, billing_profiles_, app_locale_)
60 .ToDictionaryValue();
61 base::JSONWriter::Write(*response_value, &stringified_details);
62 delegate_->OnInstrumentDetailsReady(method_name(), stringified_details);
please use gerrit instead 2017/03/30 13:14:10 delegate_ = nullptr;
anthonyvd 2017/03/30 15:43:41 Done.
63 }
64
65 void AutofillPaymentInstrument::OnFullCardRequestFailed() {}
66
53 } // namespace payments 67 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698