top of page
bottom of page
$w.onReady(function () {
document.querySelectorAll("[data-hook='CheckoutButtonDataHook.button']")[0].onclick = (e) => {
e.preventDefault();
let sum = document.querySelectorAll("[data-hook='Total.formattedValue']")[0].innerText;
let numb = sum.match(/\d/g);
numb = numb.join("").slice(0, -2);
let date = new Date(Date.now());
let numMonth = date.getMonth() + 1;
let month = numMonth >= 10 ? numMonth : '0' + numMonth;
let day = date.getDate() >= 10 ? date.getDate() : '0' + date.getDate();
let hours = date.getHours() >= 10 ? date.getHours() : '0' + date.getHours();
let minutes = date.getMinutes() >= 10 ? date.getMinutes() : '0' + date.getMinutes();
let seconds = date.getSeconds() >= 10 ? date.getSeconds() : '0' + date.getSeconds();
let postObj = {
"octo_shop_id": 4687,
"octo_secret": "adbd0c56-e741-439f-9911-2c3f291c8cfb",
"shop_transaction_id": (Date.now() + Math.random()).toFixed(),
"auto_capture": true,
"test": true,
"init_time": date.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds,
"total_sum": parseInt(numb),
"payment_methods": [
{
"method": "bank_card"
},
{
"method": "uzcard"
},
{
"method": "humo"
},
],
"currency": "UZS",
"description": "Оплата заказа",
"return_url": "https://www.bagazhnik.uz/",
"notify_url": "https://www.bagazhnik.uz/",
}
let post = JSON.stringify(postObj)
const url = "https://secure.octo.uz/prepare_payment"
let xhr = new XMLHttpRequest()
xhr.open('POST', url, true)
xhr.setRequestHeader('Content-type', 'application/json;')
xhr.send(post);
xhr.onload = function (res) {
if(xhr.status === 200) {
let response = JSON.parse(xhr.response);
window.location.href = response.octo_pay_url;
}else{
alert('Connection error')
}
}
}
});