添加badssl.com目录
This commit is contained in:
21
badssl.com/common/input/web-payment/index.html
Normal file
21
badssl.com/common/input/web-payment/index.html
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
title: web-payment
|
||||
layout: page
|
||||
favicon: gray
|
||||
background: gray
|
||||
---
|
||||
|
||||
<div id="content">
|
||||
<h1>web-payment</h1>
|
||||
<p>
|
||||
<button onclick="handleClick();">Initiate payment</button>
|
||||
<button id="log-toggle" onclick="toggleLogVisibility();">Show log</button>
|
||||
<ul id="log" hidden></ul>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div id="footer">
|
||||
<p>This page requires web payment API.</p>
|
||||
</div>
|
||||
|
||||
<script src="index.js"></script>
|
||||
75
badssl.com/common/input/web-payment/index.js
Normal file
75
badssl.com/common/input/web-payment/index.js
Normal file
@@ -0,0 +1,75 @@
|
||||
function appendLog(msg) {
|
||||
console.log(msg);
|
||||
let logList = document.getElementById('log');
|
||||
let logEntry = document.createElement('li');
|
||||
let logText = document.createTextNode(msg);
|
||||
logEntry.appendChild(logText);
|
||||
logList.appendChild(logEntry);
|
||||
}
|
||||
|
||||
function clearLog() {
|
||||
let logList = document.getElementById('log');
|
||||
while (logList.firstChild) {
|
||||
logList.removeChild(logList.firstChild);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleLogVisibility() {
|
||||
let logList = document.getElementById('log');
|
||||
let logToggle = document.getElementById('log-toggle');
|
||||
if (logList.hidden) {
|
||||
logToggle.innerHTML = 'Hide log';
|
||||
logList.hidden = false;
|
||||
} else {
|
||||
logToggle.innerHTML = 'Show log';
|
||||
logList.hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds PaymentRequest for credit cards, but does not show any UI yet.
|
||||
* @return {PaymentRequest} The PaymentRequest object.
|
||||
*/
|
||||
function initPaymentRequest() {
|
||||
const request = new PaymentRequest(
|
||||
[{
|
||||
supportedMethods: ['basic-card'],
|
||||
}],
|
||||
{
|
||||
total: {
|
||||
label: 'Total',
|
||||
amount: {
|
||||
currency: 'USD',
|
||||
value: '1.00',
|
||||
},
|
||||
},
|
||||
});
|
||||
request.canMakePayment().then(function(result) {
|
||||
appendLog('canMakePayment returned: ' + result);
|
||||
}).catch(function(err) {
|
||||
appendLog('canMakePayment rejected: ' + err.name + ': ' + err.message);
|
||||
});
|
||||
request.hasEnrolledInstrument().then(function(result) {
|
||||
appendLog('hasEnrolledInstrument returned: ' + result);
|
||||
}).catch(function(err) {
|
||||
appendLog('hasEnrolledInstrument rejected: ' + err.name + ': ' + err.message);
|
||||
});
|
||||
return request;
|
||||
}
|
||||
|
||||
let request = initPaymentRequest();
|
||||
|
||||
/** Invokes PaymentRequest for credit cards. */
|
||||
function handleClick() {
|
||||
clearLog();
|
||||
request.show().then(function(instrumentResponse) {
|
||||
appendLog('show returned: ' + JSON.stringify(instrumentResponse));
|
||||
request = initPaymentRequest();
|
||||
return instrumentResponse.complete('success');
|
||||
})
|
||||
.catch(function(err) {
|
||||
appendLog('show rejected: ' + err.name + ': ' + err.message);
|
||||
request = initPaymentRequest();
|
||||
});
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user