code: def duplicate_txn_id(ipn_obj):
      
  
      # get latest similar transaction(s)
      similars = (ipn_obj.__class__._default_manager
                  .filter(txn_id=ipn_obj.txn_id)
                  .exclude(id=ipn_obj.id)
                  .exclude(flag=True)
                  .order_by('-created_at')[:1])
  
      if len(similars) > 0:
          # we have a similar transaction, has the payment_status changed?
          return similars[0].payment_status == ipn_obj.payment_status
  
      return False
docs: Returns True if a record with this transaction id exists and its
      payment_status has not changed.
      This function has been completely changed from its previous implementation
      where it used to specifically only check for a Pending->Completed
      transition.