"use strict"; const ewano = { isObjectEmpty: obj => { for (let key in obj) if (obj.hasOwnProperty(key)) return false; return true; }, convertStringToJson: str => { try { return JSON.parse(str); } catch (err) { console.log('something went wrong: ', err); return false; } }, onWebAppReady: () => { var _window$Android, _window$Android$onWeb, _window$webkit, _window$webkit$messag, _window$webkit$messag2, _window$webkit$messag3, _window$parent, _window$parent$postMe; //Android (_window$Android = window.Android) === null || _window$Android === void 0 ? void 0 : (_window$Android$onWeb = _window$Android.onWebAppReady) === null || _window$Android$onWeb === void 0 ? void 0 : _window$Android$onWeb.call(_window$Android); //iOS (_window$webkit = window.webkit) === null || _window$webkit === void 0 ? void 0 : (_window$webkit$messag = _window$webkit.messageHandlers) === null || _window$webkit$messag === void 0 ? void 0 : (_window$webkit$messag2 = (_window$webkit$messag3 = _window$webkit$messag.onWebAppReady).postMessage) === null || _window$webkit$messag2 === void 0 ? void 0 : _window$webkit$messag2.call(_window$webkit$messag3, '1'); //pwa const onWebAppReadyMsg = JSON.stringify({ name: 'onWebAppReady' }); (_window$parent = window.parent) === null || _window$parent === void 0 ? void 0 : (_window$parent$postMe = _window$parent.postMessage) === null || _window$parent$postMe === void 0 ? void 0 : _window$parent$postMe.call(_window$parent, onWebAppReadyMsg, '*'); }, pay: (amount, orderId, callbackUrl = '') => { var _window$Android2, _window$Android2$payB, _window$Android3, _window$Android3$payB, _window$webkit2, _window$webkit2$messa, _window$webkit2$messa2, _window$webkit2$messa3, _window$parent2, _window$parent2$postM; console.log('pay: ', amount, orderId, callbackUrl); if (callbackUrl && !callbackUrl.startsWith('/')) throw Error('callbackUrl should start with "/"'); const dataAsObj = { amount, orderId }; if (callbackUrl) dataAsObj.callbackUrl = callbackUrl; //Android (_window$Android2 = window.Android) === null || _window$Android2 === void 0 ? void 0 : (_window$Android2$payB = _window$Android2.payBillByEwano) === null || _window$Android2$payB === void 0 ? void 0 : _window$Android2$payB.call(_window$Android2, amount, orderId); (_window$Android3 = window.Android) === null || _window$Android3 === void 0 ? void 0 : (_window$Android3$payB = _window$Android3.payBillByEwanoV2) === null || _window$Android3$payB === void 0 ? void 0 : _window$Android3$payB.call(_window$Android3, amount, orderId, callbackUrl); //iOS (_window$webkit2 = window.webkit) === null || _window$webkit2 === void 0 ? void 0 : (_window$webkit2$messa = _window$webkit2.messageHandlers) === null || _window$webkit2$messa === void 0 ? void 0 : (_window$webkit2$messa2 = _window$webkit2$messa.Payment) === null || _window$webkit2$messa2 === void 0 ? void 0 : (_window$webkit2$messa3 = _window$webkit2$messa2.postMessage) === null || _window$webkit2$messa3 === void 0 ? void 0 : _window$webkit2$messa3.call(_window$webkit2$messa2, dataAsObj); //pwa const payBillByEwanoMsg = JSON.stringify({ name: 'payBillByEwano', ...dataAsObj }); (_window$parent2 = window.parent) === null || _window$parent2 === void 0 ? void 0 : (_window$parent2$postM = _window$parent2.postMessage) === null || _window$parent2$postM === void 0 ? void 0 : _window$parent2$postM.call(_window$parent2, payBillByEwanoMsg, '*'); }, paymentResult: () => {}, getPlatform: () => { var _window$webkit3, _window$webkit3$messa; if (window.top !== window.self) return 'WEB';else if (window.Android) return 'ANDROID';else if ((_window$webkit3 = window.webkit) !== null && _window$webkit3 !== void 0 && (_window$webkit3$messa = _window$webkit3.messageHandlers) !== null && _window$webkit3$messa !== void 0 && _window$webkit3$messa.Payment) return 'IOS'; return null; }, getLocation: () => new Promise((resolve, reject) => { var _window$Android4, _window$Android4$requ, _window$webkit4, _window$webkit4$messa, _window$webkit4$messa2, _window$webkit4$messa3; //Android (_window$Android4 = window.Android) === null || _window$Android4 === void 0 ? void 0 : (_window$Android4$requ = _window$Android4.requestForLocationPermission) === null || _window$Android4$requ === void 0 ? void 0 : _window$Android4$requ.call(_window$Android4); //iOS (_window$webkit4 = window.webkit) === null || _window$webkit4 === void 0 ? void 0 : (_window$webkit4$messa = _window$webkit4.messageHandlers) === null || _window$webkit4$messa === void 0 ? void 0 : (_window$webkit4$messa2 = _window$webkit4$messa.requestLocationAccess) === null || _window$webkit4$messa2 === void 0 ? void 0 : (_window$webkit4$messa3 = _window$webkit4$messa2.postMessage) === null || _window$webkit4$messa3 === void 0 ? void 0 : _window$webkit4$messa3.call(_window$webkit4$messa2, '1'); //Android Result window.requestForLocationPermissionResult = response => { if (response && !ewano.isObjectEmpty(response)) { if (response.accepted) resolve(response);else reject(response); } else reject(); }; //iOS Result window.requestForLocationPermissionResultIOS = response => { if (response) { const responseObj = ewano.convertStringToJson(response); if (responseObj && responseObj.accepted === 'true') resolve({ ...responseObj, accepted: true });else reject({ ...responseObj, accepted: false }); } else reject(); }; // within iframe if (!window.Android && !window.webkit && window.navigator && window.navigator.geolocation) { navigator.geolocation.getCurrentPosition(pos => { resolve({ accepted: true, lat: pos.coords.latitude, long: pos.coords.longitude }); }, () => { reject({ accepted: false }); }, { enableHighAccuracy: true, maximumAge: 30000, timeout: 27000 }); } }) }; //payment result //Android window.payBillByEwanoResult = status => { var _window$ewano$payment, _window$ewano, _window$ewano$payment2, _window$ewano2; if (status) (_window$ewano$payment = (_window$ewano = window.ewano).paymentResult) === null || _window$ewano$payment === void 0 ? void 0 : _window$ewano$payment.call(_window$ewano, true);else (_window$ewano$payment2 = (_window$ewano2 = window.ewano).paymentResult) === null || _window$ewano$payment2 === void 0 ? void 0 : _window$ewano$payment2.call(_window$ewano2, false); }; //iOS window.payBillByEwanoResultIOS = response => { var _window$ewano$payment3, _window$ewano3, _window$ewano$payment4, _window$ewano4; const responseAsObj = ewano.convertStringToJson(response); if (responseAsObj && responseAsObj.status === 'true') (_window$ewano$payment3 = (_window$ewano3 = window.ewano).paymentResult) === null || _window$ewano$payment3 === void 0 ? void 0 : _window$ewano$payment3.call(_window$ewano3, true);else (_window$ewano$payment4 = (_window$ewano4 = window.ewano).paymentResult) === null || _window$ewano$payment4 === void 0 ? void 0 : _window$ewano$payment4.call(_window$ewano4, false); }; //pwa window.addEventListener('message', (e) => { console.log('ewano web toolkit', e); const dataAsObject = ewano.convertStringToJson(e.data); if (dataAsObject && dataAsObject.name === 'payBillByEwanoResult') { var _window$ewano$payment5, _window$ewano5, _window$ewano$payment6, _window$ewano6; const { status } = dataAsObject; if (status) (_window$ewano$payment5 = (_window$ewano5 = window.ewano).paymentResult) === null || _window$ewano$payment5 === void 0 ? void 0 : _window$ewano$payment5.call(_window$ewano5, true);else (_window$ewano$payment6 = (_window$ewano6 = window.ewano).paymentResult) === null || _window$ewano$payment6 === void 0 ? void 0 : _window$ewano$payment6.call(_window$ewano6, false); } }); window.ewano = ewano;