1.0.0 • Published 7 years ago

aemm-plugin-entitlement v1.0.0

Weekly downloads
3
License
Apache 2.0
Repository
github
Last release
7 years ago

aemm-plugin-entitlement

This plugin defines a global entitlement object, which provides methods related to entitlement and purchase . Although the object is in the global scope, it is not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(typeof cq.mobile.entitlement);
}

Installation

cordova plugin add aemm-plugin-entitlement

Object Properties

Offer object Properties

NameTypeNotes
productIdStringthe product/subscription id user input in "Products&Subscription" dashboard
labelStringthe product/subscription name user input in "Products&Subscription" dashboard, will be null if not set by the user
descriptionStringthe product/subscription description user input in "Products&Subscription" dashboard, will be null if not set by the user
priceStringprice returned from the corresponding store, will be null if product is free
offerTypeStringcould be "product" or "subscription"
subscriptionTypeStringcould be "allAccess" or "standard", valid only if offertype is "subscription"
isFreeBooleantrue if the product is set as free in "Products&Subscription" dashboard

SubscriptionInfo object Properties

NameTypeNotes
subscriptionOffersArrayan array of Offer objects, would be empty if user has an active subscription
subscriptionStateObjectan SubscriptionState object

SubscriptionState object Properties

NameTypeNotes
isSubscriberBooleantrue if the user has been a subscriber at any point in time (i.e. for past and active subscribers alike), note that subscriptionState.isSubscriber = subscriptionState.store.isSubscriber OR subscriptionState.integrator.isSubscriber
isActiveSubscriberBooleantrue if the user has an active subscription at this point in time, note that subscriptionState.isActiveSubscriber = subscriptionState.store.isActiveSubscriber OR subscriptionState.integrator.isActiveSubscriber
storeObjecta Store object which contains subscription state to product store
integratorObjectan Integrator object which contains subsciption state to the integrator
Store object Properties
NameTypeNotes
isSubscriberBooleantrue if the user has been a subscriber at any point in time (i.e. for past and active subscribers alike)
isActiveSubscriberBooleantrue if the user has an active subscription at this point in time
expirationDateNumberthe timestamp in milliseconds since the epoch, which represents when that subscription period ends, it could be null since not all subscriptions (both from the store and the integrator) have an expiration date.
subscriptionTypeStringcould be "allAccess" or "standard", valid only if isSubscriber is true
idStringproduct id of the subscription product in the store
Integrator object Properties
NameTypeNotes
isSubscriberBooleantrue if the user has been a subscriber at any point in time (i.e. for past and active subscribers alike)
isActiveSubscriberBooleantrue if the user has an active subscription at this point in time
expirationDateNumberthe timestamp in milliseconds since the epoch, which represents when that subscription period ends , it could be null since not all subscriptions (both from the store and the integrator) have an expiration date.
customDataStringcustomData will not be set if the sibling isSubscriber is false. If isSubscriber is true, it may or may not be set. customData can be returned by the integrator. It is intended to contain data that is transparent to Adobe and only meaningful to the customer.

Methods

  • entitlement.getSubscriptionInfo
  • entitlement.getOffers
  • entitlement.purchaseOffer
  • entitlement.restorePurchases

entitlement.getSubscriptionInfo

This method returns the subscription info for the current publication and device.

ParameterTypeDescription
successCallbackFunctionThe success callback, which accepts a SubscriptionInfo object
errorCallbackFunctionThe error callback

Supported Platforms

  • iOS, Android

Quick Example

function successCallback(subscriptionInfo)
{
    var offers = subscriptionInfo.subscriptionOffers;
	for(var i=0; i<offers.length; i++)
	{
		var offer = offers[i];
		console.log(offer.productId);
		console.log(offer.subscriptionType);
	}

	var subscriptionState = subscriptionInfo.subscriptionState;
}
function errorCallback(errorCode)
{
	console.log(errorCode);
}
cq.mobile.entitlement.getSubscriptionInfo(successCallback, errorCallback);

entitlement.getOffers

This method requests the available offers (products and subscriptions) for the specified collection.

ParameterTypeDescription
collectionNameStringThe name of the collection to fetch offers for, this must match the name found on Content Portal
successCallbackFunctionThe success callback,which accepts an array of Offer objects
errorCallbackFunctionThe error callback

Supported Platforms

  • iOS, Android

Quick Example

var collectionName = "Collection X";
function successCallback(offers)
{
	for(var i=0; i<offers.length; i++)
	{
		var offer = offers[i];
		console.log(offer.productId);
		console.log(offer.offerType);
	}

}
function errorCallback(errorCode)
{
	console.log(errorCode);
}
cq.mobile.entitlement.getOffers(collectionName, successCallback, errorCallback);

entitlement.purchaseOffer

This method initiates a purchase request.

ParameterTypeDescription
productIdStringThe productId of the offer to purchase
successCallbackFunctionThe success callback
errorCallbackFunctionThe error callback

Supported Platforms

  • iOS, Android

Quick Example

var productId = "com.org.product.productId1";
function successCallback()
{
	console.log("Purchase %s succeed", productId);
}
function errorCallback(errorCode)
{
	console.log(errorCode);
}
cq.mobile.entitlement.purchaseOffer(productId, successCallback, errorCallback);

entitlement.restorePurchases

This method will initiate restore previous purchases for the user.

ParameterTypeDescription
successCallbackFunctionThe success callback
errorCallbackFunctionThe error callback

Supported Platforms

  • iOS

Quick Example

function successCallback()
{
	console.log("Restore purchase succeed");
}
function errorCallback(errorCode)
{
	console.log(errorCode);
}
cq.mobile.entitlement.restorePurchases(successCallback, errorCallback);