Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (72 sloc) 2.68 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#db5945">
<title>You are paying with AliPay</title>
<!-- Bootstrap Core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://js.stripe.com/v3/"></script>
<!-- Custom Fonts -->
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Catamaran:100,200,300,400,500,600,700,800,900" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Muli" rel="stylesheet">
<!-- Theme CSS -->
<link href="/css/new-age.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1 id="heading"></h1>
</div>
<script>
let paymentRequestClient;
function redirectToAlipay(amount, currency) {
stripe.createSource({
type: 'alipay',
amount: amount,
currency: 'usd',
redirect: {
return_url: 'https://bobpay.xyz/pay/alipay.html',
},
}).then(function(result) {
if (result.error) {
console.log(result.error);
} else {
window.location.href = result.source['redirect']['url'];
}
});
}
navigator.serviceWorker.addEventListener('message', e => {
paymentRequestClient = e.source;
// TODO(mathp): amounts are hard!
redirectToAlipay(parseFloat(e.data.value) * 100, e.data.currency.toLowerCase());
});
var stripe = Stripe('pk_test_voMKxf6PQoS8JkqRZN69bgyB');
var urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('source')) {
// We are returning from AliPay. Get the source and validate that it's
// chargeable.
stripe.retrieveSource({
id: urlParams.get("source"),
client_secret: urlParams.get("client_secret")
}).then(function(result) {
var paymentAppResponse = {
methodName: "https://www.alipay.com/webpay",
details: result.source
};
navigator.serviceWorker.controller.postMessage(paymentAppResponse);
document.getElementById("heading").innerHTML = "You may now close the window!"
// TODO(mathp): currently impossible to close the window!
//window.close();
});
} else {
navigator.serviceWorker.controller.postMessage('payment_app_window_ready');
}
function cancel() {
if(!paymentRequestClient) return;
paymentRequestClient.postMessage("The payment request is cancelled by user");
window.close();
}
</script>
</body>
</html>