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

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

Issue 2808633002: [Payments] Move PaymentResponse logic to PaymentResponseHelper. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: components/payments/content/payment_response_helper.cc
diff --git a/components/payments/content/payment_response_helper.cc b/components/payments/content/payment_response_helper.cc
index bbec2f34c690b7a6d85e3933ca77eb6e7e8235c1..58b1ccf92760283e4cb82be67cbfd9217e443e52 100644
--- a/components/payments/content/payment_response_helper.cc
+++ b/components/payments/content/payment_response_helper.cc
@@ -8,10 +8,21 @@
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/autofill_type.h"
+#include "components/payments/content/payment_request_spec.h"
namespace payments {
-PaymentResponseHelper::PaymentResponseHelper(){};
+PaymentResponseHelper::PaymentResponseHelper(
+ const std::string& app_locale,
+ PaymentRequestSpec* spec,
+ autofill::AutofillProfile* selected_shipping_profile,
+ autofill::AutofillProfile* selected_contact_profile,
+ Delegate* delegate)
+ : app_locale_(app_locale),
+ spec_(spec),
+ selected_shipping_profile_(selected_shipping_profile),
+ selected_contact_profile_(selected_contact_profile),
+ delegate_(delegate){};
PaymentResponseHelper::~PaymentResponseHelper(){};
// static
@@ -51,4 +62,52 @@ PaymentResponseHelper::GetMojomPaymentAddressFromAutofillProfile(
return payment_address;
}
+void PaymentResponseHelper::OnInstrumentDetailsReady(
+ const std::string& method_name,
+ const std::string& stringified_details) {
+ mojom::PaymentResponsePtr payment_response = mojom::PaymentResponse::New();
+
+ // Make sure that we return the method name that the merchant specified for
+ // this instrument: cards can be either specified through their name (e.g.,
+ // "visa") or through basic-card's supportedNetworks.
+ payment_response->method_name =
+ spec_->IsMethodSupportedThroughBasicCard(method_name)
+ ? kBasicCardMethodName
+ : method_name;
+ payment_response->stringified_details = stringified_details;
+
+ // Shipping Address section
+ if (spec_->request_shipping()) {
+ DCHECK(selected_shipping_profile_);
+ payment_response->shipping_address =
+ GetMojomPaymentAddressFromAutofillProfile(selected_shipping_profile_,
+ app_locale_);
+
+ DCHECK(spec_->selected_shipping_option());
+ payment_response->shipping_option = spec_->selected_shipping_option()->id;
+ }
+
+ // Contact Details section.
+ if (spec_->request_payer_name()) {
+ DCHECK(selected_contact_profile_);
+ payment_response->payer_name =
+ base::UTF16ToUTF8(selected_contact_profile_->GetInfo(
+ autofill::AutofillType(autofill::NAME_FULL), app_locale_));
+ }
+ if (spec_->request_payer_email()) {
+ DCHECK(selected_contact_profile_);
+ payment_response->payer_email = base::UTF16ToUTF8(
+ selected_contact_profile_->GetRawInfo(autofill::EMAIL_ADDRESS));
+ }
+ if (spec_->request_payer_phone()) {
+ DCHECK(selected_contact_profile_);
+ // TODO(crbug.com/705945): Format phone number according to spec.
+ payment_response->payer_phone =
+ base::UTF16ToUTF8(selected_contact_profile_->GetRawInfo(
+ autofill::PHONE_HOME_WHOLE_NUMBER));
+ }
+
+ delegate_->OnPaymentResponseReady(std::move(payment_response));
Mathieu 2017/04/10 00:03:22 I'm curious why you are not getting an error here,
sebsg 2017/04/10 20:48:24 I applied when I returned the PaymentAddress above
Mathieu 2017/04/10 20:55:58 Ah yes ok
+}
+
} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698