Beispiel #1
0
 def setUp(self):
     super(TestInAppProduct, self).setUp()
     self.contribution = Contribution.objects.create(
         user=self.user,
         addon=self.addon,
     )
     self.product = InAppProduct(self.inapp)
Beispiel #2
0
    def post(self, request, *args, **kwargs):
        form = PrepareInAppForm(request.DATA)
        if not form.is_valid():
            app_pay_cef.log(
                request._request,
                'Preparing InApp JWT Failed',
                'preparing_inapp_jwt_failed',
                'Preparing InApp JWT Failed error: {0}'.format(form.errors),
                severity=3
            )
            return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)

        inapp = form.cleaned_data['inapp']

        app_pay_cef.log(
            request._request,
            'Preparing InApp JWT',
            'preparing_inapp_jwt',
            'Preparing InApp JWT for: {0}'.format(inapp.pk), severity=3
        )

        token = get_product_jwt(
            InAppProduct(inapp),
            client_data=ClientData.get_or_create(request._request),
            lang=request._request.LANG,
            source=request._request.REQUEST.get('src', ''),
        )

        return Response(token, status=status.HTTP_201_CREATED)
Beispiel #3
0
def debug(request, addon):
    if not settings.DEBUG:
        raise http.Http404

    context = {
        'app': addon,
        'inapps': [],
        'urls': {
            'es': '%s/apps/webapp/%s' % (settings.ES_URLS[0], addon.pk)
        },
    }

    if addon.is_premium():
        context['app_jwt'] = _prepare_pay(request, addon)['webpayJWT']

        for inapp in addon.inappproduct_set.all():
            contribution = Contribution.objects.create(
                addon=addon,
                inapp_product=inapp,
            )
            context['inapps'].append({
                'inapp':
                inapp,
                'jwt':
                get_product_jwt(
                    InAppProduct(inapp),
                    contribution,
                )['webpayJWT'],
            })

    return render(request, 'developers/debug.html', context)
Beispiel #4
0
    def post(self, request, *args, **kwargs):
        form = PrepareInAppForm(request.DATA)
        if not form.is_valid():
            app_pay_cef.log(
                request._request,
                'Preparing InApp JWT Failed',
                'preparing_inapp_jwt_failed',
                'Preparing InApp JWT Failed error: {0}'.format(form.errors),
                severity=3
            )
            return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)

        inapp = form.cleaned_data['inapp']

        app_pay_cef.log(
            request._request,
            'Preparing InApp JWT',
            'preparing_inapp_jwt',
            'Preparing InApp JWT for: {0}'.format(inapp.pk), severity=3
        )

        log.debug('Starting purchase of in app: {0}'.format(inapp.pk))

        contribution = Contribution.objects.create(
            addon_id=inapp.webapp and inapp.webapp.pk,
            inapp_product=inapp,
            # In-App payments are unauthenticated so we have no user
            # and therefore can't determine a meaningful region.
            amount=None,
            paykey=None,
            price_tier=inapp.price,
            source=request._request.GET.get('src', ''),
            source_locale=request._request.LANG,
            type=mkt.CONTRIB_PENDING,
            user=None,
            uuid=str(uuid.uuid4()),
        )

        log.info('Storing contrib for uuid: {0}'.format(contribution.uuid))

        if inapp.simulate:
            log.info('Preparing in-app JWT simulation for {i}'
                     .format(i=inapp))
            product = SimulatedInAppProduct(inapp)
        else:
            log.info('Preparing in-app JWT for {i}'.format(i=inapp))
            product = InAppProduct(inapp)
        token = get_product_jwt(product, contribution)

        return Response(token, status=status.HTTP_201_CREATED)
Beispiel #5
0
 def setUp(self):
     super(TestInAppProduct, self).setUp()
     self.product = InAppProduct(self.inapp)
     self.token = get_product_jwt(self.product)
     self.contribution = Contribution.objects.get()
