Пример #1
0
 def setUp(self):
     super(TestSimulatedInAppProduct, self).setUp()
     self.contribution = Contribution.objects.create()
     self.inapp.webapp = None
     self.inapp.simulate = json.dumps({'result': 'postback'})
     self.inapp.stub = True
     self.inapp.save()
     self.product = SimulatedInAppProduct(self.inapp)
Пример #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
        )

        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)
Пример #3
0
class TestSimulatedInAppProduct(InAppPurchaseTest):

    def setUp(self):
        super(TestSimulatedInAppProduct, self).setUp()
        self.contribution = Contribution.objects.create()
        self.inapp.webapp = None
        self.inapp.simulate = json.dumps({'result': 'postback'})
        self.inapp.stub = True
        self.inapp.save()
        self.product = SimulatedInAppProduct(self.inapp)

    def test_inapp_product(self):
        eq_(self.product.id(), self.inapp.pk)
        eq_(self.product.name(), unicode(self.inapp.name))
        eq_(self.product.addon(), None)
        eq_(self.product.price(), self.inapp.price)
        eq_(self.product.icons()[64], absolutify(self.inapp.logo_url))
        eq_(self.product.application_size(), None)
        eq_(self.product.description(),
            'This is a stub product for testing only')
        eq_(self.product.simulation(), {'result': 'postback'})

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