def _verify_postback(self): # ### Now we don't really care what result was, just whether a flag was set or not. from paypal.standard.pdt.forms import PayPalPDTForm response_list = self.response.split('\n') response_dict = {} for i, line in enumerate(response_list): unquoted_line = unquote_plus(line).strip() if i == 0: self.st = unquoted_line else: if self.st != "SUCCESS": self.set_flag(line) break try: if not unquoted_line.startswith(' -'): k, v = unquoted_line.split('=') response_dict[k.strip()] = v.strip() except ValueError: pass qd = QueryDict('', mutable=True) qd.update(response_dict) qd.update( dict(ipaddress=self.ipaddress, st=self.st, flag_info=self.flag_info, flag=self.flag, flag_code=self.flag_code)) pdt_form = PayPalPDTForm(qd, instance=self) pdt_form.save(commit=False)
def _verify_postback(self): # ### Now we don't really care what result was, just whether a flag was set or not. from paypal.standard.pdt.forms import PayPalPDTForm response_list = self.response.split('\n') response_dict = {} for i, line in enumerate(response_list): unquoted_line = unquote_plus(line).strip() if i == 0: self.st = unquoted_line else: if self.st != "SUCCESS": self.set_flag(line) break try: if not unquoted_line.startswith(' -'): k, v = unquoted_line.split('=') response_dict[k.strip()] = v.strip() except ValueError: pass qd = QueryDict('', mutable=True) qd.update(response_dict) qd.update(dict(ipaddress=self.ipaddress, st=self.st, flag_info=self.flag_info, flag=self.flag, flag_code=self.flag_code)) pdt_form = PayPalPDTForm(qd, instance=self) pdt_form.save(commit=False)
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 _verify_postback(self): # ### Now we don't really care what result was, just whether a flag was set or not. from paypal.standard.pdt.forms import PayPalPDTForm result = False response_list = self.response.split('\n') response_dict = {} for i, line in enumerate(response_list): unquoted_line = unquote_plus(line).strip() if i == 0: self.st = unquoted_line if self.st == "SUCCESS": result = True else: if self.st != "SUCCESS": self.set_flag(line) break try: if not unquoted_line.startswith(' -'): k, v = unquoted_line.split('=') response_dict[k.strip()] = v.strip() except ValueError: pass # Bug 4692 - response is aleady decoded above # - this does not appear to be required any more # # ensure that we decode the strings as per the encoding passed in via the # charset parameter # try: # charset = response_dict['charset'] # for key, value in response_dict.items(): # response_dict[key] = value.decode(charset) # except (KeyError, LookupError): # pass if response_dict: qd = QueryDict('', mutable=True) qd.update(response_dict) qd.update(dict(ipaddress=self.ipaddress, st=self.st, flag_info=self.flag_info, flag=self.flag, flag_code=self.flag_code, query=self.query)) pdt_form = PayPalPDTForm(qd, instance=self) pdt_form.save(commit=False)
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): """ 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 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 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 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 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 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)