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

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

Issue 2779283002: [Web Payments] Implement the CVC Unmask dialog. (Closed)
Patch Set: Make CvcUnmaskViewController the UIDelegate for FullCardRequest. 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
« no previous file with comments | « components/payments/core/autofill_payment_instrument.h ('k') | 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 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);
37 std::string stringified_details; 41 DCHECK(!delegate_);
38 // TODO(mathp): Show the CVC dialog and use the data instead of the 42 delegate_ = delegate;
39 // placeholder string. 43
40 std::unique_ptr<base::DictionaryValue> response_value = 44 full_card_request_delegate_->DoFullCardRequest(
41 payments::data_util::GetBasicCardResponseFromAutofillCreditCard( 45 credit_card_, weak_ptr_factory_.GetWeakPtr());
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 } 46 }
48 47
49 bool AutofillPaymentInstrument::IsValid() { 48 bool AutofillPaymentInstrument::IsValid() {
50 return credit_card_.IsValid(); 49 return credit_card_.IsValid();
Mathieu 2017/04/03 19:20:53 Let's change this to !credit_card_.IsExpired(Autof
Mathieu 2017/04/05 00:02:23 Bump.
anthonyvd 2017/04/05 02:12:36 Done.
51 } 50 }
52 51
52 void AutofillPaymentInstrument::OnFullCardRequestSucceeded(
53 const autofill::CreditCard& card,
54 const base::string16& cvc) {
55 DCHECK(delegate_);
56 credit_card_ = card;
57 std::string stringified_details;
58 std::unique_ptr<base::DictionaryValue> response_value =
59 payments::data_util::GetBasicCardResponseFromAutofillCreditCard(
60 credit_card_, cvc, billing_profiles_, app_locale_)
61 .ToDictionaryValue();
62 base::JSONWriter::Write(*response_value, &stringified_details);
63 delegate_->OnInstrumentDetailsReady(method_name(), stringified_details);
64 delegate_ = nullptr;
65 }
66
67 void AutofillPaymentInstrument::OnFullCardRequestFailed() {
68 // TODO(anthonyvd): Do something with the error.
69 delegate_ = nullptr;
70 }
71
53 } // namespace payments 72 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/autofill_payment_instrument.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698