onTransactionComplete called my code twice

Hello i got more wired things happend. For some reason onTransactionComplete is sending the request to my api twice.

Do you have two instances of your extension open?

onTransactionComplete is sent to every instance of the extension for that user.

Or all instances if broadcast is enabled on the product

yes you are right. I got it open with 2 browsers and diffrent account. If i close one browser it get sendet only once. So i guess i need to check if the userId from the transaction object equals the userid from the onAuthorized right?

Whatever is most approprioate to your bits products.

Sounds like you probably want broadcast disabled however.

yeah how can i disable this ?

The bottom of trhe monetization tab in the developer dashboard, when managing a version of a extension

Or via the API or a tool that implemtns the API

in my dashboard i got only the options to activate bits or if i want support subscriptions.

The developer dashboard aka developer console - Twitch Developers

Down the bottom

1 Like

ok :slight_smile: thanks in german it means “Veröffentlicht” which can implemented as that the product is ready to use or published.

is there a way to see if a viewer got two instances open?

Theres a few ways I can think of to to it.

But you won’t really know for sure without their instance making a call to your server.

Which is why you deduplicate purchases on the server via ID

i could try to set the transaction id field to unique this should preventing at least to get the same transaction written in the database.

Ok put the field to unique and check with

    if ($stmt->execute()) {
        return true;
    } else {
        return false;

solved the problem with multiple windows from a single viewer for me

oh one more thing. I was looking to get the brodcasterID from the transaction object. But i was not able to find anything. Is there a other way to get it?

When passing the Transaction JWT up to your server, also pass the “normal” JWT to your server.

You can use the channelID from the “normal” JWT

Or is using eventsub eventsub has it

the original JWT is only generated within onAuthorized right? or is there a function to recive it?

The “normal” JWT is returned from onAuthorized and is available in window.Twitch.ext.viewer.sessionToken

ah ok nice :slight_smile: thank you