onPaid.addListener is not being triggered
Nodirbek3d opened this issue · 18 comments
I have following code in my ext_pay_content.js
const extpay = ExtPay('gpt-assistant');
extpay.onPaid.addListener(() => {
console.log("onPaid listener called")
});
and following in manifest:
...
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"css": [
"style.css"
],
"js": [
"./lib/jquery.js",
"./lib/ExtPay.js",
"./js/content.js"
],
"run_at": "document_end"
},
{
"matches": [
"https://extensionpay.com/*"
],
"js": [
"./lib/ExtPay.js",
"./js/limits.js",
"./js/ext_pay_content.js"
],
"run_at": "document_start"
}
],
...
So, when in a popup, user clicks on Subscribe button, it opens up login pay, when user makes a payment, listener is not being triggered, I have ExtPay
available on background script as well:
const extpay = ExtPay('gpt-assistant')
extpay.startBackground();
I haven't dug into it yet, but what immediately jumps out is using onPaid in the content script. Instead, you might try putting the onPaid listener in your background script.
I have tried to put it everywhere, background script, popup script, content script, it is not getting triggered at all
Again, I haven't had time to play around (I will when I have time to sit down) but I just noticed you referred to "./js/ext_pay_content.js"
in your manifest but "content_expay.js"
in your example. Are you sure the files are named correctly?
yeah, the same script, I fixed here in post, in my project there is no content_expay.js
I just tested with the onPaid listener in a background service worker and it worked fine. I would not recommend putting the onpaid listener in a content script that loads on the extensionpay site as it will likely not be ready by the time the payment signal happens.
can you share sample code where it worked? I removed it from content script, and left only on background one, but it is not getting triggered.
Here you go: https://gist.github.com/Glench/373a47bc64ffc404665290ef1beaeebe
Make sure to change the extension id in that example. You'll see a console message in the service worker after a user has paid.
ok, I found the case when it did not work, when a user cancels the subscription in the subscription window, and then activates it back, in that case it is not getting triggered.
I’m not sure what you mean. Can you take screenshots of what you’re doing?
can we setup a zoom meeting: :)
No sorry I’m not available for video meetings.
The onPaid listener is not currently meant to listen for when a user cancels or uncancels their subscription. That isn’t a payment event. However that could be another event. Can you please explain your use case?
my use case is, I have to set request limit that a user can send using extension, by default there is let's say 10 requests per day, but premium users can send 100 requests per day, so I need to know if user is premium or not, or user canceled subscription, but later activated it again, I need to set limit based on the case.
And why can’t you use extpay. getUser()?
extpay.getUser()
does not provide info if user reactivated their account. so that it could trigger setting limit.
What does "reactivated" mean? When a user lets cancels their subscription and the cancel_at datetime has passed?
I would say that in your code where you do the check for request limits you just check if extPay.getUser() is paid or not.
you should consider that limit is per day, and there is an expiration that has to be checked.
would be nice to have listener when user cancels, activates, etc. subscription
It still seems the same to me, but I don't know how your extension is structured and I don't provide extension-specific support.
Since this issue has been resolved, I'll close it, but I see now that what you're actually reporting is a feature request to call the onPaid listener after a user lets their subscription cancel and then resubscribes. Since this is a rare case, it's not high on my priority list, but it does seem like a good idea.