Server IP : 162.240.98.243 / Your IP : 3.144.38.92 Web Server : Apache System : Linux server.bti.yaw.mybluehostin.me 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : btiyawmy ( 1003) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/btiyawmy/public_html/login.easenup.in/ |
Upload File : |
<!DOCTYPE html> <html> <head> <link href="/app.css" rel="stylesheet" /> <script type="text/javascript" src="https://sandbox.web.squarecdn.com/v1/square.js" ></script> <script> const appId = '{APPLICATION_ID}'; const locationId = '{LOCATION_ID}'; async function initializeCard(payments) { const card = await payments.card(); await card.attach('#card-container'); return card; } function buildPaymentRequest(payments) { return payments.paymentRequest({ countryCode: 'US', currencyCode: 'USD', total: { amount: '34.00', label: 'Total', }, }); } async function initializeGooglePay(payments) { const paymentRequest = buildPaymentRequest(payments); const googlePay = await payments.googlePay(paymentRequest); await googlePay.attach('#google-pay-button'); return googlePay; } async function createPayment(token) { const body = JSON.stringify({ locationId, sourceId: token, }); const paymentResponse = await fetch('/payment', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body, }); if (paymentResponse.ok) { return paymentResponse.json(); } const errorBody = await paymentResponse.text(); throw new Error(errorBody); } async function tokenize(paymentMethod) { const tokenResult = await paymentMethod.tokenize(); if (tokenResult.status === 'OK') { return tokenResult.token; } else { let errorMessage = `Tokenization failed with status: ${tokenResult.status}`; if (tokenResult.errors) { errorMessage += ` and errors: ${JSON.stringify( tokenResult.errors )}`; } throw new Error(errorMessage); } } // status is either SUCCESS or FAILURE; function displayPaymentResults(status) { const statusContainer = document.getElementById( 'payment-status-container' ); if (status === 'SUCCESS') { statusContainer.classList.remove('is-failure'); statusContainer.classList.add('is-success'); } else { statusContainer.classList.remove('is-success'); statusContainer.classList.add('is-failure'); } statusContainer.style.visibility = 'visible'; } document.addEventListener('DOMContentLoaded', async function () { if (!window.Square) { throw new Error('Square.js failed to load properly'); } let payments; try { payments = window.Square.payments(appId, locationId); } catch { const statusContainer = document.getElementById( 'payment-status-container' ); statusContainer.className = 'missing-credentials'; statusContainer.style.visibility = 'visible'; return; } let card; try { card = await initializeCard(payments); } catch (e) { console.error('Initializing Card failed', e); return; } let googlePay; try { googlePay = await initializeGooglePay(payments); } catch (e) { console.error('Initializing Google Pay failed', e); // There are a number of reason why Google Pay may not be supported // (e.g. Browser Support, Device Support, Account). Therefore you should handle // initialization failures, while still loading other applicable payment methods. } async function handlePaymentMethodSubmission(event, paymentMethod) { event.preventDefault(); try { // disable the submit button as we await tokenization and make a payment request. cardButton.disabled = true; const token = await tokenize(paymentMethod); const paymentResults = await createPayment(token); displayPaymentResults('SUCCESS'); console.debug('Payment Success', paymentResults); } catch (e) { cardButton.disabled = false; displayPaymentResults('FAILURE'); console.error(e.message); } } const cardButton = document.getElementById('card-button'); cardButton.addEventListener('click', async function (event) { await handlePaymentMethodSubmission(event, card); }); // Checkpoint 2. if (googlePay) { const googlePayButton = document.getElementById('google-pay-button'); googlePayButton.addEventListener('click', async function (event) { await handlePaymentMethodSubmission(event, googlePay); }); } }); </script> </head> <body> <form id="payment-form"> <div id="google-pay-button"></div> <div id="card-container"></div> <button id="card-button" type="button">Pay $1.00</button> </form> <div id="payment-status-container"></div> </body> </html>