# aemm-plugin-entitlement

> AEMM Entitlement Plugin

Latest version **1.0.0** (published 2017-02-15) · Apache 2.0 license · 0 weekly downloads

## Install

```sh
npm install aemm-plugin-entitlement
pnpm add aemm-plugin-entitlement
yarn add aemm-plugin-entitlement
bun add aemm-plugin-entitlement
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-02-15 |
| First published | 2017-02-15 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Adobe |
| Maintainers | aemmobile |
| Keywords | cordova, entitlement, cordova-ios, cordova-android, aem, aemm, aemmobile |

## Links

- npm: https://www.npmjs.com/package/aemm-plugin-entitlement
- Repository: https://github.com/adobe-marketing-cloud-mobile/aemm-plugin-entitlement
- Homepage: https://github.com/adobe-marketing-cloud-mobile/aemm-plugin-entitlement#readme
- Issues: https://github.com/adobe-marketing-cloud-mobile/aemm-plugin-entitlement/issues
- npm.io page: https://npm.io/package/aemm-plugin-entitlement

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-02-15

## README

<!--
# license: Licensed to the Apache Software Foundation (ASF) under one
#         or more contributor license agreements.  See the NOTICE file
#         distributed with this work for additional information
#         regarding copyright ownership.  The ASF licenses this file
#         to you under the Apache License, Version 2.0 (the
#         "License"); you may not use this file except in compliance
#         with the License.  You may obtain a copy of the License at
#
#           http://www.apache.org/licenses/LICENSE-2.0
#
#         Unless required by applicable law or agreed to in writing,
#         software distributed under the License is distributed on an
#         "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#         KIND, either express or implied.  See the License for the
#         specific language governing permissions and limitations
#         under the License.
-->

# 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

| Name | Type | Notes |
| --- | --- | --- |
| productId         | String           | the product/subscription id user input in "Products&Subscription" dashboard |
| label         | String           |  the product/subscription name user input in "Products&Subscription" dashboard, will be null if not set by the user|
| description           | String  | the product/subscription description user input in "Products&Subscription" dashboard, will be null if not set by the user|
| price              | String           | price returned from the corresponding store, will be null if product is free |
| offerType         | String           | could be "product" or "subscription" |
| subscriptionType      | String           | could be "allAccess" or "standard", valid only if offertype is "subscription" |
| isFree   | Boolean           | true if the product is set as free in  "Products&Subscription" dashboard |

### SubscriptionInfo object Properties

| Name | Type | Notes |
| --- | --- | --- |
| subscriptionOffers         | Array           |  an array of Offer objects, would be empty if user has an active subscription|
| subscriptionState         | Object           |  an SubscriptionState object|

#### SubscriptionState object Properties
| Name | Type | Notes |
| --- | --- | --- |
| isSubscriber         | Boolean           |  true 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|
| isActiveSubscriber         | Boolean           |  true if the user has an active subscription at this point in time, note that subscriptionState.isActiveSubscriber = subscriptionState.store.isActiveSubscriber OR subscriptionState.integrator.isActiveSubscriber|
| store         | Object           |  a Store object which contains subscription state to product store|
| integrator         | Object           |  an Integrator object which contains subsciption state to the integrator |

##### Store object Properties
| Name | Type | Notes |
| --- | --- | --- |
| isSubscriber         | Boolean           |  true if the user has been a subscriber at any point in time (i.e. for past and active subscribers alike)|
| isActiveSubscriber         | Boolean           |  true if the user has an active subscription at this point in time|
| expirationDate         | Number           |  the 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. |
| subscriptionType         | String           |  could be "allAccess" or "standard", valid only if isSubscriber is true|
| id         | String           |  product id of the subscription product in the store|

##### Integrator object Properties
| Name | Type | Notes |
| --- | --- | --- |
| isSubscriber         | Boolean           |  true if the user has been a subscriber at any point in time (i.e. for past and active subscribers alike)|
| isActiveSubscriber         | Boolean           |  true if the user has an active subscription at this point in time|
| expirationDate         | Number           |  the 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.|
| customData         | String           |  customData 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. 

| Parameter | Type | Description |
| --- | --- | ---|
| successCallback | Function | The success callback, which accepts a SubscriptionInfo object |
| errorCallback | Function | The error callback |

### Supported Platforms
- iOS, Android

### Quick Example

```javascript
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.

| Parameter | Type | Description |
| --- | --- | ---|
| collectionName | String | The name of the collection to fetch offers for, this must match the name found on Content Portal |
| successCallback | Function | The success callback,which accepts an array of Offer objects |
| errorCallback | Function | The error callback |

### Supported Platforms
- iOS, Android


### Quick Example
```javascript
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.

| Parameter | Type | Description |
| --- | --- | ---|
| productId | String | The productId of the offer to purchase |
| successCallback | Function | The success callback |
| errorCallback | Function | The error callback |

### Supported Platforms
- iOS, Android

### Quick Example
```javascript
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.

| Parameter | Type | Description |
| --- | --- | ---|
| successCallback | Function | The success callback |
| errorCallback | Function | The error callback |

### Supported Platforms
- iOS

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

---
_Source: https://npm.io/package/aemm-plugin-entitlement · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
