def send_daily_transactions_notifications(): gw = BraintreeGateway(settings.MERCHANT_ID, settings.PUBLIC_KEY, settings.PRIVATE_KEY) today = datetime.datetime.today() transactions = gw.get_transactions(today) try: msg = "This a daily transaction summary [%s]\n" % today msg = msg + "====================================================" for key in transactions.iterkeys(): total = 0 t_list = transactions[key] msg += "\n" + "[%s] transactions (with status %s) were found" % (len(t_list), key) + "\n\n" for transaction in t_list: msg += "\t transaction_id : %s\n" % transaction.id msg += "\t type : %s\n" % transaction.type msg += "\t amount : u$s %s\n" % transaction.amount msg += "\t subscription_id : %s\n" % transaction.subscription_id for key in transaction.customer.keys(): val = transaction.customer[key] if val: msg += "\t customer_%s : %s\n" % (key, transaction.customer[key]) total += decimal.Decimal(transaction.amount) msg += "\t - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n" msg += "\nTOTAL : u$s %s\n" % total msg += "===============================================================\n" send_mail('Daily Transaction Statuses', msg, '*****@*****.**', [b for (a,b) in settings.ADMINS], fail_silently=True) logging.debug(msg) except Exception, e: send_mail('Error when trying to get daily transaction statuses', e , '*****@*****.**', [b for (a,b) in settings.ADMINS], fail_silently=True)
def send_daily_transactions_notifications(): gw = BraintreeGateway(settings.MERCHANT_ID, settings.PUBLIC_KEY, settings.PRIVATE_KEY) today = datetime.datetime.today() transactions = gw.get_transactions(today) try: msg = "This a daily transaction summary [%s]\n" % today msg = msg + "====================================================" for key in transactions.iterkeys(): total = 0 t_list = transactions[key] msg += "\n" + "[%s] transactions (with status %s) were found" % ( len(t_list), key) + "\n\n" for transaction in t_list: msg += "\t transaction_id : %s\n" % transaction.id msg += "\t type : %s\n" % transaction.type msg += "\t amount : u$s %s\n" % transaction.amount msg += "\t subscription_id : %s\n" % transaction.subscription_id for key in transaction.customer.keys(): val = transaction.customer[key] if val: msg += "\t customer_%s : %s\n" % ( key, transaction.customer[key]) total += decimal.Decimal(transaction.amount) msg += "\t - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n" msg += "\nTOTAL : u$s %s\n" % total msg += "===============================================================\n" mail = EmailMessage( subject='Daily Transaction Statuses', body=msg, from_email=settings.EMAIL_FROM, to=[mail for (name, mail) in settings.STAFF], headers={ 'X-SMTPAPI': '{\"category\": \"Daily Transaction Statuses\"}' }) mail.send(fail_silently=True) # send_mail('Daily Transaction Statuses', msg, settings.EMAIL_FROM, [mail for (name, mail) in settings.STAFF], fail_silently=True) logging.debug(msg) except Exception, e: mail = EmailMessage( subject='Error when trying to get daily transaction statuses', body=e, from_email=settings.EMAIL_FROM, to=[mail for (name, mail) in settings.STAFF], headers={'X-SMTPAPI': '{\"category\": \"Error\"}'}) mail.send(fail_silently=True)
def get_daily_transactions_data(day): from payments.gateways.braintreegw import BraintreeGateway from django.conf import settings gw = BraintreeGateway(settings.MERCHANT_ID, settings.PUBLIC_KEY, settings.PRIVATE_KEY) params = {} try: transactions = gw.get_transactions(day) params['day'] = day params['columns'] = [ "TransactionID", "Amount", "Website", "Email", "User" ] sections = [] for status in transactions.iterkeys(): section = {} section['type'] = status t_list = transactions[status] section['len'] = len(t_list) section['txs'] = [] total = 0 for transaction in t_list: user_name = "- Unknown -" if transaction.customer_details.first_name is None or transaction.customer_details.last_name is None else "%s, %s" % ( transaction.customer_details.last_name, transaction.customer_details.first_name) tx = [ transaction.id, "u$s %s" % round(decimal.Decimal(transaction.amount), 2), transaction.customer_details.website, transaction.customer_details.email, user_name ] total += decimal.Decimal(transaction.amount) section['txs'].append(tx) section['total'] = total sections.append(section) params['sections'] = sections except Exception, e: logging.info(e)
def send_daily_transactions_notifications(): gw = BraintreeGateway(settings.MERCHANT_ID, settings.PUBLIC_KEY, settings.PRIVATE_KEY) today = datetime.datetime.today() transactions = gw.get_transactions(today) try: msg = "This a daily transaction summary [%s]\n" % today msg = msg + "====================================================" for key in transactions.iterkeys(): total = 0 t_list = transactions[key] msg += "\n" + "[%s] transactions (with status %s) were found" % (len(t_list), key) + "\n\n" for transaction in t_list: msg += "\t transaction_id : %s\n" % transaction.id msg += "\t type : %s\n" % transaction.type msg += "\t amount : u$s %s\n" % transaction.amount msg += "\t subscription_id : %s\n" % transaction.subscription_id for key in transaction.customer.keys(): val = transaction.customer[key] if val: msg += "\t customer_%s : %s\n" % (key, transaction.customer[key]) total += decimal.Decimal(transaction.amount) msg += "\t - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n" msg += "\nTOTAL : u$s %s\n" % total msg += "===============================================================\n" mail = EmailMessage(subject='Daily Transaction Statuses', body=msg, from_email=settings.EMAIL_FROM, to=[mail for (name, mail) in settings.STAFF], headers={'X-SMTPAPI': '{\"category\": \"Daily Transaction Statuses\"}'}) mail.send(fail_silently=True) # send_mail('Daily Transaction Statuses', msg, settings.EMAIL_FROM, [mail for (name, mail) in settings.STAFF], fail_silently=True) logging.debug(msg) except Exception, e: mail = EmailMessage(subject='Error when trying to get daily transaction statuses', body=e, from_email=settings.EMAIL_FROM, to=[mail for (name, mail) in settings.STAFF], headers={'X-SMTPAPI': '{\"category\": \"Error\"}'}) mail.send(fail_silently=True)
def get_daily_transactions_data(day): from payments.gateways.braintreegw import BraintreeGateway from django.conf import settings gw = BraintreeGateway(settings.MERCHANT_ID, settings.PUBLIC_KEY, settings.PRIVATE_KEY) params = {} try: transactions = gw.get_transactions(day) params['day'] = day params['columns'] = ["TransactionID", "Amount", "Website", "Email", "User"] sections = [] for status in transactions.iterkeys(): section = {} section['type'] = status t_list = transactions[status] section['len'] = len(t_list) section['txs'] = [] total = 0 for transaction in t_list: user_name = "- Unknown -" if transaction.customer_details.first_name is None or transaction.customer_details.last_name is None else "%s, %s" % (transaction.customer_details.last_name, transaction.customer_details.first_name) tx = [transaction.id, "u$s %s" % round(decimal.Decimal(transaction.amount), 2), transaction.customer_details.website, transaction.customer_details.email, user_name] total += decimal.Decimal(transaction.amount) section['txs'].append(tx) section['total'] = total sections.append(section) params['sections'] = sections except Exception, e: logging.info(e)