[Payments] Return a basic card response in the PaymentResponse
* Creates AutofillPaymentInstrument (and the abstract type PaymentInstrument),
which returns a basic card response.
* Brings PaymentAddress and BasicCardResponse from iOS code, because they
can be reused when serializing the stringified basic card details.
* Brings the utility functions used for PaymentAddress and BasicCardResponse.
* Hooks up Complete, OnComplete and CanMakePayment in PaymentRequest.
* Adds many TODOs!
BUG=696733
TEST=components_unittests, browser_tests (PaymentRequest*)
Review-Url: https://codereview.chromium.org/2733953003
Cr-Commit-Position: refs/heads/master@{#455540}
diff --git a/components/payments/content/payment_request.cc b/components/payments/content/payment_request.cc
index 613bff17..2739785 100644
--- a/components/payments/content/payment_request.cc
+++ b/components/payments/content/payment_request.cc
@@ -14,12 +14,18 @@
#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"
+#include "components/payments/core/autofill_payment_instrument.h"
#include "components/payments/core/currency_formatter.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
namespace payments {
+namespace {
+// Identifier for the basic card payment method in the PaymentMethodData.
+static const char* const kBasicCardMethodName = "basic-card";
+} // namespace
+
PaymentRequest::PaymentRequest(
content::WebContents* web_contents,
std::unique_ptr<PaymentRequestDelegate> delegate,
@@ -81,6 +87,30 @@
client_->OnAbort(true /* aborted_successfully */);
}
+void PaymentRequest::Complete(payments::mojom::PaymentComplete result) {
+ if (!client_.is_bound())
+ return;
+
+ // TODO(mathp): Validate |result|.
+
+ // When the renderer closes the connection,
+ // PaymentRequest::OnConnectionTerminated will be called.
+ client_->OnComplete();
+}
+
+void PaymentRequest::CanMakePayment() {
+ // TODO(mathp): Return whether we can make payment.
+ client_->OnCanMakePayment(mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT);
+}
+
+void PaymentRequest::OnInstrumentDetailsReady(
+ const std::string& method_name,
+ const std::string& stringified_details) {
+ payment_response_->method_name = method_name;
+ payment_response_->stringified_details = stringified_details;
+ client_->OnPaymentResponse(std::move(payment_response_));
+}
+
void PaymentRequest::UserCancelled() {
// If |client_| is not bound, then the object is already being destroyed as
// a result of a renderer event.
@@ -111,8 +141,19 @@
void PaymentRequest::Pay() {
DCHECK(is_ready_to_pay_);
- // TODO(mathp): Return the PaymentResponse to the |client_|.
- OnConnectionTerminated();
+ // TODO(mathp): Fill other fields in the PaymentResponsePtr object.
+ payment_response_ = mojom::PaymentResponse::New();
+
+ // TODO(mathp): PaymentRequest should know about the currently selected
+ // instrument, and not |selected_credit_card_| which is too specific.
+ // TODO(mathp): The method_name should reflect what the merchant asked, and
+ // not necessarily basic-card.
+ selected_payment_instrument_.reset(new AutofillPaymentInstrument(
+ kBasicCardMethodName, *selected_credit_card_, shipping_profiles_,
+ delegate_->GetApplicationLocale()));
+ // Fetch the instrument details, will call back into
+ // PaymentRequest::OnInstrumentsDetailsReady.
+ selected_payment_instrument_->InvokePaymentApp(this);
}
void PaymentRequest::AddObserver(Observer* observer) {
@@ -223,8 +264,6 @@
return;
}
- // Identifier for the basic card payment method in the PaymentMethodData.
- const char* const kBasicCardMethodName = "basic-card";
std::set<std::string> card_networks{"amex", "diners", "discover",
"jcb", "mastercard", "mir",
"unionpay", "visa"};