class Civicrm(object): def __init__(self, config): self.db = Connection(**dict(config)) self.config = config def transaction_exists(self, gateway_txn_id, gateway="paypal"): sql = """ SELECT COUNT(*) AS count FROM wmf_contribution_extra WHERE gateway = %s AND gateway_txn_id = %s """ count = list(self.db.execute(sql, (gateway, gateway_txn_id))) return count[0]['count'] > 0 def transaction_refunded(self, gateway_txn_id, gateway="paypal"): sql = """ SELECT contribution_status_id AS status FROM wmf_contribution_extra x INNER JOIN civicrm_contribution c on x.entity_id = c.id WHERE gateway = %s AND gateway_txn_id = %s LIMIT 1 """ status = list(self.db.execute(sql, (gateway, gateway_txn_id))) return len(status) == 1 and status[0]['status'] == 9 def subscription_exists(self, subscr_id): # FIXME: trxn_id style is inconsistent between gateways. This will only work for paypal. sql = """ SELECT COUNT(*) AS count FROM civicrm_contribution_recur WHERE trxn_id = %s """ count = list(self.db.execute(sql, (subscr_id, ))) return count[0]['count'] > 0
def main(): global config, options, db parser = OptionParser(usage="usage: %prog [options]") parser.add_option("-c", "--config", dest='configFile', default=["globalcollect-audit.cfg"], action='append', help='Path to configuration file') parser.add_option("-f", "--auditFile", dest='auditFile', default=None, help='CSV of transaction history') parser.add_option( '-l', "--logFile", dest='logFile', default="audit.log", help='Destination logfile. New messages will be appended.') (options, args) = parser.parse_args() path = options.auditFile infile = csv.DictReader(open(path, "rU"), delimiter=";") config = SafeConfigParser() config.read(options.configFile) db = DbConnection(**config._sections['mysql']) for line in infile: # TODO parse and filter on status ids #if line["Status Description"] is not "COLLECTED": normalized = { 'transaction_id': line["Order ID"], 'currency': line["Order Currency Code"], 'amount': line["Order Amount"], 'received': line["Received Date"], # GC has multiple time formats... 'time_format': "%Y-%m-%d %H:%i", #'time_format': "%c/%e/%y %k:%i", } sql = """ INSERT IGNORE INTO test.scratch_transactions SET transaction_id = %(transaction_id)s, currency = %(currency)s, amount = %(amount)s, received = STR_TO_DATE( %(received)s, %(time_format)s ), in_gateway = 1 """ db.execute(sql, normalized) db.close()
def main(): global config, options, db parser = OptionParser(usage="usage: %prog [options]") parser.add_option("-c", "--config", dest='configFile', default=[ "globalcollect-audit.cfg" ], action='append', help='Path to configuration file') parser.add_option("-f", "--auditFile", dest='auditFile', default=None, help='CSV of transaction history') parser.add_option('-l', "--logFile", dest='logFile', default="audit.log", help='Destination logfile. New messages will be appended.') (options, args) = parser.parse_args() path = options.auditFile infile = csv.DictReader(open(path, "rU"), delimiter=";") config = SafeConfigParser() config.read(options.configFile) db = DbConnection(**config._sections['mysql']) for line in infile: # TODO parse and filter on status ids #if line["Status Description"] is not "COLLECTED": normalized = { 'transaction_id': line["Order ID"], 'currency': line["Order Currency Code"], 'amount': line["Order Amount"], 'received': line["Received Date"], # GC has multiple time formats... 'time_format': "%Y-%m-%d %H:%i", #'time_format': "%c/%e/%y %k:%i", } sql = """ INSERT IGNORE INTO test.scratch_transactions SET transaction_id = %(transaction_id)s, currency = %(currency)s, amount = %(amount)s, received = STR_TO_DATE( %(received)s, %(time_format)s ), in_gateway = 1 """ db.execute(sql, normalized) db.close()
class Civicrm(object): def __init__(self, config): self.db = Connection(**dict(config)) self.config = config def transaction_exists(self, gateway_txn_id, gateway="paypal"): sql = """ SELECT COUNT(*) AS count FROM wmf_contribution_extra WHERE gateway = %s AND gateway_txn_id = %s """ count = list(self.db.execute(sql, (gateway, gateway_txn_id))) return count[0]['count'] > 0 def subscription_exists(self, subscr_id): # FIXME: trxn_id style is inconsistent between gateways. This will only work for paypal. sql = """ SELECT COUNT(*) AS count FROM civicrm_contribution_recur WHERE trxn_id = %s """ count = list(self.db.execute(sql, (subscr_id, ))) return count[0]['count'] > 0
def __init__(self, config): self.db = Connection(**dict(config)) self.config = config