| Index: components/payments/core/autofill_payment_instrument.cc
|
| diff --git a/components/payments/core/autofill_payment_instrument.cc b/components/payments/core/autofill_payment_instrument.cc
|
| index 00c59b6a925aba1bbd78977b27abd9f7be1cf508..6c307bcfa5360c7daae462ab5f3f6716b3689845 100644
|
| --- a/components/payments/core/autofill_payment_instrument.cc
|
| +++ b/components/payments/core/autofill_payment_instrument.cc
|
| @@ -8,8 +8,10 @@
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/values.h"
|
| #include "components/autofill/core/browser/autofill_data_util.h"
|
| +#include "components/autofill/core/common/autofill_clock.h"
|
| #include "components/payments/core/basic_card_response.h"
|
| #include "components/payments/core/payment_request_data_util.h"
|
| +#include "components/payments/core/payment_request_delegate.h"
|
|
|
| namespace payments {
|
|
|
| @@ -17,7 +19,8 @@ AutofillPaymentInstrument::AutofillPaymentInstrument(
|
| const std::string& method_name,
|
| const autofill::CreditCard& card,
|
| const std::vector<autofill::AutofillProfile*>& billing_profiles,
|
| - const std::string& app_locale)
|
| + const std::string& app_locale,
|
| + PaymentRequestDelegate* payment_request_delegate)
|
| : PaymentInstrument(
|
| method_name,
|
| /* label= */ card.TypeAndLastFourDigits(),
|
| @@ -28,26 +31,47 @@ AutofillPaymentInstrument::AutofillPaymentInstrument(
|
| .icon_resource_id),
|
| credit_card_(card),
|
| billing_profiles_(billing_profiles),
|
| - app_locale_(app_locale) {}
|
| + app_locale_(app_locale),
|
| + delegate_(nullptr),
|
| + payment_request_delegate_(payment_request_delegate),
|
| + weak_ptr_factory_(this) {}
|
| AutofillPaymentInstrument::~AutofillPaymentInstrument() {}
|
|
|
| void AutofillPaymentInstrument::InvokePaymentApp(
|
| PaymentInstrument::Delegate* delegate) {
|
| DCHECK(delegate);
|
| - std::string stringified_details;
|
| - // TODO(mathp): Show the CVC dialog and use the data instead of the
|
| - // placeholder string.
|
| + // There can be only one FullCardRequest going on at a time. If |delegate_| is
|
| + // not null, there's already an active request, which shouldn't happen.
|
| + // |delegate_| is reset to nullptr when the request succeeds or fails.
|
| + DCHECK(!delegate_);
|
| + delegate_ = delegate;
|
| +
|
| + payment_request_delegate_->DoFullCardRequest(credit_card_,
|
| + weak_ptr_factory_.GetWeakPtr());
|
| +}
|
| +
|
| +bool AutofillPaymentInstrument::IsValid() {
|
| + return !credit_card_.IsExpired(autofill::AutofillClock::Now());
|
| +}
|
| +
|
| +void AutofillPaymentInstrument::OnFullCardRequestSucceeded(
|
| + const autofill::CreditCard& card,
|
| + const base::string16& cvc) {
|
| + DCHECK(delegate_);
|
| + credit_card_ = card;
|
| std::unique_ptr<base::DictionaryValue> response_value =
|
| payments::data_util::GetBasicCardResponseFromAutofillCreditCard(
|
| - credit_card_, base::ASCIIToUTF16("123"), billing_profiles_,
|
| - app_locale_)
|
| + credit_card_, cvc, billing_profiles_, app_locale_)
|
| .ToDictionaryValue();
|
| + std::string stringified_details;
|
| base::JSONWriter::Write(*response_value, &stringified_details);
|
| - delegate->OnInstrumentDetailsReady(method_name(), stringified_details);
|
| + delegate_->OnInstrumentDetailsReady(method_name(), stringified_details);
|
| + delegate_ = nullptr;
|
| }
|
|
|
| -bool AutofillPaymentInstrument::IsValid() {
|
| - return credit_card_.IsValid();
|
| +void AutofillPaymentInstrument::OnFullCardRequestFailed() {
|
| + // TODO(anthonyvd): Do something with the error.
|
| + delegate_ = nullptr;
|
| }
|
|
|
| } // namespace payments
|
|
|