Example #1
0
def create_addon_purchase(sender, instance, **kw):
    """
    When the contribution table is updated with the data from PayPal,
    update the addon purchase table. Will figure out if we need to add to or
    delete from the AddonPurchase table.
    """
    if (kw.get('raw') or
        instance.type not in [amo.CONTRIB_PURCHASE, amo.CONTRIB_REFUND,
                              amo.CONTRIB_CHARGEBACK]):
        # Whitelist the types we care about. Forget about the rest.
        return

    log.debug('Processing addon purchase type: %s, addon %s, user %s'
              % (unicode(amo.CONTRIB_TYPES[instance.type]),
                 instance.addon.pk, instance.user.pk))

    if instance.type in [amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK]:
        purchases = AddonPurchase.objects.filter(addon=instance.addon,
                                                 user=instance.user)
        for p in purchases:
            log.debug('Changing addon purchase: %s, addon %s, user %s'
                      % (p.pk, instance.addon.pk, instance.user.pk))
            p.update(type=instance.type)

    cache.delete(memoize_key('users:purchase-ids', instance.user.pk))
Example #2
0
def create_addon_purchase(sender, instance, **kw):
    """
    When the contribution table is updated with the data from PayPal,
    update the addon purchase table. Will figure out if we need to add to or
    delete from the AddonPurchase table.
    """
    if (kw.get('raw') or
        instance.type not in [mkt.CONTRIB_PURCHASE, mkt.CONTRIB_REFUND,
                              mkt.CONTRIB_CHARGEBACK]):
        # Filter the types we care about. Forget about the rest.
        return

    log.info('Processing addon purchase type: {t}, addon {a}, user {u}'
             .format(t=unicode(mkt.CONTRIB_TYPES[instance.type]),
                     a=instance.addon and instance.addon.pk,
                     u=instance.user and instance.user.pk))

    if instance.is_inapp_simulation():
        log.info('Simulated in-app product {i} for contribution {c}: '
                 'not adding a purchase record'.format(
                     i=instance.inapp_product,
                     c=instance))
        return

    if instance.type == mkt.CONTRIB_PURCHASE:
        log.debug('Creating addon purchase: addon %s, user %s'
                  % (instance.addon.pk, instance.user.pk))

        data = {'addon': instance.addon, 'user': instance.user}
        purchase, created = AddonPurchase.objects.safer_get_or_create(**data)
        purchase.update(type=mkt.CONTRIB_PURCHASE)
        from mkt.webapps.models import Installed  # Circular import
        # Ensure that devs have the correct installed object found
        # or created.
        #
        is_dev = instance.addon.has_author(
            instance.user, (mkt.AUTHOR_ROLE_OWNER, mkt.AUTHOR_ROLE_DEV))
        install_type = (apps.INSTALL_TYPE_DEVELOPER if is_dev
                        else apps.INSTALL_TYPE_USER)
        Installed.objects.safer_get_or_create(
            user=instance.user, addon=instance.addon,
            install_type=install_type)

    elif instance.type in [mkt.CONTRIB_REFUND, mkt.CONTRIB_CHARGEBACK]:
        purchases = AddonPurchase.objects.filter(addon=instance.addon,
                                                 user=instance.user)
        for p in purchases:
            log.debug('Changing addon purchase: %s, addon %s, user %s'
                      % (p.pk, instance.addon.pk, instance.user.pk))
            p.update(type=instance.type)

    cache.delete(memoize_key('users:purchase-ids', instance.user.pk))
Example #3
0
def create_addon_purchase(sender, instance, **kw):
    """
    When the contribution table is updated with the data from PayPal,
    update the addon purchase table. Will figure out if we need to add to or
    delete from the AddonPurchase table.
    """
    if (kw.get('raw') or instance.type not in [
            mkt.CONTRIB_PURCHASE, mkt.CONTRIB_REFUND, mkt.CONTRIB_CHARGEBACK
    ]):
        # Filter the types we care about. Forget about the rest.
        return

    log.info('Processing addon purchase type: {t}, addon {a}, user {u}'.format(
        t=unicode(mkt.CONTRIB_TYPES[instance.type]),
        a=instance.addon and instance.addon.pk,
        u=instance.user and instance.user.pk))

    if instance.is_inapp_simulation():
        log.info('Simulated in-app product {i} for contribution {c}: '
                 'not adding a purchase record'.format(
                     i=instance.inapp_product, c=instance))
        return

    if instance.type == mkt.CONTRIB_PURCHASE:
        log.debug('Creating addon purchase: addon %s, user %s' %
                  (instance.addon.pk, instance.user.pk))

        data = {'addon': instance.addon, 'user': instance.user}
        purchase, created = AddonPurchase.objects.safer_get_or_create(**data)
        purchase.update(type=mkt.CONTRIB_PURCHASE)
        from mkt.webapps.models import Installed  # Circular import
        # Ensure that devs have the correct installed object found
        # or created.
        #
        is_dev = instance.addon.has_author(
            instance.user, (mkt.AUTHOR_ROLE_OWNER, mkt.AUTHOR_ROLE_DEV))
        install_type = (apps.INSTALL_TYPE_DEVELOPER
                        if is_dev else apps.INSTALL_TYPE_USER)
        Installed.objects.safer_get_or_create(user=instance.user,
                                              addon=instance.addon,
                                              install_type=install_type)

    elif instance.type in [mkt.CONTRIB_REFUND, mkt.CONTRIB_CHARGEBACK]:
        purchases = AddonPurchase.objects.filter(addon=instance.addon,
                                                 user=instance.user)
        for p in purchases:
            log.debug('Changing addon purchase: %s, addon %s, user %s' %
                      (p.pk, instance.addon.pk, instance.user.pk))
            p.update(type=instance.type)

    cache.delete(memoize_key('users:purchase-ids', instance.user.pk))
