From 2281c127f7dcde1804174bfa20f5329216882eff Mon Sep 17 00:00:00 2001 From: Leonid Kaganov Date: Thu, 7 Mar 2024 02:06:26 +0200 Subject: [PATCH] DOT.js fix ajaxm --- common/DOT.js | 99 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 76 insertions(+), 23 deletions(-) diff --git a/common/DOT.js b/common/DOT.js index 38158d4..bc9b5c5 100644 --- a/common/DOT.js +++ b/common/DOT.js @@ -20,13 +20,48 @@ chain: { // тут будет инфо, запрошенное от блокче cx: {}, // а тут инфо от магазина +magento_init: function(cx) { + if(cx) DOT.cx = cx; + + DOT.store = 'magento'; + + DOT.button_on=function(){ + jQuery('body').trigger('processStop'); + DOT.cx.magento_this.isPlaceOrderActionAllowed(true); + }; + DOT.button_off=function(){ + jQuery('body').trigger('processStart'); + DOT.cx.magento_this.isPlaceOrderActionAllowed(false); + }; + + var p = window.checkoutConfig.payment.kalatorimax; + if(!p) DOT.error('magento system error #0104'); + DOT.mainjs = p.assets_base_url+"/"; // "https://magento.zymologia.fi/static/version1709653373/frontend/Magento/luma/en_US/Alzymologist_KalatoriMax/js" + DOT.cx.ajax_url = p.store_base_url+"alzymologist/payment/index"; // 'https://magento.zymologia.fi/alzymologist/payment/index'; // window.checkoutConfig.staticBaseUrl + DOT.health_url = DOT.cx.ajax_url+"?health=1"; + + DOT.onpaid=function() { + DOT.button_on(); + DOT.cx.magento_this.getPlaceOrderDeferredObject().done( + function () { + DOT.cx.magento_this.afterPlaceOrder(); + if(DOT.cx.magento_this.redirectAfterPlaceOrder) { + DOT.cx.redirectOnSuccessAction.execute(); + } + } + ); + }; + + DOT.init(); +}, + opencart3_run: function(path) { DOT.store = 'opencart3'; DOT.button_on=function(){ $('#button-confirm').button('reset'); }; DOT.button_off=function(){ $('#button-confirm').button('loading'); }; - DOT.path=DOT.mainjs=path; + DOT.mainjs=path; DOT.ajaxm = DOT.mainjs+'../../theme/default/image/polkadot/ajaxm.gif'; DOT.init(); @@ -57,7 +92,7 @@ presta_init: function(cx) { // cx.ajax_url=cx.wpath.replace(/\/views$/g,'/')+'ajax.php'; } DOT.cx=cx; - DOT.path = cx.wpath; + // DOT.path = cx.wpath; DOT.mainjs = cx.wpath+'/js/'; DOT.ajaxm = cx.wpath+'/img/ajaxm.gif'; @@ -125,6 +160,9 @@ presta_init: function(cx) { button_on: function(){}, button_off: function(){}, +// ajax_headers: false, // хедеры, подставляемые в платежный запрос аякса +// ajax_headers_info: false, // хедеры, подставляемые в информационный запрос аякса + class_warning: 'alert alert-danger', h: function(s){ @@ -188,12 +226,17 @@ daemon_get_info: async function() { if(!DOT.health_url && !DOT.cx.ajax_url) return DOT.error('DOT plugin error 10802: empty cx.ajax_url'); const data = JSON.stringify({ order_id: 0, price: 0 }); - var s = await DOT.AJAX( (DOT.health_url?DOT.health_url:DOT.cx.ajax_url), data ); + var s = await DOT.AJAX( (DOT.health_url?DOT.health_url:DOT.cx.ajax_url), data, DOT.ajax_headers_info ); try { var json=JSON.parse(s); } catch(e) { return DOT.error("Json error: ["+DOT.h(s)+"]"); } // патчим старый формат for(var n in json) { if(n.substring(0,7)=='daemon_') { json[n.substring(7)]=json[n]; } } + // Если данные заказа есть только на бэкэнде, самое время их от него получить и запомнить + if(json.store_total) DOT.cx.total = json.store_total; + if(json.store_order_id) DOT.cx.order_id = json.store_order_id; + if(json.store_currency) DOT.cx.currency = json.store_currency; + if(json.wss) DOT.daemon.wss=json.wss; else { if(json.error) return DOT.error("Error "+json.error+(json.error_message?" ("+json.error_message+")":'')); @@ -318,7 +361,7 @@ all_submit: async function(y) { var data = JSON.stringify({ order_id: cx.id, price: DOT.total() }); // можно указать свой альтернативный AJAX для особых уродцев типа WooCommerce - var s = await DOT[( DOT.AJAX_ALTERNATIVE ? 'AJAX_ALTERNATIVE' : 'AJAX' )]( cx.ajax_url, data ); + var s = await DOT[( DOT.AJAX_ALTERNATIVE ? 'AJAX_ALTERNATIVE' : 'AJAX' )]( cx.ajax_url, data, DOT.ajax_headers ); var json=DOT.ajax_process_errors(s); if(!json) return false; var ans = (''+json.result).toLowerCase(); // (waiting, paid) @@ -382,6 +425,7 @@ progress: { d.style.padding = '0px 2px 1px 2px'; d.style.width = '100%'; d.style.height = '20px'; + d.style.zIndex = '99999'; document.body.appendChild(d); } @@ -398,12 +442,11 @@ progress: { }, }, -AJAX: async function(url,data) { - const r = await fetch( - url, { method:'POST', mode:'cors', credentials:'include', headers: [ - ["Content-Type", "application/json"], - ], body: data - }); +AJAX: async function(url,data,headers) { + if(!headers) headers=[]; + headers.push(["Content-Type", "application/json"]); + headers.push(["X-Requested-With", "XMLHttpRequest"]); + const r = await fetch(url,{ method:'POST',mode:'cors',credentials:'include',headers:headers,body: data}); if(!r.ok) return DOT.error("Error: " + r.status); return await r.text(); }, @@ -561,24 +604,28 @@ AJAX: async function(url,data) { DOT.Talert('clear'); DOT.button_on(); - // load JS - первая необходимая часть для кошельков, остальное загрузим позже для ускорения - if(DOT.mainjs) await DOT.LOADS_promice([ - DOT.mainjs+'bundle-polkadot-util.js', - DOT.mainjs+'bundle-polkadot-util-crypto.js', - DOT.mainjs+'bundle-polkadot-extension-dapp.js', - - DOT.mainjs+'bundle-polkadot-types.js', - DOT.mainjs+'bundle-polkadot-api.js', - DOT.mainjs+'bundle-polkadot-keyring.js', // west - DOT.mainjs+'identicon.js' - ],1); - + var originalDefine = window.define; + // delete window.define; // йобаные патчи для Magento + window.define=undefined; + if(DOT.mainjs) await DOT.LOADS_promice([ + DOT.mainjs+'bundle-polkadot-util.js', + DOT.mainjs+'bundle-polkadot-util-crypto.js', + DOT.mainjs+'bundle-polkadot-extension-dapp.js', + + DOT.mainjs+'bundle-polkadot-types.js', + DOT.mainjs+'bundle-polkadot-api.js', + DOT.mainjs+'bundle-polkadot-keyring.js', // west + DOT.mainjs+'identicon.js' + ],1); + window.define = originalDefine; // йобаные патчи для Magento try { // connect Wallets var wallets=await polkadotExtensionDapp.web3Enable('dotpay'); DOT.wallets=wallets; +// console.log('wallets='+typeof(wallets)); + var r={'':[ "", ]}; @@ -624,7 +671,7 @@ AJAX: async function(url,data) { } // if(wal_length != DOT.wal_length) { // менять страницу только если что-то изменилось - console.log('wallet list'); + // console.debug('wallet list'); DOT.wal_length = wal_length; var op=''; for(var wal in r) { @@ -646,6 +693,9 @@ AJAX: async function(url,data) { else DOT.identicon_init(); } catch(ee) { + + console.log('init error: '+ee); + if(!DOT.et) { DOT.et=0; } if(++DOT.et < 60) setTimeout(DOT.init,1000); // setTimeout(wallet_start,1000); } @@ -767,6 +817,7 @@ AJAX: async function(url,data) { if(sync) s.async=false; s.onerror=( typeof(err)=='function' ? err : function(e){ DOT.error('File not found: '+e.src); } ); s.onload=function(e){ e=e.target; + DOT.LOADES[e.getAttribute('orign')]=1; var k=1; for(var i of u) { if(!DOT.LOADES[i]){ k=0; break; } @@ -794,4 +845,6 @@ AJAX: async function(url,data) { // alert('Copy: '+(DOT.h(e).replace(/\n/g,'
')) ); }, +ajaxm: "data:image/gif;base64,R0lGODlhEAAQAPcAAAAAAIAAAACAAICAAAAAgIAAgACAgICAgMDcwKbK8Co/qio//ypfACpfVSpfqipf/yp/ACp/VSp/qip//yqfACqfVSqfqiqf/yq/ACq/VSq/qiq//yrfACrfVSrfqirf/yr/ACr/VSr/qir//1UAAFUAVVUAqlUA/1UfAFUfVVUfqlUf/1U/AFU/VVU/qlU//1VfAFVfVVVfqlVf/1V/AFV/VVV/qlV//1WfAFWfVVWfqlWf/1W/AFW/VVW/qlW//1XfAFXfVVXfqlXf/1X/AFX/VVX/qlX//38AAH8AVX8Aqn8A/38fAH8fVX8fqn8f/38/AH8/VX8/qn8//39fAH9fVX9fqn9f/39/AH9/VX9/qn9//3+fAH+fVX+fqn+f/3+/AH+/VX+/qn+//3/fAH/fVX/fqn/f/3//AH//VX//qn///6oAAKoAVaoAqqoA/6ofAKofVaofqqof/6o/AKo/Vao/qqo//6pfAKpfVapfqqpf/6p/AKp/Vap/qqp//6qfAKqfVaqfqqqf/6q/AKq/Vaq/q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