Exemple #1
0
 def test_verify_postback(self):
     dpppdt = DummyPayPalPDT()
     paypal_response = dpppdt._postback()
     assert('SUCCESS' in paypal_response)
     self.assertEqual(len(PayPalPDT.objects.all()), 0)
     pdt_obj = PayPalPDT()
     pdt_obj.ipaddress = '127.0.0.1'
     pdt_obj.response = paypal_response
     pdt_obj._verify_postback()
     self.assertEqual(len(PayPalPDT.objects.all()), 0)
     self.assertEqual(pdt_obj.txn_id, '1ED550410S3402306')
Exemple #2
0
def pdt(request, item_check_callable=None, template="pdt/pdt.html", context=None):
    """Payment data transfer implementation: http://tinyurl.com/c9jjmw"""
    context = context or {}
    pdt_obj = None
    txn_id = request.GET.get('tx')
    failed = False
    if txn_id is not None:
        # If an existing transaction with the id tx exists: use it
        try:
            pdt_obj = PayPalPDT.objects.get(txn_id=txn_id)
        except PayPalPDT.DoesNotExist:
            # This is a new transaction so we continue processing PDT request
            pass
        
        if pdt_obj is None:
            form = PayPalPDTForm(request.GET)
            if form.is_valid():
                try:
                    pdt_obj = form.save(commit=False)
                except Exception, e:
                    error = repr(e)
                    failed = True
            else:
                error = form.errors
                failed = True
            
            if failed:
                pdt_obj = PayPalPDT()
                pdt_obj.set_flag("Invalid form. %s" % error)
            
            pdt_obj.initialize(request)
        
            if not failed:
                # The PDT object gets saved during verify
                pdt_obj.verify(item_check_callable)
Exemple #3
0
 def test_verify_postback(self):
     dpppdt = DummyPayPalPDT()
     paypal_response = dpppdt._postback()
     assert ('SUCCESS' in paypal_response)
     self.assertEqual(len(PayPalPDT.objects.all()), 0)
     pdt_obj = PayPalPDT()
     pdt_obj.ipaddress = '127.0.0.1'
     pdt_obj.response = paypal_response
     pdt_obj._verify_postback()
     self.assertEqual(len(PayPalPDT.objects.all()), 0)
     self.assertEqual(pdt_obj.txn_id, '1ED550410S3402306')
Exemple #4
0
def pdt(request,
        item_check_callable=None,
        template="pdt/pdt.html",
        context=None):
    """Payment data transfer implementation: http://tinyurl.com/c9jjmw"""
    context = context or {}
    pdt_obj = None
    txn_id = request.GET.get('tx')
    failed = False
    if txn_id is not None:
        # If an existing transaction with the id tx exists: use it
        try:
            pdt_obj = PayPalPDT.objects.get(txn_id=txn_id)
        except PayPalPDT.DoesNotExist:
            # This is a new transaction so we continue processing PDT request
            pass

        if pdt_obj is None:
            form = PayPalPDTForm(request.GET)
            if form.is_valid():
                try:
                    pdt_obj = form.save(commit=False)
                except Exception, e:
                    error = repr(e)
                    failed = True
            else:
                error = form.errors
                failed = True

            if failed:
                pdt_obj = PayPalPDT()
                pdt_obj.set_flag("Invalid form. %s" % error)

            pdt_obj.initialize(request)

            if not failed:
                # The PDT object gets saved during verify
                pdt_obj.verify(item_check_callable)