1 <!DOCTYPE html
> <meta charset=
"utf-8" />
2 <title>Test for requesting billing address
</title>
5 href=
"https://github.com/w3c/payment-method-basic-card/pull/65"
7 <script src=
"/resources/testharness.js"></script>
8 <script src=
"/resources/testharnessreport.js"></script>
12 explicit_timeout
: true,
14 const basicCard
= { supportedMethods
: "basic-card" };
18 amount
: { currency
: "USD", value
: "5.00" },
25 "onpaymentmethodchange" in PaymentRequest
.prototype,
26 "The paymentmethodchange event handler is not supported on PaymentRequest"
29 "PaymentMethodChangeEvent" in window
,
30 "The PaymentMethodChangeEvent is not supported"
32 }, "PaymentMethodChangeEvent support");
34 function dontRequestBillingAddress(options
) {
35 promise_test(async t
=> {
36 const request
= new PaymentRequest([basicCard
], details
, {
37 requestBillingAddress
: false,
39 const showPromise
= request
.show();
41 // Let's check the method data from PaymentMethodChangeEvent.
42 const event
= await
new Promise(resolve
=>
43 request
.addEventListener("paymentmethodchange", resolve
)
46 event
instanceof PaymentMethodChangeEvent
,
47 "Expected instance of PaymentMethodChangeEvent"
50 event
.methodDetails
.billingAddress
,
52 "Expected methodDetails.billingAddress to be null"
55 // Let's check the billingAddress in the response
56 const response
= await showPromise
;
58 details
: { billingAddress
: responseBillingAddress
},
62 responseBillingAddress
,
64 "Expected PaymentResponse.data.billingAddress to be null"
68 await response
.complete("success");
72 function requestBillingAddress() {
73 promise_test(async t
=> {
74 const request
= new PaymentRequest([basicCard
], details
, {
75 requestBillingAddress
: true,
77 const showPromise
= request
.show();
79 // Let's check the methodDetails from event.
80 const event
= await
new Promise(resolve
=>
81 request
.addEventListener("paymentmethodchange", resolve
)
84 event
instanceof PaymentMethodChangeEvent
,
85 "Expected instance of PaymentMethodChangeEvent"
87 const { billingAddress
: eventBillingAddress
} = event
.methodDetails
;
88 checkRedactList(eventBillingAddress
);
90 // Let's check the billingAddress in the response.
91 const response
= await showPromise
;
93 details
: { billingAddress
: responseBillingAddress
},
94 } = await showPromise
;
95 checkRedactList(responseBillingAddress
);
98 await response
.complete("success");
102 function checkRedaction(billingAddress
) {
104 billingAddress
instanceof PaymentAddress
,
105 "Expected instance of PaymentAddress"
107 for (const item
of ["organization", "phone", "recipient"]) {
109 billingAddress
[item
],
111 `Expected billingAddress's "${item}" attribute to equal null (redacted).`
117 <h2>Request billing address
</h2>
119 Click on each button in sequence from top to bottom without refreshing the
120 page. Each button will bring up the Payment Request UI window.
123 When the payment sheet is presented, select a payment method (e.g., a credit
124 card), and press
"Pay".
128 <button onclick=
"dontRequestBillingAddress()">
129 When no billing address is requested,
130 `PaymentMethodChangeEvent.methodData.billingAddress` is null.
134 <button onclick=
"requestBillingAddress()">
135 When billing address is
136 requested,`PaymentMethodChangeEvent.methodData.billingAddress` is a
140 <li><button onclick=
"done()">Done!
</button></li>
143 If you find a buggy test, please
144 <a href=
"https://github.com/web-platform-tests/wpt/issues">file a bug
</a> and
147 href=
"https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml"
148 >suggested reviewers
</a