1var IAIBasketIsEnabled = true; 2var IAIBasketIsBinded = false; 3var IAIIsAfterDelete = false; 4var IsButtonRendered = false; 5var IAIProductsCounter = 0; 6var IAIIsPromoCodeActive = false; 7 8function iziCanBeBound(productId) { 9 return IAIBasketIsEnabled; 10} 11 12async function iziGetPayData(prefix = null, phoneNumber = null, bindingPlace = null) { 13 const fetchDataQueryForButton = JSON.stringify( 14 { 15 query: `query{ 16 getButtonPropertiesForInpostPay{ 17 data 18 status 19 } 20 }`, 21 } 22 ); 23 24 let buttonProperties = await expressCheckoutApi.fetchData(fetchDataQueryForButton); 25 if (buttonProperties.data.getButtonPropertiesForInpostPay.data) { 26 buttonProperties = JSON.parse(buttonProperties.data.getButtonPropertiesForInpostPay.data); 27 } 28 29 let isTrustedButNotLinked = false; 30 if (buttonProperties.bindingData) { 31 if (buttonProperties.bindingData.basket_linked === false && buttonProperties.bindingData.browser_trusted === true) { 32 isTrustedButNotLinked = true; 33 } 34 } 35 36 let result = {}; 37 if (!isTrustedButNotLinked) { 38 let requestData = {}; 39 let browserData = iziGetBrowserData(); 40 if (phoneNumber) { 41 requestData = { 42 binding_method: "PHONE", 43 binding_place: bindingPlace, 44 phone_number: { 45 country_prefix: prefix, 46 phone: phoneNumber 47 }, 48 browser: browserData 49 } 50 } else { 51 requestData = { 52 binding_method: "DEEP_LINK", 53 binding_place: bindingPlace, 54 browser: browserData 55 } 56 } 57 58 requestData = escape(JSON.stringify(requestData)); 59 let fetchDataQuery = JSON.stringify( 60 { 61 query: `mutation{ 62 bindBasketToInPostBasket(BindBasketToInPostBasketInput: "` + requestData + `"){ 63 data 64 status 65 } 66 }`, 67 } 68 ); 69 70 let ret = await iziFetchData(fetchDataQuery); 71 if (ret.data.bindBasketToInPostBasket.data) { 72 let resultData = JSON.parse(ret.data.bindBasketToInPostBasket.data); 73 result = { 74 qr_code: resultData.qr_code, 75 deep_link: resultData.deep_link, 76 deep_link_hms: resultData.deep_link_hms 77 } 78 return result; 79 } 80 return result; 81 } else { 82 await iziAddBasket(); 83 84 } 85 86 return []; 87} 88 89function sleep(ms) { 90 return new Promise(resolve => setTimeout(resolve, ms)); 91} 92 93async function iziFetchData(dataFetch) { 94 try { 95 const response = await fetch('/graphql/v1/', { 96 method: 'POST', 97 headers: {'Content-Type': 'application/json', Accept: 'application/json'}, 98 body: dataFetch, 99 }); 100 const dataJson = await response.json(); 101 102 return dataJson; 103 } catch (error) { 104 console.error('AJAX fetchData() Error:', error); 105 throw error; 106 } 107} 108 109async function iziGetOrderComplete() { 110 const fetchDataQuery = JSON.stringify( 111 { 112 query: `query{ 113 eventUpdateConfirmation{ 114 data 115 status 116 } 117 }`, 118 } 119 ); 120 121 const retJson = await iziFetchData(fetchDataQuery); 122 if (retJson.data.eventUpdateConfirmation.data) { 123 ret = JSON.parse(retJson.data.eventUpdateConfirmation.data); 124 } 125 126 return ret; 127} 128 129/** 130 * Renderuje przycisk systemu pÅatnoÅci InpostPay 131 * 132 * @param mode - product/basket 133 * @param elementId 134 * @param productId - id towaru 135 * @return {Promise<void>} 136 */ 137async function renderInpostPayButton(mode, elementId, productId = '') { 138 IsButtonRendered = true; 139 const mainContainer = document.getElementById(elementId); 140 mainContainer.classList.add('--loading'); 141 expressCheckoutApi.mode = mode; 142 const fetchDataQueryForButton = JSON.stringify( 143 { 144 query: `query{ 145 getButtonPropertiesForInpostPay{ 146 data 147 status 148 } 149 }`, 150 } 151 ); 152 153 let buttonProperties = await expressCheckoutApi.fetchData(fetchDataQueryForButton); 154 if (buttonProperties.data.getButtonPropertiesForInpostPay.data) { 155 buttonProperties = JSON.parse(buttonProperties.data.getButtonPropertiesForInpostPay.data); 156 } 157 158 let basketClientData = {}; 159 if (buttonProperties.bindingData) { 160 if (buttonProperties.bindingData.basket_linked) { 161 basketClientData.name = buttonProperties.bindingData.client_details.name; 162 basketClientData.masked_phone_number = buttonProperties.bindingData.client_details.masked_phone_number; 163 } 164 if (buttonProperties.bindingData.basket_linked === false && buttonProperties.bindingData.browser_trusted === true) { 165 basketClientData.name = buttonProperties.bindingData.client_details.name; 166 } 167 } 168 IAIProductsCounter = buttonProperties.productsNumberInBasket; 169 IAIIsPromoCodeActive = buttonProperties.isPromoCodeActive; 170 IAIBasketIsEnabled = buttonProperties.isEnabled; 171 let widget = document.createElement('inpost-izi-button'); 172 widget.setAttribute('variation', (buttonProperties.variant ?? 'primary') + (buttonProperties.isDarkMode ? 'dark' : '')); 173 widget.setAttribute('data-product-id', productId ?? ''); 174 widget.setAttribute('binding_place', mode === 'basket' ? 'BASKET_SUMMARY' : 'PRODUCT_CARD'); 175 176 mainContainer.appendChild(widget); 177 178 if (typeof InPostPayWidget !== 'undefined') { 179 window.__INPOST_PAY_WIDGET__.refresh(); 180 mainContainer.classList.remove('--loading'); 181 182 return; 183 } 184 185 var script = document.createElement('script'); 186 script.setAttribute('src', buttonProperties.inPostIziJSUrl); 187 document.getElementsByTagName('body')[0].appendChild(script); 188 189 script.onload = () => { 190 iziGetBasketBindingApiKey(false).then((basketBindingApiKey) => { 191 const widgetOptions = { 192 merchantClientId: buttonProperties.merchantClientId, 193 basketBindingApiKey: basketBindingApiKey.length ? basketBindingApiKey : undefined, 194 unboundWidgetClicked: iziGetBasketBindingApiKeyForUnboundWidgetClicked, 195 handleBasketEvent: handleBasketEvent, 196 language: 'pl', // inpost tylko w PL 197 }; 198 const widgetNew = InPostPayWidget.init(widgetOptions); 199 dispatchEvent(new Event('load')); 200 }); 201 } 202 mainContainer.classList.remove('--loading'); 203} 204 205async function handleBasketEvent(event) { 206 try { 207 switch (event) { 208 case 'orderCreated': 209 const fetchDataQuery = JSON.stringify( 210 { 211 query: `query{
212 eventUpdateConfirmation{ 213 data 214 status 215 } 216 }`, 217 } 218 ); 219 220 ret = await iziGetOrderComplete(); 221 window.location.assign(ret.redirect); 222 return true; 223 } 224 } catch (err) { 225 // W razie bÅÄdu pozwalamy widgetowi przeÅadowaÄ stronÄ, 226 // żeby stan na pewno byÅ spójny. 227 return true; 228 } 229} 230 231async function iziAddToCart(id) { 232} 233 234async function iziGetBasketBindingApiKey() { 235 const query = JSON.stringify( 236 { 237 query: `query{ 238 getBasketBindingApiKeyForInpostPay(CreateWhenNotFound: false){ 239 data 240 } 241 }`, 242 } 243 ); 244 245 const fetchDataQuery = await iziFetchData(query); 246 247 return fetchDataQuery.data.getBasketBindingApiKeyForInpostPay.data ?? ''; 248} 249 250async function iziGetBasketBindingApiKeyForUnboundWidgetClicked() { 251 const query = JSON.stringify( 252 { 253 query: `query{ 254 getBasketBindingApiKeyForInpostPay{ 255 data 256 } 257 }`, 258 } 259 ); 260 261 const fetchDataQuery = await iziFetchData(query); 262 263 return fetchDataQuery.data.getBasketBindingApiKeyForInpostPay.data ?? ''; 264} 265 266async function iziAddBasket(id) { 267 const query = JSON.stringify( 268 { 269 query: `mutation{ 270 updateOrCreateInpost{ 271 data 272 } 273 }`, 274 } 275 ); 276 let result = await iziFetchData(query) 277} 278 279function iziButtonPaired() { 280 return inpostPayProperties.isBinded === true || IAIBasketIsBinded === true; 281} 282 283async function iziMobileLink() { 284 const query = JSON.stringify( 285 { 286 query: `query{ 287 getDeepLinkForInpostPay{ 288 data 289 } 290 }`, 291 } 292 ); 293 294 let fetchDataQuery = await iziFetchData(query); 295 return Promise.resolve({ 296 link: JSON.parse(fetchDataQuery.data.getDeepLinkForInpostPay.data) ?? '' 297 }) 298} 299 300function getCookie(cookieName) { 301 let cookieValue = '0'; 302 document.cookie.split(';').every(el => { 303 let [key, value] = el.split('='); 304 if (cookieName === key.trim()) { 305 cookieValue = value; 306 return false; 307 } 308 return true; 309 }); 310 311 return cookieValue; 312}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.