def auth_campaign(link, campaign, user, pay_id=None, freebie=False): """ Authorizes (but doesn't charge) a budget with authorize.net. Args: - link: promoted link - campaign: campaign to be authorized - user: Account obj of the user doing the auth (usually the currently logged in user) - pay_id: customer payment profile id to use for this transaction. (One user can have more than one payment profile if, for instance, they have more than one credit card on file.) Set pay_id to -1 for freebies. Returns: (True, "") if successful or (False, error_msg) if not. """ void_campaign(link, campaign, reason='changed_payment') if freebie: trans_id, reason = authorize.auth_freebie_transaction( campaign.total_budget_dollars, user, link, campaign._id) else: trans_id, reason = authorize.auth_transaction( campaign.total_budget_dollars, user, pay_id, link, campaign._id) if trans_id and not reason: text = ('updated payment and/or budget for campaign %s: ' 'SUCCESS (trans_id: %d, amt: %0.2f)' % (campaign._id, trans_id, campaign.total_budget_dollars)) PromotionLog.add(link, text) if trans_id < 0: PromotionLog.add(link, 'FREEBIE (campaign: %s)' % campaign._id) if trans_id: if is_finished(link): # When a finished promo gets a new paid campaign it doesn't # need to go through approval again and is marked accepted new_status = PROMOTE_STATUS.accepted else: new_status = max(PROMOTE_STATUS.unseen, link.promote_status) else: new_status = max(PROMOTE_STATUS.unpaid, link.promote_status) update_promote_status(link, new_status) if user and (user._id == link.author_id) and trans_id > 0: emailer.promo_total_budget(link, campaign.total_budget_dollars, campaign.start_date) else: text = ("updated payment and/or budget for campaign %s: FAILED ('%s')" % (campaign._id, reason)) PromotionLog.add(link, text) trans_id = 0 campaign.trans_id = trans_id campaign._commit() return bool(trans_id), reason
def auth_campaign(link, campaign, user, pay_id=None, freebie=False): """ Authorizes (but doesn't charge) a budget with authorize.net. Args: - link: promoted link - campaign: campaign to be authorized - user: Account obj of the user doing the auth (usually the currently logged in user) - pay_id: customer payment profile id to use for this transaction. (One user can have more than one payment profile if, for instance, they have more than one credit card on file.) Set pay_id to -1 for freebies. Returns: (True, "") if successful or (False, error_msg) if not. """ void_campaign(link, campaign, reason='changed_payment') if freebie: trans_id, reason = authorize.auth_freebie_transaction( campaign.total_budget_dollars, user, link, campaign._id) else: trans_id, reason = authorize.auth_transaction( campaign.total_budget_dollars, user, pay_id, link, campaign._id) if trans_id and not reason: text = ('updated payment and/or budget for campaign %s: ' 'SUCCESS (trans_id: %d, amt: %0.2f)' % (campaign._id, trans_id, campaign.total_budget_dollars)) PromotionLog.add(link, text) if trans_id < 0: PromotionLog.add(link, 'FREEBIE (campaign: %s)' % campaign._id) if trans_id: if is_finished(link): # When a finished promo gets a new paid campaign it doesn't # need to go through approval again and is marked accepted new_status = PROMOTE_STATUS.accepted else: new_status = max(PROMOTE_STATUS.unseen, link.promote_status) else: new_status = max(PROMOTE_STATUS.unpaid, link.promote_status) update_promote_status(link, new_status) if user and (user._id == link.author_id) and trans_id > 0: emailer.promo_total_budget(link, campaign.total_budget_dollars, campaign.start_date) else: text = ( "updated payment and/or budget for campaign %s: FAILED ('%s')" % (campaign._id, reason)) PromotionLog.add(link, text) trans_id = 0 campaign.trans_id = trans_id campaign._commit() return bool(trans_id), reason