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

Unified Diff: components/payments/payment_request.cc

Issue 2621153002: [WebPayments] Add the Payment Method section in the Payment Sheet (Closed)
Patch Set: Initial patch Created 3 years, 11 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/payment_request.cc
diff --git a/components/payments/payment_request.cc b/components/payments/payment_request.cc
index 98182c155672e0a96ae518de2a66c1702ffb3226..f78d83f0a8ae0e2038b8c027f9bda4c87c8d322b 100644
--- a/components/payments/payment_request.cc
+++ b/components/payments/payment_request.cc
@@ -4,6 +4,7 @@
#include "components/payments/payment_request.h"
+#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/payments/payment_details_validation.h"
#include "components/payments/payment_request_delegate.h"
#include "components/payments/payment_request_web_contents_manager.h"
@@ -61,4 +62,23 @@ void PaymentRequest::OnError() {
manager_->DestroyRequest(this);
}
+autofill::CreditCard* PaymentRequest::GetCurrentlySelectedCreditCard() {
+ // TODO(anthonyvd): Change this code to prioritize server cards and implement
+ // a way to modify this function's return value.
+ autofill::PersonalDataManager* data_manager =
+ delegate_->GetDataManagerFromWebContents(web_contents());
+
+ const std::vector<autofill::CreditCard*> cards =
+ data_manager->GetCreditCardsToSuggest();
+
+ auto first_complete_card = std::find_if(
+ cards.begin(),
+ cards.end(),
+ [] (autofill::CreditCard* card) {
+ return card->IsValid();
+ });
+
+ return first_complete_card == cards.end() ? nullptr : *first_complete_card;
+}
+
} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698