Skip to content

Commit

Permalink
minor copy edits
Browse files Browse the repository at this point in the history
  • Loading branch information
Glench committed Feb 24, 2021
1 parent 7a13141 commit 98cbb0c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ExtPay.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ You can copy and paste this to your manifest.json file to fix this error:
}
const manifest = await manifest_resp.json()
if (!manifest.content_scripts) {
throw `ExtPay setup error: Please include ExtPay as a content script in your manifest.json. You can copy the example below into your manifest.json or check the docs: https://github.com/Glench/ExtPay#2-add-extension-permissions-to-your-manifestjson
throw `ExtPay setup error: Please include ExtPay as a content script in your manifest.json. You can copy the example below into your manifest.json or check the docs: https://github.com/Glench/ExtPay#2-configure-your-manifestjson
${content_script_template}`
}
Expand Down
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# ExtPay.js — Payments in browser extensions
The JavaScript library for [ExtensionPay.com](https://extensionpay.com), a service to easily add payments to browser extensions without needing to run your own server backend.
The JavaScript library for [ExtensionPay.com](https://extensionpay.com), a service to easily add payments to browser extensions without running your own server backend.

Below are the directions for using this library in your browser extension. If you learn better by example, you can also view the code for a **[sample extension](sample-extension/)**. This library uses [Mozilla's webextension-polyfill library](https://github.com/mozilla/webextension-polyfill) internally for compatability across browsers which means it should work on almost all modern browsers.
Below are directions for using this library in your browser extension. If you learn better by example, you can also view the code for a **[sample extension](sample-extension/)**. This library uses [Mozilla's webextension-polyfill library](https://github.com/mozilla/webextension-polyfill) internally for compatability across browsers which means it should work on almost all modern browsers.

Note: ExtPay.js does not contain malware or track your users in any way. The library only communicates with ExtensionPay.com servers to manage users' paid status.
**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.

### 1. Install

Expand Down Expand Up @@ -32,12 +32,12 @@ ExtPay needs the following configuration in your `manifest.json`:
]
}
```
The content script is required to enable `extpay.onPaid` callbacks (see below). If you're using a bundler, you can create a file called something like `ExtPay_content_script.js` that only contains `import 'ExtPay'` or `require('ExtPay')` and use that instead of `ExtPay.js` in the `"js"` field of the manifest shown above.
The content script is required to enable `extpay.onPaid` callbacks (see below). If you're using a bundler, you can create a file called something like `ExtPay_content_script.js` that only contains `import 'ExtPay'` or `require('ExtPay')` and use that in the `"js"` field above.

Also please note: the library doesn't currently support optional permissions but may in the future.


### 3. Add `ExtPay` to `background.js` (important!)
### 3. Add `ExtPay` to `background.js` (required!)

You need to put `ExtPay` in your background file, often named something like `background.js`. If you don't include `ExtPay` in your background file it won't work correctly.

Expand All @@ -60,23 +60,28 @@ const extpay = ExtPay('sample-extension')
If you're using a bundler you can `import 'ExtPay'` or `require('ExtPay')` right in your `background.js`.


### 4. Use `extpay.getUser()` to check user's paid status
### 4. Use `extpay.getUser()` to check a user's paid status

This method makes a network call to get the extension user's paid status and returns a `user` object.
```js
extpay.getUser().then(user => {
if (user.paid) // ...
else // ...
if (user.paid) {
// ...
} else {
// ...
}
})
```
or use `await`:
```js
async function foo() {
const user = await extpay.getUser();
if (user.paid) // ...
if (user.paid) {
// ...
}
}
```
It is possible for `extpay.getUser()` to throw an error in case of a network failure. Please consider this possibility in your code.
It is possible for `extpay.getUser()` to throw an error in case of a network failure. Please consider this possibility in your code e.g. `extpay.getUser().then(/* ... */).catch(/* handle error */)`

The `user` object returned from `extpay.getUser()` has the following properties:

Expand All @@ -87,15 +92,19 @@ The `user` object returned from `extpay.getUser()` has the following properties:

### 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.
Opens a browser popup where the user can pay to upgrade their status.
```js
extpay.openPaymentPage()
```
The payment page looks like this:

![popup screenshot](popup_screenshot.png)

While testing, use your ExtensionPay email to test payments without needing to enter credit card information. Reinstall the extension to reset back to an unpaid user.
It is best to open the payment page when the user has a clear idea of what they're paying for.

While testing, use your ExtensionPay email to test payments without entering credit card information. Reinstall the extension to reset back to an unpaid user.

Depending on how you configure your extension, users that have paid before can log in to activate their paid features on different browsers, profiles, or after uninstalling/reinstalling.


### 6. Use `extpay.onPaid.addListener()` to run code when the user pays
Expand Down
2 changes: 1 addition & 1 deletion dist/ExtPay.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ You can copy and paste this to your manifest.json file to fix this error:
}
const manifest = await manifest_resp.json();
if (!manifest.content_scripts) {
throw `ExtPay setup error: Please include ExtPay as a content script in your manifest.json. You can copy the example below into your manifest.json or check the docs: https://github.com/Glench/ExtPay#2-add-extension-permissions-to-your-manifestjson
throw `ExtPay setup error: Please include ExtPay as a content script in your manifest.json. You can copy the example below into your manifest.json or check the docs: https://github.com/Glench/ExtPay#2-configure-your-manifestjson
${content_script_template}`
}
Expand Down
2 changes: 1 addition & 1 deletion dist/ExtPay.js
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ You can copy and paste this to your manifest.json file to fix this error:
}
const manifest = await manifest_resp.json();
if (!manifest.content_scripts) {
throw `ExtPay setup error: Please include ExtPay as a content script in your manifest.json. You can copy the example below into your manifest.json or check the docs: https://github.com/Glench/ExtPay#2-add-extension-permissions-to-your-manifestjson
throw `ExtPay setup error: Please include ExtPay as a content script in your manifest.json. You can copy the example below into your manifest.json or check the docs: https://github.com/Glench/ExtPay#2-configure-your-manifestjson
${content_script_template}`
}
Expand Down
2 changes: 1 addition & 1 deletion dist/ExtPay.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ You can copy and paste this to your manifest.json file to fix this error:
}
const manifest = await manifest_resp.json();
if (!manifest.content_scripts) {
throw `ExtPay setup error: Please include ExtPay as a content script in your manifest.json. You can copy the example below into your manifest.json or check the docs: https://github.com/Glench/ExtPay#2-add-extension-permissions-to-your-manifestjson
throw `ExtPay setup error: Please include ExtPay as a content script in your manifest.json. You can copy the example below into your manifest.json or check the docs: https://github.com/Glench/ExtPay#2-configure-your-manifestjson
${content_script_template}`
}
Expand Down
2 changes: 1 addition & 1 deletion sample-extension/ExtPay.js
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ You can copy and paste this to your manifest.json file to fix this error:
}
const manifest = await manifest_resp.json();
if (!manifest.content_scripts) {
throw `ExtPay setup error: Please include ExtPay as a content script in your manifest.json. You can copy the example below into your manifest.json or check the docs: https://github.com/Glench/ExtPay#2-add-extension-permissions-to-your-manifestjson
throw `ExtPay setup error: Please include ExtPay as a content script in your manifest.json. You can copy the example below into your manifest.json or check the docs: https://github.com/Glench/ExtPay#2-configure-your-manifestjson
${content_script_template}`
}
Expand Down

0 comments on commit 98cbb0c

Please sign in to comment.