Example #1
0
def paypal_completed(request, post, transaction):
    # Make sure transaction has not yet been processed.
    if Contribution.objects.filter(transaction_id=post['txn_id']).exists():
        paypal_log.info('Completed IPN already processed')
        return http.HttpResponse('Transaction already processed')

    # Note that when this completes the uuid is moved over to transaction_id.
    try:
        original = Contribution.objects.get(uuid=post['txn_id'])
    except Contribution.DoesNotExist:
        return None

    paypal_log.info('Completed IPN received: %s' % post['txn_id'])
    data = StatsDictField().to_python(php.serialize(post))
    update = {'transaction_id': post['txn_id'],
              'uuid': None, 'post_data': data}

    if original.type == amo.CONTRIB_PENDING:
        # This is a purchase that has failed to hit the completed page.
        # But this ok, this IPN means that it all went through.
        update['type'] = amo.CONTRIB_PURCHASE

    if 'mc_gross' in post:
        update['amount'] = post['mc_gross']

    original.update(**update)
    # Send thankyou email.
    try:
        original.mail_thankyou(request)
    except ContributionError as e:
        # A failed thankyou email is not a show stopper, but is good to know.
        paypal_log.error('Thankyou note email failed with error: %s' % e)

    paypal_log.info('Completed successfully processed')
    return http.HttpResponse('Success!')
Example #2
0
def paypal_completed(request, transaction_id, serialize=None, amount=None):
    # Make sure transaction has not yet been processed.
    if Contribution.objects.filter(transaction_id=transaction_id).exists():
        paypal_log.info('Completed IPN already processed')
        return http.HttpResponse('Transaction already processed')

    # Note that when this completes the uuid is moved over to transaction_id.
    try:
        original = Contribution.objects.get(uuid=transaction_id)
    except Contribution.DoesNotExist:
        paypal_log.info('Ignoring transaction: %s' % transaction_id)
        return http.HttpResponse('Transaction not found; skipping.')

    paypal_log.info('Completed IPN received: %s' % transaction_id)
    data = StatsDictField().to_python(php.serialize(serialize))
    update = {
        'transaction_id': transaction_id,
        'uuid': None,
        'post_data': data
    }

    if original.type == amo.CONTRIB_PENDING:
        # This is a purchase that has failed to hit the completed page.
        # But this ok, this IPN means that it all went through.
        update['type'] = amo.CONTRIB_PURCHASE
        # If they failed to hit the completed page, they also failed
        # to get it logged properly. This will add the log in.
        amo.log(amo.LOG.PURCHASE_ADDON, original.addon)

    if amount:
        update['amount'] = _parse_currency(amount)['amount']

    original.update(**update)
    # Send thankyou email.
    try:
        original.mail_thankyou(request)
    except ContributionError as e:
        # A failed thankyou email is not a show stopper, but is good to know.
        paypal_log.error('Thankyou note email failed with error: %s' % e)

    paypal_log_cef(request, original.addon, transaction_id, 'Purchase',
                   'PURCHASE', 'A user purchased or contributed to an addon')
    paypal_log.info('Completed successfully processed')
    return http.HttpResponse('Success!')
Example #3
0
def paypal_completed(request, transaction_id, serialize=None, amount=None):
    # Make sure transaction has not yet been processed.
    if Contribution.objects.filter(transaction_id=transaction_id).exists():
        paypal_log.info('Completed IPN already processed')
        return http.HttpResponse('Transaction already processed')

    # Note that when this completes the uuid is moved over to transaction_id.
    try:
        original = Contribution.objects.get(uuid=transaction_id)
    except Contribution.DoesNotExist:
        paypal_log.info('Ignoring transaction: %s' % transaction_id)
        return http.HttpResponse('Transaction not found; skipping.')

    paypal_log.info('Completed IPN received: %s' % transaction_id)
    data = StatsDictField().to_python(php.serialize(serialize))
    update = {
        'transaction_id': transaction_id,
        'uuid': None,
        'post_data': data
    }

    if amount:
        update['amount'] = _parse_currency(amount)['amount']

    original.update(**update)
    # Send thankyou email.
    try:
        original.mail_thankyou(request)
    except ContributionError as e:
        # A failed thankyou email is not a show stopper, but is good to know.
        paypal_log.error('Thankyou note email failed with error: %s' % e)

    paypal_log_cef(request, original.addon, transaction_id, 'Contribution',
                   'CONTRIBUTION', 'A user contributed to an addon')
    paypal_log.info('Completed successfully processed')
    return http.HttpResponse('Success!')
Example #4
0
 def test_to_python_json(self):
     val = {'a': 1}
     eq_(StatsDictField().to_python(json.dumps(val)), val)
Example #5
0
 def test_to_python_php(self):
     val = {'a': 1}
     eq_(StatsDictField().to_python(php.serialize(val)), val)
Example #6
0
 def test_to_python_dict(self):
     eq_(StatsDictField().to_python({'a': 1}), {'a': 1})
Example #7
0
 def test_to_python_none(self):
     eq_(StatsDictField().to_python(None), None)