Skip to content

Commit

Permalink
3.0.3; add extpay.openLoginPage(), fixes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
Glench committed Jul 12, 2022
1 parent b01799f commit 2e447a2
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 1 deletion.
32 changes: 32 additions & 0 deletions ExtPay.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand Down
32 changes: 32 additions & 0 deletions dist/ExtPay.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions dist/ExtPay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions dist/ExtPay.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
32 changes: 32 additions & 0 deletions sample-extension-mv2/ExtPay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions sample-extension-mv3/ExtPay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2e447a2

Please sign in to comment.