Viewing File: /home/webrbaew/candycleansestore.co/checkout/public/test.html
<!-- Include Stripe.js -->
<script src="https://js.stripe.com/v3/"></script>
<!-- Express Checkout Element Container -->
<div id="express-checkout-element"></div>
<script>
// Initialize Stripe
const stripe = Stripe('pk_test_51JK74sEVex5ZGUHnGiwAr8AjWuIauxYnBau86ifwLJtjGFBMhTjZTwtSH674KKC6JnppRilEthk08Al1VfPvmgm600V3V71pxP');
// Create an instance of Elements
const elements = stripe.elements({
mode: 'payment',
amount: 2000, // Amount in cents ($20.00)
currency: 'usd',
});
// Create the Express Checkout Element
const expressCheckoutElement = elements.create('expressCheckout', {
layout: {
type: 'tabs',
defaultCollapsed: false,
},
paymentMethodOrder: ['apple_pay', 'google_pay'],
});
// Mount the Element
expressCheckoutElement.mount('#express-checkout-element');
// Handle the confirm event
expressCheckoutElement.on('confirm', async (event) => {
// Send the payment method to your server to create a PaymentIntent
const response = await fetch('/create-payment-intent.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ payment_method: event.paymentMethod.id }),
});
const paymentIntentResponse = await response.json();
// Confirm the PaymentIntent
const {error} = await stripe.confirmCardPayment(
paymentIntentResponse.client_secret,
{payment_method: event.paymentMethod.id},
{handleActions: false}
);
if (error) {
// Handle error
} else {
// Payment succeeded
}
});
</script>
Back to Directory
File Manager