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

Unified Diff: components/payments/content/payment_request.cc

Issue 2715213005: [Payments] Add the pay button, and control its enabled state (Closed)
Patch Set: tweak Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: components/payments/content/payment_request.cc
diff --git a/components/payments/content/payment_request.cc b/components/payments/content/payment_request.cc
index 0a83cf2c5afd7ef3d4b6ffe48c37e57d90770c37..8eceeaed4c87383b4396fa71c90bf7aacb552b40 100644
--- a/components/payments/content/payment_request.cc
+++ b/components/payments/content/payment_request.cc
@@ -4,10 +4,13 @@
#include "components/payments/content/payment_request.h"
+#include <algorithm>
#include <unordered_map>
#include <utility>
#include "base/memory/ptr_util.h"
+#include "components/autofill/core/browser/autofill_data_util.h"
+#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/payments/content/payment_details_validation.h"
#include "components/payments/content/payment_request_web_contents_manager.h"
@@ -26,6 +29,7 @@ PaymentRequest::PaymentRequest(
delegate_(std::move(delegate)),
manager_(manager),
binding_(this, std::move(request)),
+ is_ready_to_pay_(false),
selected_shipping_profile_(nullptr),
selected_contact_profile_(nullptr),
selected_credit_card_(nullptr) {
@@ -54,9 +58,11 @@ void PaymentRequest::Init(
}
client_ = std::move(client);
details_ = std::move(details);
+ options_ = std::move(options);
PopulateValidatedMethodData(method_data);
PopulateProfileCache();
SetDefaultProfileSelections();
+ UpdateIsReadyToPay();
}
void PaymentRequest::Show() {
@@ -103,6 +109,13 @@ void PaymentRequest::OnConnectionTerminated() {
manager_->DestroyRequest(this);
}
+void PaymentRequest::Pay() {
+ DCHECK(is_ready_to_pay_);
+
+ // TODO(mathp): Return the PaymentResponse to the |client_|.
+ UserCancelled();
+}
+
CurrencyFormatter* PaymentRequest::GetOrCreateCurrencyFormatter(
const std::string& currency_code,
const std::string& currency_system,
@@ -241,4 +254,56 @@ void PaymentRequest::PopulateValidatedMethodData(
}
}
+void PaymentRequest::UpdateIsReadyToPay() {
+ is_ready_to_pay_ =
+ ArePaymentDetailsSatisfied() && ArePaymentOptionsSatisfied();
+}
+
+bool PaymentRequest::ArePaymentDetailsSatisfied() {
+ if (selected_credit_card_ == nullptr || !selected_credit_card_->IsValid())
+ return false;
+
+ const std::string basic_card_payment_type =
+ autofill::data_util::GetPaymentRequestData(selected_credit_card_->type())
+ .basic_card_payment_type;
+ return !supported_card_networks_.empty() &&
+ std::find(supported_card_networks_.begin(),
+ supported_card_networks_.end(),
+ basic_card_payment_type) != supported_card_networks_.end();
+}
+
+bool PaymentRequest::ArePaymentOptionsSatisfied() {
+ // TODO(mathp): Have a measure of shipping address completeness.
+ if (options_->request_shipping && selected_shipping_profile_ == nullptr)
+ return false;
+
+ // TODO(mathp): Make an encompassing class to validate contact info.
+ const std::string& app_locale = delegate_->GetApplicationLocale();
+ if (options_->request_payer_name &&
+ (selected_contact_profile_ == nullptr ||
+ selected_contact_profile_
+ ->GetInfo(autofill::AutofillType(autofill::NAME_FULL), app_locale)
+ .empty())) {
+ return false;
+ }
+ if (options_->request_payer_email &&
+ (selected_contact_profile_ == nullptr ||
+ selected_contact_profile_
+ ->GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS),
+ app_locale)
+ .empty())) {
+ return false;
+ }
+ if (options_->request_payer_phone &&
+ (selected_contact_profile_ == nullptr ||
+ selected_contact_profile_
+ ->GetInfo(autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
+ app_locale)
+ .empty())) {
+ return false;
+ }
+
+ return true;
+}
+
} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698