def save(self): if "paypal_id" in self.cleaned_data: self.addon.paypal_id = self.cleaned_data["paypal_id"] self.addon.support_email = self.cleaned_data["support_email"] self.addon.save() if "price" in self.cleaned_data: premium = self.addon.premium if not premium: premium = AddonPremium() premium.addon = self.addon premium.price = self.cleaned_data["price"] premium.save() upsell = self.addon.upsold if self.cleaned_data["do_upsell"] and self.cleaned_data["text"] and self.cleaned_data["free"]: # Check if this app was already a premium version for another app. if upsell and upsell.free != self.cleaned_data["free"]: upsell.delete() if not upsell: upsell = AddonUpsell(premium=self.addon) upsell.text = self.cleaned_data["text"] upsell.free = self.cleaned_data["free"] upsell.save() elif not self.cleaned_data["do_upsell"] and upsell: upsell.delete()
def test_is_complete(self): ap = AddonPremium(addon=self.addon) assert not ap.is_complete() ap.price = self.tier_one assert not ap.is_complete() ap.addon.paypal_id = "asd" assert ap.is_complete()
def save(self): if 'price' in self.cleaned_data: premium = self.addon.premium if not premium: premium = AddonPremium() premium.addon = self.addon premium.price = self.cleaned_data['price'] premium.save() upsell = self.addon.upsold if (self.cleaned_data['do_upsell'] and self.cleaned_data['text'] and self.cleaned_data['free']): # Check if this app was already a premium version for another app. if upsell and upsell.free != self.cleaned_data['free']: upsell.delete() if not upsell: upsell = AddonUpsell(premium=self.addon) upsell.text = self.cleaned_data['text'] upsell.free = self.cleaned_data['free'] upsell.save() elif not self.cleaned_data['do_upsell'] and upsell: upsell.delete() self.addon.premium_type = self.cleaned_data['premium_type'] self.addon.support_email = self.cleaned_data['support_email'] self.addon.save() # If they checked later in the wizard and then decided they want # to keep it free, push to pending. if (not self.addon.paypal_id and self.addon.is_incomplete() and not self.addon.needs_paypal()): self.addon.mark_done()
def save(self): if 'paypal_id' in self.cleaned_data: self.addon.paypal_id = self.cleaned_data['paypal_id'] self.addon.support_email = self.cleaned_data['support_email'] self.addon.save() if 'price' in self.cleaned_data: premium = self.addon.premium if not premium: premium = AddonPremium() premium.addon = self.addon premium.price = self.cleaned_data['price'] premium.save() upsell = self.addon.upsold if (self.cleaned_data['do_upsell'] and self.cleaned_data['text'] and self.cleaned_data['free']): # Check if this app was already a premium version for another app. if upsell and upsell.free != self.cleaned_data['free']: upsell.delete() if not upsell: upsell = AddonUpsell(premium=self.addon) upsell.text = self.cleaned_data['text'] upsell.free = self.cleaned_data['free'] upsell.save() elif not self.cleaned_data['do_upsell'] and upsell: upsell.delete()
def save_price(self, obj, price): premium = obj.premium if not premium: premium = AddonPremium() premium.addon = obj premium.price = Price.objects.active().get(price=price) premium.save()
def save(self): if self.cleaned_data['paypal_id']: if (self.addon.paypal_id and self.addon.paypal_id != self.cleaned_data['paypal_id'] and self.addon.premium and self.addon.premium.paypal_permissions_token): # If a user changes their paypal id, then we need # to nuke the token. self.addon.premium.paypal_permissions_token = '' self.addon.premium.save() self.addon.paypal_id = self.cleaned_data['paypal_id'] self.addon.support_email = self.cleaned_data['support_email'] self.addon.save() if self.cleaned_data['price']: premium = self.addon.premium if not premium: premium = AddonPremium() premium.addon = self.addon premium.price = self.cleaned_data['price'] premium.save() upsell = self.addon.upsold if (self.cleaned_data['do_upsell'] and self.cleaned_data['text'] and self.cleaned_data['free']): if not upsell: upsell = AddonUpsell(premium=self.addon) upsell.text = self.cleaned_data['text'] upsell.free = self.cleaned_data['free'] upsell.save() elif not self.cleaned_data['do_upsell'] and upsell: upsell.delete()
def save(self): if 'paypal_id' in self.cleaned_data: self.addon.paypal_id = self.cleaned_data['paypal_id'] self.addon.support_email = self.cleaned_data['support_email'] self.addon.save() if 'price' in self.cleaned_data: premium = self.addon.premium if not premium: premium = AddonPremium() premium.addon = self.addon premium.price = self.cleaned_data['price'] premium.save() upsell = self.addon.upsold if (self.cleaned_data['do_upsell'] and self.cleaned_data['text'] and self.cleaned_data['free']): if not upsell: upsell = AddonUpsell(premium=self.addon) upsell.text = self.cleaned_data['text'] upsell.free = self.cleaned_data['free'] upsell.save() elif not self.cleaned_data['do_upsell'] and upsell: upsell.delete()
def save(self): if 'price' in self.cleaned_data: premium = self.addon.premium if not premium: premium = AddonPremium() premium.addon = self.addon premium.price = self.cleaned_data['price'] premium.save() upsell = self.addon.upsold if self.cleaned_data['free']: # Check if this app was already a premium version for another app. if upsell and upsell.free != self.cleaned_data['free']: upsell.delete() if not upsell: upsell = AddonUpsell(premium=self.addon) upsell.free = self.cleaned_data['free'] upsell.save() elif not self.cleaned_data['free'] and upsell: upsell.delete() # Check for free -> paid for already public apps. premium_type = self.cleaned_data['premium_type'] if (self.addon.premium_type == amo.ADDON_FREE and premium_type in amo.ADDON_PREMIUMS and self.addon.status == amo.STATUS_PUBLIC): # Free -> paid for public apps trigger re-review. log.info(u'[Webapp:%s] (Re-review) Public app, free -> paid.' % ( self.addon)) RereviewQueue.flag(self.addon, amo.LOG.REREVIEW_FREE_TO_PAID) self.addon.premium_type = premium_type if self.addon.premium and waffle.switch_is_active('currencies'): currencies = self.cleaned_data['currencies'] self.addon.premium.update(currencies=currencies) self.addon.save() # If they checked later in the wizard and then decided they want # to keep it free, push to pending. if not self.addon.needs_paypal() and self.addon.is_incomplete(): self.addon.mark_done()
def save(self): if "price" in self.cleaned_data: premium = self.addon.premium if not premium: premium = AddonPremium() premium.addon = self.addon premium.price = self.cleaned_data["price"] premium.save() upsell = self.addon.upsold if self.cleaned_data["free"]: # Check if this app was already a premium version for another app. if upsell and upsell.free != self.cleaned_data["free"]: upsell.delete() if not upsell: upsell = AddonUpsell(premium=self.addon) upsell.free = self.cleaned_data["free"] upsell.save() elif upsell: upsell.delete() self.addon.update(make_public=self.cleaned_data["make_public"])
def test_price_locale(self): ap = AddonPremium(addon=self.addon, price=self.tier_one) eq_(ap.get_price_locale('CAD'), 'CA$3.01')
def test_has_price(self): ap = AddonPremium(addon=self.addon, price=self.tier_one) eq_(ap.has_price(), True) self.tier_one.update(price=Decimal('0.00')) eq_(ap.has_price(), False)
def test_has_valid_permissions_token_ignore(self): ap = AddonPremium(addon=self.addon) assert ap.has_valid_permissions_token() ap.paypal_permissions_token = 'asd' assert ap.has_valid_permissions_token()
def test_has_valid_permissions_token(self, check_permission): ap = AddonPremium(addon=self.addon) assert not ap.has_valid_permissions_token() check_permission.return_value = True ap.paypal_permissions_token = 'some_token' assert ap.has_valid_permissions_token()
def save(self): toggle = self.is_toggling() upsell = self.addon.upsold is_premium = self.addon.premium_type in amo.ADDON_PREMIUMS if toggle == 'paid' and self.addon.premium_type == amo.ADDON_FREE: # Toggle free apps to paid by giving them a premium object. premium = self.addon.premium if not premium: log.info('[1@%s] New AddonPremium object' % self.addon.pk) premium = AddonPremium() premium.addon = self.addon premium.price = self._initial_price() premium.save() self.addon.premium_type = amo.ADDON_PREMIUM self.addon.status = amo.STATUS_NULL elif toggle == 'free' and is_premium: # If the app is paid and we're making it free, remove it as an # upsell (if an upsell exists). upsell = self.addon.upsold if upsell: log.debug('[1@%s] Removing upsell; switching to free' % self.addon.pk) upsell.delete() log.debug('[1@%s] Removing app payment account' % self.addon.pk) AddonPaymentAccount.objects.filter(addon=self.addon).delete() log.debug('[1@%s] Setting app premium_type to FREE' % self.addon.pk) self.addon.premium_type = amo.ADDON_FREE if self.addon.status == amo.STATUS_NULL: # If the app was marked as incomplete because it didn't have a # payment account, mark it as either its highest status, or as # PENDING if it was never reviewed (highest_status == NULL). log.debug('[1@%s] Switching app to free, reverting incomplete ' 'status to highest_status (%s) or pending if null.' % (self.addon.pk, self.addon.highest_status)) self.addon.status = ( self.addon.highest_status if self.addon.highest_status != amo.STATUS_NULL else amo.STATUS_PENDING) elif is_premium: # The dev is submitting updates for payment data about a paid app. self.addon.premium_type = ( amo.ADDON_PREMIUM_INAPP if self.cleaned_data.get('allow_inapp') else amo.ADDON_PREMIUM) if 'price' in self.cleaned_data: log.debug('[1@%s] Updating app price (%s)' % (self.addon.pk, self.cleaned_data['price'])) self.addon.premium.price = self.cleaned_data['price'] if 'currencies' in self.cleaned_data: log.debug('[1@%s] Updating app currencies (%s)' % (self.addon.pk, self.cleaned_data['currencies'])) self.addon.premium.currencies = self.cleaned_data['currencies'] self.addon.premium.save() log.info('[1@%s] Saving app payment changes.' % self.addon.pk) self.addon.save()
def test_add_currency(self): ap = AddonPremium(addon=self.addon, price=self.tier_one, currencies=['USD', 'CAD']) eq_(len(ap.supported_currencies()), 2) eq_(ap.supported_currencies()[1][0], 'CAD')
def test_currencies(self): ap = AddonPremium(addon=self.addon, price=self.tier_one) assert self.tier_one.currencies() eq_(len(ap.supported_currencies()), 1) eq_(ap.supported_currencies()[0][0], 'USD')
def test_has_permissions_token_ignore(self): ap = AddonPremium(addon=self.addon) assert ap.has_permissions_token() ap.paypal_permissions_token = 'asd' assert ap.has_permissions_token()
def test_has_permissions_token(self): ap = AddonPremium(addon=self.addon) assert not ap.has_permissions_token() ap.paypal_permissions_token = 'asd' assert ap.has_permissions_token()
def _make_premium(self): if self.addon.premium: return self.addon.premium log.info('New AddonPremium object for addon %s' % self.addon.pk) return AddonPremium(addon=self.addon, price=self._initial_price())