{
    "componentChunkName": "component---node-modules-rocketseat-gatsby-theme-docs-core-src-templates-docs-query-js",
    "path": "/docs/flutter/switch-subscription-plan/",
    "result": {"data":{"mdx":{"id":"9be4ee9a-1fc4-5b66-9eda-f5ef0da143ce","excerpt":"When a user purchase a subscription, you may want to offer them to switch to a different subscription plan without cancelling the first subscription. for…","fields":{"slug":"/docs/flutter/switch-subscription-plan/"},"frontmatter":{"title":"Switch Subscription plan","description":"Learn how to switch from one purchased subscription to another subscription plan.","image":null,"disableTableOfContents":true},"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\": \"Switch Subscription plan\",\n  \"description\": \"Learn how to switch from one purchased subscription to another subscription plan.\",\n  \"disableTableOfContents\": true\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(\"p\", null, \"When a user purchase a subscription, you may want to offer them to switch to a different subscription plan without cancelling the first subscription.\"), mdx(\"p\", null, \"for example, a user purchased a 1 month subscription and after some time, the user likes your app and wants to switch to a 12-months subscription plan.\\nNormally, the user has to cancel the first subscription and wait until the subscription ends. Then the user purchases the 12-months subscription.\\nBut instead of canceling the old subscription, you can offer them to switch immediately without waiting.\"), mdx(\"p\", null, \"In this case you should switch the subscription plan.\"), mdx(\"h2\", {\n    \"id\": \"the-switch-subscription-plan-function\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#the-switch-subscription-plan-function\",\n    \"aria-label\": \"the switch subscription plan function 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  }))), \"The Switch Subscription Plan Function\"), mdx(\"p\", null, \"To switch from one plan to another, you need to know from which plan you want to switch from. In our case, you can just submit what the LinkFivePurchases gives you on activeProducts.\"), mdx(\"p\", null, \"Then just call switchPlan( ... )\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-dart\"\n  }, \"LinkFivePurchases.switchPlan(\\n  oldPurchasePlan,                  // old plan\\n  linkFiveProductDetails,           // new subscription\\n  prorationMode: ProrationMode.immediateWithTimeProration\\n);\\n\")), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"oldPurchasePlan\"), \": is from LinkFivePurchases.activeProducts and is the current active Subscription which you want to end.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"linkFiveProductDetails\"), \": is coming from LinkFivePurchases.products. This is the NEW subscription plan which should be active.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"prorationMode\"), \": is can also be null! The proration mode is Google only: the default replaces immediately the subscription, and the remaining time will be prorated and credited to the user. Check \", mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode\"\n  }, \"https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode\"), \" for more information\")), mdx(\"p\", null, \"After success, the new plan should be either active immediately or after the subscription period os over (depending on your mode).\"));\n}\n;\nMDXContent.isMDXComponent = true;","headings":[{"depth":2,"value":"The Switch Subscription Plan Function"}]}},"pageContext":{"slug":"/docs/flutter/switch-subscription-plan/","next":{"label":"Introduction","link":"/docs/docs/"},"repositoryEditUrl":"","repositoryProvider":""}},
    "staticQueryHashes": ["1954253342","2328931024","2501019404","973074209"]}