Creating Apps for Cookie
Apps do not need any reprovisioning to be added to the Cookie store. However, there are optional convenience API's that give extra functionality to apps, like the subscriptions API.
Adding your app to the Cookie DB
Currently, there is not easy way to add apps to the Cookie DB. Because Cookie is still under development, we are personally reaching out to developers to get apps on Cookie. If you still feel like your app should be on Cookie, you can send us an email at [email protected].
The Subscriptions API
Import CookieApi.dll
into your project. Because the DLL is managed, it may require you to use a special loader if you are using a non-managed language. For C# you can directly import the DLL as is.
using Cookie.Api;
Next we need to authorize our app with the Cookie servers before we can continue with requesting data.
try
{
var CookieService = await CookieApp.Provision(
new CookieAppAuthentication(
"my-app",
"SECRET TOKEN",
new string[]
{
"cookie.subscriptions.verify",
"cookie.subscriptions.purchase",
}
)
);
}
// Error handle
catch (Exception e) { }
Because Cookie needs to be synchronized with the users of your service and users in the Cookie DB, it uses a user-specific id. It is the apps responsibility of storing the id safely and passing it on to each Cookie request on behalf of the user.
var UserId = MyAppSystem.GetUser().CookieId;
CookieService.SetUserId(UserId);
Now we can request the current subscription state from the Cookie servers.
var Subscription = await CookieService.GetSubscriptionByName("myapp.premium");
if (Subscription.isActive)
{
// Allow user to use app
}
else
{
Subscription.ShowPaywall();
// The showpaywall method asks the user to either close the app or renew
// their subscription in cookie. Essentially locking the app from use.
}
Last updated