Commit ac4a5c2d authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Payment Handler] CanMakePaymentEvent.respondWithMinimalUI() #1

Patch #1: Add Blink API for CanMakePaymentEvent.respondWithMinimalUI()
and CanMakePaymentEvent.currency according to the explainer for Minimal
UI payment handlers:
https://gist.github.com/rsolomakhin/eba91c185028899883d2c7f37f357d7c

The additional API surface is disabled by default and can be enabled via
chrome://flags/#enable-experimental-web-platform-features.

Demo: https://rsolomakhin.github.io/pr/apps/micro/

Chrome feature status:
https://chromestatus.com/feature/5661524146257920.

Blink-dev intent to prototype:
https://groups.google.com/a/chromium.org/d/msg/blink-dev/kTLpgFJz6Ck/IQeiGDtOAwAJ

Bug: 1005076
Change-Id: Id3d472a07992007e17c7dec4f4d826eaa84c309b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2071108Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744725}
parent dd8d5985
......@@ -400,6 +400,7 @@ static_idl_files_in_modules = get_path_info(
"//third_party/blink/renderer/modules/payments/basic_card_request.idl",
"//third_party/blink/renderer/modules/payments/can_make_payment_event.idl",
"//third_party/blink/renderer/modules/payments/can_make_payment_event_init.idl",
"//third_party/blink/renderer/modules/payments/can_make_payment_response.idl",
"//third_party/blink/renderer/modules/payments/html_iframe_element_payments.idl",
"//third_party/blink/renderer/modules/payments/image_object.idl",
"//third_party/blink/renderer/modules/payments/merchant_validation_event.idl",
......
......@@ -70,6 +70,17 @@ void CanMakePaymentEvent::respondWith(ScriptState* script_state,
}
}
const String& CanMakePaymentEvent::currency() const {
return currency_;
}
void CanMakePaymentEvent::respondWithMinimalUI(
ScriptState* script_state,
ScriptPromise script_promise,
ExceptionState& exception_state) {
respondWith(script_state, script_promise, exception_state);
}
void CanMakePaymentEvent::Trace(Visitor* visitor) {
visitor->Trace(method_data_);
visitor->Trace(modifiers_);
......@@ -91,6 +102,7 @@ CanMakePaymentEvent::CanMakePaymentEvent(
modifiers_(initializer->hasModifiers()
? initializer->modifiers()
: HeapVector<Member<PaymentDetailsModifier>>()),
currency_(initializer->currency()),
observer_(respond_with_observer) {}
} // namespace blink
......@@ -49,6 +49,9 @@ class MODULES_EXPORT CanMakePaymentEvent final : public ExtendableEvent {
void respondWith(ScriptState*, ScriptPromise, ExceptionState&);
const String& currency() const;
void respondWithMinimalUI(ScriptState*, ScriptPromise, ExceptionState&);
void Trace(Visitor*) override;
private:
......@@ -56,6 +59,7 @@ class MODULES_EXPORT CanMakePaymentEvent final : public ExtendableEvent {
String payment_request_origin_;
HeapVector<Member<PaymentMethodData>> method_data_;
HeapVector<Member<PaymentDetailsModifier>> modifiers_;
String currency_;
Member<RespondWithObserver> observer_;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://github.com/w3c/payment-handler/pull/170
// https://w3c.github.io/payment-handler/#the-canmakepaymentevent
[
RuntimeEnabled=PaymentApp,
......@@ -15,4 +15,8 @@
readonly attribute FrozenArray<PaymentDetailsModifier> modifiers;
[CallWith=ScriptState, RaisesException] void respondWith(Promise<boolean> canMakePaymentResponse);
// https://gist.github.com/rsolomakhin/eba91c185028899883d2c7f37f357d7c
[RuntimeEnabled=PaymentHandlerMinimalUI] readonly attribute DOMString currency;
[RuntimeEnabled=PaymentHandlerMinimalUI, CallWith=ScriptState, RaisesException] void respondWithMinimalUI(Promise<CanMakePaymentResponse> response);
};
......@@ -9,4 +9,7 @@ dictionary CanMakePaymentEventInit : ExtendableEventInit {
USVString paymentRequestOrigin;
sequence<PaymentMethodData> methodData;
sequence<PaymentDetailsModifier> modifiers;
// https://gist.github.com/rsolomakhin/eba91c185028899883d2c7f37f357d7c
DOMString currency;
};
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://gist.github.com/rsolomakhin/eba91c185028899883d2c7f37f357d7c
dictionary CanMakePaymentResponse {
boolean canMakePayment;
boolean readyForMinimalUI;
DOMString accountBalance;
};
......@@ -21,6 +21,7 @@ modules_dictionary_idl_files = [
"android_pay_method_data.idl",
"basic_card_request.idl",
"can_make_payment_event_init.idl",
"can_make_payment_response.idl",
"image_object.idl",
"merchant_validation_event_init.idl",
"payer_errors.idl",
......
......@@ -1283,6 +1283,10 @@
name: "PaymentHandlerHandlesShippingAndContact",
status: "stable",
},
{
name: "PaymentHandlerMinimalUI",
status: "experimental",
},
{
name: "PaymentMethodChangeEvent",
status: "stable",
......
......@@ -108,12 +108,14 @@ interface CacheStorage
method open
interface CanMakePaymentEvent : ExtendableEvent
attribute @@toStringTag
getter currency
getter methodData
getter modifiers
getter paymentRequestOrigin
getter topOrigin
method constructor
method respondWith
method respondWithMinimalUI
interface CanvasGradient
attribute @@toStringTag
method addColorStop
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment