importScripts('ExtPay.js')
const extpay = ExtPay('ureview') 
extpay.startBackground();

extpay.getUser().then(user => {
    console.log(user)
    if (user.paid) {
        console.log('test extension user is paid:', user)
    } else {
        extpay.openTrialPage()
        // extpay.openPaymentPage()
    }
})
extpay.onTrialStarted.addListener(function(user) {
    console.log('trial started!!!!!')
})

extpay.onPaid.addListener(user => {
    if (typeof browser == "undefined") {
        browser = chrome;
    }
    console.log('onPaid callback! heres the user:', user)
    browser.action.setBadgeText({text:'paid'})
    setTimeout(function() {
        browser.action.setBadgeText({text:''})
    }, 5000)
})

chrome.storage.local.get('foo', function() {
    const extpay = ExtPay('derp-extension');

    extpay.getUser().then(function(user) {
        console.log('service worker callback worked!', user)
    })
})
