def install(request): form = forms.ReceiptForm(request.DATA) if not form.is_valid(): return Response({'error_message': form.errors}, status=400) obj = form.cleaned_data['app'] type_ = install_type(request, obj) if type_ == apps.INSTALL_TYPE_DEVELOPER: receipt = install_record(obj, request, apps.INSTALL_TYPE_DEVELOPER) else: # The app must be public and if its a premium app, you # must have purchased it. if not obj.is_public(): log.info('App not public: %s' % obj.pk) return Response('App not public.', status=403) if (obj.is_premium() and not obj.has_purchased(request.amo_user)): # Apps that are premium but have no charge will get an # automatic purchase record created. This will ensure that # the receipt will work into the future if the price changes. if obj.premium and not obj.premium.price.price: log.info('Create purchase record: {0}'.format(obj.pk)) AddonPurchase.objects.get_or_create(addon=obj, user=request.amo_user, type=CONTRIB_NO_CHARGE) else: log.info('App not purchased: %s' % obj.pk) return Response('You have not purchased this app.', status=402) receipt = install_record(obj, request, type_) utils_record(request, obj) return Response({'receipt': receipt}, status=201)
def install(request): form = forms.ReceiptForm(request.DATA) if not form.is_valid(): return Response({'error_message': form.errors}, status=400) obj = form.cleaned_data['app'] type_ = install_type(request, obj) if type_ == apps.INSTALL_TYPE_DEVELOPER: receipt = install_record(obj, request, apps.INSTALL_TYPE_DEVELOPER) else: # The app must be public and if its a premium app, you # must have purchased it. if not obj.is_public(): log.info('App not public: %s' % obj.pk) return Response('App not public.', status=403) if (obj.is_premium() and not obj.has_purchased(request.user)): # Apps that are premium but have no charge will get an # automatic purchase record created. This will ensure that # the receipt will work into the future if the price changes. if obj.premium and not obj.premium.price.price: log.info('Create purchase record: {0}'.format(obj.pk)) AddonPurchase.objects.get_or_create(addon=obj, user=request.user, type=CONTRIB_NO_CHARGE) else: log.info('App not purchased: app ID={a}; user={u}'.format( a=obj.pk, u=request.user)) return Response('You have not purchased this app.', status=402) receipt = install_record(obj, request, type_) utils_record(request, obj) return Response({'receipt': receipt}, status=201)
def handle(self, bundle, request, **kwargs): form = ReceiptForm(bundle.data) if not form.is_valid(): raise self.form_errors(form) bundle.obj = form.cleaned_data["app"] type_ = install_type(request, bundle.obj) if type_ == apps.INSTALL_TYPE_DEVELOPER: return self.record(bundle, request, apps.INSTALL_TYPE_DEVELOPER) # The app must be public and if its a premium app, you # must have purchased it. if not bundle.obj.is_public(): log.info("App not public: %s" % bundle.obj.pk) raise http_error(http.HttpForbidden, "App not public.") if bundle.obj.is_premium() and not bundle.obj.has_purchased(request.amo_user): # Apps that are premium but have no charge will get an # automatic purchase record created. This will ensure that # the receipt will work into the future if the price changes. if bundle.obj.premium and not bundle.obj.premium.price.price: log.info("Create purchase record: {0}".format(bundle.obj.pk)) AddonPurchase.objects.get_or_create(addon=bundle.obj, user=request.amo_user, type=CONTRIB_NO_CHARGE) else: log.info("App not purchased: %s" % bundle.obj.pk) raise http_error(HttpPaymentRequired, "You have not purchased this app.") return self.record(bundle, request, type_)
def install(request): request._request.CORS = ['POST'] form = InstallForm(request.DATA, request=request) if form.is_valid(): app = form.cleaned_data['app'] type_ = install_type(request, app) # Users can't install non-public apps. Developers can though. if not app.is_public() and type_ == INSTALL_TYPE_USER: log.info('App not public: {0}'.format(app.pk)) raise PermissionDenied if not request.amo_user: record(request, app) else: installed, created = Installed.objects.get_or_create( addon=app, user=request.amo_user, install_type=type_) record(request, app) if not created: return Response(status=202) return Response(status=201) return Response(status=400)
def handle(self, bundle, request, **kwargs): form = ReceiptForm(bundle.data) if not form.is_valid(): raise self.form_errors(form) bundle.obj = form.cleaned_data['app'] type_ = install_type(request, bundle.obj) if type_ == apps.INSTALL_TYPE_DEVELOPER: return self.record(bundle, request, apps.INSTALL_TYPE_DEVELOPER) # The app must be public and if its a premium app, you # must have purchased it. if not bundle.obj.is_public(): log.info('App not public: %s' % bundle.obj.pk) raise http_error(http.HttpForbidden, 'App not public.') if (bundle.obj.is_premium() and not bundle.obj.has_purchased(request.amo_user)): # Apps that are premium but have no charge will get an # automatic purchase record created. This will ensure that # the receipt will work into the future if the price changes. if bundle.obj.premium and not bundle.obj.premium.price.price: log.info('Create purchase record: {0}'.format(bundle.obj.pk)) AddonPurchase.objects.get_or_create(addon=bundle.obj, user=request.amo_user, type=CONTRIB_NO_CHARGE) else: log.info('App not purchased: %s' % bundle.obj.pk) raise http_error(HttpPaymentRequired, 'You have not purchased this app.') # Anonymous users will fall through, they don't need anything else # handling. if request.user.is_authenticated(): return self.record(bundle, request, type_)