www.lightcourse.com/app/home/view/default/mall/payment/pay.html

47 lines
1.5 KiB
HTML

<html>
<head>
<title>Buy test</title>
<script src="https://js.stripe.com/v3/"></script>
</head>
<body>
<button id="checkout-button">Checkout</button>
<script type="text/javascript">
var stripe = Stripe('pk_live_51KGYh8LqMBqucQSD2C0rnD6vL6D6fejrkPn7mPEMCGKx9apA4KnugesCAgav5nvlJsoh6Q1ERYoNZ5gcRotv2rWF00wrzRwWxc');
var checkoutButton = document.getElementById('checkout-button');
checkoutButton.addEventListener('click', function() {
fetch('/Ready/pay', {
method: 'POST',
})
.then(function(response) {
return response.json();
})
.then(function(session) {
console.log(session)
return stripe.redirectToCheckout({ sessionId: session.id });
})
.then(function(result) {
// If `redirectToCheckout` fails due to a browser or network
// error, you should display the localized error message to your
// customer using `error.message`.
if (result.error) {
alert(result.error.message);
}
})
.catch(function(error) {
console.error('Error:', error);
});
});
</script>
<form action="/Ready/pay" method="POST" id="buy_form">
<input type="hidden" name="stripe" value="pk_live_51KGYh8LqMBqucQSD2C0rnD6vL6D6fejrkPn7mPEMCGKx9apA4KnugesCAgav5nvlJsoh6Q1ERYoNZ5gcRotv2rWF00wrzRwWxc">
<input type="submit">
</form>
</body>
</html>