Alexa in-skill purchasing


#1

The documentation for Alexa in-skill purchasing shows some code to check if the user already bought a product.

this.$alexaSkill
    .$inSkillPurchase
    .getProductByReferenceName(productReferenceName, (error, product) => {
        if (error) {
            console.log(error);
        }
        if (product.entitled === 'ENTITLED') {
            // user already owns it
        } else {
            // user does not own it
        }
    });

Can i use this at any time or only during a purchase/cancel transaction?
IOW: Do i have to store the information about which product(s) a user has bought myself, e.g. in a database or will Amazon provide that information in every request?


#2

Amazon will provide that information in every request.

The getProductByReferenceName method is calling the internal getProductList method which does an API call to the Alexa API: https://github.com/jovotech/jovo-framework/blob/76b0a44059879e74084689685d3d51b7463ee6fd/jovo-platforms/jovo-platform-alexa/src/modules/InSkillPurchasePlugin.ts#L153


#3

For one time purchases and Subsctiptions the product.entitled field is enough to know if the user already bought said product.

With consumables on the other hand the product.entitled field only lets you know if the user bought this product at least once.
Checking the field product.activeEntitlementCount lets you know how many times the user has bought this product. Amazon does not keep count of how many times the user has “consumed” the product.
That information you do have to keep in your skill, e.g in a db.