In-app purchases are upgrade options where users can upgrade from free to paid plans within your app. Microsoft Teams provides APIs to implement in-app purchases. The in-app purchase option is applicable only if the app is enabled with a transactable SaaS offer.
Users can buy new paid subscriptions through in-app purchases. However, they can't purchase additional or different licenses with existing paid subscriptions. To change plans, users must first cancel their current subscription before acquiring a new plan through in-app purchase.
You can activate the in-app purchase experience through one of the following ways:
Update from Developer Portal
In Teams Developer Portal, go to Permissions.
Enable Show in-app purchase offers.
Update manifest
To enable the in-app purchase experience, update your Teams app manifest.json file by adding the RSC permissions. It allows your app users to upgrade to a paid version of your app and access new features. Update the app manifest as given in the following code snippet:
To trigger in-app purchase for the app, invoke the openPurchaseExperience API from your web app. The following code snippet is an example of calling the API from the Teams app built using TeamsJS:
<div>
<divclass="sectionTitle">openPurchaseExperience</div><buttononclick="openPurchaseExperience()">openPurchaseExperience</button></div></body>
<script>
function openPurchaseExperience() {
micorosftTeams.app.initialize();
var planInfo = {
planId: "<Plan id>", // Plan Id of the published SAAS Offer
term: "<Plan Term>" // Term of the plan.
}
monetization.openPurchaseExperience(planInfo);
}
</script>
JavaScript
<div>
<divclass="sectionTitle">openPurchaseExperience</div><buttononclick="openPurchaseExperience()">openPurchaseExperience</button></div></body><script>function openPurchaseExperience()
microsoftTeams.initialize();
let callbackcalled = false;
microsoftTeams.monetization.openPurchaseExperience((e) => {
console.log("callback is being called");
console.log(e);
if (!!e && typeof e !== "string") {
alert(JSON.stringify(e));
}
return;
});
console.log("after callback: ",callbackcalled);
}
</script>
Källan för det här innehållet finns på GitHub, där du även kan skapa och granska ärenden och pull-begäranden. Se vår deltagarguide för mer information.
Feedback om Platform Docs
Platform Docs är ett öppen källkod projekt. Välj en länk för att ge feedback:
In this module, you'll learn how to monetize your Microsoft Teams apps by selling them through Microsoft AppSource, the Teams app store, and Teams Admin Center.
Visa färdigheter för att planera, distribuera, konfigurera och hantera Microsoft Teams för att fokusera på effektivt samarbete och kommunikation i en Microsoft 365-miljö.