MVCPostall/VCart/Views/Pay/Index.cshtml
2025-01-26 22:44:31 +00:00

46 lines
1.3 KiB
Plaintext

@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}
@section Scripts {
<script src="https://js.stripe.com/v3/"></script>
<script>
// This is your test secret API key.
const stripe = Stripe("pk_test_51PvIzkBk8jHwC3c0efDBJMY9dBwNqs0SDAHP0vIQr17G9iYg4GQtIrCOh2N9teJoYDXUHTWe6iEHnUylMntwhbin00R7y6lQOV");
initialize();
// Create a Checkout Session
async function initialize() {
const payPlan = get('plan');
const fetchClientSecret = async () => {
const response = await fetch("/Pay/create" + payPlan, {
method: "POST",
});
const { clientSecret } = await response.json();
return clientSecret;
};
const checkout = await stripe.initEmbeddedCheckout({
fetchClientSecret,
});
// Mount Checkout
checkout.mount('#checkout');
}
function get(name) {
if (name = (new RegExp('[?&]' + encodeURIComponent(name) + '=([^&]*)')).exec(location.search))
return decodeURIComponent(name[1]);
}
</script>
}
<br />
<br />
<div id="checkout">
<!-- Checkout will insert the payment form here -->
</div>