def asset_compare(asset_base_record): # signup differences = {} try: purchaseid = asset_base_record['PurchaseID'] asset_live_record = db_agent.asset_full_record(purchaseid)[0] asset_live_record['PCID'] = None differences = bep.dictionary_compare(asset_base_record, asset_live_record) if len(differences) == 0: print(colored(f"Asset Record Compared => Pass ", 'green')) options.append_list("Asset Record Compared => Pass ") else: print( colored( f"********************* Asset MissMatch ****************", 'red')) for k, v in differences.items(): tmp = k + " " + v options.append_list(tmp) print(k, v) except Exception as ex: traceback.print_exc() print(f"{Exception}") pass return differences
def multitrans_compare(multitrans_base_record, live_record): differences = {} try: multitrans_live_record = live_record # [0] live_record['PCID'] = None multitrans_live_record['TransDate'] = multitrans_live_record[ 'TransDate'].date() differences = bep.dictionary_compare(multitrans_base_record, multitrans_live_record) if len(differences) == 0: print(colored(f"Mulitrans Record Compared => Pass", 'green')) options.append_list("Mulitrans Record Compared => Pass") else: print( colored( f"********************* Multitrans MissMatch ****************", 'red')) options.append_list( "********************* Multitrans MissMatch ****************") for k, v in differences.items(): tmp = k + " " + v options.append_list(tmp) print(k, v) # config.logging.info(k,v) except Exception as ex: traceback.print_exc() print(f"Exception {Exception} ") # config.logging.info(f"Exception {Exception} ") pass return differences
def assets_check_reactivation(): reactivated = config.asset_reactivated rkeys = reactivated.keys() reactivation_completed = [] reactivation_completed_failed = [] current_date = (datetime.now().date()) sql = "Select * from Assets where PurchaseID = {}" for pid in rkeys: try: differences = {} time.sleep(1) live_record = db_agent.execute_select_one_parameter(sql, pid) base_record = reactivated[pid][pid] base_record['CustName'] = config.test_data[ 'firstname'] + ' ' + config.test_data['lastname'] base_record['PurchStatus'] = 801 task_type = config.tasks_type[pid] if task_type == 841: base_record['ConvDate'] = current_date base_record['LastDate'] = current_date base_record['NextDate'] = current_date + timedelta( days=base_record['PurchPeriod']) base_record['ExpiredDate'] = current_date + timedelta( days=base_record['PurchPeriod']) base_record['Purchases'] = base_record['Purchases'] + 1 base_record['PurchTotal'] = base_record[ 'PurchTotal'] + base_record['RecurringAmount'] base_record['CustZip'] = config.test_data['zip'] card_encrypted = db_agent.encrypt_card( int(config.test_data['cc'])) base_record['PaymentAcct'] = card_encrypted base_record['CardExpiration'] = config.test_data[ 'month'] + config.test_data['year'][-2:] base_record['CancelDate'] = None base_record['Retries'] = 0 base_record['LastResult'] = 'Reactivated' # base_record['CardExpiration'] = live_record['CardExpiration'] if len(base_record['CardExpiration']) < 4: print("Check Card Expiration - assets | Something is wrong") differences = bep.dictionary_compare(base_record, live_record) if len(differences) == 0: reactivation_completed.append(live_record) else: reactivation_completed_failed.append(live_record) print( colored( f"********************* Reactivation Asset MissMatch Beginning****************", 'red')) print(f"PurchaseID = {pid}") for k, v in differences.items(): print(k, v) print() except Exception as ex: print(f"{Exception} PID: {pid} ") traceback.print_exc() pass if len(reactivation_completed_failed) == 0: print( colored( f"Reactivation {len(reactivation_completed)} records reactivated => Assets Records Compared => Pass ", 'green')) else: if len(reactivation_completed) > 0: print( colored( f"Reactivation {len(reactivation_completed)} records => Assets Records Compared => Pass ", 'green')) print( colored( f"Warning ************* Reactivation {len(reactivation_completed_failed)} records => Asset MissMatch => Check Manually ****************", 'blue')) return [reactivation_completed, reactivation_completed_failed]
def asseets_check_refunds(): refunds = config.refunds[0] rkeys = refunds.keys() rebills_completed = [] rebills_failed = [] sql = "Select * from Assets where PurchaseID = {}" for pid in rkeys: try: differences = {} base_record = refunds[pid] tasks_type = config.tasks_type[pid] # refunds[pid]['tasktype'] # del refunds[pid]['tasktype'] if refunds[pid]['PurchType'] in [501, 505, 506, 511]: if tasks_type == 842 or tasks_type == 844: base_record['PurchStatus'] = 802 else: base_record['PurchStatus'] = 803 base_record['ExpiredDate'] = (datetime.now().date()) base_record['ModBy'] = 'automation' else: base_record['PurchStatus'] = 804 base_record['ModBy'] = 'SIGNUP' base_record['CancelDate'] = (datetime.now().date()) live_record = db_agent.execute_select_one_parameter(sql, pid) differences = bep.dictionary_compare(base_record, live_record) if len(differences) == 0: rebills_completed.append(live_record) else: rebills_failed.append(live_record) print( colored( f"********************* Refunds Asset MissMatch Beginning****************", 'red')) print(f"PurchaseID = {pid}") for k, v in differences.items(): print(k, v) print( colored( f"********************* Refunds Asset MissMatch End ****************", 'red')) except Exception as ex: traceback.print_exc() print( f"Exception {Exception} Module : assets.asseets_check_refunds(refunds) " ) pass if len(rebills_failed) == 0: print( colored( f"Refunds => Assets {len(rebills_completed)} Records Compared => Pass ", 'green')) else: print( colored( f"Refunds {len(rebills_completed)} records => Assets Records Compared => Pass ", 'green')) print( colored( f"Warning ************* Refunds {len(rebills_failed)} records => Asset MissMatch => CHeck Manually ****************", 'blue')) return [rebills_completed, rebills_failed]
def asseets_check_rebills(rebills): rkeys = rebills.keys() rebills_completed = [] rebills_failed = [] sql = "Select * from Assets where PurchaseID = {}" print("Checking asset after rebill") for pid in rkeys: differences = {} base_record = rebills[pid] base_record['Purchases'] = base_record['Purchases'] + 1 base_record['PurchTotal'] = base_record['PurchTotal'] + base_record[ 'RecurringAmount'] base_record['ConvDate'] = (datetime.now().date()) base_record['LastDate'] = (datetime.now().date()) date_fromat = base_record['NextDate'] + timedelta( days=base_record['PurchPeriod']) base_record['NextDate'] = datetime.date(date_fromat) base_record['ExpiredDate'] = datetime.date(date_fromat) base_record['LastResult'] = 'OK:0' base_record['Retries'] = 0 base_record['ModBy'] = 'Rebiller' live_record = db_agent.execute_select_one_parameter(sql, pid) # live_record['ConvDate'] = (datetime.now().date()) # live_record['LastDate'] = (datetime.now().date()) # tmp = live_record['NextDate'] # live_record['NextDate'] = datetime.date(tmp) # (datetime.now().date()) #datetime.date(date_fromat) # live_record['ExpiredDate'] = datetime.date(tmp)# datetime.date(date_fromat) differences = bep.dictionary_compare(base_record, live_record) if len(differences) == 0: rebills_completed.append(live_record) else: rebills_failed.append(live_record) print( colored( f"********************* Rebill Asset MissMatch Beginning****************", 'red')) print(f"PurchaseID = {pid}") for k, v in differences.items(): print(k, v) print( colored( f"********************* Rebill Asset MissMatch End ****************", 'red')) if len(rebills_failed) == 0: print( colored( f"Rebills {len(rebills_completed)} records => Assets Records Compared => Pass ", 'green')) else: print( colored( f"Rebills {len(rebills_completed)} records => Assets Records Compared => Pass ", 'green')) print( colored( f"Warning ************* Rebills {len(rebills_failed)} records => Asset MissMatch => CHeck Manually ****************", 'blue')) return [rebills_completed, rebills_failed]
def mt_check_reactivation(): reactivated = config.mt_reactivated rkeys = reactivated.keys() cnt = 0 tasks_type_status = [] reactivated_completed_mt = [] base_record = {} sql = '' pid = 0 reactivated_failed_mt = [] for tid in rkeys: try: differences = {} base_record = reactivated[tid][tid] pid = base_record['PurchaseID'] tasks_type_status = db_agent.tasks_table(tid) sql = "Select RecurringAmount, CardExpiration,PurchStatus from assets where PurchaseID = {}" asset_data = db_agent.execute_select_one_parameter(sql, pid) live_record = None if tasks_type_status[0] == 841: while live_record == None and cnt < 5: cnt += 1 sql = "Select * from multitrans where PurchaseID = {} and TransSource = 127" live_record = db_agent.execute_select_one_parameter( sql, pid) time.sleep(1) if live_record == None: print( f"******* Warning => transaction with PurchaseID: {pid} is reactivated but there is no MultiTrans record for it!! *******" ) raise Exception('norecord') # refactor after fixes for address live_record['CustAddress'] = 'N/A' live_record['CustCity'] = 'N/A' base_record['TransSource'] = 127 base_record['TransType'] = 101 base_record['TransAmount'] = asset_data['RecurringAmount'] base_record['CustZip'] = config.test_data['zip'] card_encrypted = db_agent.encrypt_card( int(config.test_data['cc'])) base_record['PaymentAcct'] = card_encrypted base_record['CardExpiration'] = config.test_data[ 'month'] + config.test_data['year'][-2:] base_record['CustName'] = live_record['CustName'] base_record['RelatedTransID'] = 0 base_record['Markup'] = round( (base_record['TransAmount'] * base_record['ExchRate']), 2) exchange_rate = 1 if base_record['ProcessorCurrency'] == base_record[ 'MerchantCurrency']: exchange_rate = 1 else: exchange_rate = db_agent.exc_rate( base_record['MerchantCurrency'], base_record['ProcessorCurrency']) if base_record['MerchantCurrency'] == 'JPY': excr = round((base_record['TransAmount'] * exchange_rate), 2) excr = round((excr)) excr = str(excr) + '.00' excr = Decimal(excr) base_record['Markup'] = excr else: base_record['Markup'] = round( (base_record['TransAmount'] * exchange_rate), 2) base_record['TransStatus'] = 186 base_record['TransID'] = live_record['TransID'] for record in [base_record, live_record]: record['TRANSGUID'] = '' record['ProcessorTransID'] = None record['PCID'] = None record['SOURCEMACHINE'] = None record['USERDATA'] = None # record['IPCountry'] = None # record['BinCountry'] = None record['RefURL'] = None record['AffiliateID'] = None # make sure they need it or not record['REF1'] = None record['REF2'] = None record['REF3'] = None record['REF4'] = None record['REF5'] = None record['REF6'] = None record['REF7'] = None record['REF8'] = None record['REF9'] = None record['REF10'] = None differences = bep.dictionary_compare(base_record, live_record) if len(differences) == 0: reactivated_completed_mt.append(live_record) else: reactivated_failed_mt.append(live_record) print( colored( f"********************* Reactivation Multitrans MissMatch Beginning**************** | PurchaseID = {pid} | TransID: {tid}", 'red')) print() for k, v in differences.items(): print(k, v) print() print() except Exception as ex: traceback.print_exc() print( f"{Exception} Tid: {tid,} Task: {tasks_type_status[0]} , {tasks_type_status[1]} SQL: {sql} BaseRecord: {base_record}" ) pass if len(reactivated_failed_mt) == 0: print( colored( f"Reactivation {len(reactivated_completed_mt)} records reactivated - Multitrans Records Compared => Pass ", 'green')) else: if len(reactivated_completed_mt) > 0: print( colored( f"Reactivation {len(reactivated_completed_mt)} records reactivated - Multitrans Records Compared => Pass ", 'green')) print() print( colored( f"******************** Reactivation {len(reactivated_failed_mt)} transactions => Multitrans MissMatch => Check Manually ***************", 'blue')) return [reactivated_completed_mt, reactivated_failed_mt]
def multitrans_check_refunds(): refunds = config.results[1] rkeys = refunds.keys() live_record = {} tasks_type_status = [] refunds_completed_mt = [] base_record = {} sql = '' pid = 0 refunds_failed_mt = [] for tid in rkeys: try: differences = {} base_record = refunds[tid] pid = base_record['PurchaseID'] tasks_type_status = db_agent.tasks_table(tid) sql = '' if tasks_type_status[0] == '': print(f"Task was not inserted TID: {tid} PID: #{pid}") elif tasks_type_status[0] == 844: print( f"Task - 844 Cancel => Nothing to refund => PID: {pid} | TID: {tid}" ) refunds_failed_mt.append(live_record) else: if base_record['TransStatus'] == 184: # Void base_record['TransType'] = 107 base_record['TxStatus'] = 8 base_record['TransStatus'] = 182 sql = "Select * from multitrans where PurchaseID = {} and TransType = 107 and RelatedTransID = {}" else: # Refund sql = "Select * from multitrans where PurchaseID = {} and TransType = 102 and RelatedTransID = {}" base_record['TransType'] = 102 base_record['TxStatus'] = 7 base_record['TransStatus'] = 186 live_record = db_agent.execute_select_two_parameters( sql, pid, base_record['TransID']) # live_record['TransTime'] = datetime.date(live_record['TransTime']) base_record['TransAmount'] = (-base_record['TransAmount']) base_record['Markup'] = (-base_record['Markup']) base_record['TransSource'] = 125 base_record['RelatedTransID'] = base_record['TransID'] base_record['TransID'] = live_record['TransID'] # base_record['TransTime'] = datetime.date(base_record['TransTime']) for record in [base_record, live_record]: record['TRANSGUID'] = '' record['ProcessorTransID'] = None record['PCID'] = None record['SOURCEMACHINE'] = None record['IPCountry'] = None record['BinCountry'] = None record['RefURL'] = None record['AffiliateID'] = None differences = bep.dictionary_compare(base_record, live_record) if len(differences) == 0: refunds_completed_mt.append(live_record) else: refunds_failed_mt.append(live_record) print( colored( f"********************* Refunds Multitrans MissMatch Beginning**************** | PurchaseID = {pid} | TransID: {tid}", 'red')) print() for k, v in differences.items(): print(k, v) print() print( colored( f"******************** Refund Multitrans MissMatch End ***************", 'red')) except Exception as ex: traceback.print_exc() print( f"{Exception} Tid: {tid,} Task: {tasks_type_status[0]} , {tasks_type_status[1]} SQL: {sql} BaseRecord: {base_record}" ) pass if len(refunds_failed_mt) == 0: print( colored( f"Refund => Multitrans {len(refunds_completed_mt)} - Records Compared => Pass ", 'green')) else: print( colored( f"Refund => Multitrans {len(refunds_completed_mt)} - Records Compared => Pass ", 'green')) print() print( colored( f"******************** Refund {len(refunds_failed_mt)} transactions => Multitrans MissMatch => Check Manually ***************", 'blue')) return config.results # [refunds_completed_mt, refunds_failed_mt]
def multitrans_check_conversion(rebills): rkeys = rebills.keys() rebills_completed_mt = [] rebills_failed_mt = [] try: for tid in rkeys: differences = {} pid = rebills[tid]['PurchaseID'] base_record = rebills[tid] base_record['TxStatus'] = 6 base_record['TransStatus'] = 186 base_record['TransSource'] = 122 sql = "Select RecurringAmount from Assets where PurchaseID = {}" rebill_amount = db_agent.execute_select_one_parameter(sql, pid) base_record['TransAmount'] = rebill_amount['RecurringAmount'] base_record['ProcessorTransID'] = '' base_record['TransID'] = 0 base_record['SOURCEMACHINE'] = '' base_record['TransDate'] = datetime.date(base_record['TransDate']) base_record['TransTime'] = datetime.date(base_record['TransTime']) base_record['PCID'] = None base_record['TRANSGUID'] = '' base_record['IPCountry'] = 'N/A' base_record['BinCountry'] = 'N/A' base_record['AffiliateID'] = None base_record['RefURL'] = None sql = "select TOP 1 Rate from ExchangeRates as rate where ConsumerIso = '{}' " \ "and MerchantIso = '{}' order by importdatetime desc" exchange_rate = db_agent.execute_select_two_parameters( sql, base_record['MerchantCurrency'], base_record['ProcessorCurrency']) if base_record['MerchantCurrency'] == 'JPY': excr = round( (base_record['TransAmount'] * exchange_rate['Rate']), 2) excr = round((excr)) excr = str(excr) + '.00' excr = Decimal(excr) base_record['Markup'] = excr else: base_record['Markup'] = round( (base_record['TransAmount'] * exchange_rate['Rate']), 2) sql = "Select * from multitrans where PurchaseID = {} and TransSource = 122" live_record = db_agent.execute_select_one_parameter(sql, pid) if base_record['TransType'] == 1011: base_record['TransType'] = 101 base_record['RelatedTransID'] = 0 live_record['ProcessorTransID'] = '' tid = live_record['TransID'] live_record['TransID'] = 0 live_record['SOURCEMACHINE'] = '' live_record['TransDate'] = datetime.date(live_record['TransDate']) live_record['TransTime'] = datetime.date(live_record['TransTime']) live_record['TRANSGUID'] = '' live_record['RefURL'] = None differences = bep.dictionary_compare(base_record, live_record) if len(differences) == 0: rebills_completed_mt.append(live_record) else: rebills_failed_mt.append(live_record) print( colored( f"********************* Conversion Multitrans MissMatch Beginning**************** | PurchaseID = {pid} | TransID: {tid}", 'red')) print() for k, v in differences.items(): print(k, v) print() print( colored( f"********************* Conversion Multitrans MissMatch End ****************", 'red')) except Exception as ex: traceback.print_exc() # (f"{Exception} Tid: {tid,} Task: {tasks_type_status[0]} , {tasks_type_status[1]} SQL: {sql} BaseRecord: {base_record}") pass if len(rebills_failed_mt) == 0: print( colored(f"Rebills => Multitrans Records Compared => Pass ", 'green')) else: print( colored( f"********************* Rebills => Multitrans MissMatch => CHeck Manually ****************", 'blue')) return [rebills_completed_mt, rebills_failed_mt]