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()
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 #3
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 #4
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)}