Example #4
0
def create_addon_purchase(sender, instance, **kw):
    """
    When the contribution table is updated with the data from PayPal,
    update the addon purchase table. Will figure out if we need to add to or
    delete from the AddonPurchase table.
    """
    if (kw.get('raw') or instance.type not in [
            amo.CONTRIB_PURCHASE, amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK
    ]):
        # Whitelist the types we care about. Forget about the rest.
        return

    if not instance.user:
        # This could be an anonymous serverless in-app purchase.
        log.info('No user for contribution {c}; '
                 'not creating purchase record'.format(c=instance))
        return

    log.debug('Processing addon purchase type: %s, addon %s, user %s' %
              (unicode(amo.CONTRIB_TYPES[instance.type]), instance.addon.pk,
               instance.user.pk))

    if instance.type == amo.CONTRIB_PURCHASE:
        log.debug('Creating addon purchase: addon %s, user %s' %
                  (instance.addon.pk, instance.user.pk))

        data = {'addon': instance.addon, 'user': instance.user}
        purchase, created = AddonPurchase.objects.safer_get_or_create(**data)
        purchase.update(type=amo.CONTRIB_PURCHASE)
        from mkt.webapps.models import Installed  # Circular import
        # Ensure that devs have the correct installed object found
        # or created.
        #
        is_dev = instance.addon.has_author(
            instance.user, (amo.AUTHOR_ROLE_OWNER, amo.AUTHOR_ROLE_DEV))
        install_type = (apps.INSTALL_TYPE_DEVELOPER
                        if is_dev else apps.INSTALL_TYPE_USER)
        Installed.objects.safer_get_or_create(user=instance.user,
                                              addon=instance.addon,
                                              install_type=install_type)

    elif instance.type in [amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK]:
        purchases = AddonPurchase.objects.filter(addon=instance.addon,
                                                 user=instance.user)
        for p in purchases:
            log.debug('Changing addon purchase: %s, addon %s, user %s' %
                      (p.pk, instance.addon.pk, instance.user.pk))
            p.update(type=instance.type)

    cache.delete(memoize_key('users:purchase-ids', instance.user.pk))
Example #5
0
def create_addon_purchase(sender, instance, **kw):
    """
    When the contribution table is updated with the data from PayPal,
    update the addon purchase table. Will figure out if we need to add to or
    delete from the AddonPurchase table.
    """
    if (kw.get('raw') or
        instance.type not in [amo.CONTRIB_PURCHASE, amo.CONTRIB_REFUND,
                              amo.CONTRIB_CHARGEBACK]):
        # Whitelist the types we care about. Forget about the rest.
        return

    if not instance.user:
        # This could be an anonymous serverless in-app purchase.
        log.info('No user for contribution {c}; '
                 'not creating purchase record'.format(c=instance))
        return

    log.debug('Processing addon purchase type: %s, addon %s, user %s'
              % (unicode(amo.CONTRIB_TYPES[instance.type]),
                 instance.addon.pk, instance.user.pk))

    if instance.type == amo.CONTRIB_PURCHASE:
        log.debug('Creating addon purchase: addon %s, user %s'
                  % (instance.addon.pk, instance.user.pk))

        data = {'addon': instance.addon, 'user': instance.user}
        purchase, created = AddonPurchase.objects.safer_get_or_create(**data)
        purchase.update(type=amo.CONTRIB_PURCHASE)
        from mkt.webapps.models import Installed  # Circular import
        # Ensure that devs have the correct installed object found
        # or created.
        #
        is_dev = instance.addon.has_author(instance.user,
                 (amo.AUTHOR_ROLE_OWNER, amo.AUTHOR_ROLE_DEV))
        install_type = (apps.INSTALL_TYPE_DEVELOPER if is_dev
                        else apps.INSTALL_TYPE_USER)
        Installed.objects.safer_get_or_create(user=instance.user,
            addon=instance.addon, install_type=install_type)

    elif instance.type in [amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK]:
        purchases = AddonPurchase.objects.filter(addon=instance.addon,
                                                 user=instance.user)
        for p in purchases:
            log.debug('Changing addon purchase: %s, addon %s, user %s'
                      % (p.pk, instance.addon.pk, instance.user.pk))
            p.update(type=instance.type)

    cache.delete(memoize_key('users:purchase-ids', instance.user.pk))