{
    "componentChunkName": "component---node-modules-rocketseat-gatsby-theme-docs-core-src-templates-docs-query-js",
    "path": "/docs/flutter/get-all-active-subscriptions/",
    "result": {"data":{"mdx":{"id":"b133392f-8071-5226-ab1d-1bb6ae34e605","excerpt":"Please read  How to initialize the plugin  before you start with this part. Usually you would want to know, if the user already purchased a subscription after…","fields":{"slug":"/docs/flutter/get-all-active-subscriptions/"},"frontmatter":{"title":"Get All Active Subscriptions","description":"If you implemented the linkfive_purchases plugin, then you're all set to get all active subscriptions","image":null,"disableTableOfContents":null},"body":"var _excluded = [\"components\"];\nfunction _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n/* @jsxRuntime classic */\n/* @jsx mdx */\n\nvar _frontmatter = {\n  \"title\": \"Get All Active Subscriptions\",\n  \"description\": \"If you implemented the linkfive_purchases plugin, then you're all set to get all active subscriptions\"\n};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n    props = _objectWithoutProperties(_ref, _excluded);\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"blockquote\", null, mdx(\"p\", {\n    parentName: \"blockquote\"\n  }, \"Please read \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/docs/flutter/initializing/\"\n  }, \"How to initialize the plugin\"), \" before you start with this part.\")), mdx(\"p\", null, \"Usually you would want to know, if the user already purchased a subscription after app start.\\nIn this case the flutter plugin has a function to get all active subscriptions.\"), mdx(\"p\", null, \"If the user has no active subscriptions, you might want to \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/docs/flutter/show-subscription-offer/\"\n  }, \"offer a subscription to the user\"), \" by fetching all available subscriptions.\"), mdx(\"h2\", {\n    \"id\": \"receive-all-active-subscriptions--plans\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#receive-all-active-subscriptions--plans\",\n    \"aria-label\": \"receive all active subscriptions  plans permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Receive all Active Subscriptions / Plans\"), mdx(\"p\", null, \"LinkFive mainly works with streams. You can listen to a stream using the LinkFivePurchases static object.\\nTo get all active subscriptions, you need to get the stream by calling .activeProducts and listen on the Stream.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-dart\"\n  }, \"// somewhere in your code\\nLinkFivePurchases\\n  .activeProducts\\n  .listen(_activeProductsUpdate))\\n\\n//...\\n\\nvoid _activeProductsUpdate(LinkFiveActiveProducts data) {\\n  // save the data, or parse it.\\n  activeProducts = data;\\n\\n  // in a provider, you might want to notify all listeners\\n  notifyListeners();\\n}\\n\")), mdx(\"p\", null, \"The stream will pass all verified and active subscriptions to your app. We also check if the receipt is valid by calling\\nthe Apple or Google APIs.\"), mdx(\"h3\", {\n    \"id\": \"cancel-your-stream-when-done\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#cancel-your-stream-when-done\",\n    \"aria-label\": \"cancel your stream when done permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Cancel your stream when done\"), mdx(\"p\", null, \"In your dispose method, please don't forget to cancel the stream by calling cancel.\"), mdx(\"p\", null, \"Looking at the first example above, you would want to save the result of the stream and call cancel on dispose.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-dart\"\n  }, \"_stream = LinkFivePurchases\\n    .activeProducts\\n    .listen(_activeProductsUpdate);\\n\\n//...\\n@override\\nvoid dispose() async {\\n  await _stream.cancel();\\n  super.dispose();\\n}\\n\")), mdx(\"h2\", {\n    \"id\": \"active-subscriptions-using-the-provider-plugin\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#active-subscriptions-using-the-provider-plugin\",\n    \"aria-label\": \"active subscriptions using the provider plugin permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Active Subscriptions using the Provider Plugin\"), mdx(\"p\", null, \"No additional work needed. You will find all active subscriptions in your provider.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-dart\"\n  }, \"// Access all active subscriptions after consuming LinkFiveProvider\\nlinkFiveProvider.activeProducts\\n\")), mdx(\"blockquote\", null, mdx(\"p\", {\n    parentName: \"blockquote\"\n  }, \"Next: \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/docs/flutter/show-subscription-offer/\"\n  }, \"Show your Subscription Offer\"))));\n}\n;\nMDXContent.isMDXComponent = true;","headings":[{"depth":2,"value":"Receive all Active Subscriptions / Plans"},{"depth":3,"value":"Cancel your stream when done"},{"depth":2,"value":"Active Subscriptions using the Provider Plugin"}]}},"pageContext":{"slug":"/docs/flutter/get-all-active-subscriptions/","next":{"label":"Introduction","link":"/docs/docs/"},"repositoryEditUrl":"","repositoryProvider":""}},
    "staticQueryHashes": ["1954253342","2328931024","2501019404","973074209"]}