alexa-samples / skill-sample-python-fact-in-skill-purchases

Demonstrates how to use the new in-skill purchasing (ISP) features of Alexa skills by offering different packs of facts behind a purchase, and a subscription to unlock all of the packs at once.
Other
16 stars 13 forks source link

Determining whether user is subscribed #7

Closed Daniyaldehleh closed 4 years ago

Daniyaldehleh commented 4 years ago

Hi There! I have read through the code multiple times. However, I am having trouble wrapping my head around determining whether a user is subscribed or not. As well as, I am quite lost on when/how to use .get_monetization_service() vs EntitledState.ENTITLE. Thus, I have prepared a simplified code. I would really appreciate if you can advise me on whether I am on the right page and if I should add anything:

class PaidIntentHandler(AbstractRequestHandler):
    def can_handle(self, handler_input):
        return ask_utils.is_intent_name("PaidIntent")(handler_input)
    def handle(self, handler_input):
        if EntitledState.ENTITLED:
            return .speak("You have this product")
        else:
            return handler_input.response_builder.add_directive(
                SendRequestDirective(
                    name="Buy",
                    payload= {
                        InSkillProduct: {
                            productId: "amzn1.adg.product.a....",
                        }
                token= "correlationToken")
            ).response

I am not sure where I shall be adding .get_monetization_service() and what else I am missing.