Beispiel #6
0
class TestInAppProduct(InAppPurchaseTest):

    def setUp(self):
        super(TestInAppProduct, self).setUp()
        self.product = InAppProduct(self.inapp)
        self.token = get_product_jwt(self.product)
        self.contribution = Contribution.objects.get()

    def test_external_id_with_no_domain(self):
        with self.settings(DOMAIN=None):
            eq_(self.product.external_id(),
                'inapp.marketplace-dev:{0}'.format(self.inapp.pk))

    def test_external_id_with_domain(self):
        with self.settings(DOMAIN='marketplace.allizom.org'):
            eq_(self.product.external_id(),
                'inapp.marketplace:{0}'.format(self.inapp.pk))

    def test_inapp_product(self):
        eq_(self.product.id(), self.inapp.pk)
        eq_(self.product.name(), unicode(self.inapp.name))
        eq_(self.product.addon(), self.inapp.webapp)
        eq_(self.product.amount(regions.US), None)
        eq_(self.product.price(), self.inapp.price)
        eq_(self.product.icons()[64], absolutify(self.inapp.logo_url))
        eq_(self.product.description(), self.inapp.webapp.description)
        eq_(self.product.application_size(), None)
        eq_(self.product.seller_uuid(), (self.inapp
                                             .webapp
                                             .single_pay_account()
                                             .payment_account
                                             .solitude_seller
                                             .uuid))

        product_data = self.product.product_data(self.contribution)
        eq_(product_data['contrib_uuid'], self.contribution.uuid)
        eq_(product_data['seller_uuid'], self.product.seller_uuid())
        eq_(product_data['addon_id'], self.product.addon().pk)
        eq_(product_data['inapp_id'], self.product.id())
        eq_(product_data['application_size'], self.product.application_size())
Beispiel #7
0
class TestInAppProduct(InAppPurchaseTest):

    def setUp(self):
        super(TestInAppProduct, self).setUp()
        self.contribution = Contribution.objects.create(
            user=self.user,
            addon=self.addon,
        )
        self.product = InAppProduct(self.inapp)

    def test_external_id_with_no_domain(self):
        with self.settings(DOMAIN=None):
            eq_(self.product.external_id(),
                'inapp.marketplace-dev:{0}'.format(self.inapp.pk))

    def test_external_id_with_domain(self):
        with self.settings(DOMAIN='marketplace.allizom.org'):
            eq_(self.product.external_id(),
                'inapp.marketplace:{0}'.format(self.inapp.pk))

    def test_inapp_product(self):
        eq_(self.product.id(), self.inapp.pk)
        eq_(self.product.name(), unicode(self.inapp.name))
        eq_(self.product.addon(), self.inapp.webapp)
        eq_(self.product.price(), self.inapp.price)
        eq_(self.product.icons()[64], absolutify(self.inapp.logo_url))
        eq_(self.product.description(), self.inapp.webapp.description)
        eq_(self.product.application_size(), None)
        eq_(self.product.simulation(), None)

        product_data = self.product.product_data(self.contribution)
        eq_(product_data['contrib_uuid'], self.contribution.uuid)
        eq_(product_data['addon_id'], self.product.addon().pk)
        eq_(product_data['inapp_id'], self.product.id())
        eq_(product_data['application_size'], self.product.application_size())
        eq_(product_data['public_id'], self.public_id)

    def test_no_url(self):
        self.inapp.logo_url = None
        with self.settings(MEDIA_URL='/media/'):
            eq_(self.product.icons()[64],
                'http://testserver/media/img/mkt/icons/rocket-64.png')

    def test_no_user(self):
        product_data = self.product.product_data(self.contribution)
        ok_('buyer_email' not in product_data)
Beispiel #8
0
 def setUp(self):
     super(TestInAppProduct, self).setUp()
     self.product = InAppProduct(self.inapp)
     self.token = get_product_jwt(self.product)
     self.contribution = Contribution.objects.get()
