def update_ach_charges(): lock = Lock(key='update-ach-charges-lock') lock.acquire() log = Log() log.it('---Starting batch ach job...') log.it('---Checking for status changes on ACH charges...') three_days_ago = (datetime.now(tz=zone) - timedelta(days=3)).strftime("%Y-%m-%d") today = datetime.now(tz=zone).strftime("%Y-%m-%d") opportunities = Opportunity.list(begin=three_days_ago, end=today, stage_name="ACH Pending") for opportunity in opportunities: if not opportunity.stripe_customer_id: continue amount = amount_to_charge(opportunity) log.it( f"---- ACH Charging ${amount} to {opportunity.stripe_customer_id} ({opportunity.name})" ) try: charge(opportunity) except ChargeException as e: logging.info("ACH batch charge error") e.send_slack_notification() log.send() lock.release()
def charge_cards(): lock = Lock(key="charge-cards-lock") lock.acquire() log = Log() log.it("---Starting batch card job...") three_days_ago = (datetime.now(tz=zone) - timedelta(days=14)).strftime("%Y-%m-%d") today = datetime.now(tz=zone).strftime("%Y-%m-%d") opportunities = Opportunity.list(begin=three_days_ago, end=today) log.it("---Processing charges...") log.it(f"Found {len(opportunities)} opportunities available to process.") for opportunity in opportunities: if not opportunity.stripe_customer_id: continue amount = amount_to_charge(opportunity) log.it( f"---- Charging ${amount} to {opportunity.stripe_customer_id} ({opportunity.name})" ) try: charge(opportunity) except ChargeException as e: logging.info("Batch charge error") e.send_slack_notification() log.send() lock.release()
def charge_cards(): lock = Lock(key="charge-cards-lock") lock.acquire() log = Log() log.it("---Starting batch job...") three_days_ago = (datetime.now(tz=zone) - timedelta(days=3)).strftime("%Y-%m-%d") today = datetime.now(tz=zone).strftime("%Y-%m-%d") opportunities = Opportunity.list(begin=three_days_ago, end=today) log.it("---Processing charges...") log.it(f"Found {len(opportunities)} opportunities available to process.") for opportunity in opportunities: if not opportunity.stripe_customer: continue amount = amount_to_charge(opportunity) log.it( f"---- Charging ${amount} to {opportunity.stripe_customer} ({opportunity.name})" ) charge(opportunity) log.send() lock.release()
def charge_cards(): lock = Lock(key="charge-cards-lock") lock.acquire() log = Log() log.it("---Starting batch job...") three_days_ago = (datetime.now(tz=zone) - timedelta(days=14)).strftime("%Y-%m-%d") today = datetime.now(tz=zone).strftime("%Y-%m-%d") opportunities = Opportunity.list(begin=three_days_ago, end=today) log.it("---Processing charges...") processing_msg = f"Found {len(opportunities)} opportunities available to process." log.it(processing_msg) send_slack_message( { "channel": "#stripe", "text": processing_msg, "icon_emoji": ":moneybag:", } ) for opportunity in opportunities: if not opportunity.stripe_customer: continue amount = amount_to_charge(opportunity) try: entry_name = opportunity.name # replaces non-ascii characters with "?" - See PR #851 encoded_name = entry_name.encode("ascii", "replace") decoded_name = encoded_name.decode("ascii") log.it( f"---- Charging ${amount} to {opportunity.stripe_customer} ({decoded_name})" ) except: log.it( f"---- Charging ${amount} to {opportunity.stripe_customer} ({opportunity.name})" ) logging.warn(f"Could not encode {opportunity.name}") try: charge(opportunity) except ChargeException as e: logging.info("Batch charge error") e.send_slack_notification() except QuarantinedException: logging.info( "Failed to charge because Opportunity %s is quarantined", opportunity ) log.send() lock.release()