I've been working on chrome extensions recently and while most of the area is well documented and pretty easy to figure out, I found setting up a free trial period to be really difficult. I ended up engaging an expert to help and have documented the steps required to help other people.
1. Publish your app on the Chrome web store if you haven't already done so and set up free trial billing.
2. Setup an app in the Google dev console https://console.developers.google.com/ and obtain the client_id. Sub steps below:
a. Create the project
b. Enable "Chrome Web Store API" for this project
c. Create application using the ID from the extension in the chrome store and when they ask you to setup credentials, choose: "OAuth client ID"
3. Add this to manifest.json:
4. Add a key to the manifest. This allows you to test the extension locally in developer mode. You can get the key in the Chrome developer dashboard if you click on the "More info" for your extension.
The key will be something like this.
key: "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCDE+RMJo4W8/j80mUQ7RHXi0Mv5yCC5l4EuoxMmXFhS5ooXKFgi7MST7E7Vzw/BDFoCUXBgSln44eKyerCSwaU2MW+LFiULeHogPySvmTxzDh8dDAQdfy9u0QMN7Q/6pr5B4lAM8XvWBlnjSCZhLpk08KVkqsd8IzYdLpBCB3lBQIDAQAB",
Make sure you remove spaces before adding it to your manifest. (When you copy it from the dev dashboard, it has unnecessary whitespace on the right hand side).
5. Check that you have same id in the store and in the chrome://extensions tab for you testing copy.
6. Add code to check the licence (note that I'm hardcoding 14 days as the free trial period - change as desired):
This needs to go in as a background script in your manifest.json, e.g.
"background": {
"scripts": ["checkLicenceKey.js"],
"persistent": false
}
Then in your content script, you'll do something like this:
(You can see I've set up config for allowed email addresses for myself and for people who've paid offline.)7. Profit!
Gotchas
Things I did wrong along the way:
1. Leaving whitespace in the key
2. Trying to test with the same account I used to set up the extension on the web store. This doesn't work. You'll need to test with a different account.
Comments
Post a Comment