Package Exports
- extpay
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (extpay) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ExtPay — Payments for browser extensions on extensionpay.com
The JavaScript library for ExtensionPay.com, a service to add payments to browser extensions.
Below are the directions for using this library in your browser extension. If you learn better by example, you can also view the sample extension:
Sample Extension Code
1. Install
Copy the dist/ExtPay.js file into your project, or, if you're using a bundler:
npm install extpay --save
2. Add extension permissions to your manifest.json
ExtPay needs the following permissions in your manifest.json
:
{
"manifest_version": 2,
"permissions": [
"https://extensionpay.com/*",
"storage"
]
}
Right now the library doesn't support adding these as optional permissions but may in the future.
3. Add ExtPay to background.js (important!)
You need to put a call to ExtPay in a background file, often named something like background.js
.
First, add ExtPay.js
to manifest.json
if you're not using the bundler:
{
"background": {
"scripts": ["ExtPay.js", "background.js"]
}
}
Then initialize ExtPay with your extension short-id
, which you need to get by signing up and registering an extension. In the example below, the short-id
is sample-extension
.
// background.js
const extpay = ExtPay('sample-extension')
(Using a bundler? You can import
or require
ExtPay
.)
4. Use extpay.getUser()
to check user's paid status
This method makes a network call to get the extension user's paid status and returns a user
object.
extpay.getUser().then(user => {
// if (user.paid) ...
}).catch(err => {
// do something if there's an error, probably from the network call
})
or use await
:
async function foo() {
const user = await extpay.getUser();
// if (user.paid) ...
}
The user
object has the following properties:
user.paid
- booleantrue
orfalse
.user.paidAt
- JSDate()
object that the user paid ornull
.user.installedAt
- JSDate()
object the user installed the extension.
5. Use extpay.openPaymentPage()
to let the user pay
Opens a browser popup where the user can pay for the extension. You can bind this to a button.
extpay.openPaymentPage()
It looks like this:
While testing, use your ExtensionPay email to test payments without entering credit card information. Reinstall the extension to reset back to an unpaid user.