Beispiel #9
0
class TestInAppProduct(InAppPurchaseTest):
    def setUp(self):
        super(TestInAppProduct, self).setUp()
        self.product = InAppProduct(self.inapp)
        self.token = get_product_jwt(self.product)
        self.contribution = Contribution.objects.get()

    def test_external_id_with_no_domain(self):
        with self.settings(DOMAIN=None):
            eq_(self.product.external_id(),
                'inapp.marketplace-dev:{0}'.format(self.inapp.pk))

    def test_external_id_with_domain(self):
        with self.settings(DOMAIN='marketplace.allizom.org'):
            eq_(self.product.external_id(),
                'inapp.marketplace:{0}'.format(self.inapp.pk))

    def test_inapp_product(self):
        eq_(self.product.id(), self.inapp.pk)
        eq_(self.product.name(), unicode(self.inapp.name))
        eq_(self.product.addon(), self.inapp.webapp)
        eq_(self.product.amount(regions.US), None)
        eq_(self.product.price(), self.inapp.price)
        eq_(self.product.icons()[64], absolutify(self.inapp.logo_url))
        eq_(self.product.description(), self.inapp.webapp.description)
        eq_(self.product.application_size(), None)
        eq_(self.product.seller_uuid(), (self.inapp.webapp.single_pay_account(
        ).payment_account.solitude_seller.uuid))

        product_data = self.product.product_data(self.contribution)
        eq_(product_data['contrib_uuid'], self.contribution.uuid)
        eq_(product_data['seller_uuid'], self.product.seller_uuid())
        eq_(product_data['addon_id'], self.product.addon().pk)
        eq_(product_data['inapp_id'], self.product.id())
        eq_(product_data['application_size'], self.product.application_size())
Beispiel #10
0
class TestInAppProduct(InAppPurchaseTest):
    def setUp(self):
        super(TestInAppProduct, self).setUp()
        self.contribution = Contribution.objects.create(
            user=self.user,
            addon=self.addon,
        )
        self.product = InAppProduct(self.inapp)

    def test_external_id_with_no_domain(self):
        with self.settings(DOMAIN=None):
            eq_(self.product.external_id(),
                'inapp.marketplace-dev:{0}'.format(self.inapp.pk))

    def test_external_id_with_domain(self):
        with self.settings(DOMAIN='marketplace.allizom.org'):
            eq_(self.product.external_id(),
                'inapp.marketplace:{0}'.format(self.inapp.pk))

    def test_inapp_product(self):
        eq_(self.product.id(), self.inapp.pk)
        eq_(self.product.name(), unicode(self.inapp.name))
        eq_(self.product.addon(), self.inapp.webapp)
        eq_(self.product.price(), self.inapp.price)
        eq_(self.product.icons()[64], absolutify(self.inapp.logo_url))
        eq_(self.product.description(), self.inapp.webapp.description)
        eq_(self.product.application_size(), None)

        product_data = self.product.product_data(self.contribution)
        eq_(product_data['contrib_uuid'], self.contribution.uuid)
        eq_(product_data['addon_id'], self.product.addon().pk)
        eq_(product_data['inapp_id'], self.product.id())
        eq_(product_data['application_size'], self.product.application_size())
        eq_(product_data['public_id'], self.public_id)
Beispiel #11
0
class TestInAppProduct(InAppPurchaseTest):

    def setUp(self):
        super(TestInAppProduct, self).setUp()
        self.contribution = Contribution.objects.create(
            user=self.user,
            addon=self.addon,
        )
        self.product = InAppProduct(self.inapp)

    def test_external_id_with_no_domain(self):
        with self.settings(DOMAIN=None):
            eq_(self.product.external_id(),
                'inapp.marketplace-dev:{0}'.format(self.inapp.pk))

    def test_external_id_with_domain(self):
        with self.settings(DOMAIN='marketplace.allizom.org'):
            eq_(self.product.external_id(),
                'inapp.marketplace:{0}'.format(self.inapp.pk))

    def test_inapp_product(self):
        eq_(self.product.id(), self.inapp.pk)
        eq_(self.product.name(), unicode(self.inapp.name))
        eq_(self.product.addon(), self.inapp.webapp)
        eq_(self.product.price(), self.inapp.price)
        eq_(self.product.icons()[64], absolutify(self.inapp.logo_url))
        eq_(self.product.description(), self.inapp.webapp.description)
        eq_(self.product.application_size(), None)

        product_data = self.product.product_data(self.contribution)
        eq_(product_data['contrib_uuid'], self.contribution.uuid)
        eq_(product_data['addon_id'], self.product.addon().pk)
        eq_(product_data['inapp_id'], self.product.id())
        eq_(product_data['application_size'], self.product.application_size())
        eq_(product_data['public_id'], self.public_id)