示例#1
0
 def test_free_with_in_app_requires_in_app(self):
     self.platforms.update(price='free', allow_inapp='False')
     form = forms_payments.PremiumForm(self.platforms, **self.kwargs)
     assert not form.is_valid()
示例#2
0
 def test_initial(self):
     form = forms_payments.PremiumForm(**self.kwargs)
     eq_(form._initial_price_id(), Price.objects.get(price='0.99').pk)
示例#3
0
 def test_initial_not_there(self):
     Price.objects.get(price='0.99').update(active=False)
     form = forms_payments.PremiumForm(**self.kwargs)
     eq_(form._initial_price_id(), None)
示例#4
0
 def test_not_is_paid_free(self):
     self.addon.update(premium_type=amo.ADDON_FREE)
     form = forms_payments.PremiumForm(data=self.platforms, **self.kwargs)
     eq_(form.is_paid(), False)
示例#5
0
 def test_can_set_desktop_for_packaged_app(self):
     self.platforms = {'free_platforms': ['free-desktop']}
     self.addon.update(is_packaged=True)
     form = forms_payments.PremiumForm(data=self.platforms, **self.kwargs)
     assert form.is_valid(), form.errors
示例#6
0
 def test_is_paid_free_inapp(self):
     self.addon.update(premium_type=amo.ADDON_FREE_INAPP)
     form = forms_payments.PremiumForm(data=self.platforms, **self.kwargs)
     eq_(form.is_paid(), True)
示例#7
0
 def test_free_inapp_price_required(self):
     self.addon.update(premium_type=amo.ADDON_FREE_INAPP)
     form = forms_payments.PremiumForm(data=self.platforms, **self.kwargs)
     assert not form.is_valid()
示例#8
0
 def test_is_paid_premium(self):
     self.make_premium(self.addon)
     form = forms_payments.PremiumForm(data=self.platforms, **self.kwargs)
     eq_(form.is_paid(), True)
示例#9
0
 def test_is_paid_premium_inapp(self):
     self.addon.update(premium_type=mkt.ADDON_PREMIUM_INAPP)
     form = forms_payments.PremiumForm(data=self.platforms, **self.kwargs)
     eq_(form.is_paid(), True)
示例#10
0
def payments(request, addon_id, addon, webapp=False):
    premium_form = forms_payments.PremiumForm(request.POST or None,
                                              request=request,
                                              addon=addon,
                                              user=request.amo_user)

    region_form = forms.RegionForm(request.POST or None,
                                   product=addon,
                                   request=request)

    upsell_form = forms_payments.UpsellForm(request.POST or None,
                                            addon=addon,
                                            user=request.amo_user)

    account_list_form = forms_payments.AccountListForm(request.POST or None,
                                                       addon=addon,
                                                       user=request.amo_user)

    if request.method == 'POST':

        success = all(
            form.is_valid() for form in
            [premium_form, region_form, upsell_form, account_list_form])

        if success:
            region_form.save()

            try:
                premium_form.save()
            except client.Error as err:
                success = False
                log.error('Error setting payment information (%s)' % err)
                messages.error(
                    request,
                    _(u'We encountered a problem connecting to the '
                      u'payment server.'))
                raise  # We want to see these exceptions!

            is_free_inapp = addon.premium_type == amo.ADDON_FREE_INAPP
            is_now_paid = (addon.premium_type in amo.ADDON_PREMIUMS
                           or is_free_inapp)

            # If we haven't changed to a free app, check the upsell.
            if is_now_paid and success:
                try:
                    if not is_free_inapp:
                        upsell_form.save()
                    account_list_form.save()
                except client.Error as err:
                    log.error('Error saving payment information (%s)' % err)
                    messages.error(
                        request,
                        _(u'We encountered a problem connecting to '
                          u'the payment server.'))
                    success = False
                    raise  # We want to see all the solitude errors now.

        # If everything happened successfully, give the user a pat on the back.
        if success:
            messages.success(request, _('Changes successfully saved.'))
            return redirect(addon.get_dev_url('payments'))

    # TODO: refactor this (bug 945267)
    is_packaged = addon.is_packaged
    android_payments_enabled = waffle.flag_is_active(request,
                                                     'android-payments')
    android_packaged_enabled = waffle.flag_is_active(request,
                                                     'android-packaged')
    desktop_packaged_enabled = waffle.flag_is_active(request,
                                                     'desktop-packaged')

    # If android payments is not allowed then firefox os must
    # be 'checked' and android-mobile and android-tablet should not be.
    invalid_paid_platform_state = []

    # If isn't packaged or it is packaged and the android-packaged flag is on
    # then we should check that desktop isn't set to True.
    if not is_packaged or (is_packaged and desktop_packaged_enabled):
        invalid_paid_platform_state.append(('desktop', True))

    if not android_payments_enabled:
        # When android-payments is off...
        # If isn't packaged or it is packaged and the android-packaged flag is on
        # then we should check for the state of android-mobile and android-tablet.
        if not is_packaged or (is_packaged and android_packaged_enabled):
            invalid_paid_platform_state += [('android-mobile', True),
                                            ('android-tablet', True)]
        invalid_paid_platform_state.append(('firefoxos', False))

    cannot_be_paid = (addon.premium_type == amo.ADDON_FREE
                      and any(premium_form.device_data['free-%s' % x] == y
                              for x, y in invalid_paid_platform_state))

    try:
        tier_zero = Price.objects.get(price='0.00', active=True)
        tier_zero_id = tier_zero.pk
    except Price.DoesNotExist:
        tier_zero = None
        tier_zero_id = ''

    # Get the regions based on tier zero. This should be all the
    # regions with payments enabled.
    paid_region_ids_by_slug = []
    if tier_zero:
        paid_region_ids_by_slug = tier_zero.region_ids_by_slug()

    provider = get_provider()
    paid_platform_names = [
        unicode(platform[1])
        for platform in PAID_PLATFORMS(request, is_packaged)
    ]

    return jingo.render(
        request,
        'developers/payments/premium.html',
        {
            'addon':
            addon,
            'webapp':
            webapp,
            'premium':
            addon.premium,
            'form':
            premium_form,
            'upsell_form':
            upsell_form,
            'tier_zero_id':
            tier_zero_id,
            'region_form':
            region_form,
            'DEVICE_LOOKUP':
            DEVICE_LOOKUP,
            'is_paid': (addon.premium_type in amo.ADDON_PREMIUMS
                        or addon.premium_type == amo.ADDON_FREE_INAPP),
            'cannot_be_paid':
            cannot_be_paid,
            'paid_platform_names':
            paid_platform_names,
            'has_incomplete_status':
            addon.status == amo.STATUS_NULL,
            'is_packaged':
            addon.is_packaged,
            # Bango values
            'account_form':
            provider.forms['account'](),
            'account_list_form':
            account_list_form,
            # Waffles
            'api_pricelist_url':
            reverse('price-list'),
            'payment_methods': {
                PAYMENT_METHOD_ALL: _('All'),
                PAYMENT_METHOD_CARD: _('Credit card'),
                PAYMENT_METHOD_OPERATOR: _('Carrier'),
            },
            'all_paid_region_ids_by_slug':
            paid_region_ids_by_slug,
            'provider':
            provider,
        })