Verify Subscription Status
To verify the status of a subscription or an IAPs you can use Glassfy permissions
so that you do not have to hardcode a specific SKU or productId
in your application.
You should configure the permission by adding all the SKUs that unlock the specific feature of your application
Then using the following code you can verify the status.
Glassfy.permissions { permission, _ in
guard let permissions = permission?.all else { return }
if let currentPermission = permissions.first(where: { permission in permission.isValid && permission.permissionId == "premium" }),
let currentSku = currentPermission.accountableSkus.first
{
Glassfy.sku(id: currentSku.skuId, store: currentSku.store) { sku, _ in
if let sku = sku {
if let sku = sku as? Glassfy.Sku {
// you can get iOS product info including the
// price and the title.
price = sku.product.price
description = sku.product.localizedDescription
priceLocale = sku.product.priceLocale
} else if let sku = sku as? Glassfy.SkuPaddle {
// you can get Paddle product info including the
// price and the title.
description = sku.name
price = sku.recurringPrice
priceLocale = sku.recurringPriceLocale
}
}
}
}
}
[Glassfy permissionsWithCompletion:^(GYPermissions *permission, NSError *err) {
NSArray<GYPermission*> *permissions = permission.all;
if (permissions) {
for (GYPermission *p in permissions) {
switch (p.permissionId) {
case @"premium":
if (p.isValid) {
// unlock aFeature
}
else {
// lock aFeature
}
break;
default:
NSLog(@"Permission not handled");
break;
}
}
}
}];
Glassfy.permissions { permission, err ->
// update app status accordingly
permission?.all?.forEach {
when (it.permissionId) {
"premium" ->
if (it.isValid) {
// unlock aFeature
} else {
// lock aFeature
}
else -> println("Permission not handled");
}
}
}
Glassfy.permissions(new PermissionsCallback() {
@Override
public void onResult(@Nullable Permissions permission, @Nullable GlassfyError error) {
// update app status accondingly
if (permission != null) {
for (Permission p: permission.getAll()) {
switch (p.getPermissionId()) {
case "premium":
if (p.isValid()) {
// unlock aFeature
} else {
// lock aFeature
}
break;
default:
Log.d(TAG, "Permission not handled");
}
}
}
}
});
try {
var permission = await Glassfy.permissions();
permission.all?.forEach((p)=> {
if (p.permissionId == "premium") {
// unlock aFeature
}
});
} catch (e) {
// initialization error
[...]
}
try {
const permissions = Glassfy.permissions();
const permission = transaction.permissions.all.find((p) => p.permissionId === "premium");
if (permission && permission.isValid) {
// unlock aFeature
}
} catch (e) {
// initialization error
[...]
}
try {
const permissions = Glassfy.permissions();
const permission = transaction.permissions.all.find((p) => p.permissionId === "premium");
if (permission && permission.isValid) {
// unlock aFeature
}
} catch (e) {
// initialization error
[...]
}
The Permissions object contains other useful information for example the accountableSkus that will return a list of SKUs responsible for unlocking that specific permission or installation specific identifier such subscriberId and installationId
Updated 15 days ago
Did this page help you?