PaddleHQ / paddle-js-wrapper

Wrapper to load Paddle.js as a module and use TypeScript definitions when working with methods.
Apache License 2.0
44 stars 6 forks source link

[Bug]: Calling p.Initialize() silently fails #66

Closed TigerHix closed 1 month ago

TigerHix commented 1 month ago

What happened?

I wrote the following code, not realizing I should pass initialization options to the initializePaddle parameter, not initialize it after I get the Paddle instance:

initializePaddle({ 
    environment: "sandbox", 
    token: clientSideToken
  })
      .then((p: Paddle | undefined) => {
        if (!p) {
          console.error('Paddle is undefined');
          return;
        }
        p.Initialize({
          token: clientSideToken,
          eventCallback: event,
        });
        console.log('Paddle initialized');
      })
      .catch((error) => {
        console.error('Paddle could not be initialized', error);
      });

After scratching my head for 2 hours why I'm not getting any events, I realized the correct code should simply be:

initializePaddle({ 
    environment: "sandbox", 
    token: clientSideToken,
    eventCallback: handleEvent,
  })
      .then((p: Paddle | undefined) => {
        if (!p) {
          console.error('Paddle is undefined');
          return;
        }
        console.log('Paddle initialized');
      })
      .catch((error) => {
        console.error('Paddle could not be initialized', error);
      });

Unfortunately this wasn't obvious at all, because the official documentation just asked us to use Paddle.initialize to pass eventCallback to Paddle.js. Moreover, the top code did not throw any errors - it just silently failed, which is bad practice. If I have gotten an error earlier, catching the bug would be much easier.

I am not sure if this is a paddle-js-wrapper bug or an upstream bug. In any case, developer feedback would be appreciated. Thank you!

Steps to reproduce

Step-by-step walkthrough provided above.

What did you expect to happen?

No response

How are you integrating?

No response

Logs

No response

danbillson commented 1 month ago

Hi @TigerHix, apologies for the delay in getting back to you. Thanks for raising, I've passed this information on to the docs team, we will look into it and provide an update soon.

danbillson commented 1 month ago

@TigerHix do you mind sharing some of your implementation details, what framework you're using if any, how you're managing state etc?

It seems like there has been some confusion between the @paddle/paddle-js implementation and the script implementation which we'd like to make sure is a clear as possible

danbillson commented 1 month ago

As the issue has been resolved we'll handle this internally, we are closing this issue for now, but please don't hesitate to reach out if you have further questions.