Exemple #1
0
def iap_process_receipt(request, receipt_data):
    """
    Verifies the receipt, and processes the purchase.
    """
    def response():
        return {
            'balance': economy.balance(request.user),
            'shop_brushes': Brush.for_shop(viewer=request.user,
                                           request=request),
        }

    #TODO To be safer against botting, the receipt_data uniqueness constraint
    # needs to be done atomically.
    if IapReceipt.objects.filter(receipt_data=receipt_data).exists():
        # Already processed this receipt, fail silently.
        return response()

    receipt = IapReceipt.objects.create(
        purchaser=request.user,
        receipt_data=receipt_data,
        timestamp=Now(),
    )

    try:
        receipt.verify()
        Metrics.receipt_verification_success.record(request)
    except ValidationError:
        Metrics.receipt_verification_error.record(request)

    if receipt.verified:
        deliver_product(request.user, receipt.product_id)

        return response()
Exemple #2
0
 def test_not_banned(self):
     IPBlock.objects.create(
         ip='.'.join(reversed(self.ip.split('.'))),
         moderator=self.staff,
         timestamp=Now(),
     )
     self.assertFalse(is_ip_blocked(self.request))
Exemple #3
0
 def test_banned(self):
     IPBlock.objects.create(
         ip=self.ip,
         moderator=self.staff,
         timestamp=Now(),
     )
     self.assertTrue(is_ip_blocked(self.request))
Exemple #4
0
 def after_setUp(self):
     self.ip = '13.33.33.7'
     IPBlock.objects.create(
         ip=self.ip,
         moderator=create_staff(),
         timestamp=Now(),
     )
     self.request = FakeRequest()
     self.request.META['REMOTE_ADDR'] = self.ip
    def append(cls, **kwargs):
        """ Ignores dupes. """
        if not 'timestamp' in kwargs:
            kwargs['timestamp'] = Now()

        instance = cls(**kwargs)

        try:
            instance.save()
        except IntegrityError:
            return

        instance.comment.details.force()

        @bgwork.defer
        def playback_action():
            Actions.playback(instance.viewer, instance.comment)
Exemple #6
0
def iap_process_receipt(request, receipt_data):
    """
    Verifies the receipt, and processes the purchase.
    """
    #TODO To be safer against botting, the receipt_data uniqueness constraint
    # needs to be done atomically.
    if IapReceipt.objects.filter(receipt_data=receipt_data).exists():
        # Already processed this receipt, fail silently.
        return {'balance': economy.balance(request.user)}

    receipt = IapReceipt.objects.create(
        purchaser=request.user,
        receipt_data=receipt_data,
        timestamp=Now(),
    )

    receipt.verify()

    if receipt.verified:
        deliver_product(request.user, receipt.product_id)

    return {'balance': economy.balance(request.user)}
Exemple #7
0
 def save_model(self, request, obj, form, change):
     obj.moderator = request.user
     obj.timestamp = Now()
     obj.save()