Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item is not defined error #52

Open
christosmito opened this issue Apr 18, 2023 · 1 comment
Open

Item is not defined error #52

christosmito opened this issue Apr 18, 2023 · 1 comment

Comments

@christosmito
Copy link

christosmito commented Apr 18, 2023

I have made a pwa and twa app and released it on play store successfully. On play console I have created a subscription, in order the users to pay for monthly(etc) subscription, but in my app I get item is not defined error when I try to "fetch" it with the digitalgoods API.
This is my code

  let [srv, setSrv] = useState([]);
  let [supported, setSupported] = useState(false);
  let [digitalGoodsError, setDigitalGoodsError] = useState(false);
  useEffect(function () {
    async function getSubs() {
      if (window.getDigitalGoodsService === undefined) {
        // Digital Goods API is not supported in this context.
        return;
      }
      try {
        setSupported(true);
        const digitalGoodsService = await window.getDigitalGoodsService(
          "https://play.google.com/billing"
        );
        const details = await digitalGoodsService.getDetails(["weekly"]);
        let data = [];
        for (item of details) {
          data.push(item.price);
        }
        setSrv(data);
      } catch (error) {
        // Our preferred service provider is not available.
        // Use a normal web-based payment flow.
        console.error("Failed to get service:", error.message);
        setDigitalGoodsError("Failed to get service: " + error.message);
        return;
      }
    }
    getSubs();
  }, []);

And those are the subscriptions, which are active
image

Why do I get the item is not defined error?

@phoglenix
Copy link
Collaborator

Can you show what the JS console output is when you run the above code?
What is the value of the data variable when you call setSrv(data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants