listojs
Version:
a package for restaurant management
60 lines (54 loc) • 2.57 kB
JavaScript
const stripe = Stripe('pk_test_WWbnKC93qOMARiC4lbirfDrg00CuCspHmW');
const elements = stripe.elements();
const callingPage = sessionStorage.getItem("payment_callingPage");
const backlink = document.getElementById("backlinkid");
backlink.setAttribute("href", callingPage);
backlink.innerText = getTextById(734);
function checkout(CHECKOUT_SESSION_ID) {
stripe.redirectToCheckout({
// Make the id field from the Checkout Session creation API response
// available to this file, so you can provide it as parameter here
// instead of the {{CHECKOUT_SESSION_ID}} placeholder.
sessionId: CHECKOUT_SESSION_ID
}).then(function (result) {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `result.error.message`.
console.log(JSON.stringify(result));
});
}
$(document).on('click', '.checkoutLink', function () {
//const id = document.getElementById("sessionID").value;
//console.log("Checkout clicked: " + id);
//checkout(id);
/*
* "productID": productID,
"price": price,
"product": productName,
"productDescription": productDescription,
"currency": currency,
"quantity": quantity
*
* */
const productID = $(this).data("productid");
const productName = $(this).data("productname");
const productDescription = $(this).data("productdescription");
const currency = $(this).data("currency");
const qty = Number(document.getElementById("creditqty").innerText).toFixed(0);
const price = Number(document.getElementById("selectedprice").innerText).toFixed(0);
const newDesc = productDescription + " (" + Number(qty * 1000) + " total clicks)";
console.log("Checkout clicked:\n productID:" + productID + ",\n price:" + price + ",\n product: " + productName + ",\nDescription: " +
newDesc + ",\n" + currency + ",\nqty: " + qty);
stripePayment(1, productID, price, productName, newDesc, currency, qty, function (data) {
const stripe_session_id = data.id;
console.log("Returned session id:" + stripe_session_id);
checkout("" + stripe_session_id);
if (!stripe_session_id) {
console.log(JSON.stringify(data));
showHttpErrorMessage("main-content", data);
}
}, function (err) {
console.log("ERROR: " + JSON.stringify(err));
showHttpErrorMessage("main-content", err);
});
});