diff --git a/ExtPay.dev.js b/ExtPay.dev.js index 0591138..e642bd1 100644 --- a/ExtPay.dev.js +++ b/ExtPay.dev.js @@ -239,6 +239,37 @@ You can copy and paste this to your manifest.json file to fix this error: } } + async function open_login_page() { + var api_key = await get_key(); + if (!api_key) { + api_key = await create_key(); + } + const url = `${EXTENSION_URL}/reactivate?api_key=${api_key}` + if (browser.windows) { + try { + browser.windows.create({ + url: url, + type: "popup", + focused: true, + width: 500, + height: 800, + left: 450 + }) + } catch(e) { + // firefox doesn't support 'focused' + browser.windows.create({ + url: url, + type: "popup", + width: 500, + height: 800, + left: 450 + }) + } + } else { + // https://developer.mozilla.org/en-US/docs/Web/API/Window/open + window.open(url, null, "toolbar=no,location=no,directories=no,status=no,menubar=no,width=500,height=800,left=450") + } + } var polling = false; @@ -302,6 +333,7 @@ You can copy and paste this to your manifest.json file to fix this error: }, openPaymentPage: open_payment_page, openTrialPage: open_trial_page, + openLoginPage: open_login_page, onTrialStarted: { addListener: function(callback) { trial_callbacks.push(callback) diff --git a/README.md b/README.md index 0fcc2aa..ed4290f 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Below are directions for using this library in your browser extension. If you le 6. [Use `extpay.onPaid.addListener()` to run code when the user pays](#6-use-extpayonpaidaddlistener-to-run-code-when-the-user-pays) 7. [Use `extpay.openPaymentPage()` to let the user manage their subscription preferences](#7-use-extpayopenpaymentpage-to-let-the-user-manage-their-subscription-preferences) 8. [Use `extpay.openTrialPage()` to let the user sign up for a free trial](#8-use-extpayopentrialpage-to-let-the-user-sign-up-for-a-free-trial) + 9. [Use `extpay.openLoginPage()` to let the user log in if they've paid already](#9-use-extpayopenloginpage-to-let-the-user-log-in-if-theyve-paid-already) **Note**: ExtPay.js doesn't contain malware or track your users in any way. This library only communicates with ExtensionPay.com servers to manage users' paid status. @@ -253,6 +254,9 @@ You can also use `extpay.onTrialStarted.addListener()` to run functions when the } ``` +## 9. Use `extpay.openLoginPage()` to let the user log in if they've paid already + +A page will open that will allow the user to enter the email they paid with to receive a magic login link. This page can also be accessed through the normal payment screen. ## Contributing diff --git a/dist/ExtPay.common.js b/dist/ExtPay.common.js index fb61638..e97b871 100644 --- a/dist/ExtPay.common.js +++ b/dist/ExtPay.common.js @@ -239,6 +239,37 @@ You can copy and paste this to your manifest.json file to fix this error: } } + async function open_login_page() { + var api_key = await get_key(); + if (!api_key) { + api_key = await create_key(); + } + const url = `${EXTENSION_URL}/reactivate?api_key=${api_key}`; + if (browser.windows) { + try { + browser.windows.create({ + url: url, + type: "popup", + focused: true, + width: 500, + height: 800, + left: 450 + }); + } catch(e) { + // firefox doesn't support 'focused' + browser.windows.create({ + url: url, + type: "popup", + width: 500, + height: 800, + left: 450 + }); + } + } else { + // https://developer.mozilla.org/en-US/docs/Web/API/Window/open + window.open(url, null, "toolbar=no,location=no,directories=no,status=no,menubar=no,width=500,height=800,left=450"); + } + } var polling = false; @@ -302,6 +333,7 @@ You can copy and paste this to your manifest.json file to fix this error: }, openPaymentPage: open_payment_page, openTrialPage: open_trial_page, + openLoginPage: open_login_page, onTrialStarted: { addListener: function(callback) { trial_callbacks.push(callback); diff --git a/dist/ExtPay.js b/dist/ExtPay.js index 3bd684f..e8d902e 100644 --- a/dist/ExtPay.js +++ b/dist/ExtPay.js @@ -1468,6 +1468,37 @@ You can copy and paste this to your manifest.json file to fix this error: } } + async function open_login_page() { + var api_key = await get_key(); + if (!api_key) { + api_key = await create_key(); + } + const url = `${EXTENSION_URL}/reactivate?api_key=${api_key}`; + if (browserPolyfill.windows) { + try { + browserPolyfill.windows.create({ + url: url, + type: "popup", + focused: true, + width: 500, + height: 800, + left: 450 + }); + } catch(e) { + // firefox doesn't support 'focused' + browserPolyfill.windows.create({ + url: url, + type: "popup", + width: 500, + height: 800, + left: 450 + }); + } + } else { + // https://developer.mozilla.org/en-US/docs/Web/API/Window/open + window.open(url, null, "toolbar=no,location=no,directories=no,status=no,menubar=no,width=500,height=800,left=450"); + } + } var polling = false; @@ -1531,6 +1562,7 @@ You can copy and paste this to your manifest.json file to fix this error: }, openPaymentPage: open_payment_page, openTrialPage: open_trial_page, + openLoginPage: open_login_page, onTrialStarted: { addListener: function(callback) { trial_callbacks.push(callback); diff --git a/dist/ExtPay.module.js b/dist/ExtPay.module.js index 8875a92..68ede01 100644 --- a/dist/ExtPay.module.js +++ b/dist/ExtPay.module.js @@ -237,6 +237,37 @@ You can copy and paste this to your manifest.json file to fix this error: } } + async function open_login_page() { + var api_key = await get_key(); + if (!api_key) { + api_key = await create_key(); + } + const url = `${EXTENSION_URL}/reactivate?api_key=${api_key}`; + if (windows) { + try { + windows.create({ + url: url, + type: "popup", + focused: true, + width: 500, + height: 800, + left: 450 + }); + } catch(e) { + // firefox doesn't support 'focused' + windows.create({ + url: url, + type: "popup", + width: 500, + height: 800, + left: 450 + }); + } + } else { + // https://developer.mozilla.org/en-US/docs/Web/API/Window/open + window.open(url, null, "toolbar=no,location=no,directories=no,status=no,menubar=no,width=500,height=800,left=450"); + } + } var polling = false; @@ -300,6 +331,7 @@ You can copy and paste this to your manifest.json file to fix this error: }, openPaymentPage: open_payment_page, openTrialPage: open_trial_page, + openLoginPage: open_login_page, onTrialStarted: { addListener: function(callback) { trial_callbacks.push(callback); diff --git a/package.json b/package.json index 909f4ef..8eef901 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "extpay", - "version": "3.0.2", + "version": "3.0.3", "description": "The JavaScript library for https://extensionpay.com - payments for browser extensions, no server needed.", "main": "./dist/ExtPay.common.js", "module": "./dist/ExtPay.module.js", diff --git a/sample-extension-mv2/ExtPay.js b/sample-extension-mv2/ExtPay.js index 3bd684f..e8d902e 100644 --- a/sample-extension-mv2/ExtPay.js +++ b/sample-extension-mv2/ExtPay.js @@ -1468,6 +1468,37 @@ You can copy and paste this to your manifest.json file to fix this error: } } + async function open_login_page() { + var api_key = await get_key(); + if (!api_key) { + api_key = await create_key(); + } + const url = `${EXTENSION_URL}/reactivate?api_key=${api_key}`; + if (browserPolyfill.windows) { + try { + browserPolyfill.windows.create({ + url: url, + type: "popup", + focused: true, + width: 500, + height: 800, + left: 450 + }); + } catch(e) { + // firefox doesn't support 'focused' + browserPolyfill.windows.create({ + url: url, + type: "popup", + width: 500, + height: 800, + left: 450 + }); + } + } else { + // https://developer.mozilla.org/en-US/docs/Web/API/Window/open + window.open(url, null, "toolbar=no,location=no,directories=no,status=no,menubar=no,width=500,height=800,left=450"); + } + } var polling = false; @@ -1531,6 +1562,7 @@ You can copy and paste this to your manifest.json file to fix this error: }, openPaymentPage: open_payment_page, openTrialPage: open_trial_page, + openLoginPage: open_login_page, onTrialStarted: { addListener: function(callback) { trial_callbacks.push(callback); diff --git a/sample-extension-mv3/ExtPay.js b/sample-extension-mv3/ExtPay.js index 3bd684f..e8d902e 100644 --- a/sample-extension-mv3/ExtPay.js +++ b/sample-extension-mv3/ExtPay.js @@ -1468,6 +1468,37 @@ You can copy and paste this to your manifest.json file to fix this error: } } + async function open_login_page() { + var api_key = await get_key(); + if (!api_key) { + api_key = await create_key(); + } + const url = `${EXTENSION_URL}/reactivate?api_key=${api_key}`; + if (browserPolyfill.windows) { + try { + browserPolyfill.windows.create({ + url: url, + type: "popup", + focused: true, + width: 500, + height: 800, + left: 450 + }); + } catch(e) { + // firefox doesn't support 'focused' + browserPolyfill.windows.create({ + url: url, + type: "popup", + width: 500, + height: 800, + left: 450 + }); + } + } else { + // https://developer.mozilla.org/en-US/docs/Web/API/Window/open + window.open(url, null, "toolbar=no,location=no,directories=no,status=no,menubar=no,width=500,height=800,left=450"); + } + } var polling = false; @@ -1531,6 +1562,7 @@ You can copy and paste this to your manifest.json file to fix this error: }, openPaymentPage: open_payment_page, openTrialPage: open_trial_page, + openLoginPage: open_login_page, onTrialStarted: { addListener: function(callback) { trial_callbacks.push(callback);