Files
firefox/testing/web-platform/tests/payment-request/show-method-postmessage-iframe.html
T
Marcos Cáceres 24e649fd03 Bug 1454335 [wpt PR 10485] - fix: ApplePay PMI is wrong, a=testonly
Automatic update from web-platform-testsfix: ApplePay PMI is wrong (#10485)

--

wpt-commits: b4cdc8ff4bda43c826fe7911e6d8e035390b90fd
wpt-pr: 10485
2018-04-24 12:22:53 +00:00

41 lines
1.0 KiB
HTML

<h1>This iframe calls shows() via postMessage()</h1>
<script>
"use strict";
const defaultMethods = Object.freeze([
{ supportedMethods: "basic-card" },
{ supportedMethods: "https://apple.com/apple-pay" },
]);
const defaultDetails = Object.freeze({
id: "fail",
total: {
label: "Total",
amount: {
currency: "USD",
value: "1.00",
},
},
});
// We are going to use the id to prove that this works
// which we will pass back to the caller
window.onmessage = async event => {
const { source, data: { id, request } } = event;
switch (request) {
case "show-payment-request": {
const details = Object.assign({}, defaultDetails, { id });
const request = new PaymentRequest(defaultMethods, details);
try {
const response = await request.show();
source.postMessage(response.toJSON(), window.location.origin);
await response.complete();
} catch (err) {
source.postMessage({ requestId: "fail" }, window.location.origin);
await request.abort();
}
}
}
};
</script>