def test_parse_paypal_response(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._parse_paypal_response(paypal_response) self.assertEqual(len(PayPalPDT.objects.all()), 0) self.assertEqual(pdt_obj.txn_id, '1ED550410S3402306')
def test_parse_paypal_response(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._parse_paypal_response(paypal_response) self.assertEqual(len(PayPalPDT.objects.all()), 0) self.assertEqual(pdt_obj.txn_id, '1ED550410S3402306')
def test_verify_postback(self): dpppdt = DummyPayPalPDT() paypal_response = dpppdt._postback().decode("ascii") 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")
def test_verify_postback(self): dpppdt = DummyPayPalPDT() paypal_response = dpppdt._postback().decode("ascii") 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") # Issue #121: Ensure for doesn't blank non-PayPal-supplied fields self.assertEqual(pdt_obj.ipaddress, "127.0.0.1") self.assertEqual(pdt_obj.response, paypal_response)
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)
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)
def pdt(request, item_check_callable=None, template="pdt/pdt.html", context=None): """Payment data transfer implementation: http://tinyurl.com/c9jjmw""" LOGGER.debug(">> Paypal's notification request: method=%s" % request.method) LOGGER.debug("GET=%s" % repr(request.GET)) LOGGER.debug("POST=%s" % repr(request.POST)) context = context or {} pdt_obj = None txn_id = getattr(request, request.method).get('txn_id', None) LOGGER.info("PDT transaction id: %s" % repr(txn_id)) 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: LOGGER.debug("This is a new transaction so we continue processing " "PDT request") if pdt_obj is None: form = PayPalPDTForm(getattr(request, request.method)) if form.is_valid(): try: pdt_obj = form.save(commit=False) pdt_obj.tx = txn_id # backward compatibillity except Exception, e: LOGGER.exception("Exception creating PDT object from " "formulary:") error = repr(e) failed = True else: error = form.errors failed = True if failed: pdt_obj = PayPalPDT() pdt_obj.set_flag("Invalid form. %s" % error) LOGGER.warn("PDT validation has failed: %s" % error) pdt_obj.initialize(request) if not failed: # The PDT object gets saved during verify pdt_obj.verify(item_check_callable) LOGGER.info("PDT validation was successful. Object saved: %s" % pdt_obj)
def process_pdt(request): """ Payment data transfer implementation: https://developer.paypal.com/webapps/developer/docs/classic/products/payment-data-transfer/ This function returns a tuple of (pdt_obj, failed) pdt_obj is an object of type PayPalPDT failed is a flag that is True if the input data didn't pass basic validation. Note: even for failed=False You must still check the pdt_obj is not flagged i.e. pdt_obj.flag == False """ 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 as e: warn_untested() error = repr(e) failed = True else: warn_untested() error = form.errors failed = True if failed: warn_untested() pdt_obj = PayPalPDT() pdt_obj.set_flag(f"Invalid form. {error}") pdt_obj.initialize(request) if not failed: # The PDT object gets saved during verify pdt_obj.verify() else: pass # we ignore any PDT requests that don't have a transaction id return (pdt_obj, failed)
def process_pdt(request, item_check_callable=None, identity_token=None): """ Payment data transfer implementation: http://tinyurl.com/c9jjmw This function returns a tuple of pdt_obj and failed pdt_obj is an object of type PayPalPDT failed is a flag that indeicates whether the transaction was processed successfully """ pdt_obj = None txn_id = request.GET.get('tx') failed = False error = '' if not identity_token: identity_token = settings.PAYPAL_IDENTITY_TOKEN 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) pdt_obj.identity_token = identity_token except Exception as e: logger.exception('Saving pdt_obj') error = repr(e) failed = True else: error = form.errors failed = True if failed: pdt_obj = PayPalPDT(identity_token=identity_token) 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) else: pass # we ignore any PDT requests that don't have a transaction id return pdt_obj, failed
def process_pdt(request, item_check_callable=None): """ Payment data transfer implementation: http://tinyurl.com/c9jjmw This function returns a tuple of (pdt_obj, failed) pdt_obj is an object of type PayPalPDT failed is a flag that is True if the input data didn't pass basic validation. Note: even for failed=False You must still check the pdt_obj is not flagged i.e. pdt_obj.flag == False """ 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 as 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) else: pass # we ignore any PDT requests that don't have a transaction id return (pdt_obj, failed)
def process_pdt(request): """ Payment data transfer implementation: https://developer.paypal.com/webapps/developer/docs/classic/products/payment-data-transfer/ This function returns a tuple of (pdt_obj, failed) pdt_obj is an object of type PayPalPDT failed is a flag that is True if the input data didn't pass basic validation. Note: even for failed=False You must still check the pdt_obj is not flagged i.e. pdt_obj.flag == False """ 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 as e: warn_untested() error = repr(e) failed = True else: warn_untested() error = form.errors failed = True if failed: warn_untested() 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() else: pass # we ignore any PDT requests that don't have a transaction id return (pdt_obj, failed)
def test_verify_postback(self): dpppdt = DummyPayPalPDT() paypal_response = dpppdt._postback().decode('ascii') 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')
def process_pdt(request, item_check_callable=None): """ Payment data transfer implementation: http://tinyurl.com/c9jjmw This function returns a tuple of pdt_obj and failed pdt_obj is an object of type PayPalPDT failed is a flag that indeicates whether the transaction was processed successfully """ pdt_obj = None txn_id = request.REQUEST.get('tx') failed = False if txn_id is '': try: txn_id = None raise ValueError('PayPalPDT txn_id is blank', txn_id) except: pass 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.REQUEST) 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)
def test_verify_postback(self): dpppdt = DummyPayPalPDT() paypal_response = dpppdt._postback().decode('ascii') 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') # Issue #121: Ensure for doesn't blank non-PayPal-supplied fields self.assertEqual(pdt_obj.ipaddress, '127.0.0.1') self.assertEqual(pdt_obj.response, paypal_response)
def process_pdt(request, item_check_callable=None): """ Payment data transfer implementation: http://tinyurl.com/c9jjmw This function returns a tuple of pdt_obj and failed pdt_obj is an object of type PayPalPDT failed is a flag that indeicates whether the transaction was processed successfully """ pdt_obj = None txn_id = request.REQUEST.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.REQUEST) 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)
def aux(request, *args, **kwargs): if request.method == 'POST': return f(request, *args, **kwargs) pdt_obj = None pdt_active = False txn_id = request.GET.get('tx') failed = False if txn_id is not None: pdt_active = True # 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)
def aux(request, *args, **kwargs): pdt_obj = None pdt_active = False txn_id = request.GET.get('tx', None) if txn_id is not None: txn_id = txn_id.strip() if not txn_id: #i.e. empty txn_id txn_id = None failed = False pdt_duplicate = False if txn_id is not None: pdt_active = True # If an existing transaction with the id tx exists: use it try: pdt_obj = PayPalPDT.objects.get(txn_id=txn_id) pdt_duplicate = True 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)
def pdt(request,item_check_callable=None): """ PayPal IPN endpoint (notify_url). Used by both PayPal Payments Pro and Payments Standard to confirm transactions. http://tinyurl.com/d9vu9d PayPal IPN Simulator: https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session """ flag = None ipn_obj = None form = PayPalPaymentsForm(request.POST) if form.is_valid(): try: pdt_obj = form.save(commit=False) except Exception as e: flag = "Exception while processing. (%s)" % e else: flag = "Invalid form. (%s)" % form.errors if ipn_obj is None: ipn_obj = PayPalPDT() ipn_obj.initialize(request) if flag is not None: ipn_obj.set_flag(flag) else: # Secrets should only be used over SSL. if request.is_secure() and 'secret' in request.GET: ipn_obj.verify_secret(form, request.GET['secret']) else: try: ipn_obj.verify(item_check_callable) except Exception as e: flag = "Exception while processing. (%s)" % e ipn_obj.save() return HttpResponse("OKAY")
def setUpClass(cls): cls.pdt = PayPalPDT()