⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
public_html
/
public
/
assets
/
front
/
js
/
View File Name :
stripe.js
"use strict"; $(document).ready(function () { $('#stripe-element').addClass('d-none'); }) /** * show or hide stripe gateway input fields, * also show or hide offline gateway informations according to checked payment gateway */ $('#payment-gateway').on('change', function () { let value = $(this).val(); let dataType = parseInt(value); if (isNaN(dataType)) { // show or hide stripe card inputs if (value == 'stripe' || value == 'Stripe') { $('#stripe-element').removeClass('d-none'); } else { $('#stripe-element').addClass('d-none'); } } else { // hide stripe gateway card inputs if (!$('#stripe-element').hasClass('d-none')) { $('#stripe-element').addClass('d-none'); $('#stripe-element').removeClass('d-block'); } } }); // Set your Stripe public key var stripe = Stripe(stripe_key); // Create a Stripe Element for the card field var elements = stripe.elements(); var cardElement = elements.create('card', { style: { base: { iconColor: '#454545', color: '#454545', fontWeight: '500', lineHeight: '50px', fontSmoothing: 'antialiased', backgroundColor: '#f2f2f2', ':-webkit-autofill': { color: '#454545', }, '::placeholder': { color: '#454545', }, } }, }); // Add an instance of the card Element into the `card-element` div cardElement.mount('#stripe-element'); // Handle form submission var form = document.getElementById('my-checkout-form'); form.addEventListener('submit', function (event) { var payment_gateway = $('.selected-payment-gateway').val(); console.log(payment_gateway); event.preventDefault(); if (payment_gateway == 'Stripe') { stripe.createToken(cardElement).then(function (result) { if (result.error) { // Display errors to the customer var errorElement = document.getElementById('stripe-errors'); errorElement.textContent = result.error.message; } else { // Send the token to your server stripeTokenHandler(result.token); } }); } else if (payment_gateway == 'Authorize.net') { sendPaymentDataToAnet(); } else { $('#my-checkout-form').submit(); } }); // Send the token to your server function stripeTokenHandler(token) { // Add the token to the form data before submitting to the server var form = document.getElementById('my-checkout-form'); var hiddenInput = document.createElement('input'); hiddenInput.setAttribute('type', 'hidden'); hiddenInput.setAttribute('name', 'stripeToken'); hiddenInput.setAttribute('value', token.id); form.appendChild(hiddenInput); // Submit the form to your server form.submit(); } //authorize.net start function sendPaymentDataToAnet() { // Set up authorisation to access the gateway. var authData = {}; authData.clientKey = anit_public_key; authData.apiLoginID = login_id; var cardData = {}; cardData.cardNumber = document.getElementById("anetCardNumber").value; cardData.month = document.getElementById("anetExpMonth").value; cardData.year = document.getElementById("anetExpYear").value; cardData.cardCode = document.getElementById("anetCardCode").value; // Now send the card data to the gateway for tokenisation. // The responseHandler function will handle the response. var secureData = {}; secureData.authData = authData; secureData.cardData = cardData; Accept.dispatchData(secureData, responseHandler); } function responseHandler(response) { if (response.messages.resultCode === "Error") { var i = 0; let errorLists = ``; while (i < response.messages.message.length) { console.log( response.messages.message[i].code + ": " + response.messages.message[i].text ); errorLists += `<li class="text-danger">${response.messages.message[i].text}</li>`; i = i + 1; } $("#anetErrors").show(); $("#anetErrors").html(errorLists); } else { paymentFormUpdate(response.opaqueData); } } function paymentFormUpdate(opaqueData) { document.getElementById("opaqueDataDescriptor").value = opaqueData.dataDescriptor; document.getElementById("opaqueDataValue").value = opaqueData.dataValue; document.getElementById("my-checkout-form").submit(); } //authorize.net start end