/* (self.SWG = self.SWG || []).push(function(subscriptions) { subscriptions.setOnEntitlementsResponse(function(entitlementsPromise) { entitlementsPromise.then(function(entitlements) { console.log(entitlements); if (entitlements.entitlements.length > 0 && entitlements.entitlements[0].source == "google") { setTimeout(function(entitlements) { data = { 'idToken': gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse().id_token, 'purchaseData': entitlements.entitlements[0].subscriptionToken, }; if (!data.idToken) { const accountPromise = new Promise(function(resolve, reject) { var xhr = new XMLHttpRequest(); xhr.open('POST', 'https://shop.ilfattoquotidiano.it/google-signin/'); xhr.withCredentials = true; xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onload = function() { //console.log('Signed in as: ' + xhr.responseText); }; xhr.onreadystatechange = function() { if (xhr.readyState == XMLHttpRequest.DONE) { var data = jQuery.parseJSON(xhr.responseText); if (data.success) { resolve(data.account); } else { reject(data.errors.join(',')); } } }; xhr_string = []; if (data.purchaseData != undefined) { xhr_string.push('purchaseData=' + data.purchaseData); } xhr.send(xhr_string.join('&')); }); subscriptions.waitForSubscriptionLookup(accountPromise).then(function(account) { if (account) { subscriptions.showLoginPrompt().then(function(response) { subscriptions.showLoginNotification().then(function(response) { if (response == undefined) { data.subscriptionProcess = 1; } else { data.idToken = response.userData.idToken } call_ifq_google_signin(data, true); }); }, function(reason) { }); } else { subscriptions.completeDeferredAccountCreation({ entitlements: entitlements, consent: true }) .then(function(response) { data.idToken = response.userData.idToken call_ifq_google_signin(data, true); }); } }); } else { subscriptions.showLoginNotification().then(function(response) { call_ifq_google_signin(data, true); }); } entitlements.ack(); }, 2000, entitlements); } else { subscriptions.setOnLoginRequest(function() { var newwindow = window.open(loginURL, '', 'height=670,width=800'); if (window.focus) { newwindow.focus(); } var l = setInterval(function() { if (newwindow.closed) { clearInterval(l); window.location.reload(); } }, 500); return false; }); if (!head.desktop && !(/iPad|iPhone|iPod/.test(navigator.userAgent)) && !window.ifq_in_edicola_unlocked) { subscriptions.showOffers(); } else { if (jQuery('#swg-offers').length > 0) { subscriptions.attachButton(document.getElementById('swg-offers'), function() { ga('send', 'event', 'SWG', 'click', 'Premium article - Subscribe with Google'); subscriptions.showOffers(); }); jQuery('#swg').show(); jQuery('#swg-offers').show(); } } } }); }); subscriptions.setOnSubscribeResponse(function(subscriptionPromise) { subscriptionPromise.then(function(response) { ga('send', 'event', 'SWG', 'purchase-completed', 'Premium Article - SWG Purchase Completed'); data = JSON.parse(response.raw); data.subscriptionProcess = 1; call_ifq_google_signin(data,false); response.complete().then(function() { location.reload(); }); }); }); window.swg = subscriptions; }); */