Glench/ExtPay

onTrialStarted listener is not getting called when user starts trial in test mode.

marioaburto10 opened this issue · 5 comments

Issue
onTrialStarted listener is not getting called when user starts trial in test mode.

Expected behavior
callback function within extpay.onTrialStarted.addListener should be executed after the user clicks on the trial link in their email.

Context
I click on a button in my options.html page that triggers the extpay.openTrialPage() function. A new window opens up, asking me to enter my email to start my free trial. A link is sent to my email. I click on the link and I get a message saying that I can now use the extension's paid features. I head back to my extension and see that nothing has changed. I inspect my extension and don't see anything in the console. I have a console.log function inside of the onTrialStarted listener and I see that it never gets called either. It's important to note that the test case where I subscribe, the onPaid listener works just fine. I'm wondering why the onPaid listener works fine but the onTrialStarted listener does not work at all? See my code below.

It is also worth noting that if I reload the options page and the getUser() function is called, the user that comes back has the property paid set as true while the property trialStartedAt is set to null. I am expecting the trialStartedAt property to have a numeric value for the trial test case. Looks like there is a bigger issue with the test trial functionality but not sure.

My Setup
background.js

importScripts('ExtPay.js');
var extpay = ExtPay('my-extension'); 
extpay.startBackground(); 

extpay.onPaid.addListener((user) => {
  console.log('user has paid');
  console.log(user);
  // do something
});

extpay.onTrialStarted.addListener((user) => {
  console.log('trial has started');
  console.log(user);
  // do something
});

manifest.json

  "content_scripts": [
      {
        "matches": ["https://extensionpay.com/*"],
        "js": ["ExtPay.js"],
        "run_at": "document_start"
      },
      {
      ...
      }
    ]
Glench commented

Is the browser that your extension runs in different from the one that opens when you click the link in your email?

Is the browser that your extension runs in different from the one that opens when you click the link in your email?

Yes it is

Glench commented

That's the issue then. Unfortunately there's really no way around that that I know of.

In an actual use case (not test mode) will the user be marked as paid when they initialize their trial and click on the link on a different browser? Currently, in my test case, if I reload the options page and the getUser() function is called, the user that comes back has the property paid set as true while the property trialStartedAt is set to null. I am expecting the trialStartedAt property to have a numeric value even if the onTrialStarted listener is not called.

For anyone wondering, in an actual start trial use case (not test mode) - the user object that is returned does have the trialStartedAt property populated even if the user clicks on the trial link on a different browser. The only issue (known) is that the onTrialStarted listener will not get called but I can work with this. Thank you @Glench for your help.